
Subset a List With Prediction Results
get_prediction_subset.RdThis function subsets the data frames and named vectors in a list based on a set of sample IDs.
Usage
get_prediction_subset(
these_predictions = NULL,
these_sample_ids = NULL,
these_samples_metadata = NULL,
samples_rownames = FALSE
)Arguments
- these_predictions
Output from
classify_samplesfunction run withinclude_data = TRUE.- these_sample_ids
A vector of sample IDs to subset the data. If NULL, sample IDs will be extracted from
these_samples_metadata.- these_samples_metadata
A data frame containing sample metadata. If provided and
these_sample_idsis NULL, sample IDs will be extracted from this data frame.- samples_rownames
A logical value indicating whether the sample IDs are stored in the row names of
these_samples_metadata. Default is TRUE.
Details
This function is designed to subset various components of a predictions list based on a
set of sample IDs. If these_sample_ids is not provided, the function will attempt to extract
sample IDs from these_samples_metadata. The function handles different structures within the
list, including data frames and named vectors, ensuring that only the specified samples are
retained. Note, this function expects that classify_samples has been run with include_data = TRUE,
if not the data component will be missing.
Examples
sjodahl_classes = classify_samples(this_data = sjodahl_2017,
log_transform = FALSE,
adjust = TRUE,
impute = TRUE,
include_data = TRUE,
verbose = FALSE)
#get some sample subsets
my_samples = head(sjodahl_2017_meta$sample_id)
my_meta = head(sjodahl_2017_meta)
#use sample IDs
data_subset <- get_prediction_subset(these_predictions = sjodahl_classes,
these_sample_ids = my_samples)
#> Sample IDs detected...
#use a metadata subset
data_subset <- get_prediction_subset(these_predictions = sjodahl_classes,
these_samples_metadata = my_meta,
samples_rownames = FALSE)
#> Metadata provided, the function will subset to the sample IDs in this object...
#> CAUTION: sample_rownames = FALSE, the funciton expects a column in the metadata called `sample_id`
#view data
head(data_subset$data)
#> 1.CEL 2.CEL 3.CEL 4.CEL 5.CEL 6.CEL
#> A1CF 4.248274 4.153923 4.186689 4.877813 4.106269 5.278318
#> A2M 8.348800 7.969504 10.755738 8.467495 8.979222 9.520587
#> A2ML1 6.694896 4.442973 8.871067 4.392010 7.685045 4.493648
#> A4GALT 7.255671 6.337239 6.925670 6.239185 6.032115 6.539985
#> A4GNT 3.740418 3.830598 3.999331 3.813662 3.718752 3.567144
#> AAAS 6.837006 7.525639 6.778506 6.658134 7.354926 6.611625
#view subtype scores
head(data_subset$subtype_scores)
#> Uro UroA UroB UroC GU BaSq Mes ScNE
#> 1.CEL 0.9924 0.9350 0.0048 0.0602 0.0072 0.0004 0.0000 0.0000
#> 2.CEL 0.0016 NA NA NA 0.0052 0.0054 0.9804 0.0074
#> 3.CEL 0.0682 NA NA NA 0.7754 0.0834 0.0390 0.0340
#> 4.CEL 0.9930 0.9334 0.0028 0.0638 0.0066 0.0004 0.0000 0.0000
#> 5.CEL 0.9808 0.0058 0.9878 0.0064 0.0076 0.0090 0.0006 0.0020
#> 6.CEL 0.0082 NA NA NA 0.9890 0.0002 0.0004 0.0022
#> prediction_delta_5_class prediction_delta_7_class
#> 1.CEL 0.9852 0.8748
#> 2.CEL 0.9730 NA
#> 3.CEL 0.6920 NA
#> 4.CEL 0.9864 0.8696
#> 5.CEL 0.9718 0.9814
#> 6.CEL 0.9808 NA
#> prediction_delta_collapsed
#> 1.CEL 0.8748
#> 2.CEL 0.9730
#> 3.CEL 0.6920
#> 4.CEL 0.8696
#> 5.CEL 0.9814
#> 6.CEL 0.9808
#view prediction classes
head(data_subset$predictions_5classes)
#> 1.CEL 2.CEL 3.CEL 4.CEL 5.CEL 6.CEL
#> "Uro" "Mes" "GU" "Uro" "Uro" "GU"