Skip to contents

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.

The following functions can be used to create an object that inherits from AbstractAnnData:

Active bindings

X

NULL or an observation x variable matrix (without dimnames) consistent with the number of rows of obs and var.

layers

The layers slot. Must be NULL or a named list with with all elements having the dimensions consistent with obs and var.

obs

A data.frame with columns containing information about observations. The number of rows of obs defines the observation dimension of the AnnData object.

var

A data.frame with columns containing information about variables. The number of rows of var defines the variable dimension of the AnnData object.

obs_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 character vector.

var_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 character vector.

obsm

The obsm slot. Must be NULL or a named list with with all elements having the same number of rows as obs.

varm

The varm slot. Must be NULL or a named list with with all elements having the same number of rows as var.

obsp

The obsp slot. Must be NULL or a named list with with all elements having the same number of rows and columns as obs.

varp

The varp slot. Must be NULL or a named list with with all elements having the same number of rows and columns as var.

uns

The uns slot. Must be NULL or a named list.

Methods


Method print()

Print a summary of the AnnData object. print() methods should be implemented so that they are not computationally expensive.

Usage

AbstractAnnData$print(...)

Arguments

...

Optional arguments to print method.


Method shape()

Dimensions (observations x variables) of the AnnData object.

Usage

AbstractAnnData$shape()


Method n_obs()

Number of observations in the AnnData object.

Usage

AbstractAnnData$n_obs()


Method n_vars()

Number of variables in the AnnData object.

Usage

AbstractAnnData$n_vars()


Method obs_keys()

Keys ('column names') of obs.

Usage

AbstractAnnData$obs_keys()


Method var_keys()

Keys ('column names') of var.

Usage

AbstractAnnData$var_keys()


Method layers_keys()

Keys (element names) of layers.

Usage

AbstractAnnData$layers_keys()


Method obsm_keys()

Keys (element names) of obsm.

Usage

AbstractAnnData$obsm_keys()


Method varm_keys()

Keys (element names) of varm.

Usage

AbstractAnnData$varm_keys()


Method obsp_keys()

Keys (element names) of obsp.

Usage

AbstractAnnData$obsp_keys()


Method varp_keys()

Keys (element names) of varp.

Usage

AbstractAnnData$varp_keys()


Method uns_keys()

Keys (element names) of uns.

Usage

AbstractAnnData$uns_keys()


Method to_SingleCellExperiment()

Convert to SingleCellExperiment

Usage

AbstractAnnData$to_SingleCellExperiment()


Method to_Seurat()

Convert to Seurat

See to_Seurat() for more details on the conversion and each of the parameters.

Usage

AbstractAnnData$to_Seurat(
  assay_name = "RNA",
  layers_mapping = NULL,
  reduction_mapping = NULL,
  graph_mapping = NULL,
  misc_mapping = NULL
)

Arguments

assay_name

The name of the assay to use as the main data

layers_mapping

A named list mapping Seurat layers to AnnData layers

reduction_mapping

A named list mapping Seurat reductions to AnnData obsm/varm

graph_mapping

A named list mapping Seurat graphs to AnnData obsp/varp

misc_mapping

A named list mapping Seurat misc to AnnData uns

Returns

A Seurat object


Method to_InMemoryAnnData()

Convert to an InMemory AnnData

Usage

AbstractAnnData$to_InMemoryAnnData()


Method to_HDF5AnnData()

Convert to an HDF5 Backed AnnData

Usage

AbstractAnnData$to_HDF5AnnData(
  file,
  compression = c("none", "gzip", "lzf"),
  mode = c("w-", "r", "r+", "a", "w", "x")
)

Arguments

file

The path to the HDF5 file

compression

The compression algorithm to use when writing the HDF5 file. Can be one of "none", "gzip" or "lzf". Defaults to "none".

mode

The mode to open the HDF5 file.

  • a creates a new file or opens an existing one for read/write.

  • r+ opens an existing file for read/write.

  • w creates a file, truncating any existing ones

  • w-/x are synonyms creating a file and failing if it already exists.

Returns

An HDF5AnnData object


Method write_h5ad()

Write the AnnData object to an H5AD file.

Usage

AbstractAnnData$write_h5ad(path, compression = "gzip", mode = "w")

Arguments

path

The path to the H5AD file

compression

The compression algorithm to use when writing the HDF5 file. Can be one of "none", "gzip" or "lzf". Defaults to "none".

mode

The mode to open the HDF5 file.

  • a creates a new file or opens an existing one for read/write.

  • r+ opens an existing file for read/write.

  • w creates a file, truncating any existing ones

  • w-/x are synonyms creating a file and failing if it already exists.

Returns

path invisibly

Examples

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)


Method clone()

The objects of this class are cloneable with this method.

Usage

AbstractAnnData$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples


## ------------------------------------------------
## Method `AbstractAnnData$write_h5ad`
## ------------------------------------------------

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)
#> [1] "/tmp/Rtmp3F3EQq/file1d144b02a93c.h5ad"