scirpy.get.airr_context

Contents

scirpy.get.airr_context#

scirpy.get.airr_context(data, airr_variable, chain=('VJ_1', 'VDJ_1', 'VJ_2', 'VDJ_2'), *, airr_mod='airr', airr_key='airr', chain_idx_key='chain_indices')#

Contextmanager that temporarily adds AIRR information to obs.

This is essentially a wrapper around obs_context() and equivalent to

ir.get.obs_context(data, ir.get.airr(airr_variable, chain))

Example

To list all combinations of patient and V genes in the VJ and VDJ chains:

with ir.get.airr_context(mdata, "v_call", chain=["VJ_1", "VDJ_1"]) as m:
    combinations = (
        m.obs.groupby(["patient", "VJ_1_v_call", "VDJ_1_v_call"], observed=True)
        .size()
        .reset_index(name="n")
    )
Parameters:
  • adata – AnnData or MuData object that contains AIRR information.

  • airr_variable (Union[str, Sequence[str]]) – One or multiple columns from the AIRR Rearrangment schema (see adata.var). If multiple values are specified, a dataframe will be returned.

  • chain (Union[Literal['VJ_1', 'VJ_2', 'VDJ_1', 'VDJ_2'], Sequence[Literal['VJ_1', 'VJ_2', 'VDJ_1', 'VDJ_2']]] (default: ('VJ_1', 'VDJ_1', 'VJ_2', 'VDJ_2'))) – choose the recptor arm (VJ/VDJ) and if you want to retrieve the primary or secondary chain. If multiple chains are specified, a adataframe will be returned

  • airr_mod (str (default: 'airr')) – 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 (str (default: 'airr')) – Key under which the AIRR information is stored in adata.obsm as an awkward array.

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