liana.multi.filter_view_markers

liana.multi.filter_view_markers#

liana.multi.filter_view_markers(mdata, markers, view_sep=':', var_column='highly_variable', inplace=False)#

Remove potential cell type marker genes found in the background of other views.

In each view, sets highly variable genes to False if they are in the markers dict for another view, but not if they are in the markers for the same view.

Parameters:
  • mdata (MuData) – MuData (multimodal) data object.

  • markers (dict[str, list[str]]) – Dictionary with markers for each view. Keys are the views and values are lists of markers. Can contain markers for views that are not in mdata.mod.keys().

  • view_sep (str (default: ':')) – Separator between view and gene names. Defaults to ‘:’.

  • var_column (str | None (default: 'highly_variable')) – Column in mdata.mod[‘some_view’].var that contains the highly variable genes. Defaults to ‘highly_variable’. If set to None, instead of setting the hvg genes to False, the hvg genes will be removed from the view.

  • inplace (bool (default: False)) – Whether to store results in place, or else to return them.

Return type:

MuData | None

Returns:

The filtered mdata instance or None if inplace=True.

Examples

Takes a multi-view object – normally from liana.multi.adata_to_views(), whose var_names are prefixed with the view they belong to – and drops from each view the genes that mark a different view, since those are picked up from the background rather than expressed by the view’s own cells. Two small views are built by hand here to show the naming convention:

>>> import numpy as np
>>> import pandas as pd
>>> from anndata import AnnData
>>> from mudata import MuData
>>> import liana as li
>>> views = {v: AnnData(X=np.ones((3, 3)),
...                     obs=pd.DataFrame(index=['s1', 's2', 's3']),
...                     var=pd.DataFrame(index=[f'{v}:g1', f'{v}:g2', f'{v}:g3']))
...          for v in ['A', 'B']}
>>> mdata = MuData(views)
>>> markers = {'A': ['g1'], 'B': ['g2']}

With var_column=None the offending genes are removed outright – each view keeps its own marker and the unmarked g3:

>>> filtered = li.mu.filter_view_markers(mdata, markers, var_column=None)
>>> filtered.mod['A'].var_names.tolist()
['A:g1', 'A:g3']
>>> filtered.mod['B'].var_names.tolist()
['B:g2', 'B:g3']

Pass var_column='highly_variable' instead to only flag them, and inplace=True to modify mdata rather than return a copy.