scdef.pl.trajectory_heatmap ¶
trajectory_heatmap(model: scDEF, factor_path: Sequence[Union[int, str]], layer_idx: int = 0, l0_path: Optional[Sequence[Union[int, str]]] = None, genes_per_factor: Optional[int] = 3, smoothing: int = 50, figwidth: float = 8, gene_height: float = 0.28, block_spacing: int = 1, 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)
Plot stacked trajectory heatmap from precomputed confident signatures.
Requires scd.tl.set_confident_signatures(model) to be run beforehand.
Cell sorting
Cells are restricted to those assigned to factor_path (and optional
subset_obs filter), then ordered by a soft trajectory progress score.
For each selected cell, the function takes its factor probabilities
(from X_<layer>_probs), keeps only the columns for the path factors,
and computes a probability-weighted average of path positions
0..len(path)-1. This gives a continuous progress coordinate used to
sort cells from early to late along the path.
If layer_idx > 0 and l0_path is provided, the sorting weights are
computed on layer 0 probabilities instead. If that yields near-zero total
path weight for all selected cells, sorting falls back to the
layer_idx path probabilities.
normalize (default True): min–max scale each gene row to [0, 1]
after smoothing; if False, use smoothed raw expression. Factor score rows
are always min–max scaled.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
scDEF
|
fitted scDEF model with confident signatures cached. |
required |
factor_path
|
Sequence[Union[int, str]]
|
factors defining the trajectory, in order, as names or indices
within |
required |
layer_idx
|
int
|
layer the path's factors belong to. |
0
|
l0_path
|
Optional[Sequence[Union[int, str]]]
|
matching layer-0 path used to order the cells when
|
None
|
genes_per_factor
|
Optional[int]
|
top genes taken from each factor's confident signature to form the heatmap rows. |
3
|
smoothing
|
int
|
window, in cells, of the rolling average applied along the trajectory. Larger values give smoother bands and hide finer structure. |
50
|
figwidth
|
float
|
figure width in inches; the height follows from the row count. |
8
|
gene_height
|
float
|
vertical inches per gene row. |
0.28
|
block_spacing
|
int
|
blank rows inserted between one factor's block and the next. |
1
|
annotation_obs_key
|
Optional[Union[str, Sequence[str]]]
|
|
None
|
subset_obs_key
|
Optional[str]
|
|
None
|
subset_obs
|
Optional[Union[str, Sequence[str]]]
|
value(s) of |
None
|
heatmap_cmap
|
str
|
colormap for the gene expression rows. |
'RdYlBu_r'
|
factor_heatmap_cmap
|
str
|
colormap for the factor score rows. |
FACTOR_CMAP
|
colorbar_gap
|
float
|
horizontal gap between the plot and its colorbars, in figure fractions. |
0.16
|
xlabel
|
str
|
label for the cell axis. |
'Cells'
|
normalize
|
bool
|
min–max scale each gene row after smoothing, so genes of different magnitudes are comparable. False keeps smoothed raw expression. |
True
|
save
|
Optional[str]
|
path to write the figure to. Defaults to not saving. |
None
|
show
|
bool
|
call |
True
|