liana.pl.lric_divergence

liana.pl.lric_divergence#

liana.pl.lric_divergence(adata=None, uns_key='lric', liana_res=None, feature_a=None, feature_b=None, max_dist=None, transform_fn=<function _log2_floor>, min_bins=3, figure_size=(6, 4), return_fig=True)#

Plot two transform_fn(g(r)) curves and the area between them.

The visual companion of liana.mt.get_lric_divergence(): both curves are drawn over radius, the grey ribbon spans their separation, the dashed line at 0 marks the null, and the dotted vertical line marks r_star – the radius where the curves diverge most. The title carries the span-normalised divergence and r_star.

Parameters:
adata AnnData | None (default: None)

Annotated data object. Its .uns[uns_key] holds the result, read when liana_res is None.

uns_key str (default: 'lric')

Key in adata.uns that contains the LIANA results. Default is 'liana_res'.

liana_res DataFrame | None (default: None)

liana_res a DataFrame in liana’s format. Where an adata is accepted too, a frame passed here takes precedence over adata.uns[uns_key], which is only read when this is None.

A lric / cross_pcf result.

feature_a dict[str, object] | None (default: None)

Selection of the first curve as {column: value} over any columns of the result, e.g. dict(interaction="Dcn^Egfr"). It must resolve to a single interaction; see liana.mt.get_lric_divergence().

feature_b dict[str, object] | None (default: None)

Selection of the second curve; same rules as feature_a.

max_dist float | None (default: None)

Compare and draw only radii r < max_dist; None uses all radii.

transform_fn Callable[[NDArray[floating]], NDArray[floating]] (default: <function _log2_floor at 0x7ef622c36a20>)

Applied to g before comparing; defaults to log2 with g floored at 0.05. Pass numpy.log2 to drop non-finite bins instead.

min_bins int (default: 3)

Minimum shared finite radius bins required; fewer raises a ValueError.

figure_size tuple[float, float] (default: (6, 4))

Figure x,y size

return_fig bool (default: True)

bool whether to return the fig object.

Return type:

plotnine.ggplot | None

Returns:

A plotnine.ggplot if return_fig else None (draws the plot).

Examples

>>> import liana as li
>>> adata = li.ds.generate_toy_spatial()
>>> li.mt.cross_pcf(adata, groupby="bulk_labels", key_added="cross_pcf")
>>> p = li.pl.lric_divergence(
...     adata,
...     "cross_pcf",
...     feature_a=dict(source="CD14+ Monocyte", target="CD34+"),
...     feature_b=dict(source="CD14+ Monocyte", target="CD19+ B"),
... )