liana.pl.misty_target_metrics

liana.pl.misty_target_metrics#

liana.pl.misty_target_metrics(misty=None, stat=None, target_metrics=None, top_n=None, ascending=False, key=None, filter_fn=None, figure_size=(5, 5), aggregate_fn=None, return_fig=True)#

Plot target metrics.

Parameters:
misty MistyData | None (default: None)

MistyData object with modelling results

stat str | None (default: None)

Statistic to plot

target_metrics DataFrame | None (default: None)

A target_metrics DataFrame

top_n int | None (default: None)

top_n entities to plot.

ascending bool (default: False)

Whether to sort in ascending order

key Callable[[Series], Series] | None (default: None)

Function to use to sort the dataframe

filter_fn Callable[[Series], bool] | None (default: None)

A function, applied along the columns (axis=1) of the results, used to filter the results to be plotted. In dotplot and tileplot it selects interactions rather than rows: an interaction (ligand_complex -> receptor_complex) is kept whenever the predicate holds for any of its source-target pairs, and is then plotted for all of them, so rows that fail the predicate are drawn alongside those that pass. circle and the misty plots filter row-wise.

aggregate_fn Callable[[Series], object] | str | None (default: None)

A function used to aggregate the results to be plotted.

figure_size tuple[float, float] (default: (5, 5))

Figure x,y size

return_fig bool (default: True)

bool whether to return the fig object.

Return type:

plotnine.ggplot | None

Returns:

Returns a plotnine plot.

Raises:

ValueError – If the misty input or stat provided are not valid.

Examples

Fit a MiSTy model, then plot one bar per target. stat chooses which of the misty.uns['target_metrics'] columns is shown, and orders the targets by it:

>>> import liana as li
>>> adata = li.ds.generate_toy_spatial()
>>> adata = adata[:, adata.var_names[:5]].copy()
>>> misty = li.mt.genericMistyData(intra=adata, bandwidth=200, set_diag=True)
>>> misty(model=li.mt.sp.LinearModel)
>>> p = li.pl.misty_target_metrics(misty, stat="gain_R2")

Pass aggregate_fn (e.g. numpy.mean) to summarise a masked model’s per-group rows into boxplots.