| Title: | AnnData interoperability in R |
|---|---|
| Description: | Bring the power and flexibility of AnnData to the R ecosystem, allowing you to effortlessly manipulate and analyse your single-cell data. This package lets you work with backed h5ad and zarr files, directly access various slots (e.g. X, obs, var), or convert the data into SingleCellExperiment and Seurat objects. |
| Authors: | Robrecht Cannoodt [aut, cre] (ORCID: <https://orcid.org/0000-0003-3641-729X>, github: rcannood), Luke Zappia [aut] (ORCID: <https://orcid.org/0000-0001-7744-8565>, github: lazappi), Martin Morgan [aut] (ORCID: <https://orcid.org/0000-0002-5874-8148>, github: mtmorgan), Louise Deconinck [aut] (ORCID: <https://orcid.org/0000-0001-8100-6823>, github: LouiseDck), Danila Bredikhin [ctb] (ORCID: <https://orcid.org/0000-0001-8089-6983>, github: gtca), Isaac Virshup [ctb] (ORCID: <https://orcid.org/0000-0002-1710-8945>, github: ivirshup), Brian Schilder [ctb] (ORCID: <https://orcid.org/0000-0001-5949-2191>, github: bschilder), Chananchida Sang-aram [ctb] (ORCID: <https://orcid.org/0000-0002-0922-0822>, github: csangara), Artür Manukyan [ctb] (ORCID: <https://orcid.org/0000-0002-0441-9517>, github: Artur-man), Hugo Gruson [ctb] (ORCID: <https://orcid.org/0000-0002-4094-1476>, github: Bisaloo), Data Intuitive [fnd], Chan Zuckerberg Initiative [fnd], scverse consortium [spn] |
| Maintainer: | Robrecht Cannoodt <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 1.3.0 |
| Built: | 2026-06-04 11:16:31 UTC |
| Source: | https://github.com/scverse/anndataR |
This class is an abstract representation of an AnnData object. It is
intended to be used as a base class for concrete implementations of
AnnData objects, such as InMemoryAnnData or HDF5AnnData.
See AnnData-usage for details on creating and using AnnData objects.
An AbstractAnnData object
XSee AnnData-usage
layersSee AnnData-usage
obsSee AnnData-usage
varSee AnnData-usage
obs_namesSee AnnData-usage
var_namesSee AnnData-usage
obsmSee AnnData-usage
varmSee AnnData-usage
obspSee AnnData-usage
varpSee AnnData-usage
unsSee AnnData-usage
print()
See AnnData-usage
AbstractAnnData$print(...)
...Optional arguments to print method
shape()
See AnnData-usage
AbstractAnnData$shape()
n_obs()
See AnnData-usage
AbstractAnnData$n_obs()
n_vars()
See AnnData-usage
AbstractAnnData$n_vars()
obs_keys()
See AnnData-usage
AbstractAnnData$obs_keys()
var_keys()
See AnnData-usage
AbstractAnnData$var_keys()
layers_keys()
See AnnData-usage
AbstractAnnData$layers_keys()
obsm_keys()
See AnnData-usage
AbstractAnnData$obsm_keys()
varm_keys()
See AnnData-usage
AbstractAnnData$varm_keys()
obsp_keys()
See AnnData-usage
AbstractAnnData$obsp_keys()
varp_keys()
See AnnData-usage
AbstractAnnData$varp_keys()
uns_keys()
See AnnData-usage
AbstractAnnData$uns_keys()
as_SingleCellExperiment()
Convert to SingleCellExperiment
See as_SingleCellExperiment() for more details on the conversion
AbstractAnnData$as_SingleCellExperiment( x_mapping = NULL, assays_mapping = TRUE, colData_mapping = TRUE, rowData_mapping = TRUE, reducedDims_mapping = TRUE, colPairs_mapping = TRUE, rowPairs_mapping = TRUE, metadata_mapping = TRUE )
x_mappingassays_mappingcolData_mappingrowData_mappingreducedDims_mappingcolPairs_mappingrowPairs_mappingmetadata_mappingA SingleCellExperiment object
as_Seurat()
Convert to Seurat
See as_Seurat() for more details on the conversion
AbstractAnnData$as_Seurat( assay_name = "RNA", x_mapping = NULL, layers_mapping = TRUE, object_metadata_mapping = TRUE, assay_metadata_mapping = TRUE, reduction_mapping = TRUE, graph_mapping = TRUE, misc_mapping = TRUE )
assay_nameSee as_Seurat()
x_mappingSee as_Seurat()
layers_mappingSee as_Seurat()
object_metadata_mappingSee as_Seurat()
assay_metadata_mappingSee as_Seurat()
reduction_mappingSee as_Seurat()
graph_mappingSee as_Seurat()
misc_mappingSee as_Seurat()
A Seurat object
as_InMemoryAnnData()
Convert to an InMemoryAnnData
See as_InMemoryAnnData() for more details on the conversion
AbstractAnnData$as_InMemoryAnnData()
An InMemoryAnnData object
as_ReticulateAnnData()
Convert to a ReticulateAnnData
See as_ReticulateAnnData() for more details on the conversion
AbstractAnnData$as_ReticulateAnnData()
A ReticulateAnnData object
as_HDF5AnnData()
Convert to an HDF5AnnData
See as_HDF5AnnData() for more details on the conversion
AbstractAnnData$as_HDF5AnnData(
file,
compression = c("none", "gzip", "lzf"),
chunk_size = "auto",
mode = c("w-", "r", "r+", "a", "w", "x")
)fileSee as_HDF5AnnData()
compressionSee as_HDF5AnnData()
chunk_sizeSee as_HDF5AnnData()
modeSee as_HDF5AnnData()
An HDF5AnnData object
as_ZarrAnnData()
Convert to a ZarrAnnData
See as_ZarrAnnData() for more details on the conversion
AbstractAnnData$as_ZarrAnnData(
file,
compression = c("none", "gzip", "blosc", "zstd", "lzma", "bz2", "zlib", "lz4"),
mode = c("w-", "r", "r+", "a", "w", "x")
)fileSee as_ZarrAnnData()
compressionSee as_ZarrAnnData()
modeSee as_ZarrAnnData()
A ZarrAnnData object
write_h5ad()
Write the AnnData object to an H5AD file
See write_h5ad() for details
AbstractAnnData$write_h5ad(
path,
compression = c("none", "gzip", "lzf"),
chunk_size = "auto",
mode = c("w-", "r", "r+", "a", "w", "x")
)pathSee write_h5ad()
compressionSee write_h5ad()
chunk_sizeSee write_h5ad()
modeSee write_h5ad()
path invisibly
write_zarr()
Write the AnnData object to a Zarr file
See write_zarr() for details
AbstractAnnData$write_zarr(
path,
compression = c("none", "gzip", "blosc", "zstd", "lzma", "bz2", "zlib", "lz4"),
mode = c("w-", "r", "r+", "a", "w", "x")
)pathSee write_zarr()
compressionSee write_zarr()
modeSee write_zarr()
path invisibly
clone()
The objects of this class are cloneable with this method.
AbstractAnnData$clone(deep = FALSE)
deepWhether to make a deep clone.
AnnData-usage for details on creating and using AnnData objects
Other AnnData classes:
AnnDataView,
HDF5AnnData,
InMemoryAnnData,
ReticulateAnnData,
ZarrAnnData
These S3 methods provide standard R interfaces for AbstractAnnData objects, making them behave like native R objects with familiar syntax.
## S3 method for class 'AbstractAnnData' dim(x) ## S3 method for class 'AbstractAnnData' nrow(x) ## S3 method for class 'AbstractAnnData' ncol(x) ## S3 method for class 'AbstractAnnData' dimnames(x) ## S3 replacement method for class 'AbstractAnnData' dimnames(x) <- value ## S3 method for class 'AbstractAnnData' x[i, j, drop = TRUE, ...]## S3 method for class 'AbstractAnnData' dim(x) ## S3 method for class 'AbstractAnnData' nrow(x) ## S3 method for class 'AbstractAnnData' ncol(x) ## S3 method for class 'AbstractAnnData' dimnames(x) ## S3 replacement method for class 'AbstractAnnData' dimnames(x) <- value ## S3 method for class 'AbstractAnnData' x[i, j, drop = TRUE, ...]
x |
An AbstractAnnData object |
value |
For |
i |
Row indices (observations). Can be numeric, logical, or character. |
j |
Column indices (variables). Can be numeric, logical, or character. |
drop |
Ignored (for compatibility with generic) |
... |
Additional arguments passed to methods |
Subsetting behaviour: The [ method supports logical, integer, and character
subsetting for both observations (rows) and variables (columns). However, unlike
standard R behaviour:
Logical vectors are not recycled and must have the exact same length as the dimension being subset
Negative indices are not supported (R's "exclude these" syntax)
These design choices ensure clear and predictable subsetting behaviour for biological data matrices, avoiding potential confusion from accidental recycling or exclusion patterns.
The following S3 methods are available:
dim(x): Get dimensions (n_obs, n_vars), equivalent to x$shape()
nrow(x): Get number of observations, equivalent to x$n_obs()
ncol(x): Get number of variables, equivalent to x$n_vars()
dimnames(x): Get dimension names, (obs_names, var_names)
rownames(x): Get observation names, equivalent to x$obs_names()
colnames(x): Get variable names, equivalent to x$var_names()
dimnames(x) <- value: Set dimension names
rownames(x) <- value: Set observation names, equivalent to x$obs_names() <- ...
colnames(x) <- value: Set variable names, equivalent to x$var_names() <- ...
x[i, j]: Subset observations and/or variables
dim: Numeric vector of length 2 (n_obs, n_vars)
nrow, ncol: Integer count
dimnames: List with obs_names and var_names
rownames, colnames: Character vector
dimnames<-, rownames<-, colnames<-: The modified object (invisibly)
[: A AnnDataView object with the specified subset
# Create example data ad <- generate_dataset(n_obs = 100, n_vars = 50, format = "AnnData") # Standard R methods work dim(ad) nrow(ad) ncol(ad) dimnames(ad) rownames(ad) colnames(ad) # Set names using dimnames dimnames(ad) <- list( paste0("cell_", 1:nrow(ad)), paste0("gene_", 1:ncol(ad)) ) # Or set names individually (uses dimnames<- internally) rownames(ad) <- paste0("cell_", 1:nrow(ad)) colnames(ad) <- paste0("gene_", 1:ncol(ad)) # Subsetting creates AnnDataView subset_ad <- ad[1:10, 1:5] subset_ad <- ad[rep(c(TRUE, FALSE), length.out = nrow(ad)), ] # logical subsetting (no recycling) subset_ad <- ad[c("cell_1", "cell_2"), c("gene_1", "gene_2")] # name subsetting# Create example data ad <- generate_dataset(n_obs = 100, n_vars = 50, format = "AnnData") # Standard R methods work dim(ad) nrow(ad) ncol(ad) dimnames(ad) rownames(ad) colnames(ad) # Set names using dimnames dimnames(ad) <- list( paste0("cell_", 1:nrow(ad)), paste0("gene_", 1:ncol(ad)) ) # Or set names individually (uses dimnames<- internally) rownames(ad) <- paste0("cell_", 1:nrow(ad)) colnames(ad) <- paste0("gene_", 1:ncol(ad)) # Subsetting creates AnnDataView subset_ad <- ad[1:10, 1:5] subset_ad <- ad[rep(c(TRUE, FALSE), length.out = nrow(ad)), ] # logical subsetting (no recycling) subset_ad <- ad[c("cell_1", "cell_2"), c("gene_1", "gene_2")] # name subsetting
For more information on the functionality of an AnnData object, see AnnData-usage
AnnData( X = NULL, obs = NULL, var = NULL, layers = NULL, obsm = NULL, varm = NULL, obsp = NULL, varp = NULL, uns = NULL, shape = NULL )AnnData( X = NULL, obs = NULL, var = NULL, layers = NULL, obsm = NULL, varm = NULL, obsp = NULL, varp = NULL, uns = NULL, shape = NULL )
X |
See the |
obs |
See the |
var |
See the |
layers |
See the |
obsm |
See the |
varm |
See the |
obsp |
See the |
varp |
See the |
uns |
See the |
shape |
Shape tuple (e.g. |
An InMemoryAnnData object
AnnData-usage for details of AnnData structure and usage
Other AnnData creators:
as_AnnData(),
read_h5ad(),
read_zarr()
adata <- AnnData( X = matrix(1:12, nrow = 3, ncol = 4), obs = data.frame( row.names = paste0("obs", 1:3), n_counts = c(1, 2, 3), n_cells = c(1, 2, 3) ), var = data.frame( row.names = paste0("var", 1:4), n_cells = c(1, 2, 3, 4) ) ) adataadata <- AnnData( X = matrix(1:12, nrow = 3, ncol = 4), obs = data.frame( row.names = paste0("obs", 1:3), n_counts = c(1, 2, 3), n_cells = c(1, 2, 3) ), var = data.frame( row.names = paste0("var", 1:4), n_cells = c(1, 2, 3, 4) ) ) adata
The AnnData object stores a data matrix X together with annotations of
observations obs (obsm, obsp) and variables var (varm, varp).
Additional layers of data can be stored in layers and unstructured
annotations in uns.
There are different back ends for AnnData objects that inherit from the
abstract AbstractAnnData class and store and access data in different ways:
InMemoryAnnData stores data in memory
HDF5AnnData provides an interface to a H5AD file
ZarrAnnData provides an interface to a Zarr store
ReticulateAnnData wraps a Python AnnData object via reticulate
See the class documentation for details.
The items listed as "Slots" are elements of the AnnData object that
contain data and can be accessed or set. "Fields" return information
about the AnnData object but cannot be set directly. Both, as well as
methods, can be accessed using the $ operator
For example:
adata$X returns the X matrix
adata$X <- x sets the X matrix
adata$method() calls a method
An AnnData object inheriting from AbstractAnnData
shapeDimensions (observations x variables) of the AnnData object
n_obsNumber of observations
n_varsNumber of variables
obs_keysKeys (column names) of obs
var_keysKeys (column names) of var
layers_keysKeys (element names) of layers
obsm_keysKeys (element names) of obsm
varm_keysKeys (element names) of varm
obsp_keysKeys (element names) of obsp
varp_keysKeys (element names) of varp
uns_keysKeys (element names) of uns
XThe main data matrix. Either NULL or an observation x variable
matrix (without dimnames) with dimensions consistent with n_obs and
n_vars.
layersAdditional data layers. Must be NULL or a named list of
matrices having dimensions consistent with n_obs and n_vars.
obsObservation annotations. A data.frame with columns containing
information about observations. The number of rows of obs defines the
observation dimension of the AnnData object (n_obs). If NULL, an
n_obs × 0 data.frame will automatically be generated.
varVariable annotations. A data.frame with columns containing
information about variables. The number of rows of var defines the
variable dimension of the AnnData object (n_vars). If NULL, an
n_vars × 0 data.frame will automatically be generated.
obs_namesObservation names. Either NULL or a vector of unique
identifiers used to identify each row of obs and to act as an index into
the observation dimension of the AnnData object. For compatibility with
R representations, obs_names should be a unique character vector.
var_namesVariable names. Either NULL or a vector of unique
identifiers used to identify each row of var and to act as an index into
the variable dimension of the AnnData object. For compatibility with R
representations, var_names should be a unique character vector.
obsmMulti-dimensional observation annotation. Must be NULL or a
named list of array-like elements with number of rows equal to n_obs.
varmMulti-dimensional variable annotations. Must be NULL or a named
list of array-like elements with number of rows equal to n_vars.
obspObservation pairs. Must be NULL or a named list of array-like
elements with number of rows and columns equal to n_obs.
varpVariable pairs. Must be NULL or a named list of array-like
elements with number of rows and columns equal to n_vars.
unsUnstructured annotations. Must be NULL or a named list.
as_SingleCellExperiment()
Convert to SingleCellExperiment::SingleCellExperiment, see
as_SingleCellExperiment()
as_Seurat()Convert to SeuratObject::Seurat, see as_Seurat()
as_InMemoryAnnData()Convert to InMemoryAnnData, as as_InMemoryAnnData()
as_HDF5AnnData()Convert to HDF5AnnData, see as_HDF5AnnData()
as_ZarrAnnData()Convert to ZarrAnnData, see as_ZarrAnnData()
as_ReticulateAnnData()Convert to ReticulateAnnData, see as_ReticulateAnnData()
write_h5ad()
Write the AnnData object to an HDF5 file, see write_h5ad()
write_zarr()
Write the AnnData object to a Zarr store, see write_zarr()
print()Print a summary of the AnnData object
AnnData()Create an InMemoryAnnData object
read_h5ad()Read an AnnData from a H5AD file
read_zarr()Read an AnnData from a Zarr store
as_AnnData()Convert other objects to an AnnData object
The documentation for the Python anndata package
https://anndata.readthedocs.io/en/stable/
AbstractAnnData for the abstract class that all AnnData objects
inherit from
InMemoryAnnData for the in-memory implementation of AnnData
HDF5AnnData for the HDF5-backed implementation of AnnData
ZarrAnnData for the Zarr-backed implementation of AnnData
ReticulateAnnData for the reticulate-based implementation that wraps Python AnnData objects
A lazy view of an AnnData object that allows applying subsetting operations without immediately executing them. Subsetting is applied when converting to a concrete AnnData implementation (InMemoryAnnData, HDF5AnnData) or other formats (SingleCellExperiment, Seurat).
A AnnDataView object
anndataR::AbstractAnnData -> AnnDataView
XSee AnnData-usage
layersSee AnnData-usage
obsSee AnnData-usage
varSee AnnData-usage
obs_namesSee AnnData-usage
var_namesSee AnnData-usage
obsmSee AnnData-usage
varmSee AnnData-usage
obspSee AnnData-usage
varpSee AnnData-usage
unsSee AnnData-usage
anndataR::AbstractAnnData$as_HDF5AnnData()anndataR::AbstractAnnData$as_InMemoryAnnData()anndataR::AbstractAnnData$as_ReticulateAnnData()anndataR::AbstractAnnData$as_Seurat()anndataR::AbstractAnnData$as_SingleCellExperiment()anndataR::AbstractAnnData$as_ZarrAnnData()anndataR::AbstractAnnData$layers_keys()anndataR::AbstractAnnData$n_obs()anndataR::AbstractAnnData$n_vars()anndataR::AbstractAnnData$obs_keys()anndataR::AbstractAnnData$obsm_keys()anndataR::AbstractAnnData$obsp_keys()anndataR::AbstractAnnData$print()anndataR::AbstractAnnData$shape()anndataR::AbstractAnnData$uns_keys()anndataR::AbstractAnnData$var_keys()anndataR::AbstractAnnData$varm_keys()anndataR::AbstractAnnData$varp_keys()anndataR::AbstractAnnData$write_h5ad()anndataR::AbstractAnnData$write_zarr()new()
Create a new AnnDataView object
AnnDataView$new(base_adata, i, j)
base_adataAn existing AnnData object to create a view of
iOptional initial obs subset (logical, integer, or character vector)
jOptional initial var subset (logical, integer, or character vector)
A new AnnDataView object
Subset the AnnDataView
subset()
AnnDataView$subset(i, j)
iRow indices (observations). Can be numeric, logical, or character.
jColumn indices (variables). Can be numeric, logical, or character.
A new AnnDataView object
clone()
The objects of this class are cloneable with this method.
AnnDataView$clone(deep = FALSE)
deepWhether to make a deep clone.
AnnData-usage for details on creating and using AnnData objects
Other AnnData classes:
AbstractAnnData,
HDF5AnnData,
InMemoryAnnData,
ReticulateAnnData,
ZarrAnnData
# Create a base AnnData object ad <- AnnData( X = matrix(1:15, 3L, 5L), obs = data.frame(row.names = LETTERS[1:3], cell_type = c("A", "B", "A")), var = data.frame(row.names = letters[1:5], gene_type = c("X", "Y", "X", "Y", "Z")) ) # Create a view with lazy subsetting using S3 [ method view <- ad[ad$obs$cell_type == "A", ad$var$gene_type %in% c("X", "Y")] # Apply subsetting by converting to a concrete implementation result <- view$as_InMemoryAnnData()# Create a base AnnData object ad <- AnnData( X = matrix(1:15, 3L, 5L), obs = data.frame(row.names = LETTERS[1:3], cell_type = c("A", "B", "A")), var = data.frame(row.names = letters[1:5], gene_type = c("X", "Y", "X", "Y", "Z")) ) # Create a view with lazy subsetting using S3 [ method view <- ad[ad$obs$cell_type == "A", ad$var$gene_type %in% c("X", "Y")] # Apply subsetting by converting to a concrete implementation result <- view$as_InMemoryAnnData()
AnnData objectConvert other objects to an AnnData object. See the sections below for
details on how slots are mapped between objects. For more information on the
functionality of an AnnData object, see AnnData-usage.
as_AnnData( x, x_mapping = NULL, layers_mapping = TRUE, obs_mapping = TRUE, var_mapping = TRUE, obsm_mapping = TRUE, varm_mapping = TRUE, obsp_mapping = TRUE, varp_mapping = TRUE, uns_mapping = TRUE, assay_name = NULL, output_class = c("InMemory", "HDF5AnnData", "ZarrAnnData", "ReticulateAnnData"), ... ) ## S3 method for class 'SingleCellExperiment' as_AnnData( x, x_mapping = NULL, layers_mapping = TRUE, obs_mapping = TRUE, var_mapping = TRUE, obsm_mapping = TRUE, varm_mapping = TRUE, obsp_mapping = TRUE, varp_mapping = TRUE, uns_mapping = TRUE, assay_name = TRUE, output_class = c("InMemory", "HDF5AnnData", "ZarrAnnData", "ReticulateAnnData"), ... ) ## S3 method for class 'Seurat' as_AnnData( x, x_mapping = NULL, layers_mapping = TRUE, obs_mapping = TRUE, var_mapping = TRUE, obsm_mapping = TRUE, varm_mapping = TRUE, obsp_mapping = TRUE, varp_mapping = TRUE, uns_mapping = TRUE, assay_name = NULL, output_class = c("InMemory", "HDF5AnnData", "ZarrAnnData", "ReticulateAnnData"), ... )as_AnnData( x, x_mapping = NULL, layers_mapping = TRUE, obs_mapping = TRUE, var_mapping = TRUE, obsm_mapping = TRUE, varm_mapping = TRUE, obsp_mapping = TRUE, varp_mapping = TRUE, uns_mapping = TRUE, assay_name = NULL, output_class = c("InMemory", "HDF5AnnData", "ZarrAnnData", "ReticulateAnnData"), ... ) ## S3 method for class 'SingleCellExperiment' as_AnnData( x, x_mapping = NULL, layers_mapping = TRUE, obs_mapping = TRUE, var_mapping = TRUE, obsm_mapping = TRUE, varm_mapping = TRUE, obsp_mapping = TRUE, varp_mapping = TRUE, uns_mapping = TRUE, assay_name = TRUE, output_class = c("InMemory", "HDF5AnnData", "ZarrAnnData", "ReticulateAnnData"), ... ) ## S3 method for class 'Seurat' as_AnnData( x, x_mapping = NULL, layers_mapping = TRUE, obs_mapping = TRUE, var_mapping = TRUE, obsm_mapping = TRUE, varm_mapping = TRUE, obsp_mapping = TRUE, varp_mapping = TRUE, uns_mapping = TRUE, assay_name = NULL, output_class = c("InMemory", "HDF5AnnData", "ZarrAnnData", "ReticulateAnnData"), ... )
x |
The object to convert |
x_mapping |
A string specifying the data to map to the |
layers_mapping |
A named character vector where the names are keys of
|
obs_mapping |
A named character vector where the names are names of
|
var_mapping |
A named character vector where the names are names of
|
obsm_mapping |
A named character vector where the names are keys of
|
varm_mapping |
A named character vector where the names are keys of
|
obsp_mapping |
A named character vector where the names are keys of
|
varp_mapping |
A named character vector where the names are keys of
|
uns_mapping |
A named character vector where the names are keys of |
assay_name |
For |
output_class |
The |
... |
Additional arguments passed to the generator function for
|
An AnnData object of the class requested by output_class
containing the data specified in the mapping arguments.
All mapping arguments except for x_mapping expect a named character
vector where names are the keys of the slot in the AnnData object and
values are the names of items in the corresponding slot of x. If TRUE,
the conversion function will guess which items to copy as described in the
conversion tables for each object type. In most cases, the default is to
copy all items using the same names except where the correspondence between
objects is unclear. To avoid copying anything to a slot, set the mapping
argument to FALSE. Empty mapping arguments (NULL, c(), list()) will
be treated as FALSE with a warning. If an unnamed vector is provided, the
values will be used as names.
TRUE will guess which items to copy as described in the conversion
tables for each object type
c(adata_item = "x_item") will copy x_item from the slot in x to
adata_item in the corresponding slot of new AnnData object
FALSE will avoid copying anything to the slot
c("x_item") is equivalent to c(x_item = "x_item")
SingleCellExperiment objectThis table describes how slots in a
SingleCellExperiment::SingleCellExperiment object to the new AnnData
object.
From SingleCellExperiment |
To AnnData |
Example mapping argument | Default |
assays(x) |
adata$X |
x_mapping = "counts" |
Nothing is copied to X |
assays(x) |
adata$layers |
layers_mapping = c(counts = "counts") |
All items are copied by name |
colData(x) |
adata$obs |
obs_mapping = c(n_counts = "n_counts", cell_type = "CellType") |
All columns are copied by name |
rowData(x) |
adata$var |
var_mapping = c(n_cells = "n_cells", pct_zero = "PctZero") |
All columns are copied by name |
reducedDims(x) |
adata$obsm |
obsm_mapping = c(X_pca = "pca") |
All items are copied by name |
featureLoadings(reducedDims(x)) |
adata$varm |
varm_mapping = c(PCs = "pca") |
Feature loadings from all SingleCellExperiment::LinearEmbeddingMatrix objects in reducedDims(x) |
colPairs(x) |
adata$obsp |
obsp_mapping = c(connectivities = "RNA_nn") |
All items are copied by name |
rowPairs(x) |
adata$varp |
varp_mapping = c(similarities = "gene_overlaps") |
All items are copied by name |
metadata(x) |
adata$uns |
uns_mapping = c(metadata = "project_metadata") |
All items are copied by name |
If assayNames(x) is NULL or any assay names are empty they will
automatically be named with a warning:
Examples:
Old names: NULL -> New names: "assay1", "assay2", ...
Old names: "counts" -> New names: "counts", "assay2"
Seurat objectOnly one assay can be converted from a SeuratObject::Seurat object to
an AnnData object at a time. This can be controlled using the
assay_name argument. By default, the current default assay will be used.
This table describes how slots in a SeuratObject::Seurat object to the
new AnnData object.
From Seurat |
To AnnData |
Example mapping argument | Default |
Layers(x) |
adata$X |
x_mapping = "counts" |
Nothing is copied to X |
Layers(x) |
adata$layers |
layers_mapping = c(counts = "counts") |
All items are copied by name |
x[[]] |
adata$obs |
obs_mapping = c(n_counts = "n_counts", cell_type = "CellType") |
All columns are copied by name |
x[[assay_name]][[]] |
adata$var |
var_mapping = c(n_cells = "n_cells", pct_zero = "PctZero") |
All columns are copied by name |
Reductions(x) |
adata$obsm |
obsm_mapping = c(X_pca = "pca") |
All embeddings matching assay_name are copied by name |
Loadings(x) |
adata$varm |
varm_mapping = c(PCs = "pca") |
All valid loadings are copied by name |
Graphs(x) |
adata$obsp |
obsp_mapping = c(connectivities = "RNA_nn") |
All graphs matching assay_name are copied by name |
Misc(x) |
adata$varp |
varp_mapping = c(similarities = "gene_overlaps") |
No data is copied to varp |
Misc(x) |
adata$uns |
uns_mapping = c(metadata = "project_metadata") |
All items are copied by name |
By default, all graphs in a SeuratObject::Seurat object that match the
assay being converted are copied to the obsp slot of the new AnnData
object. If a graph does not have an associated assay:
If assay_name is the default assay, they will be converted with a
warning
if assay_name is not the default assay, they will be skipped with a
warning
To override this behaviour, provide a custom mapping using the
obsp_mapping argument.
A SeuratObject::Seurat is more flexible in terms of the dimensions of
items that can be stored in various slots. For example, a Layer does not
have to match the dimensions of the whole object. If an item has
unexpected dimensions, it will be skipped with a warning.
Other AnnData creators:
AnnData(),
read_h5ad(),
read_zarr()
Other object converters:
as_HDF5AnnData(),
as_InMemoryAnnData(),
as_ReticulateAnnData(),
as_Seurat(),
as_SingleCellExperiment(),
as_ZarrAnnData(),
reticulate-helpers
# Convert a Seurat object to an AnnData object library(Seurat) counts <- matrix(rbinom(20000, 1000, .001), nrow = 100) obj <- CreateSeuratObject(counts = counts) obj <- NormalizeData(obj) obj <- FindVariableFeatures(obj) obj <- ScaleData(obj) obj <- RunPCA(obj, npcs = 10L) obj <- FindNeighbors(obj) obj <- RunUMAP(obj, dims = 1:10) as_AnnData(obj) # Convert a SingleCellExperiment object to an AnnData object library(SingleCellExperiment) sce <- SingleCellExperiment( assays = list(counts = matrix(1:5, 5L, 3L)), colData = DataFrame(cell = 1:3, row.names = paste0("Cell", 1:3)), rowData = DataFrame(gene = 1:5, row.names = paste0("Gene", 1:5)) ) as_AnnData(sce)# Convert a Seurat object to an AnnData object library(Seurat) counts <- matrix(rbinom(20000, 1000, .001), nrow = 100) obj <- CreateSeuratObject(counts = counts) obj <- NormalizeData(obj) obj <- FindVariableFeatures(obj) obj <- ScaleData(obj) obj <- RunPCA(obj, npcs = 10L) obj <- FindNeighbors(obj) obj <- RunUMAP(obj, dims = 1:10) as_AnnData(obj) # Convert a SingleCellExperiment object to an AnnData object library(SingleCellExperiment) sce <- SingleCellExperiment( assays = list(counts = matrix(1:5, 5L, 3L)), colData = DataFrame(cell = 1:3, row.names = paste0("Cell", 1:3)), rowData = DataFrame(gene = 1:5, row.names = paste0("Gene", 1:5)) ) as_AnnData(sce)
AnnData to a Seurat
Convert an AnnData object to a Seurat object
as_Seurat( adata, assay_name = "RNA", x_mapping = NULL, layers_mapping = TRUE, object_metadata_mapping = TRUE, assay_metadata_mapping = TRUE, reduction_mapping = TRUE, graph_mapping = TRUE, misc_mapping = TRUE )as_Seurat( adata, assay_name = "RNA", x_mapping = NULL, layers_mapping = TRUE, object_metadata_mapping = TRUE, assay_metadata_mapping = TRUE, reduction_mapping = TRUE, graph_mapping = TRUE, misc_mapping = TRUE )
adata |
The |
assay_name |
Name of the assay to be created in the new |
x_mapping |
A string specifying the name of the layer in the resulting
|
layers_mapping |
A named vector where names are names of |
object_metadata_mapping |
A named vector where names are cell metadata
columns in the resulting |
assay_metadata_mapping |
A named vector where names are variable
metadata columns in the assay of the resulting |
reduction_mapping |
A named vector where names are names of |
graph_mapping |
A named vector where names are names of |
misc_mapping |
A named vector where names are names of |
All mapping arguments expect a named character vector where names are the
names of the slot in the Seurat object and values are the keys of the
corresponding slot of adata. If TRUE, the conversion function will guess
which items to copy as described in the conversion table below. In most
cases, the default is to copy all items using the same names except where the
correspondence between objects is unclear. The reduction_mapping argument
can also accept a more complex list format, see below for details. To avoid
copying anything to a slot, set the mapping argument to FALSE. Empty
mapping arguments (NULL, c(), list()) will be treated as FALSE with
a warning. If an unnamed vector is provided, the values will be used as
names.
TRUE will guess which items to copy as described in the conversion
table
c(seurat_item = "adata_item") will copy adata_item from the slot in
adata to seurat_item in the corresponding slot of the new Seurat
object
FALSE will avoid copying anything to the slot
c("adata_item") is equivalent to c(adata_item = "adata_item")
From AnnData |
To Seurat |
Example mapping argument | Default |
adata$X |
Layers(seurat) |
x_mapping = "counts" OR layers_mapping = c(counts = NA) |
The data in adata$X is copied to a layer named X |
adata$layers |
Layers(seurat) |
layers_mapping = c(counts = "counts") |
All items are copied by name |
adata$obs |
seurat[[]] |
object_metadata_mapping = c(n_counts = "n_counts", cell_type = "CellType") |
All columns are copied by name |
adata$var |
seurat[[assay_name]][[]] |
assay_metadata_mapping = c(n_cells = "n_cells", pct_zero = "PctZero") |
All columns are copied by name |
adata$obsm |
Reductions(seurat) |
reduction_mapping = c(pca = "X_pca") OR reduction_mapping = list(pca = c(key = "PC_", embeddings = "X_pca", loadings = "PCs")) |
All items that can be coerced to a numeric matrix are copied by name without loadings except for "X_pca" for which loadings are added from "PCs" |
adata$obsp |
Graphs(seurat) |
graph_mapping = c(nn = "connectivities") |
All items are copied by name |
adata$varp |
NA | NA | There is no corresponding slot for varp |
adata$uns |
Misc(seurat) |
misc_mapping = c(project_metadata = "metadata") |
All items are copied by name |
reduction_mapping argumentFor the simpler named vector format, the names should be the names of
Embeddings in the resulting Seurat object, and the values
should be the keys of obsm in adata. A key will created from the obsm
key.
For more advanced mapping, use the list format where each item is a vector
with the following names defining arguments to
SeuratObject::CreateDimReducObject():
key: the key of the resulting SeuratObject::DimReduc object, passed
to the key argument after processing with SeuratObject::Key()
embeddings: a key of the obsm slot in adata,
adata$obsm[[embeddings]] is passed to the embeddings argument
loadings: a key of the varm slot in adata (optional),
adata$varm[[loadings]] is passed to the loadings argument
x_mapping and layers_mapping argumentsIn order to specify where the data in adata$X will be stored in the
Layers(seurat) slot of the resulting object, you can use either the x_mapping
argument or the layers_mapping argument.
If you use x_mapping, it should be a string specifying the name of the layer
in Layers(seurat) where the data in adata$X will be stored.
If you use layers_mapping, it should be a named vector where names are names
of Layers(seurat) and values are keys of layers in adata.
In order to indicate the adata$X slot, you use NA as the value in the vector.
The name you provide for x_mapping may not be a name in layers_mapping.
A Seurat object containing the requested data from adata
Other object converters:
as_AnnData(),
as_HDF5AnnData(),
as_InMemoryAnnData(),
as_ReticulateAnnData(),
as_SingleCellExperiment(),
as_ZarrAnnData(),
reticulate-helpers
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) ) # Default usage seurat <- ad$as_Seurat( assay_name = "RNA", x_mapping = "counts", layers_mapping = TRUE, object_metadata_mapping = TRUE, assay_metadata_mapping = TRUE, reduction_mapping = TRUE, graph_mapping = TRUE, misc_mapping = TRUE )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) ) # Default usage seurat <- ad$as_Seurat( assay_name = "RNA", x_mapping = "counts", layers_mapping = TRUE, object_metadata_mapping = TRUE, assay_metadata_mapping = TRUE, reduction_mapping = TRUE, graph_mapping = TRUE, misc_mapping = TRUE )
AnnData to a SingleCellExperiment
Convert an AnnData object to a SingleCellExperiment object
as_SingleCellExperiment( adata, x_mapping = NULL, assays_mapping = TRUE, colData_mapping = TRUE, rowData_mapping = TRUE, reducedDims_mapping = TRUE, colPairs_mapping = TRUE, rowPairs_mapping = TRUE, metadata_mapping = TRUE )as_SingleCellExperiment( adata, x_mapping = NULL, assays_mapping = TRUE, colData_mapping = TRUE, rowData_mapping = TRUE, reducedDims_mapping = TRUE, colPairs_mapping = TRUE, rowPairs_mapping = TRUE, metadata_mapping = TRUE )
adata |
The |
x_mapping |
A string specifying the name of the assay in the resulting
|
assays_mapping |
A named vector where names are names of |
colData_mapping |
A named vector where names are columns of |
rowData_mapping |
A named vector where names are columns of |
reducedDims_mapping |
A named vector where names are names of
|
colPairs_mapping |
A named vector where names are names of |
rowPairs_mapping |
A named vector where names are names of |
metadata_mapping |
A named vector where names are names of |
All mapping arguments expect a named character vector where names are the
names of the slot in the SingleCellExperiment object and values are the
keys of the corresponding slot of adata. If TRUE, the conversion function
will guess which items to copy as described in the conversion tables below.
In most cases, the default is to copy all items using the same names except
where the correspondence between objects is unclear. The
reducedDims_mapping argument can also accept a more complex list format,
see below for details. To avoid copying anything to a slot, set the mapping
argument to FALSE. Empty mapping arguments (NULL, c(), list()) will
be treated as FALSE with a warning. If an unnamed vector is provided, the
values will be used as names.
TRUE will guess which items to copy as described in the conversion
table
c(sce_item = "adata_item") will copy adata_item from the slot in
adata to sce_item in the corresponding slot of the new
SingleCellExperiment object
FALSE will avoid copying anything to the slot
c("adata_item") is equivalent to c(adata_item = "adata_item")
From AnnData |
To SingleCellExperiment |
Example mapping argument | Default |
adata$X |
assays(sce) |
x_mapping = "counts" |
The data in adata$X is copied to the assay named X |
adata$layers |
assays(sce) |
assays_mapping = c(counts = "counts") |
All items are copied by name |
adata$obs |
colData(sce) |
colData_mapping = c(n_counts = "n_counts", cell_type = "CellType") |
All columns are copied by name |
adata$var |
rowData(sce) |
rowData_mapping = c(n_cells = "n_cells", pct_zero = "PctZero") |
All columns are copied by name |
adata$obsm |
reducedDims(sce) |
reducedDims_mapping = c(pca = "X_pca") OR reducedDims_mapping = list(pca = c(sampleFactors = "X_pca", featureLoadings = "PCs", metadata = "pca_metadata")) |
All items are copied by name without loadings except for "X_pca" for which loadings are added from "PCs" |
adata$obsp |
colPairs(sce) |
colPairs_mapping = c(nn = "connectivities") |
All items are copied by name |
adata$varp |
rowPairs(sce) |
rowPairs_mapping = c(gene_overlaps = "similarities") |
All items are copied by name |
adata$uns |
metadata(sce) |
uns_mapping = c(project_metadata = "metadata") |
All items are copied by name |
reducedDims_mapping argumentFor the simpler named vector format, the names should be the names of
reducedDims in the resulting SingleCellExperiment object, and the values
should be the keys of obsm in adata.
For more advanced mapping, use the list format where each item is a vector
with the following names used to create a
SingleCellExperiment::LinearEmbeddingMatrix (if featureLoadings or
metadata is provided):
sampleFactors: a key of the obsm slot in adata,
adata$obsm[[sampleFactors]] is passed to the sampleFactors argument
featureLoadings: a key of the varm slot in adata (optional),
adata$varm[[featureLoadings]] is passed to the featureLoadings argument
metadata: a key of the uns slot in adata (optional),
adata$uns[[metadata]] is passed to the metadata argument
x_mapping and assays_mapping argumentsIn order to specify where the data in adata$X will be stored in the
assays(sce) slot of the resulting object, you can use either the
x_mapping argument or the assays_mapping argument.
If you use x_mapping, it should be a string specifying the name of the
layer in assays(sce) where the data in adata$X will be stored.
If you use assays_mapping, it should be a named vector where names are
names of assays(sce) and values are keys of layers in adata.
In order to indicate the adata$X slot, you use NA as the value in the
vector. The name you provide for x_mapping may not be a name in
assays_mapping.
A SingleCellExperiment object containing the requested data from
adata
Other object converters:
as_AnnData(),
as_HDF5AnnData(),
as_InMemoryAnnData(),
as_ReticulateAnnData(),
as_Seurat(),
as_ZarrAnnData(),
reticulate-helpers
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) ) # Default usage sce <- ad$as_SingleCellExperiment( assays_mapping = TRUE, colData_mapping = TRUE, rowData_mapping = TRUE, reducedDims_mapping = TRUE, colPairs_mapping = TRUE, rowPairs_mapping = TRUE, metadata_mapping = TRUE )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) ) # Default usage sce <- ad$as_SingleCellExperiment( assays_mapping = TRUE, colData_mapping = TRUE, rowData_mapping = TRUE, reducedDims_mapping = TRUE, colPairs_mapping = TRUE, rowPairs_mapping = TRUE, metadata_mapping = TRUE )
Generate a mock synthetic dataset with different types of columns and layers. This is primarily designed for use in tests, examples, vignettes and other documentation but is also provided to users for creating reproducible examples.
Use get_generator_types() to get the available types for each slot.
generate_dataset( n_obs = 10L, n_vars = 20L, x_type = "numeric_matrix", layer_types = get_generator_types(slot = "layers"), obs_types = get_generator_types(slot = "obs"), var_types = get_generator_types(slot = "var"), obsm_types = get_generator_types(slot = "obsm"), varm_types = get_generator_types(slot = "varm"), obsp_types = get_generator_types(slot = "obsp"), varp_types = get_generator_types(slot = "varp"), uns_types = get_generator_types(slot = "uns"), example = FALSE, format = c("list", "AnnData", "SingleCellExperiment", "Seurat") ) get_generator_types(example = FALSE, slot = NULL)generate_dataset( n_obs = 10L, n_vars = 20L, x_type = "numeric_matrix", layer_types = get_generator_types(slot = "layers"), obs_types = get_generator_types(slot = "obs"), var_types = get_generator_types(slot = "var"), obsm_types = get_generator_types(slot = "obsm"), varm_types = get_generator_types(slot = "varm"), obsp_types = get_generator_types(slot = "obsp"), varp_types = get_generator_types(slot = "varp"), uns_types = get_generator_types(slot = "uns"), example = FALSE, format = c("list", "AnnData", "SingleCellExperiment", "Seurat") ) get_generator_types(example = FALSE, slot = NULL)
n_obs |
Number of observations to generate |
n_vars |
Number of variables to generate |
x_type |
Type of matrix to generate for |
layer_types |
Types of matrices to generate for |
obs_types |
Types of vectors to generate for |
var_types |
Types of vectors to generate for |
obsm_types |
Types of matrices to generate for |
varm_types |
Types of matrices to generate for |
obsp_types |
Types of matrices to generate for |
varp_types |
Types of matrices to generate for |
uns_types |
Types of objects to generate for |
example |
If |
format |
Object type to output, one of "list", "AnnData", "SingleCellExperiment", or "Seurat". |
slot |
Which slot to return types for, if |
To generate no data for a given slot, set the matching type argument to
NULL or an empty vector, e.g. obs_types = c() will generate an empty
obs data frame.
When generating SingleCellExperiment or Seurat objects, only some of the
generated slots will be included in the output object. To generate a more
complete object, use format = "AnnData" followed by
adata$as_SingleCellExperiment() or adata$as_Seurat().
Use get_generator_types() to get a list of the available types for each
slot, or for a specific slot by setting slot. If example = TRUE, only the
example types are returned.
For generate_dataset(), an object as defined by output containing
the generated dataset
For get_generator_types(), a named list of character vectors or a
single character vector if slot is not NULL
# Generate all types as a list dummy <- generate_dataset() # Generate the example types dummy_example <- generate_dataset(example = TRUE) # Generate an AnnData dummy_anndata <- generate_dataset(format = "AnnData", example = TRUE) # Generate a SingleCellExperiment if (rlang::is_installed("SingleCellExperiment")) { dummy_sce <- generate_dataset(format = "SingleCellExperiment", example = TRUE) } # Generate a Seurat object if (rlang::is_installed("SeuratObject")) { dummy_seurat <- generate_dataset(format = "Seurat", example = TRUE) } # Get all available generator types get_generator_types() # Get generator types for a specific slot get_generator_types(slot = "obs") # Get generator types used when example = TRUE get_generator_types(example = TRUE)# Generate all types as a list dummy <- generate_dataset() # Generate the example types dummy_example <- generate_dataset(example = TRUE) # Generate an AnnData dummy_anndata <- generate_dataset(format = "AnnData", example = TRUE) # Generate a SingleCellExperiment if (rlang::is_installed("SingleCellExperiment")) { dummy_sce <- generate_dataset(format = "SingleCellExperiment", example = TRUE) } # Generate a Seurat object if (rlang::is_installed("SeuratObject")) { dummy_seurat <- generate_dataset(format = "Seurat", example = TRUE) } # Get all available generator types get_generator_types() # Get generator types for a specific slot get_generator_types(slot = "obs") # Get generator types used when example = TRUE get_generator_types(example = TRUE)
Implementation of an HDF5-backed AnnData object. This class provides an
interface to a H5AD file and minimal data is stored in memory until it is
requested by the user. It is primarily designed as an intermediate object
when reading/writing H5AD files but can be useful for accessing parts of
large files.
See AnnData-usage for details on creating and using AnnData objects.
An HDF5AnnData object
anndataR::AbstractAnnData -> HDF5AnnData
XSee AnnData-usage
layersSee AnnData-usage
obsmSee AnnData-usage
varmSee AnnData-usage
obspSee AnnData-usage
varpSee AnnData-usage
obsSee AnnData-usage
varSee AnnData-usage
obs_namesSee AnnData-usage
var_namesSee AnnData-usage
unsSee AnnData-usage
anndataR::AbstractAnnData$as_HDF5AnnData()anndataR::AbstractAnnData$as_InMemoryAnnData()anndataR::AbstractAnnData$as_ReticulateAnnData()anndataR::AbstractAnnData$as_Seurat()anndataR::AbstractAnnData$as_SingleCellExperiment()anndataR::AbstractAnnData$as_ZarrAnnData()anndataR::AbstractAnnData$print()anndataR::AbstractAnnData$shape()anndataR::AbstractAnnData$write_h5ad()anndataR::AbstractAnnData$write_zarr()new()
Close the HDF5 file when the object is garbage collected
HDF5AnnData constructor
HDF5AnnData$new(
file,
X = NULL,
obs = NULL,
var = NULL,
layers = NULL,
obsm = NULL,
varm = NULL,
obsp = NULL,
varp = NULL,
uns = NULL,
shape = NULL,
mode = c("a", "r", "r+", "w", "w-", "x"),
compression = c("none", "gzip", "lzf"),
chunk_size = "auto"
)fileThe file name (character) of the .h5ad file. If this file
already exits, other arguments must be NULL.
XSee the X slot in AnnData-usage
obsSee the obs slot in AnnData-usage
varSee the var slot in AnnData-usage
layersSee the layers slot in AnnData-usage
obsmSee the obsm slot in AnnData-usage
varmSee the varm slot in AnnData-usage
obspSee the obsp slot in AnnData-usage
varpSee the varp slot in AnnData-usage
unsSee the uns slot in AnnData-usage
shapeShape tuple (e.g. c(n_obs, n_vars)). Can be provided if
both X or obs and var are not provided.
modeThe mode to open the HDF5 file. See as_HDF5AnnData() for
details
compressionThe compression algorithm to use. See
as_HDF5AnnData() for details
chunk_sizeThe target chunk size in bytes. See
as_HDF5AnnData() for details
The constructor creates a new HDF5 AnnData interface object. This can
either be used to either connect to an existing .h5ad file or to
create a new one. If any additional slot arguments are set an existing
file will be overwritten.
obs_keys()
See AnnData-usage
HDF5AnnData$obs_keys()
var_keys()
See AnnData-usage
HDF5AnnData$var_keys()
layers_keys()
See AnnData-usage
HDF5AnnData$layers_keys()
obsm_keys()
See AnnData-usage
HDF5AnnData$obsm_keys()
varm_keys()
See AnnData-usage
HDF5AnnData$varm_keys()
obsp_keys()
See AnnData-usage
HDF5AnnData$obsp_keys()
varp_keys()
See AnnData-usage
HDF5AnnData$varp_keys()
uns_keys()
See AnnData-usage
HDF5AnnData$uns_keys()
close()
Close the HDF5 file
HDF5AnnData$close()
n_obs()
See the n_obs field in AnnData-usage
HDF5AnnData$n_obs()
n_vars()
See the n_vars field in AnnData-usage
HDF5AnnData$n_vars()
AnnData-usage for details on creating and using AnnData objects
Other AnnData classes:
AbstractAnnData,
AnnDataView,
InMemoryAnnData,
ReticulateAnnData,
ZarrAnnData
Implementation of an in-memory AnnData object where data is stored within
the R session. This is the simplest back end and will be most familiar to
users. It is want you will want to use in most cases where you want to
interact with an AnnData object.
See AnnData-usage for details on creating and using AnnData objects.
An InMemoryAnnData object
anndataR::AbstractAnnData -> InMemoryAnnData
XSee AnnData-usage
layersSee AnnData-usage
obsSee AnnData-usage
varSee AnnData-usage
obs_namesSee AnnData-usage
var_namesSee AnnData-usage
obsmSee AnnData-usage
varmSee AnnData-usage
obspSee AnnData-usage
varpSee AnnData-usage
unsSee AnnData-usage
anndataR::AbstractAnnData$as_HDF5AnnData()anndataR::AbstractAnnData$as_InMemoryAnnData()anndataR::AbstractAnnData$as_ReticulateAnnData()anndataR::AbstractAnnData$as_Seurat()anndataR::AbstractAnnData$as_SingleCellExperiment()anndataR::AbstractAnnData$as_ZarrAnnData()anndataR::AbstractAnnData$layers_keys()anndataR::AbstractAnnData$n_obs()anndataR::AbstractAnnData$n_vars()anndataR::AbstractAnnData$obs_keys()anndataR::AbstractAnnData$obsm_keys()anndataR::AbstractAnnData$obsp_keys()anndataR::AbstractAnnData$print()anndataR::AbstractAnnData$shape()anndataR::AbstractAnnData$uns_keys()anndataR::AbstractAnnData$var_keys()anndataR::AbstractAnnData$varm_keys()anndataR::AbstractAnnData$varp_keys()anndataR::AbstractAnnData$write_h5ad()anndataR::AbstractAnnData$write_zarr()new()
Creates a new instance of an in-memory AnnData object.
Inherits from AbstractAnnData.
InMemoryAnnData$new( X = NULL, obs = NULL, var = NULL, layers = NULL, obsm = NULL, varm = NULL, obsp = NULL, varp = NULL, uns = NULL, shape = NULL )
XSee the X slot in AnnData-usage
obsSee the obs slot in AnnData-usage
varSee the var slot in AnnData-usage
layersSee the layers slot in AnnData-usage
obsmSee the obsm slot in AnnData-usage
varmSee the varm slot in AnnData-usage
obspSee the obsp slot in AnnData-usage
varpSee the varp slot in AnnData-usage
unsSee the uns slot in AnnData-usage
shapeShape tuple (e.g. c(n_obs, n_vars)). Can be provided if
both X or obs and var are not provided.
clone()
The objects of this class are cloneable with this method.
InMemoryAnnData$clone(deep = FALSE)
deepWhether to make a deep clone.
AnnData-usage for details on creating and using AnnData objects
Other AnnData classes:
AbstractAnnData,
AnnDataView,
HDF5AnnData,
ReticulateAnnData,
ZarrAnnData
## complete example ad <- AnnData( X = matrix(1:15, 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) ) ad ## minimum example AnnData( obs = data.frame(row.names = letters[1:10]), var = data.frame(row.names = LETTERS[1:5]) )## complete example ad <- AnnData( X = matrix(1:15, 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) ) ad ## minimum example AnnData( obs = data.frame(row.names = letters[1:10]), var = data.frame(row.names = LETTERS[1:5]) )
Read data from a H5AD file
read_h5ad( path, as = c("InMemoryAnnData", "HDF5AnnData", "SingleCellExperiment", "Seurat"), mode = c("r", "r+", "a", "w", "w-", "x"), ... )read_h5ad( path, as = c("InMemoryAnnData", "HDF5AnnData", "SingleCellExperiment", "Seurat"), mode = c("r", "r+", "a", "w", "w-", "x"), ... )
path |
Path to the H5AD file to read |
as |
The type of object to return. One of:
|
mode |
The mode to open the HDF5 file.
|
... |
Extra arguments provided to the |
The object specified by as
Other AnnData creators:
AnnData(),
as_AnnData(),
read_zarr()
h5ad_file <- system.file("extdata", "example.h5ad", package = "anndataR") # Read the H5AD as a SingleCellExperiment object if (requireNamespace("SingleCellExperiment", quietly = TRUE)) { sce <- read_h5ad(h5ad_file, as = "SingleCellExperiment") } # Read the H5AD as a Seurat object if (requireNamespace("SeuratObject", quietly = TRUE)) { seurat <- read_h5ad(h5ad_file, as = "Seurat") }h5ad_file <- system.file("extdata", "example.h5ad", package = "anndataR") # Read the H5AD as a SingleCellExperiment object if (requireNamespace("SingleCellExperiment", quietly = TRUE)) { sce <- read_h5ad(h5ad_file, as = "SingleCellExperiment") } # Read the H5AD as a Seurat object if (requireNamespace("SeuratObject", quietly = TRUE)) { seurat <- read_h5ad(h5ad_file, as = "Seurat") }
Read data from a Zarr store
read_zarr( path, as = c("InMemoryAnnData", "ZarrAnnData", "SingleCellExperiment", "Seurat"), mode = c("r", "r+", "a", "w", "w-", "x"), ... )read_zarr( path, as = c("InMemoryAnnData", "ZarrAnnData", "SingleCellExperiment", "Seurat"), mode = c("r", "r+", "a", "w", "w-", "x"), ... )
path |
Path to the Zarr store to read |
as |
The type of object to return. One of:
|
mode |
The mode to open the Zarr file.
|
... |
Extra arguments provided to the |
The object specified by as
Other AnnData creators:
AnnData(),
as_AnnData(),
read_h5ad()
# Please use "example_v3.zarr.zip" for AnnData stored as Zarr version 3 zarr_dir <- system.file("extdata", "example_v2.zarr.zip", package = "anndataR") td <- tempdir(check = TRUE) unzip(zarr_dir, exdir = td) zarr_store <- file.path(td, "example_v2.zarr") # Read the Zarr as a SingleCellExperiment object if (requireNamespace("SingleCellExperiment", quietly = TRUE)) { sce <- read_zarr(zarr_store, as = "SingleCellExperiment") } # Read the Zarr as a Seurat object if (requireNamespace("SeuratObject", quietly = TRUE)) { seurat <- read_zarr(zarr_store, as = "Seurat") }# Please use "example_v3.zarr.zip" for AnnData stored as Zarr version 3 zarr_dir <- system.file("extdata", "example_v2.zarr.zip", package = "anndataR") td <- tempdir(check = TRUE) unzip(zarr_dir, exdir = td) zarr_store <- file.path(td, "example_v2.zarr") # Read the Zarr as a SingleCellExperiment object if (requireNamespace("SingleCellExperiment", quietly = TRUE)) { sce <- read_zarr(zarr_store, as = "SingleCellExperiment") } # Read the Zarr as a Seurat object if (requireNamespace("SeuratObject", quietly = TRUE)) { seurat <- read_zarr(zarr_store, as = "Seurat") }
This file contains helper functions that enable seamless conversion between R and Python AnnData objects using the reticulate package. These functions provide automatic S3 method dispatch for converting AnnData objects across the R-Python boundary.
## S3 method for class 'collections.abc.Mapping' py_to_r(x) ## S3 method for class 'anndata._core.anndata.AnnData' py_to_r(x) ## S3 method for class 'AbstractAnnData' r_to_py(x, convert = TRUE)## S3 method for class 'collections.abc.Mapping' py_to_r(x) ## S3 method for class 'anndata._core.anndata.AnnData' py_to_r(x) ## S3 method for class 'AbstractAnnData' r_to_py(x, convert = TRUE)
x |
An AbstractAnnData object (any anndataR implementation) |
convert |
Whether to convert the result (passed to reticulate) |
The main conversion functions include:
py_to_r.anndata._core.anndata.AnnData: Converts Python AnnData
objects to R ReticulateAnnData objects
r_to_py.AbstractAnnData: Converts R AbstractAnnData objects
to Python AnnData objects
py_to_r.collections.abc.Mapping: Converts Python mapping
objects to R lists
These functions are automatically registered as S3 methods and are called
when using reticulate::py_to_r() and reticulate::r_to_py() on compatible
objects.
A ReticulateAnnData object wrapping the Python object
A Python AnnData object
Other object converters:
as_AnnData(),
as_HDF5AnnData(),
as_InMemoryAnnData(),
as_ReticulateAnnData(),
as_Seurat(),
as_SingleCellExperiment(),
as_ZarrAnnData()
# Requires Python anndata to be installed if (requireNamespace("reticulate", quietly = TRUE) && reticulate::py_module_available("anndata")) { library(reticulate) # Create Python AnnData object ad_py <- import("anndata", convert = FALSE) py_adata <- ad_py$AnnData(X = r_to_py(matrix(1:12, 3, 4))) # Automatic conversion to R (uses py_to_r.anndata._core.anndata.AnnData) r_adata <- py_to_r(py_adata) # Automatic conversion back to Python (uses r_to_py.AbstractAnnData) py_adata2 <- r_to_py(r_adata) }# Requires Python anndata to be installed if (requireNamespace("reticulate", quietly = TRUE) && reticulate::py_module_available("anndata")) { library(reticulate) # Create Python AnnData object ad_py <- import("anndata", convert = FALSE) py_adata <- ad_py$AnnData(X = r_to_py(matrix(1:12, 3, 4))) # Automatic conversion to R (uses py_to_r.anndata._core.anndata.AnnData) r_adata <- py_to_r(py_adata) # Automatic conversion back to Python (uses r_to_py.AbstractAnnData) py_adata2 <- r_to_py(r_adata) }
Implementation of an AnnData object that wraps a Python anndata
AnnData object using reticulate. This allows direct interaction with
Python AnnData objects while maintaining the R interface. It is useful when
you already have a Python AnnData or to access functionality that has not
yet been implemented in anndataR.
See AnnData-usage for details on creating and using AnnData objects.
A ReticulateAnnData object
anndataR::AbstractAnnData -> ReticulateAnnData
XSee AnnData-usage
layersSee AnnData-usage
obsSee AnnData-usage
varSee AnnData-usage
obs_namesSee AnnData-usage
var_namesSee AnnData-usage
obsmSee AnnData-usage
varmSee AnnData-usage
obspSee AnnData-usage
varpSee AnnData-usage
unsSee AnnData-usage
anndataR::AbstractAnnData$as_HDF5AnnData()anndataR::AbstractAnnData$as_InMemoryAnnData()anndataR::AbstractAnnData$as_ReticulateAnnData()anndataR::AbstractAnnData$as_Seurat()anndataR::AbstractAnnData$as_SingleCellExperiment()anndataR::AbstractAnnData$as_ZarrAnnData()anndataR::AbstractAnnData$layers_keys()anndataR::AbstractAnnData$obs_keys()anndataR::AbstractAnnData$obsm_keys()anndataR::AbstractAnnData$obsp_keys()anndataR::AbstractAnnData$print()anndataR::AbstractAnnData$shape()anndataR::AbstractAnnData$uns_keys()anndataR::AbstractAnnData$var_keys()anndataR::AbstractAnnData$varm_keys()anndataR::AbstractAnnData$varp_keys()anndataR::AbstractAnnData$write_h5ad()anndataR::AbstractAnnData$write_zarr()new()
ReticulateAnnData constructor
ReticulateAnnData$new( py_anndata = NULL, X = NULL, obs = NULL, var = NULL, layers = NULL, obsm = NULL, varm = NULL, obsp = NULL, varp = NULL, uns = NULL, shape = NULL )
py_anndataA Python AnnData object created using reticulate, or NULL to create a new empty Python AnnData object
XSee the X slot in AnnData-usage (only used if py_anndata is NULL)
obsSee the obs slot in AnnData-usage (only used if py_anndata is NULL)
varSee the var slot in AnnData-usage (only used if py_anndata is NULL)
layersSee the layers slot in AnnData-usage (only used if py_anndata is NULL)
obsmSee the obsm slot in AnnData-usage (only used if py_anndata is NULL)
varmSee the varm slot in AnnData-usage (only used if py_anndata is NULL)
obspSee the obsp slot in AnnData-usage (only used if py_anndata is NULL)
varpSee the varp slot in AnnData-usage (only used if py_anndata is NULL)
unsSee the uns slot in AnnData-usage (only used if py_anndata is NULL)
shapeShape tuple (e.g. c(n_obs, n_vars)). Can be provided if
both X or obs and var are not provided. (only used if py_anndata is NULL)
The constructor creates a new ReticulateAnnData interface object that
wraps a Python AnnData object. If py_anndata is provided, it must be
a valid Python AnnData object. If NULL, a new Python AnnData object
will be created using the other provided arguments.
n_obs()
See the n_obs field in AnnData-usage
ReticulateAnnData$n_obs()
n_vars()
See the n_vars field in AnnData-usage
ReticulateAnnData$n_vars()
py_anndata()
Get the underlying Python AnnData object
ReticulateAnnData$py_anndata()
The Python AnnData object wrapped by this ReticulateAnnData
AnnData-usage for details on creating and using AnnData objects
Other AnnData classes:
AbstractAnnData,
AnnDataView,
HDF5AnnData,
InMemoryAnnData,
ZarrAnnData
Write an H5AD file
write_h5ad( object, path, compression = c("none", "gzip", "lzf"), chunk_size = "auto", mode = c("w-", "r", "r+", "a", "w", "x"), ... )write_h5ad( object, path, compression = c("none", "gzip", "lzf"), chunk_size = "auto", mode = c("w-", "r", "r+", "a", "w", "x"), ... )
object |
The object to write, either a
|
path |
Path of the file to write to |
compression |
The compression algorithm to use when writing the HDF5
file. Can be one of |
chunk_size |
The target chunk size in bytes to use when writing HDF5
datasets. When |
mode |
The mode to open the HDF5 file.
|
... |
Additional arguments passed to |
Compression is currently not supported for Boolean arrays, they will be written uncompressed.
NULL valuesFor compatibility with changes in Python anndata 0.12.0, NULL values
in uns are written to H5AD files as a NULL dataset (instead of not being
written at all). To disable this behaviour, set
option(anndataR.write_null = FALSE). This may be required to allow the file
to be read by older versions of Python anndata.
path invisibly
adata <- 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) ) h5ad_file <- tempfile(fileext = ".h5ad") adata$write_h5ad(h5ad_file) # Write a SingleCellExperiment as an H5AD if (requireNamespace("SingleCellExperiment", quietly = TRUE)) { ncells <- 100 counts <- matrix(rpois(20000, 5), ncol = ncells) logcounts <- log2(counts + 1) pca <- matrix(runif(ncells * 5), ncells) tsne <- matrix(rnorm(ncells * 2), ncells) sce <- SingleCellExperiment::SingleCellExperiment( assays = list(counts = counts, logcounts = logcounts), reducedDims = list(PCA = pca, tSNE = tsne) ) adata <- as_AnnData(sce) h5ad_file <- tempfile(fileext = ".h5ad") adata$write_h5ad(h5ad_file) } # Write a Seurat as a H5AD if (requireNamespace("Seurat", quietly = TRUE)) { library(Seurat) counts <- matrix(1:15, 5L, 3L) dimnames(counts) <- list( LETTERS[1:5], letters[1:3] ) cell.metadata <- data.frame( row.names = letters[1:3], cell = 1:3 ) obj <- CreateSeuratObject(counts, meta.data = cell.metadata) gene.metadata <- data.frame( row.names = LETTERS[1:5], gene = 1:5 ) obj[["RNA"]] <- AddMetaData(GetAssay(obj), gene.metadata) adata <- as_AnnData(obj) h5ad_file <- tempfile(fileext = ".h5ad") adata$write_h5ad(h5ad_file) }adata <- 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) ) h5ad_file <- tempfile(fileext = ".h5ad") adata$write_h5ad(h5ad_file) # Write a SingleCellExperiment as an H5AD if (requireNamespace("SingleCellExperiment", quietly = TRUE)) { ncells <- 100 counts <- matrix(rpois(20000, 5), ncol = ncells) logcounts <- log2(counts + 1) pca <- matrix(runif(ncells * 5), ncells) tsne <- matrix(rnorm(ncells * 2), ncells) sce <- SingleCellExperiment::SingleCellExperiment( assays = list(counts = counts, logcounts = logcounts), reducedDims = list(PCA = pca, tSNE = tsne) ) adata <- as_AnnData(sce) h5ad_file <- tempfile(fileext = ".h5ad") adata$write_h5ad(h5ad_file) } # Write a Seurat as a H5AD if (requireNamespace("Seurat", quietly = TRUE)) { library(Seurat) counts <- matrix(1:15, 5L, 3L) dimnames(counts) <- list( LETTERS[1:5], letters[1:3] ) cell.metadata <- data.frame( row.names = letters[1:3], cell = 1:3 ) obj <- CreateSeuratObject(counts, meta.data = cell.metadata) gene.metadata <- data.frame( row.names = LETTERS[1:5], gene = 1:5 ) obj[["RNA"]] <- AddMetaData(GetAssay(obj), gene.metadata) adata <- as_AnnData(obj) h5ad_file <- tempfile(fileext = ".h5ad") adata$write_h5ad(h5ad_file) }
Write a Zarr file
write_zarr( object, path, compression = c("none", "gzip", "blosc", "zstd", "lzma", "bz2", "zlib", "lz4"), mode = c("w-", "r", "r+", "a", "w", "x"), ... )write_zarr( object, path, compression = c("none", "gzip", "blosc", "zstd", "lzma", "bz2", "zlib", "lz4"), mode = c("w-", "r", "r+", "a", "w", "x"), ... )
object |
The object to write, either a
|
path |
Path of the file to write to |
compression |
The compression algorithm to use when writing the Zarr
file. Can be one of |
mode |
The mode to open the Zarr file.
|
... |
Additional arguments passed to |
NULL valuesFor compatibility with changes in Python anndata 0.12.0, NULL values
in uns are written to Zarr files as a NULL dataset (instead of not being
written at all). To disable this behaviour, set
option(anndataR.write_null = FALSE). This may be required to allow the file
to be read by older versions of Python anndata.
path invisibly
adata <- 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) ) zarr_store <- tempfile(fileext = ".zarr") adata$write_zarr(zarr_store) # Write a SingleCellExperiment as a Zarr store if (requireNamespace("SingleCellExperiment", quietly = TRUE)) { ncells <- 100 counts <- matrix(rpois(20000, 5), ncol = ncells) logcounts <- log2(counts + 1) pca <- matrix(runif(ncells * 5), ncells) tsne <- matrix(rnorm(ncells * 2), ncells) sce <- SingleCellExperiment::SingleCellExperiment( assays = list(counts = counts, logcounts = logcounts), reducedDims = list(PCA = pca, tSNE = tsne) ) adata <- as_AnnData(sce) zarr_store <- tempfile(fileext = ".zarr") adata$write_zarr(zarr_store) } # Write a Seurat as a Zarr if (requireNamespace("Seurat", quietly = TRUE)) { library(Seurat) counts <- matrix(1:15, 5L, 3L) dimnames(counts) <- list( LETTERS[1:5], letters[1:3] ) cell.metadata <- data.frame( row.names = letters[1:3], cell = 1:3 ) obj <- CreateSeuratObject(counts, meta.data = cell.metadata) gene.metadata <- data.frame( row.names = LETTERS[1:5], gene = 1:5 ) obj[["RNA"]] <- AddMetaData(GetAssay(obj), gene.metadata) adata <- as_AnnData(obj) zarr_store <- tempfile(fileext = ".zarr") adata$write_zarr(zarr_store) }adata <- 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) ) zarr_store <- tempfile(fileext = ".zarr") adata$write_zarr(zarr_store) # Write a SingleCellExperiment as a Zarr store if (requireNamespace("SingleCellExperiment", quietly = TRUE)) { ncells <- 100 counts <- matrix(rpois(20000, 5), ncol = ncells) logcounts <- log2(counts + 1) pca <- matrix(runif(ncells * 5), ncells) tsne <- matrix(rnorm(ncells * 2), ncells) sce <- SingleCellExperiment::SingleCellExperiment( assays = list(counts = counts, logcounts = logcounts), reducedDims = list(PCA = pca, tSNE = tsne) ) adata <- as_AnnData(sce) zarr_store <- tempfile(fileext = ".zarr") adata$write_zarr(zarr_store) } # Write a Seurat as a Zarr if (requireNamespace("Seurat", quietly = TRUE)) { library(Seurat) counts <- matrix(1:15, 5L, 3L) dimnames(counts) <- list( LETTERS[1:5], letters[1:3] ) cell.metadata <- data.frame( row.names = letters[1:3], cell = 1:3 ) obj <- CreateSeuratObject(counts, meta.data = cell.metadata) gene.metadata <- data.frame( row.names = LETTERS[1:5], gene = 1:5 ) obj[["RNA"]] <- AddMetaData(GetAssay(obj), gene.metadata) adata <- as_AnnData(obj) zarr_store <- tempfile(fileext = ".zarr") adata$write_zarr(zarr_store) }
Implementation of a Zarr-backed AnnData object. This class provides an
interface to a Zarr file and minimal data is stored in memory until it is
requested by the user. It is primarily designed as an intermediate object
when reading/writing Zarr files but can be useful for accessing parts of
large files.
See AnnData-usage for details on creating and using AnnData objects.
A ZarrAnnData object
anndataR::AbstractAnnData -> ZarrAnnData
XSee AnnData-usage
layersSee AnnData-usage
obsmSee AnnData-usage
varmSee AnnData-usage
obspSee AnnData-usage
varpSee AnnData-usage
obsSee AnnData-usage
varSee AnnData-usage
obs_namesSee AnnData-usage
var_namesSee AnnData-usage
unsSee AnnData-usage
anndataR::AbstractAnnData$as_HDF5AnnData()anndataR::AbstractAnnData$as_InMemoryAnnData()anndataR::AbstractAnnData$as_ReticulateAnnData()anndataR::AbstractAnnData$as_Seurat()anndataR::AbstractAnnData$as_SingleCellExperiment()anndataR::AbstractAnnData$as_ZarrAnnData()anndataR::AbstractAnnData$print()anndataR::AbstractAnnData$shape()anndataR::AbstractAnnData$write_h5ad()anndataR::AbstractAnnData$write_zarr()new()
ZarrAnnData constructor
ZarrAnnData$new(
file,
X = NULL,
obs = NULL,
var = NULL,
layers = NULL,
obsm = NULL,
varm = NULL,
obsp = NULL,
varp = NULL,
uns = NULL,
shape = NULL,
mode = c("a", "r", "r+", "w", "w-", "x"),
compression = c("none", "gzip", "blosc", "zstd", "lzma", "bz2", "zlib", "lz4")
)fileThe file name (character) of the .zarr file. If this file
already exits, other arguments must be NULL.
XSee the X slot in AnnData-usage
obsSee the obs slot in AnnData-usage
varSee the var slot in AnnData-usage
layersSee the layers slot in AnnData-usage
obsmSee the obsm slot in AnnData-usage
varmSee the varm slot in AnnData-usage
obspSee the obsp slot in AnnData-usage
varpSee the varp slot in AnnData-usage
unsSee the uns slot in AnnData-usage
shapeShape tuple (e.g. c(n_obs, n_vars)). Can be provided if
both X or obs and var are not provided.
modeThe mode to open the Zarr file. See as_ZarrAnnData() for
details
compressionThe compression algorithm to use. See
as_ZarrAnnData() for details
The constructor creates a new Zarr AnnData interface object. This can
either be used to either connect to an existing .zarr file or to
create a new one. If any additional slot arguments are set an existing
file will be overwritten.
n_obs()
See the n_obs field in AnnData-usage
ZarrAnnData$n_obs()
n_vars()
See the n_vars field in AnnData-usage
ZarrAnnData$n_vars()
obs_keys()
See AnnData-usage
ZarrAnnData$obs_keys()
var_keys()
See AnnData-usage
ZarrAnnData$var_keys()
layers_keys()
See AnnData-usage
ZarrAnnData$layers_keys()
obsm_keys()
See AnnData-usage
ZarrAnnData$obsm_keys()
varm_keys()
See AnnData-usage
ZarrAnnData$varm_keys()
obsp_keys()
See AnnData-usage
ZarrAnnData$obsp_keys()
varp_keys()
See AnnData-usage
ZarrAnnData$varp_keys()
uns_keys()
See AnnData-usage
ZarrAnnData$uns_keys()
AnnData-usage for details on creating and using AnnData objects
Other AnnData classes:
AbstractAnnData,
AnnDataView,
HDF5AnnData,
InMemoryAnnData,
ReticulateAnnData