Convert an AnnData object to a SingleCellExperiment object
Source:R/SingleCellExperiment.R
to_SingleCellExperiment.Rd
to_SingleCellExperiment()
converts an AnnData object
to a SingleCellExperiment object.
Usage
to_SingleCellExperiment(
adata,
assays_mapping = NULL,
colData_mapping = NULL,
rowData_mapping = NULL,
reduction_mapping = NULL,
colPairs_mapping = NULL,
rowPairs_mapping = NULL,
metadata_mapping = NULL
)
Arguments
- adata
an AnnData object, e.g., InMemoryAnnData
- assays_mapping
A named list mapping
layers
inadata
toassay
names in the created SingleCellExperiment object. The names of the list should be the names of theassays
in the resulting SingleCellExperiment object, and the values should be the names of thelayers
inadata
, and should include theX
matrix as well. IfX
is not in the list, it will be added ascounts
ordata
.- colData_mapping
a named list mapping
obs
inadata
tocolData
in the created SingleCellExperiment object. The names of the list should be the names of thecolData
columns in the resulting SingleCellExperiment object. The values of the list should be the names of theobs
columns inadata
.- rowData_mapping
a named list mapping
var
names inadata
torowData
in the created SingleCellExperiment object. The names of the list should be the names of therowData
columns in the resulting SingleCellExperiment object. The values of the list should be the names of thevar
columns inadata
.- reduction_mapping
a named list mapping reduction names in
adata
to reduction names in the created SingleCellExperiment object. The names of the list should be the names of thereducedDims
in the resulting SingleCellExperiment object. The values of the list should also be a named list with the following keys:obsm
: the name of theobsm
slot inadata
varm
: the name of thevarm
slot inadata
uns
: the name of theuns
slot inadata
- colPairs_mapping
a named list mapping obsp names in
adata
to colPairs names in the created SingleCellExperiment object. The names of the list should be the names of thecolPairs
in the resulting SingleCellExperiment object. The values of the list should be the names of theobsp
inadata
.- rowPairs_mapping
a named list mapping varp names in
adata
to rowPairs names in the created SingleCellExperiment object. The names of the list should be the names of therowPairs
in the resulting SingleCellExperiment object. The values of the list should be the names of thevarp
inadata
.- metadata_mapping
a named list mapping uns names in
adata
to metadata names in the created SingleCellExperiment object. The names of the list should be the names of themetadata
in the resulting SingleCellExperiment object. The values of the list should be the names of theuns
inadata
.
Examples
if (interactive()) {
## useful when interacting with the SingleCellExperiment !
library(SingleCellExperiment)
}
ad <- AnnData(
X = matrix(1:5, 3L, 5L),
layers = list(
A = matrix(5:1, 3L, 5L),
B = matrix(letters[1:5], 3L, 5L)
),
obs = data.frame(row.names = LETTERS[1:3], cell = 1:3),
var = data.frame(row.names = letters[1:5], gene = 1:5)
)
## construct a SingleCellExperiment from an AnnData object
sce <- to_SingleCellExperiment(ad)
sce
#> class: SingleCellExperiment
#> dim: 5 3
#> metadata(0):
#> assays(3): counts A B
#> rownames(5): a b c d e
#> rowData names(1): gene
#> colnames(3): A B C
#> colData names(1): cell
#> reducedDimNames(0):
#> mainExpName: NULL
#> altExpNames(0):