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.
Back ends
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
ReticulateAnnData wraps a Python
AnnDataobject via reticulate
See the class documentation for details.
Usage
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$Xreturns theXmatrixadata$X <- xsets theXmatrixadata$method()calls a method
Value
An AnnData object inheriting from AbstractAnnData
Fields
shapeDimensions (observations x variables) of the
AnnDataobjectn_obsNumber of observations
n_varsNumber of variables
obs_keysKeys (column names) of
obsvar_keysKeys (column names) of
varlayers_keysKeys (element names) of
layersobsm_keysKeys (element names) of
obsmvarm_keysKeys (element names) of
varmobsp_keysKeys (element names) of
obspvarp_keysKeys (element names) of
varpuns_keysKeys (element names) of
uns
Slots
XThe main data matrix. Either
NULLor an observation x variable matrix (without dimnames) with dimensions consistent withn_obsandn_vars.layersAdditional data layers. Must be
NULLor a named list of matrices having dimensions consistent withn_obsandn_vars.obsObservation annotations. A
data.framewith columns containing information about observations. The number of rows ofobsdefines the observation dimension of theAnnDataobject (n_obs). IfNULL, ann_obs× 0data.framewill automatically be generated.varVariable annotations. A
data.framewith columns containing information about variables. The number of rows ofvardefines the variable dimension of theAnnDataobject (n_vars). IfNULL, ann_vars× 0data.framewill automatically be generated.obs_namesObservation names. Either
NULLor a vector of unique identifiers used to identify each row ofobsand to act as an index into the observation dimension of theAnnDataobject. For compatibility with R representations,obs_namesshould be a unique character vector.var_namesVariable names. Either
NULLor a vector of unique identifiers used to identify each row ofvarand to act as an index into the variable dimension of theAnnDataobject. For compatibility with R representations,var_namesshould be a unique character vector.obsmMulti-dimensional observation annotation. Must be
NULLor a named list of array-like elements with number of rows equal ton_obs.varmMulti-dimensional variable annotations. Must be
NULLor a named list of array-like elements with number of rows equal ton_vars.obspObservation pairs. Must be
NULLor a named list of array-like elements with number of rows and columns equal ton_obs.varpVariable pairs. Must be
NULLor a named list of array-like elements with number of rows and columns equal ton_vars.unsUnstructured annotations. Must be
NULLor a named list.
Methods
Conversion methods:
-
as_SingleCellExperiment() Convert to
SingleCellExperiment::SingleCellExperiment, seeas_SingleCellExperiment()as_Seurat()Convert to
SeuratObject::Seurat, seeas_Seurat()as_InMemoryAnnData()Convert to
InMemoryAnnData, asas_InMemoryAnnData()as_HDF5AnnData()Convert to
HDF5AnnData, seeas_HDF5AnnData()as_ReticulateAnnData()Convert to
ReticulateAnnData, seeas_ReticulateAnnData()
Output methods:
-
write_h5ad() Write the
AnnDataobject to an HDF5 file, seewrite_h5ad()
General methods:
print()Print a summary of the
AnnDataobject
Functions that can be used to create AnnData objects
AnnData()Create an InMemoryAnnData object
read_h5ad()Read an
AnnDatafrom a H5AD fileas_AnnData()Convert other objects to an
AnnDataobject
See also
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
ReticulateAnnData for the reticulate-based implementation that wraps Python AnnData objects