Skip to contents

Extract genes by row and cells by column.

Usage

# S4 method for class 'CellRanger,ANY,ANY,ANY'
x[i, j, ..., drop = FALSE]

Arguments

x

Object.

i, j, ...

indices specifying elements to extract or replace. Indices are numeric or character vectors or empty (missing) or NULL. Numeric values are coerced to integer or whole numbers as by as.integer or for large values by trunc (and hence truncated towards zero). Character vectors will be matched to the names of the object (or for matrices/arrays, the dimnames): see ‘Character indices’ below for further details.

For [-indexing only: i, j, ... can be logical vectors, indicating elements/slices to select. Such vectors are recycled if necessary to match the corresponding extent. i, j, ... can also be negative integers, indicating elements/slices to leave out of the selection.

When indexing arrays by [ a single argument i can be a matrix with as many columns as there are dimensions of x; the result is then a vector with elements corresponding to the sets of indices in each row of i.

An index value of NULL is treated as if it were integer(0).

drop

relevant 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 RA, Chambers JM, Wilks AR (1988). The New S Language. Chapman and Hall/CRC, London. ISBN 053409192X.

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):