anndata.acc.MultiAcc#

class anndata.acc.MultiAcc[R: AdRef[int, AnnDataLikeMetadataOnly]](dim, k, *, ref_class, scope=None)[source]#

Bases: RefAcc[R, int, AnnDataLikeMetadataOnly, AlignedArray, InMemoryArray | ExtensionArray | Variable]

Reference accessor for arrays from multi-dimensional containers (A.obsm/A.varm).

Examples

>>> from anndata.acc import A, MultiAcc
>>> assert isinstance(A.obsm["pca"], MultiAcc)
>>> A.obsm["pca"][:, 0]
A.obsm['pca'][:, 0]

Note that something like this is invalid, as it references an array that isn’t aligned to an anndata dimension.

A.varm["PCs"]["cell-0", :]

Attributes

property DF: DFAcc[R][source]#

Treat the array as a data frame, to refer to its columns by name, e.g. A.obsm['x'].DF['c'].

scope: ScopeAcc | None = None#

Accessor for the element whose .AD cast this accessor is in, e.g. A.uns['a'] for A.uns['a'].AD.obsm['x'].DF.

If None, this accessor refers into the object passed to get()/set()/isin() itself.

dim: Literal['obs', 'var']#

Dimension this accessor refers to, e.g. A.obsm[k].dim == 'obs'.

k: str#

Key this accessor refers to, e.g. A.varm['x'].k == 'x'.

ref_class: type[R]#

Methods

dims(i, /)[source]#

Get along which dimensions the referenced array is.

Return type:

Collection[Literal['obs', 'var']]

get(data, i=NO_IDX, /)[source]#

Get the indexed array or element from the AnnData object at idx.

Overloads:

When idx is omitted (i.e., idx is NO_IDX), return the full array one level up instead. This has the same semantics as the AdRef path but one level up: adata[A.obs] returns the full DataFrame, adata[A.obsm["pca"]] the full numpy.ndarray, and adata[A.layers] the full Mapping. The first two both have defined shape-like properties (or awkward.Array), but layers or similar do not.

idx_repr(i)[source]#

Get a string representation of the index.

Return type:

str

isin(data, idx=None)[source]#

Check if the referenced array is in the AnnData object.

Returns False if scope (or frame_acc) isn’t in data or doesn’t have the type this accessor casts it to (.AD/.DF).

The base implementation only checks scope. Subclasses should return False if super().isin(data, idx) does, so container() won’t fail afterwards.

Return type:

bool

static process_idx(i, /)[source]#
Return type:

int

set(data, i, value, /)[source]#

Set the indexed array or element in the AnnData object at idx.

When idx is NO_IDX, replace the full element one level up (see get()), otherwise assign into the existing element in-place.

Return type:

None