Skip to contents

This constructor function is meant to handle .tar.gz tarball files from 10X Genomics.

Usage

TENxFileList(..., version, compressed = FALSE)

Arguments

...

Typically, a file path to a tarball archive. Can be named arguments corresponding to file paths, or a named list of file paths.

version

character(1) The version in the tarball. See details.

compressed

logical(1) Whether or not the file provided is compressed, usually as tar.gz (default FALSE)

Value

Either a SingleCellExperiment or a list of imported data

Details

These tarballs usually contain three files:

  1. matrix.mtx.gz - the counts matrix

  2. features.tsv.gz - row metadata usually represented as rowData

  3. barcodes.tsv.gz - column names corresponding to cell barcode identifiers If all above files are in the tarball, the import method will provide a SingleCellExperiment. 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 the version argument in the TENxFileList constructor 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)