liana.pl.annulus

Contents

liana.pl.annulus#

liana.pl.annulus(adata, spatial_key='spatial', radius_step=20.0, annulus_steps=1, extend_first_annulus=True, n_rings=10, seed=1337, figure_size=(6, 6), return_fig=True)#

Visualise concentric annuli around a randomly chosen cell on a tissue section.

Useful for inspecting the local neighbourhood structure and choosing sensible radius_step / annulus_steps parameters before running spatial statistics (e.g. cross-PCF or LRIC).

Parameters:
adata AnnData

Annotated data object.

spatial_key str (default: 'spatial')

Key in adata.obsm that contains the spatial coordinates.

radius_step float (default: 20.0)

Step size between successive ring inner radii (in the same units as the spatial coordinates, e.g. µm).

annulus_steps int (default: 1)

Ring width of each annulus, in units of radius_step (width = annulus_steps * radius_step). 1 (default) gives disjoint annuli that tile the range without gaps or overlap; > 1 gives overlapping annuli – a annulus_steps-wide moving window over the same tiles, i.e. a smoothed g(r).

extend_first_annulus bool (default: True)

If True (default), draw the innermost ring from radius 0 (spanning [0, (1 + annulus_steps) * radius_step)) to mirror the merged first bin used by liana.mt.lric / liana.mt.cross_pcf. False starts the first ring at radius_step.

n_rings int (default: 10)

Number of concentric rings to draw.

seed int (default: 1337)

Random seed for reproducibility.

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

Figure x,y size

return_fig bool (default: True)

bool whether to return the fig object.

Return type:

Figure | None

Returns:

The resulting figure, unless return_fig is False.

Raises:

KeyError – If spatial_key is not found in adata.obsm.

Examples

Draws the annuli that liana.mt.cross_pcf and liana.mt.lric bin distances into, around one seeded random cell, with the number of cells falling in each ring. Use it to sanity-check radius_step and annulus_steps against the density of the tissue:

>>> import liana as li
>>> adata = li.ds.generate_toy_spatial()
>>> fig = li.pl.annulus(adata, radius_step=200, n_rings=4)