Accessors and paths

Accessors and paths#

anndata.acc creates references to 1D and 2D arrays in an AnnData object. You can use these to drive e.g. plotting or validation code. For these purposes, they

  1. are easy to create:

    The central A object allows you to create AdRef objects that reference arrays along one or two dimensions of an anndata.AnnData object:

    >>> from anndata.acc import A
    >>> A[:, "gene-3"]  # reference to `adata[:, 3].X` as 1D vector
    A[:, 'gene-3']
    >>> type(A[:, "gene-3"])
    <class 'anndata.acc.AdRef'>
    
  2. introspectible

    AdRefs have the AdRef.dims, AdRef.idx, and AdRef.acc attributes, allowing you to inspect all relevant properties.

    >>> pc0 = A.obsm["pca"][:, 0]
    >>> pc0  # reference to the 0th column of `adata.obsm['pca']`
    A.obsm['pca'][:, 0]
    >>> pc0.idx
    0
    >>> pc0.acc
    A.obsm['pca']
    >>> A.var["symbol"].dims
    {'var'}
    >>> pc0.acc.k
    'pca'
    
  3. convenient

    Want to reference multiple vectors from the same object? Pass a list of indices to the vector accessor:

    >>> A.obsp["connectivities"][:, ["cell0", "cell1"]]
    [A.obsp['connectivities'][:, 'cell0'], A.obsp['connectivities'][:, 'cell1']]
    
  4. extensible (see extending accessors)

API#

The central starting point is A:

anndata.acc.A: AdAcc[AdRef] = A[source]#

A global accessor to create AdRefs.

See AdAcc for examples of how to use it:

AdAcc(*, ref_class)

Accessor to create AdRefs (A).

AdRef(acc, idx)

A reference to a 1D or 2D array along one or two dimensions of an AnnData object.

The following classes are behind AdRef.acc, and therefore useful in matches or isinstance() checks:

RefAcc(*, ref_class)

Abstract base class for reference accessors.

Finally, these classes are only useful for extending:

MapAcc()

Accessor for mapping containers.

LayerMapAcc(*, ref_class)

Accessor for layers (A.layers).

MultiMapAcc(dim, *, ref_class)

Accessor for multi-dimensional array containers (A.obsm/A.varm).

GraphMapAcc(dim, *, ref_class)

Accessor for graph containers (A.obsp/A.varp).

Extending accessors#

Attention

TODO