Visualization¶
Sequence logos, spatial model plots, and regression diagnostic figures.
Dependencies
All functions require matplotlib. The plot_pssm_logo function uses
logomaker if available, falling back to a bar-chart representation.
pyprego.visualization ¶
Visualization functions for motif logos and regression diagnostics.
Mirrors plot-logo.R and plot-regression.R from the R prego package. Uses matplotlib as the base; logomaker is optional for sequence logos. All matplotlib imports are lazy so pyprego works without matplotlib installed.
plot_pssm_logo ¶
plot_pssm_logo(pssm: DataFrame, *, ax: Axes | None = None, title: str | None = None, method: str = 'bits') -> matplotlib.axes.Axes
Plot a sequence logo for a PSSM.
Tries to use logomaker for high-quality logos. If logomaker is not
installed, falls back to a stacked bar chart rendered with plain
matplotlib.
| PARAMETER | DESCRIPTION |
|---|---|
pssm
|
PSSM DataFrame with columns
TYPE:
|
ax
|
Axes to plot on. If
TYPE:
|
title
|
Optional title for the plot.
TYPE:
|
method
|
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Axes
|
The axes with the logo drawn. |
plot_spat_model ¶
plot_spat_model(spat: DataFrame, *, ax: Axes | None = None, title: str | None = 'Spatial model') -> matplotlib.axes.Axes
Plot a spatial model as a line-and-point chart.
Mirrors plot_spat_model() from R which uses geom_line + geom_point.
| PARAMETER | DESCRIPTION |
|---|---|
spat
|
Spatial model DataFrame with columns
TYPE:
|
ax
|
Axes to plot on. If
TYPE:
|
title
|
Optional title.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Axes
|
The axes with the plot. |
plot_regression_prediction ¶
plot_regression_prediction(pred: ndarray, response: ndarray, *, ax: Axes | None = None, point_size: float = 0.5, alpha: float = 1.0, title: str | None = 'Regression prediction') -> matplotlib.axes.Axes
Scatter plot of predicted vs observed response.
Mirrors the R plot_regression_prediction which shows response on
x-axis and prediction on y-axis, annotated with R-squared and r.
| PARAMETER | DESCRIPTION |
|---|---|
pred
|
Predicted scores.
TYPE:
|
response
|
Observed response values.
TYPE:
|
ax
|
Axes to plot on.
TYPE:
|
point_size
|
Marker size (matplotlib
TYPE:
|
alpha
|
Marker transparency.
TYPE:
|
title
|
Optional title.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Axes
|
|
plot_regression_prediction_binary ¶
plot_regression_prediction_binary(pred: ndarray, response: ndarray, *, ax: Axes | None = None, title: str | None = 'Regression prediction') -> matplotlib.axes.Axes
Plot 1-ECDF of predictions stratified by binary response class.
Mirrors the R plot_regression_prediction_binary which shows the
inverted empirical CDF (1 - ECDF) for class 0 (blue) and class 1 (red),
plus a KS D statistic annotation.
| PARAMETER | DESCRIPTION |
|---|---|
pred
|
Predicted scores.
TYPE:
|
response
|
Binary response (0/1).
TYPE:
|
ax
|
Axes to plot on.
TYPE:
|
title
|
Optional title.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Axes
|
|
plot_regression_qc ¶
plot_regression_qc(result: RegressionResult, response: ndarray | None = None, *, title: str | None = None, point_size: float = 0.5, alpha: float = 0.5) -> matplotlib.figure.Figure
Multi-panel QC figure for a single-motif regression result.
Creates a figure with three panels:
- PSSM sequence logo
- Spatial model
- Prediction vs response scatter (continuous) or 1-ECDF (binary)
Mirrors plot_regression_qc from R.
| PARAMETER | DESCRIPTION |
|---|---|
result
|
Output of :func:
TYPE:
|
response
|
Response variable. Required -- used for the prediction panel.
TYPE:
|
title
|
Overall figure title. Defaults to showing the consensus.
TYPE:
|
point_size
|
Point size for scatter plot.
TYPE:
|
alpha
|
Transparency for scatter plot.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Figure
|
The figure containing all panels. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If response is |
plot_regression_qc_multi ¶
plot_regression_qc_multi(result, response: ndarray | None = None, *, title: str | None = None, point_size: float = 0.01, alpha: float = 0.5) -> matplotlib.figure.Figure
Multi-panel QC figure for a multi-motif regression result.
For each motif, shows: PSSM logo, spatial model, and prediction panel. Also shows a score summary panel at the bottom.
Mirrors plot_regression_qc_multi from R.
| PARAMETER | DESCRIPTION |
|---|---|
result
|
Output of :func:
TYPE:
|
response
|
Response variable. Required -- used for prediction panels.
TYPE:
|
title
|
Overall figure title.
TYPE:
|
point_size
|
Point size for scatter plots.
TYPE:
|
alpha
|
Transparency for scatter plots.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Figure
|
The figure containing all panels. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If response is |