Skip to contents

Prepare quant files for tximport

Usage

prepareTximportFiles(
  dir,
  type = c("salmon", "kallisto"),
  makeNames = c("makeNames", "snakeCase", "camelCase")
)

Arguments

dir

character(1). Directory path containing quant files. See tximport() for details.

type

character(1). Type of quant/abundance file to find. Expecting "quant.sf" for salmon, "abundance.h5" for kallisto.

makeNames

character(1). Syntactic name function to apply on sample names. Uses match.arg() internally.

Value

character. Return quant file paths, with valid sample names automatically applied.

Details

Runs the following internal comments:

  1. Extract sample directory name from quant file using dirname() and basename().

  2. Autopad zeros, if necessary, via autopadZeros().

  3. Sanitizes names with snakeCase().

  4. Sorts files alphabetically.

Note

Updated 2023-07-13.

See also

  • tximport vignette

Examples

suppressPackageStartupMessages({
    library(AcidBase)
})
tempdir <- tempdir2()
samples <- c("1-sample-A", "2-sample-B")
salmonDir <- initDir(file.path(tempdir, "salmon"))
kallistoDir <- initDir(file.path(tempdir, "kallisto"))
invisible({
    lapply(X = file.path(salmonDir, samples), FUN = initDir)
    file.create(file.path(salmonDir, samples, "quant.sf"))
    lapply(X = file.path(kallistoDir, samples), FUN = initDir)
    file.create(file.path(kallistoDir, samples, "abundance.h5"))
})
salmonFiles <- prepareTximportFiles(dir = salmonDir, type = "salmon")
print(salmonFiles)
#>                                                                                                                 X1_sample_A 
#> "/private/var/folders/l1/8y8sjzmn15v49jgrqglghcfr0000gn/T/RtmpaRGehr/9J2LBgpVFy-171157278561667/salmon/1-sample-A/quant.sf" 
#>                                                                                                                 X2_sample_B 
#> "/private/var/folders/l1/8y8sjzmn15v49jgrqglghcfr0000gn/T/RtmpaRGehr/9J2LBgpVFy-171157278561667/salmon/2-sample-B/quant.sf" 
kallistoFiles <- prepareTximportFiles(dir = kallistoDir, type = "kallisto")
print(kallistoFiles)
#>                                                                                                                       X1_sample_A 
#> "/private/var/folders/l1/8y8sjzmn15v49jgrqglghcfr0000gn/T/RtmpaRGehr/9J2LBgpVFy-171157278561667/kallisto/1-sample-A/abundance.h5" 
#>                                                                                                                       X2_sample_B 
#> "/private/var/folders/l1/8y8sjzmn15v49jgrqglghcfr0000gn/T/RtmpaRGehr/9J2LBgpVFy-171157278561667/kallisto/2-sample-B/abundance.h5" 
unlink2(tempdir)