Plotting
Clustering Results
Plots of Clumppling results and feature metrics.
Classes
Functions
get_kde_outliers(df, x_col, y_col, *, min_x=0.0, levels=8, cut=0, top_n=None, scale='zscore', return_mask=False)
Find features outside the outermost KDE contour of two metrics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Feature metrics. |
required |
x_col
|
str
|
Columns to use. |
required |
y_col
|
str
|
Columns to use. |
required |
min_x
|
float | None
|
Use only features with x above this value; None uses all finite values. |
0.0
|
levels
|
int
|
Number of KDE contour levels. |
8
|
cut
|
float
|
KDE cut (see |
0
|
top_n
|
int | None
|
Keep only the top_n outliers, ranked by distance in scaled (x, y). |
None
|
scale
|
str
|
Scaling for the ranking: "zscore" (mean, std), "robust" (median, IQR) or "none". |
'zscore'
|
return_mask
|
bool
|
Also return a mask of the outliers, aligned to df. |
False
|
Returns:
| Type | Description |
|---|---|
outliers
|
Outlier rows of df. |
mask
|
Outlier mask, if return_mask. |
in_outer_contour(x, y, paths)
Whether (x, y) lies inside any of the given contour paths.
make_mode_grid(modes, *, n_cols=4, panel_size=(4.0, 2.5), dpi=150)
Figure with one panel per mode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
modes
|
list[str]
|
Mode names. |
required |
n_cols
|
int
|
Number of columns. |
4
|
panel_size
|
tuple[float, float]
|
(width, height) of each panel, in inches. |
(4.0, 2.5)
|
dpi
|
int
|
Figure resolution. |
150
|
Returns:
| Type | Description |
|---|---|
fig
|
|
ax_by_mode
|
{mode name: Axes}. |
make_mode_grid_by_K(results, *, modes=None, panel_size=(3.0, 2.5), dpi=150)
Figure with one panel per mode, one row per K, as in plot_Q_grid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
ClumpplingResults
|
Clumppling results. |
required |
modes
|
Sequence[str] | None
|
Mode names; None uses all. |
None
|
panel_size
|
tuple[float, float]
|
(width, height) of each panel, in inches. |
(3.0, 2.5)
|
dpi
|
int
|
Figure resolution. |
150
|
Returns:
| Type | Description |
|---|---|
fig
|
|
axes_by_mode
|
{mode name: Axes}. |
plot_P_profile(P_sorted, LFC_sorted, ax=None, title='', lw=0.2)
Sorted log2 P of each feature, colored by the position of its largest gap.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
P_sorted
|
ndarray
|
Sorted P values (n_features, K). |
required |
LFC_sorted
|
ndarray
|
Log2 ratios between sorted values (n_features, K-1). |
required |
ax
|
Axes | None
|
Axes to draw on; None creates a figure. |
None
|
title
|
str
|
Title. |
''
|
lw
|
float
|
Line width. |
0.2
|
Returns:
| Type | Description |
|---|---|
(fig, ax)
|
|
plot_Q_grid(results, *, sort_by='max', cmap=None, figsize=None, n_ticks=8)
Heatmaps of the Q matrices of all modes, one row per K, with a shared colorbar.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
ClumpplingResults
|
Clumppling results. |
required |
sort_by
|
str
|
"max" sorts cells by their largest membership; "none" keeps the order. |
'max'
|
cmap
|
Optional[str]
|
Colormap. |
None
|
figsize
|
Optional[Tuple[float, float]]
|
Figure size; None sets it from the grid. |
None
|
n_ticks
|
int
|
Maximum number of ticks per axis. |
8
|
Returns:
| Type | Description |
|---|---|
(fig, axes)
|
|
plot_Q_heatmap(results, mode_name, *, sort_by='max', cmap=None, colorbar=True, ax=None)
Heatmap of the Q matrix of one mode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
ClumpplingResults
|
Clumppling results. |
required |
mode_name
|
str
|
Mode name. |
required |
sort_by
|
str
|
"max" sorts cells by their largest membership; "none" keeps the order. |
'max'
|
cmap
|
Optional[str]
|
Colormap. |
None
|
colorbar
|
bool
|
Add a colorbar. |
True
|
ax
|
Optional[Axes]
|
Axes to draw on; None creates a figure. |
None
|
Returns:
| Type | Description |
|---|---|
(fig, ax)
|
|
plot_cluster_bars(results, mode_name, colors=None, *, ax=None)
Bar chart of cluster sizes (sum of memberships) in one mode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
ClumpplingResults
|
Clumppling results. |
required |
mode_name
|
str
|
Mode name. |
required |
colors
|
Optional[Sequence]
|
Color per cluster. |
None
|
ax
|
Optional[Axes]
|
Axes to draw on; None creates a figure. |
None
|
Returns:
| Type | Description |
|---|---|
(fig, ax)
|
|
plot_cluster_in_grid(results, coords, mode_name, cluster_index, *, cmap=None, xlabel='Dim 1', ylabel='Dim 2', base_size=5.0, size_scale=20.0, figsize=None, colorbar=True, **scatter_kwargs)
Membership of one cluster of one mode, in its cell of a grid of modes (rows) by clusters (columns).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
ClumpplingResults
|
Clumppling results. |
required |
coords
|
ndarray
|
Coordinates (n_cells, 2). |
required |
mode_name
|
str
|
Mode name. |
required |
cluster_index
|
int
|
Cluster index. |
required |
cmap
|
Optional[str]
|
Colormap. |
None
|
xlabel
|
str
|
Axis labels. |
'Dim 1'
|
ylabel
|
str
|
Axis labels. |
'Dim 1'
|
base_size
|
float
|
Marker size at zero membership. |
5.0
|
size_scale
|
float
|
Marker size added per unit of membership. |
20.0
|
figsize
|
Optional[Tuple[float, float]]
|
Figure size. |
None
|
colorbar
|
bool
|
Add a colorbar. |
True
|
**scatter_kwargs
|
Passed to |
{}
|
Returns:
| Type | Description |
|---|---|
(fig, axes)
|
|
plot_cluster_overlay(results, coords, *, cluster_colors=None, val_threshold=0.5, s=0.05, alpha=0.6, vmin=0.0, vmax=1.0, figsize=None, dpi=150, suptitle=None, suptitle_kwargs=None)
Memberships of all clusters of each mode on 2D coordinates, one panel per mode, one row per K.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
ClumpplingResults
|
Clumppling results. |
required |
coords
|
ndarray
|
Coordinates (n_cells, 2). |
required |
cluster_colors
|
Optional[Sequence]
|
Color per cluster; None uses tab20. |
None
|
val_threshold
|
float
|
Plot only cells with membership above this value. |
0.5
|
s
|
float
|
Marker size. |
0.05
|
alpha
|
float
|
Marker transparency. |
0.6
|
vmin
|
float
|
Range of the color scale. |
0.0
|
vmax
|
float
|
Range of the color scale. |
0.0
|
figsize
|
Optional[Tuple[float, float]]
|
Figure size; None sets it from the grid. |
None
|
dpi
|
int
|
Figure resolution. |
150
|
suptitle
|
Optional[str]
|
Figure title. |
None
|
suptitle_kwargs
|
Optional[dict]
|
Passed to |
None
|
Returns:
| Type | Description |
|---|---|
(fig, axes)
|
|
plot_cluster_panels(results, coords, *, cluster_colors=None, val_threshold=0.0, s=1.0, alpha=1.0, vmin=0.0, vmax=1.0, figsize=None, dpi=150, suptitle=None, suptitle_kwargs=None)
Membership of each cluster on 2D coordinates, one row per mode and one column per cluster.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
ClumpplingResults
|
Clumppling results. |
required |
coords
|
ndarray
|
Coordinates (n_cells, 2). |
required |
cluster_colors
|
Optional[Sequence]
|
Color per cluster; None uses tab20. |
None
|
val_threshold
|
float
|
Plot only cells with membership above this value. |
0.0
|
s
|
float
|
Marker size. |
1.0
|
alpha
|
float
|
Marker transparency. |
1.0
|
vmin
|
float
|
Range of the color scale. |
0.0
|
vmax
|
float
|
Range of the color scale. |
0.0
|
figsize
|
Optional[Tuple[float, float]]
|
Figure size; None sets it from the grid. |
None
|
dpi
|
int
|
Figure resolution. |
150
|
suptitle
|
Optional[str]
|
Figure title. |
None
|
suptitle_kwargs
|
Optional[dict]
|
Passed to |
None
|
Returns:
| Type | Description |
|---|---|
(fig, axes)
|
|
plot_cluster_scatter(coords, cluster_labels, *, cmap=None, colorbar=True, xlabel='Dim 1', ylabel='Dim 2', title=None, ax=None, max_colorbar_ticks=8, **scatter_kwargs)
Scatter plot of 2D coordinates colored by discrete cluster labels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coords
|
ndarray
|
Coordinates (n_cells, 2). |
required |
cluster_labels
|
ndarray
|
Label per cell. |
required |
cmap
|
Optional[str]
|
Colormap. |
None
|
colorbar
|
bool
|
Add a colorbar. |
True
|
xlabel
|
str
|
Axis labels. |
'Dim 1'
|
ylabel
|
str
|
Axis labels. |
'Dim 1'
|
title
|
Optional[str]
|
Title. |
None
|
ax
|
Optional[Axes]
|
Axes to draw on; None creates a figure. |
None
|
max_colorbar_ticks
|
int
|
Maximum number of colorbar ticks. |
8
|
**scatter_kwargs
|
Passed to |
{}
|
Returns:
| Type | Description |
|---|---|
(fig, ax)
|
|
plot_feature_across_modes(df_pvs_modes, modes, selected_feature, custom_color_dict, *, x_col='weighted_Psum', y_col='sepLFC', sep_col='sepCls', xlim=None, ylim=None, figsize=(3.5, 4), dpi=150, legend_loc='upper right', legend_bbox_to_anchor=(0.0, 0.9), style_label=None, ax=None)
weighted_Psum vs. sepLFC of one feature in each mode, labeled by mode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df_pvs_modes
|
dict[str, DataFrame]
|
{mode name: feature metrics}. |
required |
modes
|
list[str]
|
Mode names. |
required |
selected_feature
|
str
|
Feature name. |
required |
custom_color_dict
|
dict[str, str]
|
{separation type ("Cls.1", ..., "Multi.Cls"): color}. |
required |
x_col
|
Columns to plot. |
'weighted_Psum'
|
|
y_col
|
Columns to plot. |
'weighted_Psum'
|
|
sep_col
|
Column with sepCls. |
'sepCls'
|
|
xlim
|
Axis limits, as [max] or [min, max]. |
None
|
|
ylim
|
Axis limits, as [max] or [min, max]. |
None
|
|
figsize
|
Figure size. |
(3.5, 4)
|
|
dpi
|
int
|
Figure resolution. |
150
|
legend_loc
|
str
|
Legend position. |
'upper right'
|
legend_bbox_to_anchor
|
str
|
Legend position. |
'upper right'
|
style_label
|
list[str]
|
Labels of the low and high side markers. |
None
|
ax
|
Axes | None
|
Axes to draw on; None creates a figure. |
None
|
Returns:
| Type | Description |
|---|---|
(fig, ax)
|
|
df
|
The plotted values, one row per mode. |
plot_feature_bar(df, *, mode_name=None, metric='weighted_Psum', top_n=20, ax=None)
Bar chart of the top features by a metric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Feature metrics, indexed by feature name. |
required |
mode_name
|
str | None
|
Title. |
None
|
metric
|
str
|
Column to rank by. |
'weighted_Psum'
|
top_n
|
int
|
Number of features to show. |
20
|
ax
|
Optional[Axes]
|
Axes to draw on; None creates a figure. |
None
|
Returns:
| Type | Description |
|---|---|
(fig, ax)
|
|
plot_feature_kde(df, x_col, y_col, outlier_mask, *, mode_name=None, label_col=None, levels=8, cmap='viridis_r', bg_point_size=10.0, bg_alpha=0.1, outlier_point_size=30.0, outlier_alpha=0.85, x_pad_frac=0.02, y_pad_frac=0.05, min_x_pad=0.005, min_y_pad=1.0, adjust_text_kwargs=None, ax=None, dpi=150)
Scatter plot of two feature metrics over their KDE, with outliers labeled.
Labels are repelled if adjustText is installed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Feature metrics. |
required |
x_col
|
str
|
Columns to plot. |
required |
y_col
|
str
|
Columns to plot. |
required |
outlier_mask
|
ndarray
|
Features to label, aligned to df (e.g. from |
required |
mode_name
|
str | None
|
Title. |
None
|
label_col
|
str | None
|
Column with the labels; None uses the index. |
None
|
levels
|
int
|
Number of KDE contour levels. |
8
|
cmap
|
str
|
Colormap of the contours. |
'viridis_r'
|
bg_point_size
|
float
|
Size and transparency of the other points. |
10.0
|
bg_alpha
|
float
|
Size and transparency of the other points. |
10.0
|
outlier_point_size
|
float
|
Size and transparency of the outliers. |
30.0
|
outlier_alpha
|
float
|
Size and transparency of the outliers. |
30.0
|
x_pad_frac
|
float
|
Axis padding, as a fraction of the data range. |
0.02
|
y_pad_frac
|
float
|
Axis padding, as a fraction of the data range. |
0.02
|
min_x_pad
|
float
|
Minimum axis padding. |
0.005
|
min_y_pad
|
float
|
Minimum axis padding. |
0.005
|
adjust_text_kwargs
|
dict | None
|
Passed to |
None
|
ax
|
Axes | None
|
Axes to draw on; None creates a figure. |
None
|
dpi
|
int
|
Figure resolution. |
150
|
Returns:
| Type | Description |
|---|---|
(fig, ax)
|
|
plot_feature_metrics(df_mode, mode_name, x_col='weighted_Psum', y_col='sepLFC', sep_col='sepCls', annot_mask=None, xmax=None, ymax=None, custom_color_dict=None)
Joint plot of two feature metrics in one mode, colored by the separated clusters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df_mode
|
Feature metrics of one mode. |
required | |
mode_name
|
Title. |
required | |
x_col
|
Columns to plot. |
'weighted_Psum'
|
|
y_col
|
Columns to plot. |
'weighted_Psum'
|
|
sep_col
|
Column with sepCls. |
'sepCls'
|
|
annot_mask
|
Features to label. |
None
|
|
xmax
|
Axis limits; None sets them from the data. |
None
|
|
ymax
|
Axis limits; None sets them from the data. |
None
|
|
custom_color_dict
|
{separation type ("Cls.1", ..., "Multi.Cls"): color}. |
None
|
Returns:
| Type | Description |
|---|---|
g
|
Seaborn JointGrid. |
ax
|
Joint Axes. |
plot_feature_scatter(df, *, mode_name=None, x='weighted_Psum', y='sepLFC', highlight=None, ax=None)
Scatter plot of two feature metrics (by default weighted_Psum vs. sepLFC).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Feature metrics, indexed by feature name. |
required |
mode_name
|
str | None
|
Title. |
None
|
x
|
str
|
Columns to plot. |
'weighted_Psum'
|
y
|
str
|
Columns to plot. |
'weighted_Psum'
|
highlight
|
Iterable[str] | None
|
Features to label. |
None
|
ax
|
Optional[Axes]
|
Axes to draw on; None creates a figure. |
None
|
Returns:
| Type | Description |
|---|---|
(fig, ax)
|
|
plot_feature_sepLFC_across_modes(res_model, df_pvs_modes, selected_feature, feature_names, colors, *, label_rank=True, dpi=150, ax=None)
Bar chart of the sepLFC of one feature in each mode, colored by the separated clusters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
res_model
|
Clumppling results. |
required | |
df_pvs_modes
|
Mapping[str, 'pd.DataFrame']
|
{mode name: feature metrics}, rows in the order of feature_names. |
required |
selected_feature
|
str
|
Feature name. |
required |
feature_names
|
Sequence[str]
|
All feature names. |
required |
colors
|
Sequence
|
Color per cluster. |
required |
label_rank
|
bool
|
Label each bar with the feature's sepLFC rank in that mode. |
True
|
dpi
|
int
|
Figure resolution. |
150
|
ax
|
Optional[Axes]
|
Axes to draw on; None creates a figure. |
None
|
Returns:
| Type | Description |
|---|---|
(fig, ax)
|
|
plot_mode_P_profile(results, mode_name, ax=None, title=None, lw=0.2)
Sorted log2 P of each feature in one mode (see plot_P_profile).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
ClumpplingResults
|
Results loaded with P matrices. |
required |
mode_name
|
str
|
Mode name. |
required |
ax
|
Axes | None
|
Axes to draw on; None creates a figure. |
None
|
title
|
str | None
|
Title; None uses the mode name. |
None
|
lw
|
float
|
Line width. |
0.2
|
Returns:
| Type | Description |
|---|---|
(fig, ax)
|
|
plot_sepLFC_dist(results, mode_name, *, lfc_threshold=10.0, ax=None, title=None)
Distribution of sepLFC in one mode, by the position of the largest gap.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
ClumpplingResults
|
Results loaded with P matrices. |
required |
mode_name
|
str
|
Mode name. |
required |
lfc_threshold
|
float
|
sepLFC values above this are highlighted. |
10.0
|
ax
|
Axes | None
|
Axes to draw on; None creates a figure. |
None
|
title
|
str | None
|
Title; None uses the mode name. |
None
|
Returns:
| Type | Description |
|---|---|
(fig, ax)
|
|
plot_sepLFC_labels(df_selected, modes, *, sepLFC_threshold=0.0, cmap='Reds', vmin=1e-05, vmax=None, y_max=40.0, hi_sepLFC_threshold=32.0, n_top_hi=15, n_top_lo=8, figsize_scale=0.95, dpi=150)
sepLFC of the selected features in each mode, with the top features labeled and colored by weighted_Psum.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df_selected
|
DataFrame
|
Output of |
required |
modes
|
Sequence[str]
|
Mode names, one panel each. |
required |
sepLFC_threshold
|
float
|
Show only features with sepLFC above this value. |
0.0
|
cmap
|
str
|
Colormap of weighted_Psum. |
'Reds'
|
vmin
|
float
|
Range of the (log) color scale; vmax None uses the data. |
1e-05
|
vmax
|
float
|
Range of the (log) color scale; vmax None uses the data. |
1e-05
|
y_max
|
float
|
Upper y limit. |
40.0
|
hi_sepLFC_threshold
|
float
|
If the top sepLFC of a mode is above this, label n_top_hi features; otherwise n_top_lo. |
32.0
|
n_top_hi
|
int
|
Number of features to label. |
15
|
n_top_lo
|
int
|
Number of features to label. |
15
|
figsize_scale
|
float
|
Figure width per mode, in inches. |
0.95
|
dpi
|
int
|
Figure resolution. |
150
|
Returns:
| Type | Description |
|---|---|
fig
|
|
axes_by_mode
|
{mode name: Axes}. |
plot_spatial_membership(Q, coords, ref_color, *, cls_idx=0, ax=None, val_threshold=0.0, vmin=0.0, vmax=1.0, s=1.0, alpha=1.0, title=None, keep_ticks=False)
Scatter plot of 2D coordinates colored by the membership of one cluster.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q
|
Q matrix (n_cells, K), or memberships of one cluster (n_cells,). |
required | |
coords
|
Coordinates (n_cells, 2), or a tuple (x, y). |
required | |
ref_color
|
Color of full membership. |
required | |
cls_idx
|
int
|
Cluster index, if Q is a matrix. |
0
|
ax
|
Optional[Axes]
|
Axes to draw on; None creates a figure. |
None
|
val_threshold
|
float
|
Plot only cells with membership above this value. |
0.0
|
vmin
|
float
|
Range of the color scale. |
0.0
|
vmax
|
float
|
Range of the color scale. |
0.0
|
s
|
float
|
Marker size. |
1.0
|
alpha
|
float
|
Marker transparency. |
1.0
|
title
|
Optional[str]
|
Title. |
None
|
keep_ticks
|
bool
|
Keep the axis ticks. |
False
|
Returns:
| Type | Description |
|---|---|
ax
|
|
sp
|
The scatter plot. |
Model Comparison
Plots comparing modes and models.
Classes
Functions
plot_avg_membership_barh(avg_cls_memberships, *, annot_col='annot', model_order=None, cluster_order=None, cluster_mode='auto', colors=None, figsize_per_cluster=(2.2, 4.0), dpi=150)
Mean cluster membership per annotation group, one panel per cluster, one bar per model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
avg_cls_memberships
|
Dict[str, DataFrame]
|
Output of |
required |
annot_col
|
str
|
Annotation column. |
'annot'
|
model_order
|
Optional[Sequence[str]]
|
Order of the models; None keeps the dict order. |
None
|
cluster_order
|
Optional[Sequence[str]]
|
Order of the clusters. |
None
|
cluster_mode
|
Literal['intersection', 'union', 'auto']
|
Clusters to show: "intersection", "union", or "auto" (intersection if not empty). |
'auto'
|
colors
|
Optional[Sequence[str]]
|
Color of each cluster title. |
None
|
figsize_per_cluster
|
Tuple[float, float]
|
(width, height) of each panel, in inches. |
(2.2, 4.0)
|
dpi
|
int
|
Figure resolution. |
150
|
Returns:
| Type | Description |
|---|---|
(fig, axes)
|
|
plot_compmodels_Q_grid(comp_res, coords, models=None, models_plot_order=None, val_threshold=0.5, s=0.05, colors=None, figsize_scale=(2.5, 2.0), suptitle=None, y_suptitle=0.92)
Memberships on 2D coordinates for all modes, one column per model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
comp_res
|
CompModelsResults
|
compModels results. |
required |
coords
|
Coordinates (n_cells, 2), or a tuple (x, y). |
required | |
models
|
Optional[Sequence[str]]
|
Models to include; None uses all. |
None
|
models_plot_order
|
Optional[Sequence[str]]
|
Column order; None uses models. |
None
|
val_threshold
|
float
|
Plot only cells with membership above this value. |
0.5
|
s
|
float
|
Marker size. |
0.05
|
colors
|
Optional[Sequence]
|
Color per cluster; None uses tab20. |
None
|
figsize_scale
|
Tuple[float, float]
|
(width, height) of each panel, in inches. |
(2.5, 2.0)
|
suptitle
|
Optional[str]
|
Figure title. |
None
|
y_suptitle
|
float
|
Vertical position of the title. |
0.92
|
Returns:
| Type | Description |
|---|---|
fig
|
|
axes_by_model_mode
|
{(model, mode name): Axes}. |
plot_compmodels_Q_selected(comp_res, coords, model_mode_list, *, n_rows=None, n_cols=None, val_threshold=0.5, s=0.05, colors=None, figsize_scale=(2.5, 2.0), suptitle=None, y_suptitle=0.92)
Memberships on 2D coordinates for selected modes, one panel each.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
comp_res
|
compModels results. |
required | |
coords
|
Coordinates (n_cells, 2), or a tuple (x, y). |
required | |
model_mode_list
|
Sequence[Tuple[str, str]]
|
(model, mode name) pairs, e.g. [("scanpy.leiden", "K8M1")]. |
required |
n_rows
|
Optional[int]
|
Grid shape; by default one row. |
None
|
n_cols
|
Optional[int]
|
Grid shape; by default one row. |
None
|
val_threshold
|
float
|
Plot only cells with membership above this value. |
0.5
|
s
|
float
|
Marker size. |
0.05
|
colors
|
Optional[Sequence]
|
Color per cluster; None uses tab20. |
None
|
figsize_scale
|
Tuple[float, float]
|
(width, height) of each panel, in inches. |
(2.5, 2.0)
|
suptitle
|
Optional[str]
|
Figure title. |
None
|
y_suptitle
|
float
|
Vertical position of the title. |
0.92
|
Returns:
| Type | Description |
|---|---|
fig
|
|
axes_by_model_mode
|
{(model, mode name): Axes}. |
plot_compmodels_alignment_by_model(comp_res, cmap=None, *, models=None, models_plot_order=None, row_by_K=False, wspace_padding=1.3, marker_size=200.0, alt_ls=False, ls_alt=('-', '--'), lw=1.0, connect_identity=False, adjacent_only=True, label_modes=True, figsize_scale=(0.3, 2), dpi=150, pair_mappings=None)
Alignment graph of several models, one column per model.
Each mode is a row of cluster markers; lines join aligned clusters between models (and between modes of the same model, if pair_mappings is given).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
comp_res
|
compModels results. |
required | |
cmap
|
Colormap or list of colors; None uses tab20. |
None
|
|
models
|
Optional[Sequence[str]]
|
Models to include; None uses all. |
None
|
models_plot_order
|
Optional[Sequence[str]]
|
Column order; None uses models. |
None
|
row_by_K
|
bool
|
Put modes with the same K in the same row across models; otherwise rows follow the mode order of each model. |
False
|
wspace_padding
|
float
|
Space between model columns, in units of K_max. |
1.3
|
marker_size
|
float
|
Marker size. |
200.0
|
alt_ls
|
bool
|
Use ls_alt line styles. |
False
|
ls_alt
|
Sequence[str]
|
Line styles of changed and unchanged cluster mappings. |
('-', '--')
|
lw
|
float
|
Line width. |
1.0
|
connect_identity
|
bool
|
Also draw unchanged cluster mappings. |
False
|
adjacent_only
|
bool
|
Draw lines only between adjacent model columns. |
True
|
label_modes
|
bool
|
Label each mode. |
True
|
figsize_scale
|
Tuple[float, float]
|
(width per cluster, height per row), in inches. |
(0.3, 2)
|
dpi
|
int
|
Figure resolution. |
150
|
pair_mappings
|
Optional[Dict[str, Sequence[Tuple[int, int]]]]
|
Output of |
None
|
Returns:
| Type | Description |
|---|---|
(fig, ax)
|
|
plot_compmodels_alignment_list(comp_res, cmap=None, marker_size=250, figsize=(6, 6))
Alignment list of all modes of all models (Clumppling's plot_alignment_list).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
comp_res
|
compModels results. |
required | |
cmap
|
Colormap or list of colors; None uses tab20. |
None
|
|
marker_size
|
int
|
Marker size. |
250
|
figsize
|
Tuple[float, float]
|
Figure size. |
(6, 6)
|
Returns:
| Type | Description |
|---|---|
fig
|
|
Q_names_reordered
|
Full mode names, in plot order. |
mode_K
|
K of each mode, in plot order. |
plot_compmodels_diff_grid(comp_res, pair_mappings, coords, ref_mode, models_plot_order=None, val_threshold=0.5, diff_threshold=0.5, *, colors=None, s=0.05, alpha=0.6, figsize_scale=(2.5, 2.0), suptitle=None, y_suptitle=0.92, strict_pair_mapping=True)
Membership differences from a reference mode on 2D coordinates, for all modes, one column per model.
The reference mode shows its memberships; every other mode shows cells whose difference is above diff_threshold. Titles give the overall difference (see compute_membership_diff).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
comp_res
|
compModels results. |
required | |
pair_mappings
|
Dict[str, Sequence[Tuple[int, int]]]
|
Output of |
required |
coords
|
Coordinates (n_cells, 2), or a tuple (x, y). |
required | |
ref_mode
|
str
|
Full mode name of the reference mode. |
required |
models_plot_order
|
Optional[Sequence[str]]
|
Column order; None uses all models. |
None
|
val_threshold
|
float
|
Plot only cells with membership above this value. |
0.5
|
diff_threshold
|
float
|
Plot only cells with a difference above this value. |
0.5
|
colors
|
Optional[Sequence]
|
Color per cluster; None uses tab20. |
None
|
s
|
float
|
Marker size. |
0.05
|
alpha
|
float
|
Marker transparency. |
0.6
|
figsize_scale
|
Tuple[float, float]
|
(width, height) of each panel, in inches. |
(2.5, 2.0)
|
suptitle
|
Optional[str]
|
Figure title. |
None
|
y_suptitle
|
float
|
Vertical position of the title. |
0.92
|
strict_pair_mapping
|
bool
|
Raise an error if a pair mapping is missing. |
True
|
Returns:
| Type | Description |
|---|---|
fig
|
|
axes_by_model_mode
|
{(model, mode name): Axes}. |
plot_compmodels_diff_selected(comp_res, pair_mappings, coords, ref_mode, model_mode_list, *, n_rows=None, n_cols=None, val_threshold=0.5, diff_threshold=0.5, colors=None, s=0.05, alpha=0.6, figsize_scale=(2.5, 2.0), suptitle=None, y_suptitle=0.92, strict_pair_mapping=True)
Membership differences from a reference mode on 2D coordinates, for selected modes.
Same as plot_compmodels_diff_grid, with one panel per (model, mode name) in model_mode_list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
comp_res
|
compModels results. |
required | |
pair_mappings
|
Dict[str, Sequence[Tuple[int, int]]]
|
Output of |
required |
coords
|
Coordinates (n_cells, 2), or a tuple (x, y). |
required | |
ref_mode
|
str
|
Full mode name of the reference mode. |
required |
model_mode_list
|
Sequence[Tuple[str, str]]
|
(model, mode name) pairs. |
required |
n_rows
|
Optional[int]
|
Grid shape; by default one row. |
None
|
n_cols
|
Optional[int]
|
Grid shape; by default one row. |
None
|
val_threshold
|
float
|
Plot only cells with membership above this value. |
0.5
|
diff_threshold
|
float
|
Plot only cells with a difference above this value. |
0.5
|
colors
|
Optional[Sequence]
|
Color per cluster; None uses tab20. |
None
|
s
|
float
|
Marker size. |
0.05
|
alpha
|
float
|
Marker transparency. |
0.6
|
figsize_scale
|
Tuple[float, float]
|
(width, height) of each panel, in inches. |
(2.5, 2.0)
|
suptitle
|
Optional[str]
|
Figure title. |
None
|
y_suptitle
|
float
|
Vertical position of the title. |
0.92
|
strict_pair_mapping
|
bool
|
Raise an error if a pair mapping is missing. |
True
|
Returns:
| Type | Description |
|---|---|
fig
|
|
axes_by_model_mode
|
{(model, mode name): Axes}. |
plot_discrete_colorbar(colors, K_max=None, *, labels=None, ax=None, figsize=None, dpi=150, facecolor='white')
Strip of cluster colors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
colors
|
Sequence[ColorSpec]
|
Color per cluster. |
required |
K_max
|
Optional[int]
|
Number of clusters; None uses len(colors). |
None
|
labels
|
Optional[Sequence[str]]
|
Tick labels; None uses "Cls.1", "Cls.2", ... |
None
|
ax
|
Optional[Axes]
|
Axes to draw on; None creates a figure. |
None
|
figsize
|
Optional[Tuple[float, float]]
|
Figure size; None scales with K. |
None
|
dpi
|
int
|
Figure resolution. |
150
|
facecolor
|
str
|
Background color. |
'white'
|
Returns:
| Type | Description |
|---|---|
(fig, ax)
|
|
im
|
The image. |
plot_feature_cluster_panels(results, coords, df_pvs_modes, selected_feature, *, modes=None, colors=None, plot_both_sides=False, val_threshold=0.0, w_scale=1.2, h_scale=1.4, dpi=150, suptitle=None)
Memberships of the clusters that one feature separates, in each mode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
Clumppling results. |
required | |
coords
|
Coordinates (n_cells, 2), or a tuple (x, y). |
required | |
df_pvs_modes
|
dict
|
{mode name: feature metrics}. |
required |
selected_feature
|
str
|
Feature name. |
required |
modes
|
Mode names; None uses all modes with the feature. |
None
|
|
colors
|
Color per cluster (list or colormap); None uses tab20. |
None
|
|
plot_both_sides
|
bool
|
Show both sides of each separation (one row per mode); otherwise only the side with fewer clusters. |
False
|
val_threshold
|
float
|
Plot only cells with membership above this value. |
0.0
|
w_scale
|
float
|
Panel width and height, in inches. |
1.2
|
h_scale
|
float
|
Panel width and height, in inches. |
1.2
|
dpi
|
int
|
Figure resolution. |
150
|
suptitle
|
str | None
|
Figure title. |
None
|
Returns:
| Type | Description |
|---|---|
fig
|
|
axes
|
{(mode name, column): Axes}. |
plot_feature_count(feature_counts, coords, *, feature_name='', log_transformed=True, vmax=6, vmin=None, size=5, cmap='RdYlBu_r', cbar_loc='bottom', cbar_label=None, ax=None)
Values of one feature on 2D coordinates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature_counts
|
Value per cell (dense or sparse). |
required | |
coords
|
ndarray
|
Coordinates (n_cells, 2). |
required |
feature_name
|
str | None
|
Title. |
''
|
log_transformed
|
bool
|
Whether the values are already log-transformed; otherwise log1p is applied. |
True
|
vmax
|
float | None
|
Range of the color scale; vmax None or 0 uses the data. |
6
|
vmin
|
float | None
|
Range of the color scale; vmax None or 0 uses the data. |
6
|
size
|
float
|
Marker size. |
5
|
cmap
|
str
|
Colormap. |
'RdYlBu_r'
|
cbar_loc
|
str
|
Colorbar position: "bottom", "top", "left" or "right". |
'bottom'
|
cbar_label
|
str | None
|
Colorbar label. |
None
|
ax
|
Axes to draw on; None creates a figure. |
None
|
Returns:
| Type | Description |
|---|---|
fig
|
|
plot_group_diff(df_mode_group_diff, *, mode_sizes=None, annotation_group_sizes=None, ref_mode=None, show_top=True, show_left=True, annot=None, cmap='Reds', cbar_label='Fraction of different cells', top_ylabel='#cells in the group', left_xlabel='Mode size', x_label='Annotation groups', y_label='Modes', figsize=(10, 8), dpi=300, height_ratios=(1, 6), width_ratios=(1.5, 6), wspace=0.01, hspace=0.01, vmin=0.0, vmax=1.0, cbar_fraction=0.6, xtick_rotation=45, xtick_fontsize=8, ytick_fontsize=8, label_fontsize=7, border_width=0.5, border_color='lightgray', zero_label_eps=0.001, top_round_to=500, show_mode_size_labels=True, add_model_separators=True, model_sep_kwargs=None)
Heatmap of membership differences by mode (rows) and annotation group (columns), with optional bars of group sizes (top) and mode sizes (left).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df_mode_group_diff
|
DataFrame
|
Differences, modes by annotation groups (e.g. from |
required |
mode_sizes
|
Optional[Series]
|
Mode sizes indexed by full mode name (e.g. from |
None
|
annotation_group_sizes
|
Optional[Series]
|
Group sizes (e.g. from |
None
|
ref_mode
|
Optional[str]
|
Reference mode, highlighted in the row labels. |
None
|
show_top
|
bool
|
Show the group size and mode size bars. |
True
|
show_left
|
bool
|
Show the group size and mode size bars. |
True
|
annot
|
Cell labels; None shows values at or above zero_label_eps. |
None
|
|
cmap
|
str
|
Colormap. |
'Reds'
|
cbar_label
|
str
|
Colorbar label. |
'Fraction of different cells'
|
top_ylabel
|
str
|
Labels of the size bars. |
'#cells in the group'
|
left_xlabel
|
str
|
Labels of the size bars. |
'#cells in the group'
|
x_label
|
str
|
Heatmap axis labels. |
'Annotation groups'
|
y_label
|
str
|
Heatmap axis labels. |
'Annotation groups'
|
figsize
|
Tuple[float, float]
|
Figure size. |
(10, 8)
|
dpi
|
int
|
Figure resolution. |
300
|
height_ratios
|
Tuple[float, float]
|
Relative sizes of the bars and the heatmap. |
(1, 6)
|
width_ratios
|
Tuple[float, float]
|
Relative sizes of the bars and the heatmap. |
(1, 6)
|
wspace
|
float
|
Space between panels. |
0.01
|
hspace
|
float
|
Space between panels. |
0.01
|
vmin
|
float
|
Range of the color scale. |
0.0
|
vmax
|
float
|
Range of the color scale. |
0.0
|
cbar_fraction
|
float
|
Colorbar size, as a fraction of the heatmap. |
0.6
|
xtick_rotation
|
float
|
Tick and label formatting. |
45
|
xtick_fontsize
|
float
|
Tick and label formatting. |
45
|
ytick_fontsize
|
float
|
Tick and label formatting. |
45
|
label_fontsize
|
float
|
Tick and label formatting. |
45
|
border_width
|
float
|
Heatmap cell borders. |
0.5
|
border_color
|
float
|
Heatmap cell borders. |
0.5
|
zero_label_eps
|
float
|
Values below this are not labeled. |
0.001
|
top_round_to
|
int
|
Round the group size axis limit up to a multiple of this. |
500
|
show_mode_size_labels
|
bool
|
Label the mode size bars. |
True
|
add_model_separators
|
bool
|
Draw lines between models. |
True
|
model_sep_kwargs
|
Optional[dict]
|
Passed to |
None
|
Returns:
| Type | Description |
|---|---|
fig
|
|
axes
|
{"heatmap", "top", "left": Axes}. |
plot_mapping_alignment(*, pair_mapping, ref_K, alt_K, ref_mode, alt_mode, colors, figsize=(5, 2), dpi=150, node_size=150, node_edgecolor='black', node_linewidth=0.5, line_color='k', line_alpha=0.5, line_lw=1.0, ax=None, title=None)
Diagram of the cluster mapping between two modes, one row each.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pair_mapping
|
Sequence[Tuple[int, int]]
|
(reference cluster, alternative cluster) pairs. |
required |
ref_K
|
int
|
Number of clusters of each mode. |
required |
alt_K
|
int
|
Number of clusters of each mode. |
required |
ref_mode
|
str
|
Mode names. |
required |
alt_mode
|
str
|
Mode names. |
required |
colors
|
Union[Sequence, Mapping[int, str]]
|
Color per cluster (list or dict). |
required |
figsize
|
Tuple[float, float]
|
Figure size. |
(5, 2)
|
dpi
|
int
|
Figure resolution. |
150
|
node_size
|
float
|
Marker size and edge. |
150
|
node_edgecolor
|
float
|
Marker size and edge. |
150
|
node_linewidth
|
float
|
Marker size and edge. |
150
|
line_color
|
str
|
Line color, transparency and width. |
'k'
|
line_alpha
|
str
|
Line color, transparency and width. |
'k'
|
line_lw
|
str
|
Line color, transparency and width. |
'k'
|
ax
|
Optional[Axes]
|
Axes to draw on; None creates a figure. |
None
|
title
|
Optional[str]
|
Title. |
None
|
Returns:
| Type | Description |
|---|---|
(fig, ax)
|
|
plot_mapping_grid(*, ref_Q, alt_Q, pair_mappings, ref_mode, alt_mode, coords, colors, show=('alt',), dpi=150, s=0.5, figsize_scale=(2.0, 2.0), strict_pair_mapping=True, connect_lines=True, connect_color='k', connect_alpha=0.25, connect_lw=0.8)
Memberships of a reference and an alternative mode on 2D coordinates, showing how their clusters map.
The first row is the mode with the smaller K. The show argument adds rows of the other mode as is ("alt"), mapped onto the first ("mapped_alt"), and the absolute differences ("diff").
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ref_Q
|
ndarray
|
Q matrix of the reference mode. |
required |
alt_Q
|
ndarray
|
Q matrix of the alternative mode. |
required |
pair_mappings
|
Dict[str, Sequence[Tuple[int, int]]]
|
Output of |
required |
ref_mode
|
str
|
Mode names. |
required |
alt_mode
|
str
|
Mode names. |
required |
coords
|
Coordinates (n_cells, 2), or a tuple (x, y). |
required | |
colors
|
Sequence
|
Color per cluster. |
required |
show
|
Sequence[str]
|
Rows to add: any of "alt", "mapped_alt" and "diff". |
('alt',)
|
dpi
|
int
|
Figure resolution. |
150
|
s
|
float
|
Marker size. |
0.5
|
figsize_scale
|
Tuple[float, float]
|
(width, height) of each panel, in inches. |
(2.0, 2.0)
|
strict_pair_mapping
|
bool
|
Raise an error if the pair mapping is missing. |
True
|
connect_lines
|
bool
|
Draw lines between mapped clusters. |
True
|
connect_color
|
str
|
Line color, transparency and width. |
'k'
|
connect_alpha
|
str
|
Line color, transparency and width. |
'k'
|
connect_lw
|
str
|
Line color, transparency and width. |
'k'
|
Returns:
| Type | Description |
|---|---|
(fig, axes)
|
|
plot_membership_reordered(P, cmap, lbs, ax, title='', annot='')
Structure plot of a Q matrix, with clusters ordered by size and cells sorted within each label group.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
P
|
Q matrix (n_cells, K). |
required | |
cmap
|
Color per cluster. |
required | |
lbs
|
Label per cell. |
required | |
ax
|
Axes to draw on. |
required | |
title
|
y-axis label. |
''
|
|
annot
|
Text at the top right. |
''
|
plot_model_diff_heatmap(cross_model_overall_membership_diff, comp_res, models, *, figsize=(9, 8), dpi=150, cmap='Reds', decimals=2, vmin=0.0, vmax=1.0, linewidths=0.5, linecolor='white', ax=None, cbar=True, annot_size=8, tight_layout=True, show=False)
Heatmap of overall membership differences between the modes of two models.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cross_model_overall_membership_diff
|
Union[Mapping[Tuple[str, str], float], Series]
|
{(mode of model 1, mode of model 2): difference}, as a dict or Series. |
required |
comp_res
|
Any
|
compModels results, used to order the modes. |
required |
models
|
Sequence[str]
|
The two model names, in the order of the keys. |
required |
figsize
|
Tuple[float, float]
|
Figure and heatmap formatting. |
(9, 8)
|
dpi
|
Tuple[float, float]
|
Figure and heatmap formatting. |
(9, 8)
|
cmap
|
Tuple[float, float]
|
Figure and heatmap formatting. |
(9, 8)
|
vmin
|
Tuple[float, float]
|
Figure and heatmap formatting. |
(9, 8)
|
vmax
|
Tuple[float, float]
|
Figure and heatmap formatting. |
(9, 8)
|
linewidths
|
Tuple[float, float]
|
Figure and heatmap formatting. |
(9, 8)
|
linecolor
|
Tuple[float, float]
|
Figure and heatmap formatting. |
(9, 8)
|
decimals
|
int
|
Number of decimals in the cell labels; negative hides them. |
2
|
annot_size
|
int
|
Font size of the cell labels. |
8
|
ax
|
Optional[Axes]
|
Axes to draw on; None creates a figure. |
None
|
cbar
|
bool
|
Add a colorbar. |
True
|
tight_layout
|
bool
|
Call |
True
|
show
|
bool
|
Call |
False
|
Returns:
| Type | Description |
|---|---|
(fig, ax)
|
|
mat
|
The plotted matrix. |
plot_model_diff_summary(comp_res, mat_diffs, coords, models_plot_order=None, *, colors=None, figsize_scale=(2.5, 2.5), diff_cmap='RdPu', diff_vmin=0.0, diff_vmax=1.0, point_size=2.0, alpha=1.0, suptitle=None)
Per model, the major mode (top) and the mean difference per cell from the reference, weighted by mode size (bottom).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
comp_res
|
compModels results. |
required | |
mat_diffs
|
Output of |
required | |
coords
|
Coordinates (n_cells, 2), or a tuple (x, y). |
required | |
models_plot_order
|
Column order; None uses the keys of mat_diffs. |
None
|
|
colors
|
Color per cluster; None uses tab20. |
None
|
|
figsize_scale
|
(width, height) of each panel, in inches. |
(2.5, 2.5)
|
|
diff_cmap
|
Colormap of the differences. |
'RdPu'
|
|
diff_vmin
|
Range of the difference color scale. |
0.0
|
|
diff_vmax
|
Range of the difference color scale. |
0.0
|
|
point_size
|
Marker size. |
2.0
|
|
alpha
|
Marker transparency. |
1.0
|
|
suptitle
|
Figure title. |
None
|
Returns:
| Type | Description |
|---|---|
fig
|
|
axes
|
Array (2, n_models). |
plot_spatial_structure_grid(results, coords, grps, *, modes=None, cmap=None, mode_labels=None, grp_seps=None, s=1.0, alpha=1.0, vmin=0.0, vmax=1.0, figsize=None, dpi=150)
For each mode, the structure plot and each cluster's membership on 2D coordinates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
ClumpplingResults
|
Clumppling results. |
required |
coords
|
ndarray
|
Coordinates (n_cells, 2). |
required |
grps
|
Sequence[str]
|
Label per cell, used to group cells in the structure plots. |
required |
modes
|
Optional[Sequence[str]]
|
Mode names; None uses all. |
None
|
cmap
|
Optional[Any]
|
Color per cluster (list or colormap); None uses tab20. |
None
|
mode_labels
|
Optional[Sequence[str]]
|
Row labels; None uses the mode names. |
None
|
grp_seps
|
Optional[Sequence[float]]
|
Group separator positions; None computes them from grps. |
None
|
s
|
float
|
Marker size. |
1.0
|
alpha
|
float
|
Marker transparency. |
1.0
|
vmin
|
float
|
Range of the color scale. |
0.0
|
vmax
|
float
|
Range of the color scale. |
0.0
|
figsize
|
Optional[Tuple[float, float]]
|
Figure size; None scales with the grid. |
None
|
dpi
|
int
|
Figure resolution. |
150
|
Returns:
| Type | Description |
|---|---|
fig
|
|
plot_structure_one_level(results, *, modes=None, cmap=None, grp_labels=(), mode_labels=None, reorder_clsind=True, grp_seps_ymin=-0.2, lb_suffix_sep=None, figsize=None, dpi=150, x_rot=0, x_ha='center')
Structure plots of several modes, with cells grouped by one level of labels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
Clumppling results. |
required | |
modes
|
Optional[Sequence[str]]
|
Mode names; None uses all. |
None
|
cmap
|
Color per cluster. |
None
|
|
grp_labels
|
Sequence[str]
|
Label per cell. |
()
|
mode_labels
|
Optional[Sequence[str]]
|
Row labels; None uses the mode names. |
None
|
reorder_clsind
|
bool
|
Use |
True
|
grp_seps_ymin
|
float
|
How far the group separator lines extend below each plot. |
-0.2
|
lb_suffix_sep
|
Optional[str]
|
Show only the part of each label after this separator. |
None
|
figsize
|
Optional[Tuple[float, float]]
|
Figure size; None scales with the number of modes. |
None
|
dpi
|
int
|
Figure resolution. |
150
|
x_rot
|
float
|
Rotation and alignment of the group labels. |
0
|
x_ha
|
float
|
Rotation and alignment of the group labels. |
0
|
Returns:
| Type | Description |
|---|---|
fig
|
|
plot_structure_two_level(results, *, modes=None, cmap=None, grp_labels=(), supgrp_labels=None, mode_labels=None, reorder_clsind=True, grp_seps_ymin=-0.2, supgrp_seps_ymin=-0.6, lb_suffix_sep=None, figsize=None, dpi=150)
Structure plots of several modes, with cells grouped by two levels of labels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
ClumpplingResults
|
Clumppling results. |
required |
modes
|
Optional[Sequence[str]]
|
Mode names; None uses all. |
None
|
cmap
|
Color per cluster. |
None
|
|
grp_labels
|
Sequence[str]
|
Label per cell (lower level). |
()
|
supgrp_labels
|
Optional[Sequence[str]]
|
Label per cell (upper level), or None. |
None
|
mode_labels
|
Optional[Sequence[str]]
|
Row labels; None uses the mode names. |
None
|
reorder_clsind
|
bool
|
Use |
True
|
grp_seps_ymin
|
float
|
How far the group separator lines extend below each plot. |
-0.2
|
supgrp_seps_ymin
|
float
|
How far the group separator lines extend below each plot. |
-0.2
|
lb_suffix_sep
|
Optional[str]
|
Show only the part of each label after this separator. |
None
|
figsize
|
Optional[Tuple[float, float]]
|
Figure size; None scales with the number of modes. |
None
|
dpi
|
int
|
Figure resolution. |
150
|
Returns:
| Type | Description |
|---|---|
fig
|
|
strip_leading_zero(x, decimals=2)
Format a number with the given decimals, without the leading zero (0.25 -> ".25").
Gene Set Enrichment
Plots of gene set enrichment results.
Classes
Functions
plot_LFC_enrichment_grid(res_by_mode, ax_by_mode, results, cb_cmap)
Pairwise LFC z-score heatmaps of each mode, drawn into a grid of Axes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
res_by_mode
|
Output of |
required | |
ax_by_mode
|
{mode name: Axes}, e.g. from |
required | |
results
|
Clumppling results, for K of each mode. |
required | |
cb_cmap
|
Color per cluster. |
required |
plot_LFC_enrichment_heatmap(res_by_mode, results, value='z', sig_level=0.05, cmap='coolwarm', center_zero=True, figsize=None, dpi=150, title=None, ax=None)
Heatmap of pairwise LFC enrichment by mode (rows) and cluster pair (columns), with significant cells marked by *.
Each pair (i < j) has the same column in every mode; pairs beyond a mode's K are blank.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
res_by_mode
|
dict
|
Output of |
required |
results
|
Clumppling results, for K of each mode. |
required | |
value
|
str
|
"z" (z-score) or "obs" (observed LFC). |
'z'
|
sig_level
|
float
|
Significance level of q. |
0.05
|
cmap
|
str
|
Colormap. |
'coolwarm'
|
center_zero
|
bool
|
Center the color scale on 0. |
True
|
figsize
|
tuple | None
|
Figure size; None scales with the data. |
None
|
dpi
|
int
|
Figure resolution. |
150
|
title
|
str | None
|
Title. |
None
|
ax
|
Axes to draw on; None creates a figure. |
None
|
Returns:
| Type | Description |
|---|---|
(fig, ax)
|
|
plot_P_enrichment_by_cluster(res_by_mode, results, cb_cmap, kind='pval', ncols=None, figsize_per_panel=(3.0, 2.8), dpi=150, sig_threshold=None)
P enrichment of each cluster across modes, one panel per cluster.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
res_by_mode
|
Output of |
required | |
results
|
Clumppling results, for K of each mode. |
required | |
cb_cmap
|
Color per cluster. |
required | |
kind
|
"pval" (-log10 p_emp) or "zscore". |
'pval'
|
|
ncols
|
Number of columns; None uses K_max. |
None
|
|
figsize_per_panel
|
(width, height) of each panel, in inches. |
(3.0, 2.8)
|
|
dpi
|
Figure resolution. |
150
|
|
sig_threshold
|
Reference line: p-value for "pval" (default 0.05), |z| for "zscore" (default 2). |
None
|
Returns:
| Type | Description |
|---|---|
(fig, axes)
|
|
plot_P_enrichment_grid(res_by_mode, ax_by_mode, results, cb_cmap, kind='pval')
P enrichment bars of each mode, drawn into a grid of Axes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
res_by_mode
|
Output of |
required | |
ax_by_mode
|
{mode name: Axes}, e.g. from |
required | |
results
|
Clumppling results, for K of each mode. |
required | |
cb_cmap
|
Color per cluster. |
required | |
kind
|
"pval" or "zscore". |
'pval'
|
plot_P_enrichment_heatmap(res_by_mode, results, value='z', sig_level=0.05, cmap='OrRd', center_zero=False, figsize=None, dpi=150, title=None, ax=None)
Heatmap of P enrichment by mode (rows) and cluster (columns), with significant cells marked by *.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
res_by_mode
|
dict
|
Output of |
required |
results
|
Clumppling results, for K of each mode. |
required | |
value
|
str
|
"z" (z-score) or "p" (empirical p-value). |
'z'
|
sig_level
|
float
|
Significance level of p_emp. |
0.05
|
cmap
|
str
|
Colormap. |
'OrRd'
|
center_zero
|
bool
|
Center the color scale on 0. |
False
|
figsize
|
tuple | None
|
Figure size; None scales with the data. |
None
|
dpi
|
int
|
Figure resolution. |
150
|
title
|
str | None
|
Title. |
None
|
ax
|
Axes to draw on; None creates a figure. |
None
|
Returns:
| Type | Description |
|---|---|
(fig, ax)
|
|
plot_P_enrichment_pval(p_res, cluster_labels, colors, title='', figsize=(4, 4), dpi=150, ax=None)
Bar chart of -log10 empirical p-values of P enrichment per cluster.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p_res
|
Dict[str, float]
|
Output of |
required |
cluster_labels
|
List[str]
|
Cluster labels. |
required |
colors
|
List[str]
|
Color per cluster. |
required |
title
|
str
|
Title. |
''
|
figsize
|
Tuple[float, float]
|
Figure size. |
(4, 4)
|
dpi
|
int
|
Figure resolution. |
150
|
ax
|
Axes to draw on; None creates a figure. |
None
|
Returns:
| Type | Description |
|---|---|
(fig, ax)
|
|
plot_P_enrichment_zscore(p_res, cluster_labels, colors, title='', figsize=(4, 4), dpi=150, ax=None)
Bar chart of P enrichment z-scores per cluster.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p_res
|
Dict[str, float]
|
Output of |
required |
cluster_labels
|
List[str]
|
Cluster labels. |
required |
colors
|
List[str]
|
Color per cluster. |
required |
title
|
str
|
Title. |
''
|
figsize
|
Tuple[float, float]
|
Figure size. |
(4, 4)
|
dpi
|
int
|
Figure resolution. |
150
|
ax
|
Axes to draw on; None creates a figure. |
None
|
Returns:
| Type | Description |
|---|---|
(fig, ax)
|
|
plot_gene_P_bars(P_gs, gene_set, cluster_labels, colors, top_n=None, gene_label_colors=None)
Per cluster, the P of each gene set gene, as sorted horizontal bars.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
P_gs
|
ndarray
|
Gene set rows of the P matrix (n_gs, K). |
required |
gene_set
|
List[str]
|
Gene names of the P_gs rows. |
required |
cluster_labels
|
List[str]
|
Cluster labels. |
required |
colors
|
List[str]
|
Color per cluster. |
required |
top_n
|
int | None
|
Show only the top_n genes per cluster; None shows all. |
None
|
gene_label_colors
|
dict | None
|
{gene: color} for the gene labels. |
None
|
Returns:
| Type | Description |
|---|---|
fig
|
|
axes
|
One Axes per cluster. |
plot_gene_P_stacked(P_gs, gene_set, cluster_labels, gs_title='', log_scale=True, sort_by_sum=False, top_n=None, gene_colors=None, figsize=(6, 4), dpi=150)
Stacked bar chart of the P of each gene set gene, one bar per cluster.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
P_gs
|
ndarray
|
Gene set rows of the P matrix (n_gs, K). |
required |
gene_set
|
List[str]
|
Gene names of the P_gs rows. |
required |
cluster_labels
|
List[str]
|
Cluster labels. |
required |
gs_title
|
str
|
Title prefix. |
''
|
log_scale
|
bool
|
Use a log y-axis. |
True
|
sort_by_sum
|
bool
|
Sort clusters by total P (descending). |
False
|
top_n
|
int | None
|
Show only the top_n genes by total P; None shows all. |
None
|
gene_colors
|
Color per gene; None uses tab20. |
None
|
|
figsize
|
Tuple[float, float]
|
Figure size. |
(6, 4)
|
dpi
|
int
|
Figure resolution. |
150
|
Returns:
| Type | Description |
|---|---|
(fig, ax)
|
|
plot_gene_lfc(df_gene_lfc, sepL, sepH, gs_sepLFC, figsize=(5, 3), dpi=150, ax=None, kind='mean', top_n=None, show_labels=None)
Bar chart of each gene's LFC between the high and low clusters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df_gene_lfc
|
DataFrame
|
Output of |
required |
sepL
|
List[int]
|
Low cluster indices. |
required |
sepH
|
List[int]
|
High cluster indices. |
required |
gs_sepLFC
|
float
|
Gene set sepLFC; sets the color scale limits. |
required |
figsize
|
Tuple[float, float]
|
Figure size. |
(5, 3)
|
dpi
|
int
|
Figure resolution. |
150
|
ax
|
Axes to draw on; None creates a figure. |
None
|
|
kind
|
str
|
"extreme" or "mean", as used in |
'mean'
|
top_n
|
int | None
|
Show only the top_n genes by |LFC|; None shows all. |
None
|
show_labels
|
bool | None
|
Show gene names; None shows them if top_n is set or there are at most 30 genes. |
None
|
Returns:
| Type | Description |
|---|---|
(fig, ax)
|
|
plot_pairwise_heatmap(value_mat, sig_mat=None, labels=None, title=None, upper_only=True, cmap='coolwarm', center_zero=True, sig_level=0.05, figsize=(7, 6), dpi=150, ax=None)
Heatmap of a cluster-by-cluster matrix, with significant cells marked by *.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value_mat
|
ndarray
|
Values (K, K). |
required |
sig_mat
|
p- or q-values (K, K); cells below sig_level are marked. |
None
|
|
labels
|
Cluster labels. |
None
|
|
title
|
Title. |
None
|
|
upper_only
|
Show only the upper triangle. |
True
|
|
cmap
|
Colormap. |
'coolwarm'
|
|
center_zero
|
Center the color scale on 0. |
True
|
|
sig_level
|
Significance level. |
0.05
|
|
figsize
|
Figure size. |
(7, 6)
|
|
dpi
|
Figure resolution. |
150
|
|
ax
|
Axes to draw on; None creates a figure. |
None
|
Returns:
| Type | Description |
|---|---|
(fig, ax)
|
|
plot_pairwise_heatmap_bidir(upper_mat, lower_mat, upper_cmap='coolwarm', lower_cmap='PuOr', upper_sig=None, lower_sig=None, sig_level=0.05, labels=None, upper_label='', lower_label='', title=None, center_zero=True, figsize=(6, 5), dpi=150, ax=None)
Heatmap of two cluster-by-cluster matrices, one in each triangle, with significant cells marked by *.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
upper_mat
|
ndarray
|
Values (K, K) of the upper and lower triangles. |
required |
lower_mat
|
ndarray
|
Values (K, K) of the upper and lower triangles. |
required |
upper_cmap
|
Colormaps. |
'coolwarm'
|
|
lower_cmap
|
Colormaps. |
'coolwarm'
|
|
upper_sig
|
ndarray | None
|
p- or q-values (K, K); cells below sig_level are marked. |
None
|
lower_sig
|
ndarray | None
|
p- or q-values (K, K); cells below sig_level are marked. |
None
|
sig_level
|
float
|
Significance level. |
0.05
|
labels
|
Cluster labels. |
None
|
|
upper_label
|
str
|
Colorbar labels. |
''
|
lower_label
|
str
|
Colorbar labels. |
''
|
title
|
str | None
|
Title. |
None
|
center_zero
|
bool
|
Center the color scales on 0. |
True
|
figsize
|
Figure size. |
(6, 5)
|
|
dpi
|
int
|
Figure resolution. |
150
|
ax
|
Axes to draw on; None creates a figure. |
None
|
Returns:
| Type | Description |
|---|---|
(fig, ax)
|
|
plot_per_cluster_P(P_gs, gene_set, cluster_labels, colors, null_mean_P=None, gs_title='', dpi=150)
Gene set mean P per cluster against the null (top), and per-cluster gene bars (bottom, as in plot_gene_P_bars).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
P_gs
|
ndarray
|
Gene set rows of the P matrix (n_gs, K). |
required |
gene_set
|
List[str]
|
Gene names of the P_gs rows. |
required |
cluster_labels
|
List[str]
|
Cluster labels. |
required |
colors
|
List[str]
|
Color per cluster. |
required |
null_mean_P
|
Optional[ndarray]
|
Output of |
None
|
gs_title
|
str
|
Title prefix. |
''
|
dpi
|
int
|
Figure resolution. |
150
|
Returns:
| Type | Description |
|---|---|
fig
|
|
ax_top
|
|
axes_bottom
|
One Axes per cluster. |
plot_sepLFC_distribution(df, gs_genes, title='', kind='auto', show_gs_textbox=True, gs_textbox_threshold=None, n_gs_textbox=10, show_non_gs_textbox=False, n_non_gs_textbox=10, textbox_fontsize=9, figsize=(6, 5), dpi=150, ax=None)
Distribution of sepLFC over genes, with the gene set's genes highlighted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Feature metrics with sepLFC and rank_sepLFC columns, sorted by sepLFC (descending). |
required |
gs_genes
|
Gene set genes. |
required | |
title
|
str
|
Title. |
''
|
kind
|
str
|
"bar", "hist", or "auto" (bar if fewer than 30 genes). |
'auto'
|
show_gs_textbox
|
bool
|
List gene set genes in a text box (hist only). |
True
|
gs_textbox_threshold
|
float | None
|
Minimum sepLFC to list; None lists the top n_gs_textbox. |
None
|
n_gs_textbox
|
int
|
Maximum number of gene set genes to list. |
10
|
show_non_gs_textbox
|
bool
|
List the top other genes in a text box (hist only). |
False
|
n_non_gs_textbox
|
int
|
Number of other genes to list. |
10
|
textbox_fontsize
|
int
|
Font size of the text boxes. |
9
|
figsize
|
Tuple[float, float]
|
Figure size. |
(6, 5)
|
dpi
|
int
|
Figure resolution. |
150
|
ax
|
Axes to draw on; None creates a figure. |
None
|
Returns:
| Type | Description |
|---|---|
(fig, ax)
|
|
plot_sepLFC_distribution_heatmap(res_by_mode, n_bins=60, cmap='Blues', figsize=(10, 0.45), dpi=150, kind='null_sep', pval_threshold=None, annotate_pval=False)
Null sepLFC distribution of each mode as a heatmap row, with the gene set's sepLFC marked.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
res_by_mode
|
Output of |
required | |
n_bins
|
Number of histogram bins. |
60
|
|
cmap
|
Colormap. |
'Blues'
|
|
figsize
|
(width, height per row). |
(10, 0.45)
|
|
dpi
|
Figure resolution. |
150
|
|
kind
|
"null_sep" (best sepLFC of each random gene set) or "null_fixed" (LFC at the observed split). |
'null_sep'
|
|
pval_threshold
|
Mark modes with an empirical p-value below this with a star; None or <= 0 disables. |
None
|
|
annotate_pval
|
Write the empirical p-value next to each mark. |
False
|
Returns:
| Type | Description |
|---|---|
(fig, ax)
|
|
plot_sepLFC_enrichment_grid(res_by_mode, ax_by_mode, results, cb_cmap, kind='null_sep')
sepLFC null histograms of each mode, drawn into a grid of Axes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
res_by_mode
|
Output of |
required | |
ax_by_mode
|
{mode name: Axes}, e.g. from |
required | |
results
|
Clumppling results, for K of each mode. |
required | |
cb_cmap
|
Color per cluster. |
required | |
kind
|
"null_sep" ( |
'null_sep'
|
plot_sepLFC_null_fixed(sep_res, cluster_labels, title='', figsize=(5, 4), dpi=150, ax=None)
Histogram of the LFC of each random gene set at the observed split, with the gene set's sepLFC marked.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sep_res
|
Dict[str, float]
|
Output of |
required |
cluster_labels
|
List[str]
|
Cluster labels. |
required |
title
|
str
|
Title. |
''
|
figsize
|
Tuple[float, float]
|
Figure size. |
(5, 4)
|
dpi
|
int
|
Figure resolution. |
150
|
ax
|
Axes to draw on; None creates a figure. |
None
|
Returns:
| Type | Description |
|---|---|
(fig, ax)
|
|
plot_sepLFC_null_sep(sep_res, title='', figsize=(5, 4), dpi=150, ax=None)
Histogram of the best sepLFC of each random gene set, with the gene set's sepLFC marked.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sep_res
|
Dict[str, float]
|
Output of |
required |
title
|
str
|
Title. |
''
|
figsize
|
Tuple[float, float]
|
Figure size. |
(5, 4)
|
dpi
|
int
|
Figure resolution. |
150
|
ax
|
Axes to draw on; None creates a figure. |
None
|
Returns:
| Type | Description |
|---|---|
(fig, ax)
|
|
plot_seplfc_bipartite(gene_set, sepH, sepL, cluster_labels, df_mode, top_n_per_pair=5, gs_title='', lw_scale=10.0, min_lw=0.5, seg_gap=0.008, label_mode='auto', label_fontsize=7.0, arrow_fan=0.06, cmap='Spectral', vmin=None, vmax=None, colors=None, figsize=(8, 4), dpi=150, ax=None)
Diagram of the gene set's high (top) and low (bottom) clusters, with the top genes drawn on the cluster pair at their own largest gap.
Each gene is placed on the pair (A, B), where A is its lowest high cluster and B its highest low cluster; only genes with A in sepH and B in sepL are shown.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gene_set
|
List[str]
|
Gene names. |
required |
sepH
|
List[int]
|
High cluster indices. |
required |
sepL
|
List[int]
|
Low cluster indices. |
required |
cluster_labels
|
List[str]
|
Cluster labels. |
required |
df_mode
|
Feature metrics of the mode, indexed by gene name. |
required | |
top_n_per_pair
|
int
|
Maximum number of genes per cluster pair. |
5
|
gs_title
|
str
|
Title prefix. |
''
|
lw_scale
|
float
|
Largest line width. |
10.0
|
min_lw
|
float
|
Smallest line width. |
0.5
|
seg_gap
|
float
|
Gap between gene segments. |
0.008
|
label_mode
|
str
|
Gene labels: "all", "none", or "auto" (segments above an equal share). |
'auto'
|
label_fontsize
|
float
|
Font size of the gene labels. |
7.0
|
arrow_fan
|
float
|
Spread of arrowheads at each node. |
0.06
|
cmap
|
str
|
Colormap of sepLFC. |
'Spectral'
|
vmin
|
float
|
Range of the color scale; None uses the data. |
None
|
vmax
|
float
|
Range of the color scale; None uses the data. |
None
|
colors
|
Color per cluster. |
None
|
|
figsize
|
Tuple[float, float]
|
Figure size. |
(8, 4)
|
dpi
|
int
|
Figure resolution. |
150
|
ax
|
Axes to draw on; None creates a figure. |
None
|
Returns:
| Type | Description |
|---|---|
(fig, ax)
|
|
plot_top_pairwise_df(df, value_col='z', sig_col='q', alpha=0.05, top_n=-1, labels=None, sort_by='q', figsize=(8, 6), dpi=150, ax=None)
Dot plot of cluster pairs from test_LFC_enrichment (df), with significant pairs circled.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Per-pair table, with columns i, j, value_col and sig_col. |
required |
value_col
|
Column to plot. |
'z'
|
|
sig_col
|
Column of q- or p-values. |
'q'
|
|
alpha
|
Significance level. |
0.05
|
|
top_n
|
Number of pairs to show; non-positive shows all. |
-1
|
|
labels
|
Cluster labels. |
None
|
|
sort_by
|
Column to sort by, or "abs_value" for |value_col|. |
'q'
|
|
figsize
|
Figure size. |
(8, 6)
|
|
dpi
|
Figure resolution. |
150
|
|
ax
|
Axes to draw on; None creates a figure. |
None
|
Returns:
| Type | Description |
|---|---|
(fig, ax)
|
|