Skip to content

scdef.pl.path_trajectory_heatmap

path_trajectory_heatmap(model: scDEF, path_id: int, paths_key: str = 'differentiation_paths', score_key: Optional[str] = None, min_sort_affinity: float = 0.05, path_mass_eps: float = 1e-12, genes_per_factor: Optional[int] = 3, smoothing: int = 50, figwidth: float = 8, gene_height: float = 0.28, block_spacing: int = 1, ytick_prefix_layer: bool = True, genes: Optional[Sequence[str]] = None, annotation_obs_key: Optional[Union[str, Sequence[str]]] = None, subset_obs_key: Optional[str] = None, subset_obs: Optional[Union[str, Sequence[str]]] = None, heatmap_cmap: str = 'RdYlBu_r', factor_heatmap_cmap: str = FACTOR_CMAP, colorbar_gap: float = 0.16, xlabel: str = 'Cells', normalize: bool = True, save: Optional[str] = None, show: bool = True) -> Optional[Figure]

Trajectory heatmap along a stored multi-layer path (differentiation or transition).

Uses adata.uns[paths_key]['paths'][path_id] factor nodes (root→leaf for differentiation paths) only for cell ordering along the path.

Default mode: per-node factor scores from adata.obs['<factor>_score'] (annotate_adata / fit) plus confident genes from scd.tl.set_confident_signatures(model).

Custom genes (genes=[...]): one heatmap block, one row per gene; no factor score rows and no confident-signature cache required.

Cell order

Prefer scd.tl.score_paths matrices {score_key}_positions and {score_key}_affinities (same column order as paths). Cells must meet min_sort_affinity and have finite positions. If no such cells remain, falls back to the same logic as trajectory_heatmap: anchor cells on the L0 terminus (differentiation) or transition source/target on L0, then sort by probability-weighted index along nodes using X_<layer>_probs.

If genes is set to a non-empty list of gene names, skips per-factor blocks (no <factor>_score rows and no confident signatures). Renders a single heatmap block with one row per gene (same path-based cell order). genes_per_factor is ignored in that mode.

Parameters:

Name Type Description Default
model scDEF

fitted scDEF model.

required
path_id int

path_id field stored with the path, or a list index.

required
paths_key str

adata.uns key from build_differentiation_paths or build_transition_paths.

'differentiation_paths'
score_key Optional[str]

prefix for obsm position/affinity matrices from score_paths; defaults to paths_key.

None
min_sort_affinity float

when using score_paths output, minimum affinity along the path for a cell to be included and ordered.

0.05
path_mass_eps float

minimum summed path-node probability mass in fallback mode.

1e-12
ytick_prefix_layer bool

if True, factor row labels are '<layer> <name>'.

True
genes Optional[Sequence[str]]

optional list of adata.var_names entries to plot as rows only.

None
normalize bool

min–max scale each gene expression row after smoothing (default True); factor score rows are always scaled. Same as trajectory_heatmap.

True