Skip to contents

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 the X matrix

  • adata$X <- x sets the X matrix

  • adata$method() calls a method

Fields

shape

Dimensions (observations x variables) of the AnnData object

n_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 with n_obs and n_vars.

layers

Additional data layers. Must be NULL or a named list of matrices having dimensions consistent with n_obs and n_vars.

obs

Observation 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.

var

Variable 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_names

Observation 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_names

Variable 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.

obsm

Multi-dimensional observation annotation. Must be NULL or a named list of array-like elements with number of rows equal to n_obs.

varm

Multi-dimensional variable annotations. Must be NULL or a named list of array-like elements with number of rows equal to n_vars.

obsp

Observation pairs. Must be NULL or a named list of array-like elements with number of rows and columns equal to n_obs.

varp

Variable pairs. Must be NULL or a named list of array-like elements with number of rows and columns equal to n_vars.

uns

Unstructured annotations. Must be NULL or a named list.

Methods

Output methods:

write_h5ad()

Write the AnnData object to an HDF5 file, see write_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 file

as_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