diff options
| author | Pjotr <wrk@bosa.lan> | 2026-11-11 14:05:30 +0000 |
|---|---|---|
| committer | Pjotr <wrk@bosa.lan> | 2026-11-11 14:05:30 +0000 |
| commit | 83b30cabe99757f44a80988027594871540b8f50 (patch) | |
| tree | 98cf2b1e969ad358ae956304dc84e827135a3240 /scripts/plot-gemma.py | |
| parent | 9cb59caa1f13ee44ed6fcf7bc6526a87311e8e9f (diff) | |
| download | genenetwork4-83b30cabe99757f44a80988027594871540b8f50.tar.gz | |
plot/gemma: no reference line by default; Bonferroni is one more labelled line
A line on a plot is an annotation, not part of the result, so the default is now no line at all. GEMMA's Bonferroni becomes opt-in like any other: ?bonferroni=true GEMMA's own line, labelled ?thresholds=3.65&threshold_labels=… another engine's, labelled (nothing) just the scan Which means a reader sees exactly the lines someone chose, each with its source in the label -- and the accidental "this plot says significant" impression of a default convention line is gone. The plotter's summary and its <desc> no longer mention Bonferroni unless it was drawn. tests/plot.rs: the plain plot has neither line; with thresholds the two BulkLMM lines are labelled and Bonferroni is absent; with ?bonferroni=true GEMMA's own line appears.
Diffstat (limited to 'scripts/plot-gemma.py')
| -rw-r--r-- | scripts/plot-gemma.py | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/scripts/plot-gemma.py b/scripts/plot-gemma.py index 3f75c2b..7f2e2d3 100644 --- a/scripts/plot-gemma.py +++ b/scripts/plot-gemma.py @@ -3,7 +3,7 @@ Input is the JSON response of POST /gn4/compute/gemma (saved as-is). Plots -log10(p_lrt) per marker. GEMMA has no permutation test through the -API, so the only reference line is a Bonferroni threshold, 0.05 / number of +API, so the only line GEMMA can justify is a Bonferroni threshold, 0.05 / number of markers (conservative: neighbouring markers are correlated). python3 plot-gemma.py g20010.json --trait 20010 -o g20010_manhattan.svg @@ -27,7 +27,9 @@ def main(): ap.add_argument("-o", "--out", default="gemma_manhattan.svg") 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("--bonferroni", action="store_true", + help="draw GEMMA's Bonferroni line (off by default: a reference line is a " + "label on the plot, not part of the result)") 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)") @@ -58,7 +60,7 @@ def main(): tot += by[c][-1][0] + gap top = max(((v, c, pos, rs) for c in order for pos, v, rs in by[c])) - bonf = -math.log10(0.05 / nrows) + bonf = -math.log10(0.05 / nrows) if a.bonferroni else None # 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. @@ -66,7 +68,7 @@ def main(): 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] + + ymax = max(4, math.ceil(max([top[0]] + ([bonf] if bonf else []) + [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 @@ -85,7 +87,8 @@ def main(): sub = "GEMMA LOCO linear mixed model (-lmm 9)" + (f", {panel}" if panel else "") + (f", {nstr}" if nstr else "") desc = (f"GEMMA scan over {nrows} markers. The strongest association is -log10 p {top[0]:.2f} " f"on chromosome {top[1]} at {top[2]:.1f} Mb ({top[3]}). " - f"Bonferroni threshold for {nrows} markers: -log10 p {bonf:.2f}.") + f"Bonferroni threshold for {nrows} markers: -log10 p {bonf:.2f}." if bonf is not None + else "") s = [f'''<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 {W} {H}" width="{W}" height="{H}" role="img" aria-labelledby="t d" font-family="system-ui,-apple-system,Segoe UI,sans-serif"> <title id="t">{title}</title> @@ -114,7 +117,7 @@ text{{fill:var(--ink2);font-size:12px}} .ttl{{fill:var(--ink);font-size:16px;fon for c in order: pts = " ".join(f"{X(c, p):.1f},{Y(v):.1f}" for p, v, _ in by[c]) s.append(f'<polyline points="{pts}" fill="none" stroke="var(--s2)" stroke-width="1.5" stroke-linejoin="round"/>') - if not a.no_bonferroni: + if bonf is not None: y = Y(bonf) s.append(f'<line x1="{L}" x2="{W - R}" y1="{y:.1f}" y2="{y:.1f}" stroke="var(--ink2)" stroke-width="1.25" stroke-dasharray="7 4"/>') s.append(f'<text x="{W - R - 4}" y="{y - 5:.1f}" text-anchor="end">Bonferroni, {nrows:,} markers: {bonf:.2f}</text>') @@ -131,8 +134,9 @@ text{{fill:var(--ink2);font-size:12px}} .ttl{{fill:var(--ink);font-size:16px;fon 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}") + bonf_note = f"; Bonferroni {bonf:.2f} over {nrows} markers" if bonf is not None else "" + print(f"wrote {a.out}: peak {top[3]} chr{top[1]} {top[2]:.1f} Mb -log10p {top[0]:.2f}" + f"{bonf_note}{extra_note}") if __name__ == "__main__": |
