Match user metadata to file names used for tximport

matchMetadataToFiles(metadata, files)

Arguments

metadata

data.frame. User-defined metadata. The function assumes that sample identifiers are defined in the first metadata column.

files

character. Quant file paths passed to tximport::tximport(). Sanitize return from prepareTximportFiles() is recommended.

Value

data.frame. Modified metadata frame, with updated sample identifiers in slotted in first column. Original values are stashed in "originalSampleId".

Note

Updated 2021-06-28.

Examples

metadata <- data.frame( "sampleId" = paste( seq_len(4L), "sample", LETTERS[seq_len(4L)], sep = "_" ), "condition" = rep(LETTERS[seq_len(2L)], times = 2L) ) files <- file.path( "salmon", paste(seq_len(4L), "sample", LETTERS[seq_len(4L)], sep = "-"), "quant.sf" ) ## The function will match regardless of row order in user metadata. files <- rev(files) print(metadata)
#> sampleId condition #> 1 1_sample_A A #> 2 2_sample_B B #> 3 3_sample_C A #> 4 4_sample_D B
print(files)
#> [1] "salmon/4-sample-D/quant.sf" "salmon/3-sample-C/quant.sf" #> [3] "salmon/2-sample-B/quant.sf" "salmon/1-sample-A/quant.sf"
matchMetadataToFiles(metadata = metadata, files = files)
#> sampleId condition originalSampleId #> 1 1-sample-A A 1_sample_A #> 2 2-sample-B B 2_sample_B #> 3 3-sample-C A 3_sample_C #> 4 4-sample-D B 4_sample_D