anndata.acc.LayerAcc#

class anndata.acc.LayerAcc[R: AdRef[Idx2D, AnnDataLike]](k, *, ref_class, scope=None)[source]#

Bases: RefAcc[R, Idx2D, AnnDataLike, AlignedArray, InMemoryArray | ExtensionArray | Variable]

Reference accessor for arrays in layers (A.layers).

Examples

>>> from anndata.acc import A, LayerAcc
>>> assert isinstance(A.layers["counts"], LayerAcc)
>>> A.layers["counts"]["cell-1", :]
A.layers['counts']['cell-1', :]

Attributes

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.

k: str | None#

Key this accessor refers to, e.g. A.layers['counts'].k == 'counts'.

ref_class: type[R]#

Methods

container(data, /)[source]#

Get the AnnData object this accessor indexes into.

That is data itself, or the element scope refers to in data. Call this in get(), set(), and isin() so your subclass works when nested.

Examples

>>> from anndata import AnnData
>>> from anndata.acc import A
>>> adata = AnnData(shape=(3, 2), uns={"n": AnnData(shape=(5, 4))})
>>> A.obs.container(adata) is adata
True
>>> A.uns["n"].AD.obs.container(adata) is adata.uns["n"]
True
Raises:

TypeError – If the element scope refers to isn’t an AnnData object.

Return type:

AnnDataLike

dims(idx, /)[source]#

Get along which dimensions the referenced array is.

Return type:

set[Literal['obs', 'var']]

get(adata, idx=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(idx)[source]#

Get a string representation of the index.

Return type:

str

isin(adata, 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

set(adata, idx, 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