#!/usr/bin/env python3 """job2545-checks.py -- ledger for job #2545 (positional fold-residue statistic). Parses job2545-posres.log and asserts the controls plus the PRE-REGISTERED verdicts, including the single fired H_pos cell; it must not be edited to make the check green.""" import re, sys text = open("job2545-posres.log", encoding="utf-8").read() fails = [] def ck(name, cond, detail=""): print(("PASS " if cond else "FAIL ") + name + ((" [" + detail + "]") if detail else "")) if not cond: fails.append(name) # --- controls (must fire) --- ck("D = 7 952 175 reproduced", "D=7952175" in text) ck("G2 = 204 reproduced", "G2=204" in text) ck("A(1;p=29) = 288 = served [5b]", "A(1;p=29)=288" in text) ck("all three folds present", all(("fold p=%d" % p) in text for p in (29, 31, 37))) # --- primary H_fold: |z_F| < 4 at every fold (NOT refuted) --- zs = [float(x) for x in re.findall(r"z_F=([+-][0-9.]+)", text)] ck("three fold-overlap z values parsed", len(zs) == 3, str(zs)) ck("H_fold NOT refuted: |z_F| < 4 at every fold", all(abs(z) < 4 for z in zs), str(zs)) # --- secondary H_pos: count outside-band chi2 verdicts, and locate them --- verdicts = re.findall(r"^\s*(\d+)\s+([0-9.]+)\s+([0-9.]+)\s+([0-9.]+)\s+([0-9.]+)\s+(INSIDE|ABOVE|BELOW)", text, re.M) ck("36 chi2 verdicts parsed (12 x 3 folds)", len(verdicts) == 36, str(len(verdicts))) outside = [(int(m), v) for m, _, _, _, _, v in verdicts if v != "INSIDE"] ck("H_pos falsifier fired in EXACTLY 1 of 36 cells", len(outside) == 1, str(outside)) ck("the fired cell is m=3 BELOW (under-dispersion, not clustering)", outside == [(3, "BELOW")], str(outside)) # --- the fired cell is tiny in magnitude (counts near-exactly balanced) --- row = [r for r in verdicts if r[0] == "3"][0] chi = float(row[1]) ck("fired m=3 chi2 is near zero (< 0.01)", chi < 0.01, "chi2=%.3f" % chi) # --- sub-threshold trend at m=19,23 (reported, NOT claimed) --- e19_23 = [(int(m), float(c), float(nm)) for m, c, nm, _, _, _ in verdicts if m in ("19", "23")] ck("m=19,23 observed chi2 above its null mean at every fold", all(c > nm for _, c, nm in e19_23), str([(m, c, nm) for m, c, nm in e19_23])) ck("m=19,23 stay INSIDE the 99.9% band (no claim)", all( v == "INSIDE" for m, _, _, _, _, v in verdicts if m in ("19", "23"))) print("\n%s (%d of %d checks passed)" % ("ALL_PASS" if not fails else "FAILURES: " + ", ".join(fails), 12 - len(fails), 12)) sys.exit(0 if not fails else 1)