Extract genes by row and cells by column.
Arguments
- x
Object.
- i, j, ...
indices specifying elements to extract or replace. Indices are
numericorcharactervectors or empty (missing) orNULL. Numeric values are coerced to integer or whole numbers as byas.integeror for large values bytrunc(and hence truncated towards zero). Character vectors will be matched to thenamesof the object (or for matrices/arrays, thedimnames): 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 argumentican be a matrix with as many columns as there are dimensions ofx; the result is then a vector with elements corresponding to the sets of indices in each row ofi.An index value of
NULLis treated as if it wereinteger(0).- drop
relevant for matrices and arrays. If
TRUEthe result is coerced to the lowest possible dimension (see the examples). This only works for extracting elements, not for the replacement. Seedropfor further details.
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.
References
Becker RA, Chambers JM, Wilks AR (1988). The New S Language. Chapman and Hall/CRC, London. ISBN 053409192X.
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):