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. For example, the InMemoryAnnData stores
data in memory or the HDF5AnnData is backed by a H5AD file.
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$X
returns theX
matrixadata$X <- x
sets theX
matrixadata$method()
calls a method
Fields
shape
Dimensions (observations x variables) of the
AnnData
objectn_obs
Number of observations
n_vars
Number of variables
obs_keys
Keys (column names) of
obs
var_keys
Keys (column names) of
var
layers_keys
Keys (element names) of
layers
obsm_keys
Keys (element names) of
obsm
varm_keys
Keys (element names) of
varm
obsp_keys
Keys (element names) of
obsp
varp_keys
Keys (element names) of
varp
uns_keys
Keys (element names) of
uns
Slots
X
The main data matrix. Either
NULL
or an observation x variable matrix (without dimnames) with dimensions consistent withn_obs
andn_vars
.layers
Additional data layers. Must be
NULL
or a named list of matrices having dimensions consistent withn_obs
andn_vars
.obs
Observation annotations. A
data.frame
with columns containing information about observations. The number of rows ofobs
defines the observation dimension of theAnnData
object (n_obs
). IfNULL
, ann_obs
× 0data.frame
will automatically be generated.var
Variable annotations. A
data.frame
with columns containing information about variables. The number of rows ofvar
defines the variable dimension of theAnnData
object (n_vars
). IfNULL
, ann_vars
× 0data.frame
will automatically be generated.obs_names
Observation names. Either
NULL
or a vector of unique identifiers used to identify each row ofobs
and to act as an index into the observation dimension of theAnnData
object. For compatibility with R representations,obs_names
should be a unique character vector.var_names
Variable names. Either
NULL
or a vector of unique identifiers used to identify each row ofvar
and to act as an index into the variable dimension of theAnnData
object. For compatibility with R representations,var_names
should be a unique character vector.obsm
Multi-dimensional observation annotation. Must be
NULL
or a named list of array-like elements with number of rows equal ton_obs
.varm
Multi-dimensional variable annotations. Must be
NULL
or a named list of array-like elements with number of rows equal ton_vars
.obsp
Observation pairs. Must be
NULL
or a named list of array-like elements with number of rows and columns equal ton_obs
.varp
Variable pairs. Must be
NULL
or a named list of array-like elements with number of rows and columns equal ton_vars
.uns
Unstructured annotations. Must be
NULL
or 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()
Output methods:
-
write_h5ad()
Write the
AnnData
object to an HDF5 file, seewrite_h5ad()
General methods:
print()
Print a summary of the
AnnData
object
Functions that can be used to create AnnData objects
AnnData()
Create an InMemoryAnnData object
read_h5ad()
Read an
AnnData
from a H5AD fileas_AnnData()
Convert other objects to an
AnnData
object
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