Skip to contents

Extract genes by row and cells by column.

Usage

# S4 method for CellRanger,ANY,ANY,ANY
[(x, i, j, ..., drop = FALSE)

Arguments

x

Object.

i

Indices specifying elements to extract or replace. Indices are numeric or character vectors, empty (missing), or NULL.

For more information:

help(topic = "Extract", package = "base")

j

Indices specifying elements to extract or replace. Indices are numeric or character vectors, empty (missing), or NULL.

For more information:

help(topic = "Extract", package = "base")

...

Additional arguments.

drop

For matrices and arrays. If TRUE the result is coerced to the lowest possible dimension (see the examples). This only works for extracting elements, not for the replacement. See drop for further details.

Value

CellRanger.

Details

Refer to cellToSample() and selectSamples() if sample-level extraction is desired. Note that sampleId is slotted into colData() and defines the cell-to-sample mappings.

Unfiltered cellular barcode distributions for the entire dataset, including cells not kept in the matrix will be dropped in favor of the nCount column of colData.

Note

Updated 2023-09-25.

References

Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) The New S Language. Wadsworth & Brooks/Cole.

Author

Michael Steinbaugh

Examples

data(pbmc_v3)

## CellRanger ====
object <- pbmc_v3

cells <- head(colnames(object), 100L)
head(cells)
#> [1] "AAAGGATAGAGGCCAT" "AAAGGATGTGATTAGA" "AACAACCGTGCACATT" "AACAACCTCTAAGAAG"
#> [5] "AACCAACGTAACATCC" "AAGAACACAACGGCCT"
genes <- head(rownames(object), 100L)
head(genes)
#> [1] "CD11b" "CD127" "CD137" "CD14"  "CD15"  "CD16" 

## Subset by cell identifiers.
object[, cells]
#> class: CellRanger 
#> dim: 500 100 
#> metadata(23): allSamples call ... wd subset
#> assays(1): counts
#> rownames(500): CD11b CD127 ... PD_1 TIGIT
#> rowData names(8): broadClass geneBiotype ... source type
#> colnames(100): AAAGGATAGAGGCCAT AAAGGATGTGATTAGA ... TTCACGCGTACGGCAA
#>   TTTGTTGCAAGCGGAT
#> colData names(8): sampleId sampleName ... log10FeaturesPerCount
#>   mitoRatio
#> reducedDimNames(0):
#> mainExpName: NULL
#> altExpNames(0):

## Subset by genes.
object[genes, ]
#> class: CellRanger 
#> dim: 100 100 
#> metadata(23): allSamples call ... wd subset
#> assays(1): counts
#> rownames(100): CD11b CD127 ... ENSG00000102317 ENSG00000102879
#> rowData names(8): broadClass geneBiotype ... source type
#> colnames(100): AAAGGATAGAGGCCAT AAAGGATGTGATTAGA ... TTCACGCGTACGGCAA
#>   TTTGTTGCAAGCGGAT
#> colData names(8): sampleId sampleName ... log10FeaturesPerCount
#>   mitoRatio
#> reducedDimNames(0):
#> mainExpName: NULL
#> altExpNames(0):

## Subset by both genes and cells.
object[genes, cells]
#> class: CellRanger 
#> dim: 100 100 
#> metadata(23): allSamples call ... wd subset
#> assays(1): counts
#> rownames(100): CD11b CD127 ... ENSG00000102317 ENSG00000102879
#> rowData names(8): broadClass geneBiotype ... source type
#> colnames(100): AAAGGATAGAGGCCAT AAAGGATGTGATTAGA ... TTCACGCGTACGGCAA
#>   TTTGTTGCAAGCGGAT
#> colData names(8): sampleId sampleName ... log10FeaturesPerCount
#>   mitoRatio
#> reducedDimNames(0):
#> mainExpName: NULL
#> altExpNames(0):