scdef.pl.obs_cell_factor_heatmap ¶
obs_cell_factor_heatmap(model: scDEF, subset_obs_key: str, subset_obs: Union[str, Sequence[str]], group_obs_key: str, layer_idx: int = 0, factors: Optional[Sequence[Union[str, int]]] = None, values: Literal['score', 'prob'] = 'score', cluster_cells: bool = True, sort_layer_factors: bool = True, merge_batch_technical: bool = False, group_order: Optional[Sequence[str]] = None, show_group_track: bool = True, figsize: Optional[Tuple[float, float]] = None, figwidth: float = 10.0, row_height: float = 0.004, group_track_width: float = 0.05, cmap: Union[str, Colormap] = FACTOR_CMAP, norm: Optional[Normalize] = None, vmin: Optional[float] = None, vmax: Optional[float] = None, colorbar_label: Optional[str] = None, group_separator_linewidth: float = 1.0, group_separator_color: str = 'white', group_separator_alpha: float = 0.9, xlabel: str = 'Factors', factor_label_rotation: float = 90.0, factor_fontsize: int = 8, label_fontsize: int = 10, colorbar_label_fontsize: int = 9, colorbar_tick_fontsize: int = 8, show_annotations: bool = False, annotation_fontsize: int = 8, annotation_rotation: float = 45.0, save: Optional[str] = None, show: bool = True) -> Optional[Figure]
Heatmap of per-cell factor scores or probabilities for one or more obs subsets.
Restricts to cells matching subset_obs in subset_obs_key (for example
one patient or coarse cell type), orders rows by group_obs_key (for example
treatment or subtype), and within each group optionally sorts cells by Ward
hierarchical clustering on the displayed factor vectors. Columns are factors
from layer_idx. By default columns follow the hierarchy graph
(model.get_layer_factor_orders()); pass factors to select and order
columns explicitly.
When subset_obs contains multiple values, one heatmap panel is drawn per
value as a vertical stack of subplots with a shared x-axis (factor columns).
The group_obs_key color strip is drawn to the left of each heatmap.
Requires model.annotate() (or equivalent) so layer scores and/or
probabilities are stored in adata.obsm as X_<layer> and
X_<layer>_probs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
scDEF
|
scDEF model instance. |
required |
subset_obs_key
|
str
|
|
required |
subset_obs
|
Union[str, Sequence[str]]
|
Value or values of |
required |
group_obs_key
|
str
|
|
required |
layer_idx
|
int
|
Layer whose factors form the heatmap columns. |
0
|
factors
|
Optional[Sequence[Union[str, int]]]
|
Optional list of factor names (or indices within the layer) to
plot. Columns appear in this order; overrides |
None
|
values
|
Literal['score', 'prob']
|
|
'score'
|
cluster_cells
|
bool
|
If True, hierarchically cluster cells within each
|
True
|
sort_layer_factors
|
bool
|
If True and |
True
|
merge_batch_technical
|
bool
|
If True, replace each group of batch-technical
splits with one merged column via
|
False
|
group_order
|
Optional[Sequence[str]]
|
Optional explicit order of |
None
|
show_group_track
|
bool
|
Draw a narrow color strip for |
True
|
figsize
|
Optional[Tuple[float, float]]
|
Figure size |
None
|
figwidth
|
float
|
Figure width in inches when |
10.0
|
row_height
|
float
|
Height in inches per cell row when |
0.004
|
group_track_width
|
float
|
Gridspec width ratio for the group strip (default matches the colorbar column width). |
0.05
|
cmap
|
Union[str, Colormap]
|
Matplotlib colormap name or |
FACTOR_CMAP
|
norm
|
Optional[Normalize]
|
Optional normalization for the heatmap colormap (e.g.
|
None
|
vmin
|
Optional[float]
|
Optional lower bound for the color scale (ignored when |
None
|
vmax
|
Optional[float]
|
Optional upper bound for the color scale (ignored when |
None
|
colorbar_label
|
Optional[str]
|
Optional colorbar title; inferred from |
None
|
group_separator_linewidth
|
float
|
Line width of horizontal separators between
|
1.0
|
group_separator_color
|
str
|
Color of subgroup separator lines. |
'white'
|
group_separator_alpha
|
float
|
Alpha of subgroup separator lines. |
0.9
|
xlabel
|
str
|
X-axis label. |
'Factors'
|
factor_label_rotation
|
float
|
Rotation of factor names on the x-axis. |
90.0
|
factor_fontsize
|
int
|
Font size for factor name tick labels. |
8
|
label_fontsize
|
int
|
Font size for the x-axis label. |
10
|
colorbar_label_fontsize
|
int
|
Font size for the colorbar title. |
9
|
colorbar_tick_fontsize
|
int
|
Font size for colorbar tick labels. |
8
|
show_annotations
|
bool
|
If True, show |
False
|
annotation_fontsize
|
int
|
Font size for top annotation labels. |
8
|
annotation_rotation
|
float
|
Rotation of top annotation labels in degrees. |
45.0
|
save
|
Optional[str]
|
If set, save the figure to this path (in addition to returning it when
|
None
|
show
|
bool
|
Whether to call |
True
|
Returns:
| Type | Description |
|---|---|
Optional[Figure]
|
|