Skip to content

Data structure of anndata in scanpy style

Guang-Wei Zhang edited this page Sep 7, 2023 · 1 revision

Data structure of anndata in scanpy style

The AnnData (Annotated Data) object in Scanpy is a central data structure that stores large-scale single-cell data. It's designed to efficiently handle sparse and dense matrices and is used to store various annotations and derived computational results. Here's a breakdown of its main components:

  1. X: This is the main data matrix where the rows represent cells (or samples) and the columns represent features (such as genes). It can be a dense matrix (e.g., a NumPy array) or a sparse matrix (e.g., a SciPy sparse matrix).

  2. .obs: This is a Pandas DataFrame that stores one row for each cell. It contains observations (obs) annotations, such as cell type, cluster labels, or any other information related to the cells.

  3. .var: This is a Pandas DataFrame that stores one row for each feature (e.g., gene). It contains variable (var) annotations, such as gene names, gene IDs, or other feature-related information.

  4. .obsm: This is a container for storing multiple observation-related data matrices, such as coordinates for visualization (e.g., t-SNE, UMAP). It allows for the alignment of different representations of the data in a way that is consistent with .obs.

  5. .varm: Similar to .obsm, this is a container for storing multiple variable-related data matrices, such as PCA loadings.

  6. .uns: This is a dictionary-like container for storing unstructured annotations, such as clustering results, graphs, or any other data that doesn't fit into the above categories.

  7. .layers: This is a container for storing additional data matrices that have the same shape as X. It can be used to store, for example, raw counts alongside normalized expression values.

Here's a visual representation of the structure:

AnnData object with n_obs × n_vars = number_of_cells × number_of_genes
    obs: 'cell_annotations_1', 'cell_annotations_2', ...
    var: 'gene_annotations_1', 'gene_annotations_2', ...
    uns: 'clustering_results', 'graphs', ...
    obsm: 'X_pca', 'X_umap', ...
    varm: 'PCs', ...
    layers: 'raw_counts', 'normalized', ...
    X: main data matrix (e.g., expression values)

The AnnData object provides a flexible and efficient way to work with single-cell data, allowing for the integration of various data types and computational results in a single container. It's central to the Scanpy ecosystem and is used throughout the analysis workflow.

Data processing pipeline

preparation of cell bin data

Data Structure of scanpy

Clone this wiki locally