to_Seurat()
converts an AnnData object to a Seurat object. Only one assay can be converted at a time.
Arguments are used to configure the conversion. If NULL
, the functions to_Seurat_guess_*
will be used to guess
the mapping.
Usage
to_Seurat(
adata,
assay_name = "RNA",
layers_mapping = NULL,
reduction_mapping = NULL,
graph_mapping = NULL,
misc_mapping = NULL
)
Arguments
- adata
An AnnData object to be converted
- assay_name
Name of the assay to be created (default: "RNA").
- layers_mapping
A named list to map AnnData layers to Seurat layers. See section "Layer mapping" for more details.
- reduction_mapping
A named list to map AnnData reductions to Seurat reductions. Each item in the list must be a named list with keys 'key', 'obsm', and 'varm'. See section "Reduction mapping" for more details.
- graph_mapping
A named list to map AnnData graphs to Seurat graphs. Each item in the list must be a character vector of length 1. See section "Graph mapping" for more details.
- misc_mapping
A named list to map miscellaneous data to the names of the data in the Seurat object. See section "Miscellaneous mapping" for more details.
Layer mapping
A named list to map AnnData layers to Seurat layers. Each item in the list must be a character vector of length 1,
where the values correspond to the names of the layers in the AnnData object, and the names correspond
to the names of the layers in the resulting Seurat object. A value of NULL
corresponds to the AnnData X
slot.
Example: layers_mapping = list(counts = "counts", data = NULL, foo = "bar")
.
If NULL
, the internal function to_Seurat_guess_layers
will be used to guess the layer mapping as follows:
All AnnData layers are copied to Seurat layers by name.
Reduction mapping
A named list to map AnnData $obsm
and $varm
to Seurat reductions. Each item in the list must be a named list
with keys 'key'
, 'obsm'
, and 'varm'
.
Example: reduction_mapping = list(pca = list(key = "PC_", obsm = "X_pca", varm = "PCs"))
.
If NULL
, the internal function to_Seurat_guess_reductions
will be used to guess the reduction mapping as follows:
All
$obsm
items starting withX_
are copied by name.
Graph mapping
A named list mapping graph names to the names of the graphs in the AnnData object. Each item in the list must be a character vector of length 1. The values correspond to the names of the graphs in the resulting Seurat object, while the names correspond to the names of the graphs in the AnnData object.
Example: graph_mapping = list(nn = "connectivities")
.
If NULL
, the internal function to_Seurat_guess_graphs
will be used to guess the graph mapping as follows:
An obsp named
connectivities
will be mapped tonn
.Other graphs starting with
connectivities_
are stripped of the prefix and copied by name.
Miscellaneous mapping
A named list mapping miscellaneous data to the names of the data in the AnnData object. Each item in the list must be a vector with one or two elements. The first element must be one of: 'X', 'layers', 'obs', 'obsm', 'obsp', 'var', 'varm', 'varp', 'uns'. The second element is the name of the data in the corresponding slot. If the second element is not present, the whole slot as specified by the first element will be used.
Example: misc_mapping = list(uns = "uns", varp_neighbors = c("varp", "neighbors"))
.
If NULL
, the internal function to_Seurat_guess_misc
will be used to guess the miscellaneous mapping as follows:
If
$uns
is defined, all values in$uns
are copied to the Seurat misc.
Examples
ad <- AnnData(
X = matrix(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)
)
to_Seurat(ad)
#> Warning: Data is of class matrix. Coercing to dgCMatrix.
#> An object of class Seurat
#> 5 features across 3 samples within 1 assay
#> Active assay: RNA (5 features, 0 variable features)
#> 1 layer present: counts