From 9cb59caa1f13ee44ed6fcf7bc6526a87311e8e9f Mon Sep 17 00:00:00 2001 From: Pjotr Date: Wed, 11 Nov 2026 13:46:24 +0000 Subject: plot/gemma: draw thresholds computed elsewhere, labelled with their source GEMMA has no permutation test here, so its plot carries a Bonferroni line. A threshold from /compute/bulklmm belongs to a different null and must not look like GEMMA's, so it is passed in and named: POST /plot/gemma?thresholds=3.50,3.65 &threshold_labels=bulklmm%20alpha%200.10,bulklmm%20alpha%200.05 Each is drawn dashed in the series colour with "label: value" beside the line, with GEMMA's Bonferroni line still there, and the plotter's x-plot-summary names the reference lines it drew. A threshold that is not a positive number is a 422 invalid_threshold rather than a silent omission. /compute/bulklmm's reply offers that href already, with its alpha 0.05 threshold filled in -- so "same values, two models, one picture" is one link from the scan, and the labels keep the two nulls apart. tests/plot.rs: the plain plot has no bulklmm line; with thresholds both are drawn and labelled; a non-numeric threshold is refused. --- scripts/plot-gemma.py | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'scripts/plot-gemma.py') diff --git a/scripts/plot-gemma.py b/scripts/plot-gemma.py index f2a6302..3f75c2b 100644 --- a/scripts/plot-gemma.py +++ b/scripts/plot-gemma.py @@ -28,6 +28,9 @@ def main(): ap.add_argument("--trait", default="", help="trait label for the title, e.g. 20010") ap.add_argument("--title", default=None, help="override the title text") ap.add_argument("--no-bonferroni", action="store_true", help="omit the threshold line") + ap.add_argument("--threshold", action="append", default=[], + help="extra reference line as VALUE[:LABEL], e.g. 3.81:bulklmm alpha 0.05 " + "(thresholds another engine computed for the same values)") a = ap.parse_args() doc = json.load(open(a.result)) @@ -56,7 +59,15 @@ def main(): top = max(((v, c, pos, rs) for c in order for pos, v, rs in by[c])) bonf = -math.log10(0.05 / nrows) - ymax = max(4, math.ceil(max(top[0], 0 if a.no_bonferroni else bonf) + 0.3)) + # Reference lines from elsewhere: (value, label). Whoever computed them gets + # named in the label, so a reader can tell a BulkLMM threshold from GEMMA's + # own Bonferroni line -- they are not the same null. + external = [] + for spec in a.threshold: + value, _, label = spec.partition(":") + external.append((float(value), label.strip() or "bulklmm threshold")) + ymax = max(4, math.ceil(max([top[0], 0 if a.no_bonferroni else bonf] + + [value for value, _ in external]) + 0.3)) W, H, L, R, T, B = 1000, 430, 62, 20, 64, 52 pw, ph = W - L - R, H - T - B X = lambda c, p: L + (off[c] + p) / tot * pw @@ -107,11 +118,21 @@ text{{fill:var(--ink2);font-size:12px}} .ttl{{fill:var(--ink);font-size:16px;fon y = Y(bonf) s.append(f'') s.append(f'Bonferroni, {nrows:,} markers: {bonf:.2f}') + for value, label in external: + y = Y(value) + s.append(f'') + s.append(f'{label}: {value:.2f}') s.append(f'{top[3]}: chr{top[1]} {top[2]:.1f} Mb, -log10 p {top[0]:.2f}') s.append(f'chr{top[1]} {top[2]:.0f} Mb, -log10 p {top[0]:.2f}') s.append("") open(a.out, "w").write("\n".join(s)) - print(f"wrote {a.out}: peak {top[3]} chr{top[1]} {top[2]:.1f} Mb -log10p {top[0]:.2f}; Bonferroni {bonf:.2f} over {nrows} markers") + extra_note = "" + if external: + extra_note = "; reference line(s) " + ", ".join( + f"{label} {value:.2f}" for value, label in external) + print(f"wrote {a.out}: peak {top[3]} chr{top[1]} {top[2]:.1f} Mb -log10p {top[0]:.2f}; " + f"Bonferroni {bonf:.2f} over {nrows} markers{extra_note}") if __name__ == "__main__": -- cgit 1.4.1