anndata.acc.RefAcc#
- class anndata.acc.RefAcc[R: AdRef, I: Hashable, D: AnnDataLikeMetadataOnly, E = object, V = object](*, ref_class, scope=None)[source]#
Bases:
ABCAbstract base class for reference accessors.
See reference accessors for all existing subclasses.
Attributes
- scope: ScopeAcc | None = None[source]#
Accessor for the element whose
.ADcast this accessor is in, e.g.A.uns['a']forA.uns['a'].AD.obsm['x'].DF.If
None, this accessor refers into the object passed toget()/set()/isin()itself.
Methods
- __getitem__(idx, /)[source]#
Get a reference to an array.
- Parameters:
- idx
Any Index into the referenced element. Subclasses define which indices are valid.
- idx
- Return type:
R
- abstractmethod __repr__()[source]#
Get a display representation of the accessor.
This is not a simplified representation supported by
AdAcc.resolve(), but instead the code used to create the accessor, e.g.A.layers['counts'].- Return type:
- container(data, /)[source]#
Get the AnnData object this accessor indexes into.
That is
dataitself, or the elementscoperefers to indata. Call this inget(),set(), andisin()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
- abstractmethod dims(idx, /)[source]#
Get along which dimensions the referenced array is.
- Return type:
Collection[Literal['obs','var']]
- abstractmethod get(data, idx=NO_IDX, /)[source]#
Get the indexed array or element from the AnnData object at
idx.- Overloads:
data (
D), / →Edata (
D), idx (I), / →V
When
idxis omitted (i.e.,idxisNO_IDX), return the full array one level up instead. This has the same semantics as theAdRefpath but one level up:adata[A.obs]returns the fullDataFrame,adata[A.obsm["pca"]]the fullnumpy.ndarray, andadata[A.layers]the fullMapping. The first two both have definedshape-like properties (orawkward.Array), butlayersor similar do not.
- abstractmethod isin(data, idx=None, /)[source]#
Check if the referenced array is in the AnnData object.
Returns
Falseifscope(orframe_acc) isn’t indataor doesn’t have the type this accessor casts it to (.AD/.DF).The base implementation only checks
scope. Subclasses should returnFalseifsuper().isin(data, idx)does, socontainer()won’t fail afterwards.- Return type: