locate

Locate the attribute data container in AnnData.

Given, adata and a key that points to a specific matrix stored in adata, return the data, formatted either as np.ndarray or torch.Tensor. If formatted as torch.Tensor, device may be specified based on available devices.

Uses the class: adata_query._core.AnnDataLocator.

attr_key = locate(adata: anndata.AnnData, key: str)
Parameters

adata (anndata.AnnData)

key (str)

  • Key to access a matrix in adata. For example, if you wanted to access adata.obsm['X_pca'], you would pass: "X_pca".

Returns

attr_key(str)

  • Attribute of adata containing the passed key

Exceptions

There are two possible KeyErrors that may arise when using this function. The first is the requirement that the passed key is found in any attribute of adata. Should it not be found, the following KeyError will be returned:

KeyError: {key} NOT FOUND

The second possible KeyError that may arise indicates the discovery of multiple adata attributes containing a key-value pair where the passed key is observed in both attributes. For example, if the passed key matches a column name in obs and a key in adata.obsm, the following KeyError would arise:

KeyError: Found more than one match: ['obs', 'obsm']

In the event of the second KeyError in which multiple locations are found, rename the key-value pairs in adata, such that each is unique.

  • Attribute of adata containing the passed key

Source code: GitHub.com/mvinyard/AnnDataQuery/adata_query/_core/_locator.py

Last updated