Convert a seurat object to an anndata object using reticulate
Source:R/SCP-analysis.R
srt_to_adata.Rd
This function takes a Seurat object and converts it to an anndata object using the reticulate package.
Usage
srt_to_adata(
srt,
features = NULL,
assay_X = "RNA",
slot_X = "counts",
assay_layers = c("spliced", "unspliced"),
slot_layers = "counts",
convert_tools = FALSE,
convert_misc = FALSE,
verbose = TRUE
)
Arguments
- srt
A Seurat object.
- features
Optional vector of features to include in the anndata object. Defaults to all features in assay_X.
- assay_X
Assay to convert as the main data matrix (X) in the anndata object.
- slot_X
Slot name for assay_X in the Seurat object.
- assay_layers
Assays to convert as layers in the anndata object.
- slot_layers
Slot names for the assay_layers in the Seurat object.
- convert_tools
Logical indicating whether to convert the tool-specific data.
- convert_misc
Logical indicating whether to convert the miscellaneous data.
- verbose
Logical indicating whether to print verbose messages during the conversion process.
Examples
data("pancreas_sub")
adata <- srt_to_adata(pancreas_sub)
#> 'misc' slot is not converted.
#> 'tools' slot is not converted.
adata
#> AnnData object with n_obs × n_vars = 1000 × 15958
#> obs: 'orig.ident', 'nCount_RNA', 'nFeature_RNA', 'S_score', 'G2M_score', 'nCount_spliced', 'nFeature_spliced', 'nCount_unspliced', 'nFeature_unspliced', 'CellType', 'SubCellType', 'Phase'
#> var: 'features', 'highly_variable_genes', 'highly_variable'
#> obsm: 'PCA', 'UMAP'
#> layers: 'spliced', 'unspliced'
### Or save as an h5ad file or a loom file
# adata$write_h5ad("pancreas_sub.h5ad")
# adata$write_loom("pancreas_sub.loom", write_obsm_varm = TRUE)