liana.utils.mdata_to_anndata

liana.utils.mdata_to_anndata#

liana.utils.mdata_to_anndata(mdata, x_mod, y_mod, x_layer=None, y_layer=None, x_use_raw=False, y_use_raw=False, x_transform=None, y_transform=None, verbose=True)#

Convert a MultiData object to an AnnData object.

Parameters:
  • mdata (MuData) – MuData object.

  • x_mod (str) – Name of the modality to be used as x.

  • y_mod (str) – Name of the modality to be used as y.

  • x_layer (str (default: None)) – Layer to be used for modality x.

  • y_layer (str (default: None)) – Layer to be used for modality y.

  • x_use_raw (bool (default: False)) – Whether to use raw counts for modality x.

  • y_use_raw (bool (default: False)) – Whether to use raw counts for modality y.

  • x_transform (Callable (default: None)) – Transformation function to be applied to modality x.

  • y_transform (Callable (default: None)) – Transformation function to be applied to modality y.

  • verbose (bool (default: True)) – Verbosity flag.

Return type:

AnnData

Returns:

An AnnData object with the two modalities concatenated. Information related to observations (obs, obsp, obsm) and .uns are copied from the original MuData object.

Raises:

ValueError – If x_mod and/or y_mod are not provided.

Examples

Joins two modalities of a MuData along the variable axis, which is what liana.method.bivariate expects when relating one modality to another:

>>> import liana as li
>>> mdata = li.testing.generate_toy_mdata()
>>> adata = li.ut.mdata_to_anndata(mdata,
...                                x_mod='adata_x',
...                                y_mod='adata_y',
...                                x_layer='scaled',
...                                y_layer='scaled')