scirpy.util.DataHandler#

class scirpy.util.DataHandler(data, airr_mod=None, airr_key=None, chain_idx_key=None)#

Transparent access to airr modality in both AnnData and MuData objects.

Performs a plausibility check of the input data for public scirpy functions.

Provides convenient accessors to the airr data that is stored somewhere in the input AnnData/MuData.

DataHandler may be called with another DataHandler instance as data attribute. In that case all attributes are taken from the existing DataHandler instance and all keyword attributes are ignored.

Parameters:
  • adata – AnnData or MuData object that contains AIRR information.

  • airr_mod (Optional[str] (default: None)) – Name of the modality with AIRR information is stored in the MuData object. if an AnnData object is passed to the function, this parameter is ignored.

  • airr_key (Optional[str] (default: None)) – Key under which the AIRR information is stored in adata.obsm as an awkward array.

  • chain_idx_key (Optional[str] (default: None)) – Key under which the chain indices are stored in adata.obsm. If chain indices are not present, index_chains() is run with default parameters.

Attributes table#

TYPE

Supported Data types

adata

Reference to the AnnData object of the AIRR modality.

airr

Reference to the awkward array with AIRR information.

chain_indices

Reference to the chain indices

data

Get the outermost container.

mdata

Reference to the MuData object.

Methods table#

check_schema_pre_v0_7(adata)

Raise an error if AnnData is in pre scirpy v0.7 format.

default(data)

Initailize a DataHandler object with default keys.

get_obs(columns)

Get one or multiple obs columns from either MuData or AIRR AnnData

inject_param_docs(**kwargs)

Inject parameter documentation into a function docstring

set_obs(key, value)

Store results in .obs of AnnData and MuData.

strings_to_categoricals()

Convert strings to categoricals.

Attributes#

DataHandler.data#

Get the outermost container. If MuData is defined, return the MuData object. Otherwise the AnnData object.

DataHandler.adata#

Reference to the AnnData object of the AIRR modality.

DataHandler.mdata#

Reference to the MuData object.

Raises an attribute error if only AnnData is available.

DataHandler.airr#

Reference to the awkward array with AIRR information.

DataHandler.chain_indices#

Reference to the chain indices

Raises an AttributeError if chain indices are not available.

DataHandler.TYPE#

Supported Data types

alias of AnnData | MuData | DataHandler

Methods#

static DataHandler.check_schema_pre_v0_7(adata)#

Raise an error if AnnData is in pre scirpy v0.7 format.

static DataHandler.default(data)#

Initailize a DataHandler object with default keys. Returns None if data is None. Particularly useful for testing.

DataHandler.get_obs(columns)#

Get one or multiple obs columns from either MuData or AIRR AnnData

Checks if the column is available in MuData.obs. If it can’t be found or DataHandler is initalized without MuData object, AnnData.obs is tried.

The returned object always has the dimensions and index of MuData, even if only columns from AnnData are used. It is easy to subset to AnnData if required:

params.get_obs([col1, col2]).reindex(params.adata.obs_names)
Parameters:

columns – one or multiple columns.

Returns:

If this is a single column passed as str, a Series will be returned, otherwise a DataFrame.

static DataHandler.inject_param_docs(**kwargs)#

Inject parameter documentation into a function docstring

Parameters:

**kwargs (str) – Further, custom {keys} to replace in the docstring.

Return type:

Callable

DataHandler.set_obs(key, value)#

Store results in .obs of AnnData and MuData.

If value is not a Series, if the length is equal to the params.mdata, we assume it aligns to the MuData object. Otherwise, if the length is equal to the params.adata, we assume it aligns to the AnnData object. Otherwise, a ValueError is thrown.

The result will be written to mdata.obs["{airr_mod}:{key}"] and to adata.obs[key].

Return type:

None

DataHandler.strings_to_categoricals()#

Convert strings to categoricals. If MuData is not defined, perform this on AnnData