readSparseMatrix: Load data from a 10X Genomics experiment

View source: R/read_sparse_matrix.R

readSparseMatrixR Documentation

Load data from a 10X Genomics experiment

Description

Creates a SparseMatrix from the CellRanger output directories for 10X Genomics data.

Usage

readSparseMatrix(
  sample,
  col.names = FALSE,
  row.names = c("id", "symbol"),
  genome = NULL
)

Arguments

sample

character(1) directory name corresponding to a 10X sample. The directory should contain a matrix file, a gene/feature annotation file, and a barcode annotation file.

Alternatively, the string may contain a path to a HDF5 file in the sparse matrix format generated by 10X.

Alternatively, the string may contain a prefix of names for the three-file system described above, where the rest of the name of each file follows the standard 10X output.

col.names

logical(1) indicating whether the columns of the matrix should be named with the cell barcodes.

row.names

character(1) specifying whether to use Ensembl IDs ("id") or gene symbols ("symbol") as row names. If using symbols, the Ensembl ID will be appended to disambiguate in case the same symbol corresponds to multiple Ensembl IDs.

genome

character(1) specifying the genome for HDF5 files output by CellRanger v2.

Details

The signature of this function and its corresponding documentation has largely been adapted from the Read10xCounts function in the DropletUtils package.

Note that user-level manipulation of sparse matrices requires loading of the SparseArray package. Otherwise, calculation of rowSums, colSums, etc. will result in errors.

Value

A SparseMatrix object containing count data for each gene (row) and cell (column) in sample.

References

Zheng GX, Terry JM, Belgrader P, and others (2017). Massively parallel digital transcriptional profiling of single cells. Nat Commun 8:14049.

10X Genomics (2017). Gene-Barcode Matrices. https://support.10xgenomics.com/single-cell-gene-expression/software/pipelines/2.2/output/matrices

10X Genomics (2018). Feature-Barcode Matrices. https://support.10xgenomics.com/single-cell-gene-expression/software/pipelines/latest/output/matrices

10X Genomics (2018). HDF5 Gene-Barcode Matrix Format. https://support.10xgenomics.com/single-cell-gene-expression/software/pipelines/2.2/advanced/h5_matrices

10X Genomics (2018). HDF5 Feature Barcode Matrix Format. https://support.10xgenomics.com/single-cell-gene-expression/software/pipelines/latest/advanced/h5_matrices

Examples

data("tenx_subset") # Original dataset
new <- readSparseMatrix(system.file(
    "extdata/tenx_subset.csv.gz",
    package = "smallcount"
))
identical(new, tenx_subset)


rafalab/smallcount documentation built on June 1, 2025, 2:10 p.m.