peach.pl.cellrank_viz

peach.pl.cellrank_viz#

Visualization functions for CellRank archetypal trajectories.

Functions

fate_probabilities(adata[, lineages, basis, ...])

Plot fate probabilities on embedding.

gene_trends(adata, genes, lineage, time_key)

Plot gene expression trends along lineage pseudotime.

lineage_drivers(adata, lineage[, n_genes, ...])

Plot heatmap of top driver genes for a lineage.

peach.pl.cellrank_viz.fate_probabilities(adata, lineages=None, basis='X_umap', same_plot=False, ncols=3, figsize=None, **kwargs)[source]#

Plot fate probabilities on embedding.

Visualizes the probability of cells committing to each lineage/archetype using CellRank’s plotting functionality.

Parameters:
  • adata (AnnData) – Annotated data matrix with fate probabilities computed.

  • lineages (list of str, optional) – Specific lineages to plot. If None, plots all lineages.

  • basis (str, default: 'X_umap') – Embedding to use (‘X_umap’, ‘X_pca’, etc.).

  • same_plot (bool, default: False) – If True, plots all lineages on same axes (pie chart style). If False, creates separate panel per lineage.

  • ncols (int, default: 3) – Number of columns for multi-panel plot (if same_plot=False).

  • figsize (tuple, optional) – Figure size. If None, automatically determined.

  • **kwargs – Additional arguments passed to CellRank’s plot function.

Returns:

Displays matplotlib figure. CellRank’s plotting functions display directly rather than returning figure objects.

Return type:

None

Raises:

Examples

>>> pc.pl.fate_probabilities(adata, same_plot=False, ncols=3)
>>> pc.pl.fate_probabilities(adata, lineages=["archetype_3", "archetype_5"], same_plot=True)

Plot gene expression trends along lineage pseudotime.

Visualizes how gene expression changes as cells progress toward a specific lineage/archetype.

Parameters:
  • adata (AnnData) – Annotated data matrix.

  • genes (str or list of str) – Gene name(s) to plot.

  • lineage (str) – Target lineage name (e.g., ‘archetype_5’).

  • time_key (str) – Key in adata.obs containing pseudotime (e.g., ‘pseudotime_to_archetype_5’).

  • model (cellrank.models.BaseModel, optional) – Model for fitting trends (e.g., cr.models.GAMR(adata)). If None, plots raw scatter without smoothed fit.

  • data_key (str, default: 'X') – Key in adata layers for expression data.

  • ncols (int, default: 3) – Number of columns for multi-gene plot.

  • figsize (tuple, optional) – Figure size.

  • **kwargs – Additional arguments passed to CellRank’s gene_trends.

Returns:

Displays matplotlib figure directly. CellRank’s plotting functions display rather than returning figure objects.

Return type:

None

Raises:

Notes

GAMR models require R installation with mgcv package and R_HOME set:

>>> import os
>>> os.environ["R_HOME"] = "/Library/Frameworks/R.framework/Resources"

Examples

>>> pc.pl.gene_trends(
...     adata,
...     genes=["RARRES1", "SOD2"],
...     lineage="archetype_5",
...     time_key="pseudotime_to_archetype_5",
...     model=cr.models.GAMR(adata),
... )
peach.pl.cellrank_viz.lineage_drivers(adata, lineage, n_genes=20, driver_key=None, figsize=(10, 8), **kwargs)[source]#

Plot heatmap of top driver genes for a lineage.

Visualizes expression of genes most correlated with commitment to a specific lineage/archetype.

Parameters:
  • adata (AnnData) – Annotated data matrix

  • lineage (str) – Target lineage name (e.g., ‘archetype_5’)

  • n_genes (int, optional (default: 20)) – Number of top genes to plot

  • driver_key (str, optional) – Key in adata.varm containing driver gene scores. If None, computes drivers on-the-fly using correlation method

  • figsize (tuple, optional (default: (10, 8))) – Figure size

  • **kwargs – Additional arguments passed to seaborn.heatmap

Returns:

fig – Figure object

Return type:

matplotlib.figure.Figure

Examples

Plot top 20 driver genes:

>>> import peach as pc
>>> pc.pl.lineage_drivers(adata, lineage="archetype_5", n_genes=20)

Custom number of genes:

>>> pc.pl.lineage_drivers(adata, lineage="archetype_3", n_genes=30, figsize=(12, 10))

Using pre-computed drivers:

>>> drivers = pc.tl.compute_lineage_drivers(adata, lineage="archetype_5")
>>> adata.var["driver_scores"] = drivers[f"archetype_5_corr"]
>>> pc.pl.lineage_drivers(adata, lineage="archetype_5", driver_key="driver_scores")

Notes

  • If driver_key is None, uses simple correlation method

  • Heatmap rows are cells ordered by fate probability

  • Heatmap columns are top driver genes

See also

gene_trends

Plot expression trends along pseudotime

fate_probabilities

Visualize fate probability distributions