liana.ms.lrdata_to_mudata

liana.ms.lrdata_to_mudata#

liana.ms.lrdata_to_mudata(lrdata, xy_sep='^', min_cells=5, min_features=10, obs_keys=None, verbose=False)#

Convert an inflow score AnnData object to a MuData object, where each modality corresponds to a unique sender cell type.

Parameters:
adata

Annotated data object.

xy_sep str (default: '^')

Separator between the sender cell-type/view prefix and the ligand-receptor interaction name in lrdata.var_names (e.g. "celltype^ligand^receptor"). Matches the xy_sep convention used by liana.mt.inflow. Defaults to '^'.

min_cells int | None (default: 5)

Minimum cells (per cell identity if grouped by groupby) to be considered for downstream analysis.

min_features int | None (default: 10)

Modalities with fewer than this many features after cell-filtering are dropped entirely. Pass None to keep all modalities.

obs_keys list[str] | None (default: None)

List of keys in lrdata.obs that should be included in the MuData object.

verbose bool (default: False)

Verbosity flag.

Return type:

MuData

Returns:

MuData MuData object with one modality per sender cell type.

Raises:
  • TypeError – If lrdata is not an AnnData object.

  • ValueError – If any of the provided keys are not found in lrdata.obs.

Examples

lrdata is normally the output of liana.mt.inflow, whose var_names encode the sender cell type as a prefix:

>>> import liana as li
>>> adata = li.ds.generate_toy_spatial()
>>> lrdata = li.mt.inflow(adata, groupby="bulk_labels", resource_name="consensus")
>>> mdata = li.ms.lrdata_to_mudata(lrdata)

The sender in each 'sender^ligand^receptor' name becomes one modality, so that every sender cell type can be modelled as its own view.