#!/usr/bin/env python3 """Check Tables S2, S3 and S4 of the mint paper's supplement against themselves and against the paper. The tables are typed in below from the supplement's PDF. RULES, written 2026-11-04 after the supplement arrived and before any test was run on these tables. All of the printed tables had been seen. Student's t is the primary test, Welch's a sensitivity check, Benjamini-Hochberg at q = 0.05 and Holm at 0.05 for multiplicity. TABLES S2 AND S3 (no n printed) T1. Parse each row as GMF mean, GMF SD, NNMF mean, NNMF SD, printed P. T2. Find the n per group: for every pair (n1, n2) from 3 to 10, recompute Student's P on every row and take the pair with the smallest sum of squared log ratios to the printed P, skipping rows printed as P = 1.000. Check that against the fractional parts of the printed means, which a mean of n numbers with few decimals constrains. This is an inference from the numbers: say so if the tables don't print n. T3. Count printed P < 0.05; apply BH and Holm to the printed P values. T4. Compare the main text's quoted P values with Table S3's, row by row. TABLE S4 (note: n = 3; no P values printed, only asterisks) H1. Recompute Student's P from each mean and SD at n = 3, as the note says, and at n = 5, as the heatmap in Fig. 4A has five columns per group. H2. Report which asterisks reproduce at P < 0.05 at each n. Apply BH and Holm at n = 3. Added after a fresh review of the page, as description only (no new test): the percent changes in Table S2's raw amplitudes, for the comparison with the lab's 10-second paper. Plain Python; run with `python3 -I`. Usage: python3 -I recheck_tables.py """ import json import math import sys from itertools import product from pathlib import Path sys.stdout.reconfigure(encoding="utf-8") # name, GMF mean, GMF SD, NNMF mean, NNMF SD, printed P S2 = [ ("Fo", 4992.50, 407.36, 5184.57, 277.99, 0.365), ("Fj", 15007.50, 1745.77, 14921.00, 621.91, 0.913), ("Fi", 24414.25, 980.72, 25267.00, 1278.74, 0.226), ("Fm", 28195.25, 1188.24, 28445.86, 1161.34, 0.720), ("Fv", 23202.75, 914.18, 23261.29, 951.62, 0.916), ("Vj", 0.43, 0.05, 0.42, 0.01, 0.650), ("Vi", 0.84, 0.01, 0.86, 0.02, 0.063), ("Fm/Fo", 5.66, 0.30, 5.49, 0.17, 0.262), ("Fv/Fo", 4.66, 0.30, 4.49, 0.17, 0.262), ("Fv/Fm", 0.82, 0.01, 0.82, 0.01, 1.000), ("Mo", 0.81, 0.13, 0.81, 0.04, 1.000), ("Area", 11415518.50, 170863.15, 10742095.14, 976825.64, 0.153), ("Fix Area", 27753106.50, 1174036.56, 28027007.71, 1152766.06, 0.692), ("Sm", 492.34, 11.93, 462.18, 42.16, 0.145), ("Ss", 0.54, 0.02, 0.51, 0.02, 0.027), ("N", 921.60, 48.07, 897.16, 56.61, 0.440), ("phi Po", 0.82, 0.01, 0.82, 0.01, 1.000), ("psi o", 0.57, 0.05, 0.58, 0.01, 0.650), ("phi Eo", 0.47, 0.05, 0.48, 0.01, 0.651), ("phi Do", 0.18, 0.01, 0.18, 0.01, 1.000), ("phi Pav", 961.11, 1.97, 961.92, 1.91, 0.486), ("PIabs", 2.80, 0.77, 2.63, 0.27, 0.627), ("ABS/RC", 2.28, 0.13, 2.38, 0.09, 0.156), ("TRo/RC", 1.87, 0.08, 1.95, 0.06, 0.081), ("ETo/RC", 1.06, 0.06, 1.13, 0.04, 0.042), ("DIo/RC", 0.40, 0.05, 0.43, 0.03, 0.243), ] S3 = [ ("Fo", 2814.25, 139.24, 3154.83, 304.27, 0.046), ("Fm", 17039, 271.98, 18312.67, 1111.62, 0.058), ("Fp", 15551, 352.24, 17115.5, 1129.81, 0.030), ("FmL1", 16051.75, 277.96, 17381.5, 884.8, 0.021), ("FmL2", 11386, 412.29, 13161.17, 951.17, 0.008), ("FmL3", 8928.25, 388.36, 10551.83, 656.21, 0.002), ("FmL4", 7879.25, 388.22, 9180, 267.47, 0.0002), ("FmLss", 7417.75, 401.28, 8532.67, 219.85, 0.0004), ("NPQL1", 0.06, 0.02, 0.05, 0.02, 0.437), ("NPQL2", 0.5, 0.07, 0.4, 0.15, 0.266), ("NPQL3", 0.91, 0.11, 0.74, 0.17, 0.115), ("NPQL4", 1.17, 0.13, 1, 0.12, 0.064), ("NPQLss", 1.3, 0.15, 1.15, 0.11, 0.086), ("QpL1", 0.24, 0.04, 0.16, 0.01, 0.002), ("QpL2", 0.24, 0.05, 0.18, 0.03, 0.026), ("QpL3", 0.31, 0.05, 0.23, 0.04, 0.022), ("QpL4", 0.36, 0.06, 0.28, 0.04, 0.028), ("QpLss", 0.49, 0.07, 0.39, 0.04, 0.016), ("Rfd", 1.9, 0.31, 1.56, 0.17, 0.054), ("FmD1", 8497, 619.83, 9246, 236.54, 0.025), ("FmD2", 12432.75, 659.37, 12286.67, 830.85, 0.777), ("FmD3", 14082.5, 455.99, 13966.67, 1105.7, 0.850), ("NPQD1", 1.01, 0.14, 0.98, 0.1, 0.711), ("NPQD2", 0.37, 0.06, 0.49, 0.08, 0.028), ("NPQD3", 0.21, 0.03, 0.31, 0.06, 0.017), ("QpD1", 0.93, 0.02, 0.91, 0.02, 0.275), ("QpD2", 0.95, 0.01, 0.93, 0.01, 0.042), ("QpD3", 0.95, 0.0, 0.94, 0.01, 0.016), ("QYmax", 0.84, 0.01, 0.83, 0.01, 0.174), ("QYL1", 0.2, 0.03, 0.13, 0.01, 0.001), ("QYL2", 0.19, 0.03, 0.14, 0.02, 0.013), ("QYL3", 0.22, 0.03, 0.17, 0.02, 0.025), ("QYL4", 0.25, 0.04, 0.19, 0.02, 0.020), ("QYLss", 0.27, 0.04, 0.22, 0.03, 0.032), ("QYD1", 0.66, 0.02, 0.65, 0.01, 0.111), ("QYD2", 0.74, 0.01, 0.71, 0.02, 0.009), ("QYD3", 0.77, 0.01, 0.74, 0.02, 0.004), ("NPQE", 1.09, 0.15, 0.84, 0.13, 0.015), ("qE", 0.47, 0.04, 0.36, 0.08, 0.011), ] # organ, hormone, GMF mean, SD, NNMF mean, SD, asterisk printed S4 = [ ("root", "IAA", 5.77, 1.43, 4.34, 1.26, False), ("root", "SA", 3.68, 2.00, 1.84, 0.06, True), ("root", "JA", 53.73, 4.53, 57.77, 2.68, False), ("root", "OPDA", 315.71, 13.36, 447.70, 15.77, True), ("root", "ABA", 280.63, 26.01, 282.37, 24.57, False), ("root", "tZ", 194.66, 11.96, 194.04, 10.96, False), ("root", "tZR", 31.22, 1.96, 26.99, 1.76, True), ("root", "dZ", 68.21, 1.74, 65.44, 1.90, True), ("root", "dZR", 45.32, 11.23, 45.59, 5.19, False), ("shoot", "IAA", 26.92, 3.98, 17.89, 1.48, True), ("shoot", "SA", 8.75, 1.52, 6.52, 0.72, True), ("shoot", "JA", 87.99, 10.64, 72.84, 4.64, True), ("shoot", "OPDA", 382.76, 6.90, 288.62, 9.28, True), ("shoot", "ABA", 124.61, 44.23, 236.27, 49.65, True), ("shoot", "tZ", 155.02, 2.49, 171.90, 2.83, True), ("shoot", "tZR", 25.50, 8.32, 43.05, 5.19, True), ("shoot", "dZ", 69.78, 12.62, 62.61, 5.49, False), ("shoot", "dZR", 428.60, 11.84, 511.74, 10.81, True), ] # What the Results (p. 5) quote, as (Table S3 row, printed P in the text) TEXT_P = [("QpLss", 0.024), ("NPQD2", 0.028), ("NPQD3", 0.017), ("QYD2", 0.025), ("QYD3", 0.025), ("NPQE", 0.012)] def betacf(a, b, x): fpmin = 1e-300 qab, qap, qam = a + b, a + 1.0, a - 1.0 c, d = 1.0, 1.0 - qab * x / qap d = fpmin if abs(d) < fpmin else d d = 1.0 / d h = d for m in range(1, 500): m2 = 2 * m aa = m * (b - m) * x / ((qam + m2) * (a + m2)) d = 1.0 + aa * d d = fpmin if abs(d) < fpmin else d c = 1.0 + aa / c c = fpmin if abs(c) < fpmin else c d = 1.0 / d h *= d * c aa = -(a + m) * (qab + m) * x / ((a + m2) * (qap + m2)) d = 1.0 + aa * d d = fpmin if abs(d) < fpmin else d c = 1.0 + aa / c c = fpmin if abs(c) < fpmin else c d = 1.0 / d de = d * c h *= de if abs(de - 1.0) < 3e-14: break return h def betai(a, b, x): if x <= 0.0: return 0.0 if x >= 1.0: return 1.0 bt = math.exp(math.lgamma(a + b) - math.lgamma(a) - math.lgamma(b) + a * math.log(x) + b * math.log(1.0 - x)) if x < (a + 1.0) / (a + b + 2.0): return bt * betacf(a, b, x) / a return 1.0 - bt * betacf(b, a, 1.0 - x) / b def p_from_t(t, df): if t == 0: return 1.0 return betai(df / 2.0, 0.5, df / (df + t * t)) def student(m1, s1, n1, m2, s2, n2): df = n1 + n2 - 2 sp2 = ((n1 - 1) * s1 ** 2 + (n2 - 1) * s2 ** 2) / df if sp2 == 0: return float("inf") if m1 != m2 else 0.0, 0.0 if m1 != m2 else 1.0 t = abs(m1 - m2) / math.sqrt(sp2 * (1 / n1 + 1 / n2)) return t, p_from_t(t, df) def welch(m1, s1, n1, m2, s2, n2): v1, v2 = s1 ** 2 / n1, s2 ** 2 / n2 if v1 + v2 == 0: return 0.0 if m1 != m2 else 1.0 t = abs(m1 - m2) / math.sqrt(v1 + v2) df = (v1 + v2) ** 2 / (v1 ** 2 / (n1 - 1) + v2 ** 2 / (n2 - 1)) return p_from_t(t, df) def bh(ps, q=0.05): order = sorted(range(len(ps)), key=lambda i: ps[i]) m, kmax = len(ps), 0 for rank, i in enumerate(order, 1): if ps[i] <= q * rank / m: kmax = rank return sorted(order[:kmax]) def holm(ps, a=0.05): order = sorted(range(len(ps)), key=lambda i: ps[i]) keep = [] for rank, i in enumerate(order): if ps[i] <= a / (len(ps) - rank): keep.append(i) else: break return sorted(keep) def fit_n(rows): best = None table = {} for n1, n2 in product(range(3, 11), range(3, 11)): s = 0.0 for name, m1, s1, m2, s2, p in rows: if p >= 0.999 or s1 == 0 and s2 == 0: continue pc = student(m1, s1, n1, m2, s2, n2)[1] s += math.log(max(pc, 1e-12) / p) ** 2 table[(n1, n2)] = s if best is None or s < best[0]: best = (s, n1, n2) return best, sorted(table.items(), key=lambda kv: kv[1])[:4] def fraction_n(values): """The denominators (1-10) that make every printed mean a multiple of 1/n, to the printed two decimals.""" out = {} for n in range(1, 11): ok = all(abs(v * n - round(v * n)) <= n * 0.005 + 1e-9 for v in values) out[n] = ok return [n for n, ok in out.items() if ok] def main(): outdir = Path(sys.argv[1]) outdir.mkdir(parents=True, exist_ok=True) res = {"rules": "see the script's docstring"} for label, rows in (("S2", S2), ("S3", S3)): (score, n1, n2), top = fit_n(rows) ps = [r[5] for r in rows] keep_bh, keep_h = bh(ps), holm(ps) big = [r for r in rows if abs(r[1]) >= 1000] # raw fluorometer counts and areas; derived ratios can't constrain n frac_g = fraction_n([r[1] for r in big]) frac_n = fraction_n([r[3] for r in big]) recomputed = [] for name, m1, s1, m2, s2, p in rows: recomputed.append({"row": name, "GMF": m1, "GMF_SD": s1, "NNMF": m2, "NNMF_SD": s2, "P_printed": p, "P_student": round(student(m1, s1, n1, m2, s2, n2)[1], 4), "P_welch": round(welch(m1, s1, n1, m2, s2, n2), 4)}) at_fraction_n = {} for fn1, fn2 in ((4, 7), (4, 6)): st = [student(r[1], r[2], fn1, r[3], r[4], fn2)[1] for r in rows if r[5] < 0.999] we = [welch(r[1], r[2], fn1, r[3], r[4], fn2) for r in rows if r[5] < 0.999] pr = [r[5] for r in rows if r[5] < 0.999] close = lambda a, b: max(a, b) / max(min(a, b), 1e-12) <= 1.5 or abs(a - b) <= 0.03 at_fraction_n[f"{fn1},{fn2}"] = {"student_rows_close": sum(close(a, b) for a, b in zip(st, pr)), "welch_rows_close": sum(close(a, b) for a, b in zip(we, pr)), "rows": len(pr), "student_sig_agree": sum((a < 0.05) == (b < 0.05) for a, b in zip(st, pr)), "welch_sig_agree": sum((a < 0.05) == (b < 0.05) for a, b in zip(we, pr))} res[label] = {"at_fraction_n": at_fraction_n, "rows": len(rows), "printed_P_below_05": sum(p < 0.05 for p in ps), "expected_by_chance": round(0.05 * len(rows), 1), "best_n_GMF_NNMF": [n1, n2], "next_best": [[list(k), round(v, 2)] for k, v in top[1:]], "score": round(score, 2), "denominators_fitting_large_GMF_means": frac_g, "denominators_fitting_large_NNMF_means": frac_n, "BH_survivors": [rows[i][0] for i in keep_bh], "Holm_survivors": [rows[i][0] for i in keep_h], "rows_detail": recomputed} print(f"{label}: {len(rows)} rows, printed P<0.05: {sum(p < 0.05 for p in ps)} (chance {0.05 * len(rows):.1f}); best n GMF, NNMF = {n1}, {n2} (score {score:.2f}), next {[(k, round(v, 1)) for k, v in top[1:3]]}") print(f" means' fractions fit denominators: GMF {frac_g}, NNMF {frac_n}") print(f" fit at n from the fractions: {at_fraction_n}") print(f" BH survivors {len(keep_bh)}: {[rows[i][0] for i in keep_bh]}") print(f" Holm survivors {len(keep_h)}: {[rows[i][0] for i in keep_h]}") s2 = {r[0]: r for r in S2} res["S2_amplitudes_percent_change"] = {n: {"percent": round(100 * (s2[n][3] - s2[n][1]) / s2[n][1], 2), "P_printed": s2[n][5]} for n in ("Fo", "Fm", "Fv")} print("Table S2 amplitudes:", res["S2_amplitudes_percent_change"]) s3 = {r[0]: r for r in S3} res["S3_Fm_percent_change"] = {n: {"percent": round(100 * (s3[n][3] - s3[n][1]) / s3[n][1], 2), "P_printed": s3[n][5]} for n in ("Fm", "FmL1", "FmL2", "FmL3", "FmL4", "FmLss")} res["S3_vs_text"] = [{"row": n, "P_in_text": p, "P_in_S3": s3[n][5]} for n, p in TEXT_P] print("Text vs Table S3:", [(n, p, s3[n][5]) for n, p in TEXT_P]) rows = [] for organ, h, m1, s1, m2, s2_, star in S4: p3, p5 = student(m1, s1, 3, m2, s2_, 3)[1], student(m1, s1, 5, m2, s2_, 5)[1] rows.append({"organ": organ, "hormone": h, "GMF": m1, "GMF_SD": s1, "NNMF": m2, "NNMF_SD": s2_, "change_pct": round(100 * (m2 - m1) / m1, 1), "asterisk": star, "P_n3": round(p3, 4), "P_n5": round(p5, 4), "P_welch_n3": round(welch(m1, s1, 3, m2, s2_, 3), 4)}) p3s = [r["P_n3"] for r in rows] res["S4"] = {"rows": rows, "asterisks": sum(r["asterisk"] for r in rows), "asterisks_reproduced_n3": sum(r["asterisk"] and r["P_n3"] < 0.05 for r in rows), "asterisks_reproduced_n5": sum(r["asterisk"] and r["P_n5"] < 0.05 for r in rows), "no_asterisk_but_P_below_05_n3": sum((not r["asterisk"]) and r["P_n3"] < 0.05 for r in rows), "no_asterisk_but_P_below_05_n5": sum((not r["asterisk"]) and r["P_n5"] < 0.05 for r in rows), "BH_n3": [f"{rows[i]['organ']} {rows[i]['hormone']}" for i in bh(p3s)], "Holm_n3": [f"{rows[i]['organ']} {rows[i]['hormone']}" for i in holm(p3s)]} print("\nS4 (asterisk, P at n=3, P at n=5):") for r in rows: print(f" {r['organ']:<5} {r['hormone']:<5} {r['GMF']:>7} vs {r['NNMF']:>7} {r['change_pct']:>7}% star={r['asterisk']!s:<5} n3 {r['P_n3']:<7} n5 {r['P_n5']:<7}") print(" ", {k: v for k, v in res["S4"].items() if k != "rows"}) with open(outdir / "recheck_tables.json", "w", encoding="utf-8", newline="\n") as fh: json.dump(res, fh, indent=1, ensure_ascii=False) if __name__ == "__main__": main()