spacr.regression_panels¶
Publication panel packages for regression and permutation results.
One call writes exactly four files for one manuscript panel: a vector PDF with its narrative legend, a plot-only PNG, a point-level data CSV, and a key-value statistics CSV. The numerical result table remains the source of truth; this module only applies a declared call rule and renders it.
Classes¶
Text placed below a panel in its PDF deliverable. |
|
Visual settings shared by all manuscript panels. |
Functions¶
|
Attach the common BH-plus-positive-gRNA-cut call fields. |
|
Validate a declared run manifest, then write every panel and figure. |
|
Compose one vector page and transform every URI link rectangle. |
|
Return arithmetic mean + |
|
Return finite padded limits shared by a set of matched panels. |
|
Write one deterministic box-and-jitter four-file panel package. |
|
Write the PDF, PNG, stats CSV, and plotted-data CSV for one panel. |
Module Contents¶
- class spacr.regression_panels.PanelNarrative[source]¶
Text placed below a panel in its PDF deliverable.
- Parameters:
legend (str) – Panel-specific opening of the legend. The writer appends the shared palette and statistical-threshold explanations.
purpose (str) – Scientific question or comparison the panel was designed to address.
shows (str) – Direct visual result a reader should be able to find in the panel.
implications (str) – Interpretation supported by the displayed data, kept distinct from the observation in
shows.
- class spacr.regression_panels.PanelStyle[source]¶
Visual settings shared by all manuscript panels.
- Parameters:
point_size (float) – Scatter-marker area in squared typographic points; must be positive.
point_alpha (float) – Marker and box opacity in the interval
(0, 1].line_width (float) – Width in points for threshold lines, spines, ticks, and box outlines.
line_color (str) – Matplotlib-compatible color for those lines and outlines.
figure_width (float) – Width in inches shared by raster, vector, and PDF deliverables.
plot_height (float) – Height in inches of the standalone PNG and SVG plot canvas.
pdf_height (float) – Height in inches of the PDF page containing plot and narrative text.
png_dpi (int) – Raster resolution in dots per inch used for the PNG deliverable.
axes_left (float) – Left edge of the plotting axes in normalized figure coordinates.
axes_width (float) – Width of the plotting axes as a fraction of the figure width.
pdf_axes_bottom (float) – Bottom edge of the PDF plotting axes in normalized figure coordinates.
pdf_axes_height (float) – Height of the PDF plotting axes as a fraction of the page height.
- spacr.regression_panels.apply_primary_call(results: pandas.DataFrame, *, effect_column: str, bh_column: str, effect_threshold: float) pandas.DataFrame[source]¶
Attach the common BH-plus-positive-gRNA-cut call fields.
- Parameters:
results – regression results; the frame is copied, not modified.
effect_column – column of numeric effect sizes compared with
effect_threshold; a non-numeric value raises.bh_column – column whose truth value (after
astype(bool)) marks rows that pass Benjamini-Hochberg correction.effect_threshold – effect-size cut;
primary_callis true where the BH flag is set and the effect is strictly greater than this.
- spacr.regression_panels.build_manifest_packages(manifest: Mapping[str, object] | str | pathlib.Path, artifacts: Mapping[str, Mapping[str, object]], destination: str | pathlib.Path, *, style: PanelStyle = DEFAULT_PANEL_STYLE) dict[str, Any][source]¶
Validate a declared run manifest, then write every panel and figure.
- Parameters:
manifest – the figure manifest, a mapping or the path of a JSON file, with a filename-safe
figure_id, an optionalcolumnscount and a non-emptypanelslist.artifacts – run artifacts keyed by the
sourcenames the panels use; each declareslevel('grna'or'gene'),phenotypeand exactly one ofdata(a DataFrame) orpath.destination – output folder; each panel is written to its own
<panel_id>subfolder and the composed figure to<figure_id>.pdf.
- spacr.regression_panels.compose_vector_figure(panel_pdfs: Sequence[str | pathlib.Path], destination: str | pathlib.Path, *, columns: int = 2) pathlib.Path[source]¶
Compose one vector page and transform every URI link rectangle.
- Parameters:
panel_pdfs – single-page panel PDFs, placed row by row on a grid of equal tiles; at least one is required.
destination – path of the composed PDF; its parent folder is created and the file is replaced atomically.
- spacr.regression_panels.guide_control_threshold(guide_results: pandas.DataFrame, *, effect_column: str, guide_column: str = 'grna', multiplier: float = 3.0) tuple[float, dict[str, float | int]][source]¶
Return arithmetic mean +
multipliersample SD of NT gRNAs.- Parameters:
guide_results – per-gRNA results; non-targeting controls are the rows whose normalised guide name starts with
000000_, and at least two are required.effect_column – column of numeric control effects whose mean and sample SD define the threshold.
Return finite padded limits shared by a set of matched panels.
- Parameters:
frames – the panels’ data frames; at least one is required and every value in both columns must be finite.
x_column – column giving horizontal positions.
y_column – column giving vertical positions; the lower y limit is always 0.
- spacr.regression_panels.write_box_jitter_package(results: pandas.DataFrame, destination: str | pathlib.Path, *, panel_id: str, category_column: str, value_column: str, category_order: Sequence[str], x_label: str, y_label: str, narrative: PanelNarrative, gene_label_column: str | None = None, gene_url_column: str | None = None, statistics: Mapping[str, object] | None = None, style: PanelStyle = DEFAULT_PANEL_STYLE) dict[str, pathlib.Path][source]¶
Write one deterministic box-and-jitter four-file panel package.
- Parameters:
results – regression results, one row per point; the frame is copied and extended with the plotted values before writing.
destination – folder the four files (
<panel_id>.pdf,<panel_id>.png,<panel_id>_stats.csvand<panel_id>_data.csv) are written to; created if absent.panel_id – panel identifier used as the file-name stem and recorded in the stats CSV.
category_column – column holding each row’s category, compared as strings.
value_column – column of vertical values; every value must be numeric and finite.
category_order – left-to-right order of the categories; the names must be distinct and match the observed categories exactly.
x_label – horizontal axis label.
y_label – vertical axis label.
narrative – legend, purpose, observation and implication text placed below the panel in the PDF.
- spacr.regression_panels.write_panel_package(results: pandas.DataFrame, destination: str | pathlib.Path, *, panel_id: str, x_column: str, y_column: str, lopit_column: str, x_label: str, y_label: str, x_limits: tuple[float, float], y_limits: tuple[float, float], horizontal_threshold: float, horizontal_threshold_label: str, effect_threshold: float, effect_threshold_label: str, narrative: PanelNarrative, gene_label_column: str | None = None, gene_url_column: str | None = None, point_label_column: str | None = None, statistics: Mapping[str, object] | None = None, style: PanelStyle = DEFAULT_PANEL_STYLE, palette: Mapping[str, str] = LOPIT_COLOURS) dict[str, pathlib.Path][source]¶
Write the PDF, PNG, stats CSV, and plotted-data CSV for one panel.
- Parameters:
results – regression results, one row per point; the frame is copied and extended with the plotted values before writing.
destination – folder the four files (
<panel_id>.pdf,<panel_id>.png,<panel_id>_stats.csvand<panel_id>_data.csv) are written to; created if absent.panel_id – panel identifier used as the file-name stem and recorded in the stats CSV.
x_column – column of horizontal (effect) values; must be numeric.
y_column – column of vertical values; must be numeric.
lopit_column – column of LOPIT/TAGM localisation categories that colour the points; every category must have a colour in
palette.x_label – horizontal axis label.
y_label – vertical axis label.
x_limits –
(min, max)horizontal axis limits, also recorded in the stats CSV.y_limits –
(min, max)vertical axis limits, also recorded in the stats CSV.horizontal_threshold – y value of the dashed horizontal threshold line; points with a label that lie above it and to the right of
effect_thresholdget their label drawn.horizontal_threshold_label – what the dashed horizontal line represents, quoted in the legend text and stats CSV.
effect_threshold – x value of the dotted vertical effect-threshold line.
effect_threshold_label – what the dotted vertical line represents, quoted in the legend text and stats CSV.
narrative – legend, purpose, observation and implication text placed below the panel in the PDF.