ddmc.figures.common¶
Shared plotting and figure-assembly helpers used across the paper's
ddmc/figures/figureM*.py reproduction scripts.
ddmc.figures.common ¶
Shared plotting and figure-assembly helpers used across ddmc/figures/figureM*.py.
Contains
getSetup/subplotLabel/overlayCartoon: build a labeled multi-panel matplotlib figure and overlay static SVG cartoons onto it.genFigure: thefbuildconsole-script entry point (seepyproject.toml) that generates a givenfigureM*.pymodule's figure and saves it to./output/.plot_motifs: sequence-logo plot of aDDMCcluster's PSSM.plot_cluster_kinase_distances: strip plot of kinase-vs-cluster PSSM distances, annotated with the top kinase hit(s) per cluster.get_pvals_across_clusters/plot_p_signal_across_clusters_and_binary_feature: statistically compare cluster centers between two groups of samples and plot the result as an annotated violin plot.plot_pca_on_cluster_centers: PCA scores/loadings plot of cluster centers.
getSetup ¶
getSetup(
figsize: tuple[int, int],
gridd: tuple[int, int],
multz: None | dict = None,
labels: bool = True,
) -> tuple
Establish figure set-up with subplots.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
figsize
|
tuple[int, int]
|
Figure size in inches, as |
required |
gridd
|
tuple[int, int]
|
Subplot grid shape, as |
required |
multz
|
None | dict
|
Maps a subplot's flat grid index to how many extra
consecutive grid cells it should span (e.g. |
None
|
labels
|
bool
|
Whether to add bold uppercase letter labels (A, B, C, ...)
to each subplot via |
True
|
Returns:
| Type | Description |
|---|---|
tuple
|
A tuple |
tuple
|
the parent |
Source code in ddmc/figures/common.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | |
subplotLabel ¶
subplotLabel(axs: list[Axes]) -> None
Place bold uppercase letter labels (A, B, C, ...) above each axes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
axs
|
list[Axes]
|
Axes to label, in the order they should be lettered. |
required |
Source code in ddmc/figures/common.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | |
overlayCartoon ¶
overlayCartoon(
figFile: str,
cartoonFile: str,
x: float,
y: float,
scalee: float = 1.0,
) -> None
Overlay a static SVG cartoon onto a saved figure, in place.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
figFile
|
str
|
Path to the SVG figure to overlay onto and overwrite. |
required |
cartoonFile
|
str
|
Path to the SVG cartoon to overlay. |
required |
x
|
float
|
X position (in SVG units) to place the cartoon's origin. |
required |
y
|
float
|
Y position (in SVG units) to place the cartoon's origin. |
required |
scalee
|
float
|
Uniform scale factor applied to the cartoon. |
1.0
|
Source code in ddmc/figures/common.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | |
genFigure ¶
genFigure() -> None
Console-script entry point (fbuild, see pyproject.toml) for
generating one paper figure.
Reads the figure name suffix from sys.argv[1] (e.g. "M2"), imports
the corresponding ddmc.figures.figureM2 module, calls its
makeFigure(), and saves the result to ./output/figureM2.svg. Some
figures (M2, M5) additionally get a static SVG cartoon overlaid via
overlayCartoon after saving.
Source code in ddmc/figures/common.py
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | |
plot_motifs ¶
plot_motifs(
pssm, ax: Axes, titles=False, yaxis=False
) -> None
Draw a sequence-logo plot of a single cluster's PSSM.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pssm
|
ndarray | DataFrame
|
Position-specific scoring
matrix of shape (20, 11) or (20, 9), e.g. one entry from
|
required |
ax
|
Axes
|
Axes to plot onto. |
required |
titles
|
str | bool
|
If given (and not |
False
|
yaxis
|
Sequence[float] | bool
|
If given (and not |
False
|
Source code in ddmc/figures/common.py
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 | |
plot_cluster_kinase_distances ¶
plot_cluster_kinase_distances(
distances: DataFrame,
pssms: ndarray,
ax: Axes,
num_hits: int = 1,
) -> None
Strip plot of kinase-vs-cluster PSSM distances, annotated with the top predicted kinase(s) per cluster.
For each cluster, restricts candidate kinases to those whose known
phosphoacceptor (ddmc.motifs.KinToPhosphotypeDict) matches that
cluster's most frequent phosphoacceptor, then annotates the closest
num_hits of those.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
distances
|
DataFrame
|
Kinase-by-cluster Frobenius distance matrix (kinases as
rows, cluster/PSSM names as columns), as returned by
|
required |
pssms
|
ndarray
|
The PSSMs corresponding to |
required |
ax
|
Axes
|
Axes to plot onto. |
required |
num_hits
|
int
|
Number of top kinase hits to annotate per cluster. |
1
|
Source code in ddmc/figures/common.py
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 | |
get_pvals_across_clusters ¶
get_pvals_across_clusters(
label: Series | ndarray, centers: DataFrame | ndarray
) -> np.ndarray
Test whether each cluster's center differs between two groups of samples.
Runs a Mann-Whitney U test per cluster between the samples where
label is True and where it's False, then corrects for multiple
testing across clusters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
Series | ndarray
|
Boolean mask of shape (n_samples,) splitting samples into two groups (e.g. tumor vs. NAT). |
required |
centers
|
DataFrame | ndarray
|
Cluster centers of shape (n_samples, n_components),
aligned to |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Multiple-testing-corrected p-value for each cluster, of shape |
ndarray
|
(n_components,). |
Source code in ddmc/figures/common.py
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 | |
plot_p_signal_across_clusters_and_binary_feature ¶
plot_p_signal_across_clusters_and_binary_feature(
feature: Series | ndarray,
centers: DataFrame,
label_name: str,
ax: Axes,
) -> None
Violin-plot cluster centers split by a binary sample feature, with a
significance marker on each cluster whose center differs between the
two groups (see get_pvals_across_clusters).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature
|
Series | ndarray
|
Boolean mask of shape (n_samples,) splitting samples into
two groups (e.g. tumor vs. NAT), aligned to |
required |
centers
|
DataFrame
|
Cluster centers of shape (n_samples, n_components), e.g.
from |
required |
label_name
|
str
|
Name to use for |
required |
ax
|
Axes
|
Axes to plot onto. |
required |
Source code in ddmc/figures/common.py
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 | |
plot_pca_on_cluster_centers ¶
plot_pca_on_cluster_centers(
centers: DataFrame,
axes: Sequence,
hue_scores: Sequence | ndarray | None = None,
hue_scores_title: str | None = None,
hue_loadings: Sequence | ndarray | None = None,
hue_loadings_title: str | None = None,
) -> None
Plot a 2-component PCA of cluster centers, as a scores plot (one point per sample) and a loadings plot (one point per cluster).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
centers
|
DataFrame
|
Cluster centers of shape (n_samples, n_components), e.g.
from |
required |
axes
|
Sequence
|
A length-2 sequence of Axes: |
required |
hue_scores
|
Sequence | ndarray | None
|
Per-sample values to color the scores plot points by. |
None
|
hue_scores_title
|
str | None
|
If given, shown as the scores plot's legend title. |
None
|
hue_loadings
|
Sequence | ndarray | None
|
Per-cluster values to color the loadings plot points by. |
None
|
hue_loadings_title
|
str | None
|
If given, adds a |
None
|
Source code in ddmc/figures/common.py
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 | |