diff options
Diffstat (limited to 'scripts/plot-gemma.py')
| -rw-r--r-- | scripts/plot-gemma.py | 25 |
1 files changed, 23 insertions, 2 deletions
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'<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>') + for value, label in external: + y = Y(value) + s.append(f'<line x1="{L}" x2="{W - R}" y1="{y:.1f}" y2="{y:.1f}" ' + f'stroke="var(--s2)" stroke-width="1.5" stroke-dasharray="2 4"/>') + s.append(f'<text x="{L + 6}" y="{y - 5:.1f}">{label}: {value:.2f}</text>') s.append(f'<circle cx="{tx:.1f}" cy="{ty:.1f}" r="4.5" fill="var(--s2)" stroke="var(--surface)" stroke-width="2"><title>{top[3]}: chr{top[1]} {top[2]:.1f} Mb, -log10 p {top[0]:.2f}</title></circle>') s.append(f'<text class="ann" x="{tx + 10:.1f}" y="{ty + 4:.1f}">chr{top[1]} {top[2]:.0f} Mb, -log10 p {top[0]:.2f}</text>') s.append("</svg>") 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__": |
