TENxFileList: Represent groups of files from 10X Genomic
Source:R/TENxFileList-class.R
TENxFileList.RdThis constructor function is meant to handle .tar.gz tarball
files from 10X Genomics.
Details
These tarballs usually contain three files:
matrix.mtx.gz- the counts matrixfeatures.tsv.gz- row metadata usually represented asrowDatabarcodes.tsv.gz- column names corresponding to cell barcode identifiers If all above files are in the tarball, the import method will provide aSingleCellExperiment. Otherwise, a simple list of imported data is given. Note that version "3" uses 'features.tsv.gz' and version "2" uses 'genes.tsv.gz'. If known, indicate theversionargument in theTENxFileListconstructor function.
Examples
fl <- system.file(
"extdata", "pbmc_granulocyte_sorted_3k_ff_bc_ex_matrix.tar.gz",
package = "TENxIO", mustWork = TRUE
)
## Method 1 (tarball)
TENxFileList(fl)
#> TENxFileList of length 1
## metadata before import
metadata(TENxFileList(fl))
#> $TENxFileList
#> $TENxFileList$extension
#> [1] "tar.gz"
#>
#> $TENxFileList$compressed
#> [1] TRUE
#>
#> $TENxFileList$version
#> [1] "3"
#>
#> $TENxFileList$resources
#> $TENxFileList$resources[[1]]
#> [1] "pbmc_granulocyte_sorted_3k_ff_bc_ex_matrix.tar.gz"
#>
#>
#>
## import() method
import(TENxFileList(fl))
#> class: SingleCellExperiment
#> dim: 10 10
#> metadata(1): TENxFileList
#> assays(1): counts
#> rownames(10): ENSG00000243485 ENSG00000237613 ... ENSG00000286448
#> ENSG00000236601
#> rowData names(3): ID Symbol Type
#> colnames(10): AAACAGCCAAATATCC-1 AAACAGCCAGGAACTG-1 ...
#> AAACCGCGTGAGGTAG-1 AAACGCGCATACCCGG-1
#> colData names(0):
#> reducedDimNames(0):
#> mainExpName: Gene Expression
#> altExpNames(0):
## metadata after import
import(TENxFileList(fl)) |>
metadata()
#> $TENxFileList
#> $TENxFileList$extension
#> [1] "tar.gz"
#>
#> $TENxFileList$compressed
#> [1] TRUE
#>
#> $TENxFileList$version
#> [1] "3"
#>
#> $TENxFileList$resources
#> $TENxFileList$resources[[1]]
#> [1] "pbmc_granulocyte_sorted_3k_ff_bc_ex_matrix.tar.gz"
#>
#>
#>
## untar to simulate folder output
dir.create(tdir <- tempfile())
untar(fl, exdir = tdir)
## Method 2 (folder)
TENxFileList(tdir)
#> TENxFileList of length 3
#> names(3): barcodes.tsv.gz features.tsv.gz matrix.mtx.gz
import(TENxFileList(tdir))
#> class: SingleCellExperiment
#> dim: 10 10
#> metadata(1): TENxFileList
#> assays(1): counts
#> rownames(10): ENSG00000243485 ENSG00000237613 ... ENSG00000286448
#> ENSG00000236601
#> rowData names(3): ID Symbol Type
#> colnames(10): AAACAGCCAAATATCC-1 AAACAGCCAGGAACTG-1 ...
#> AAACCGCGTGAGGTAG-1 AAACGCGCATACCCGG-1
#> colData names(0):
#> reducedDimNames(0):
#> mainExpName: Gene Expression
#> altExpNames(0):
## Method 3 (list of TENxFile objects)
files <- list.files(tdir, recursive = TRUE, full.names = TRUE)
names(files) <- basename(files)
filelist <- lapply(files, TENxFile)
TENxFileList(filelist, compressed = FALSE)
#> TENxFileList of length 3
#> names(3): barcodes.tsv.gz features.tsv.gz matrix.mtx.gz
## Method 4 (SimpleList)
TENxFileList(as(filelist, "SimpleList"), compressed = FALSE)
#> TENxFileList of length 3
#> names(3): barcodes.tsv.gz features.tsv.gz matrix.mtx.gz
## Method 5 (named arguments)
TENxFileList(
barcodes.tsv.gz = TENxFile(files[1]),
features.tsv.gz = TENxFile(files[2]),
matrix.mtx.gz = TENxFile(files[3])
)
#> TENxFileList of length 3
#> names(3): barcodes.tsv.gz features.tsv.gz matrix.mtx.gz
unlink(tdir, recursive = TRUE)