"""EXPLORATORY (not pre-registered): leave-one-library-out for the 5 uT comparison (GMF50 vs GMF45). Data only. Fact-Checked Science ("Our analysis"), https://factchecked.science/planthopper-magnetic-genes/ Data: Xie, W., et al. (2026), Dryad, doi:10.5061/dryad.r4xgxd2vx (CC0); make the input folder with prepare_inputs.py, then pass /dataset (or /field for igrf_route.py) as the script's usage says. Per-comparison scope; method A (trend and conservative dispersions). Reports the DEG count with each library left out, and how many of the authors' 244 DEGs are still called. Usage: python3 exploratory_loo.py """ import json, os, sys import numpy as np sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) import rederive as R def main(): folder, out_path = sys.argv[1], sys.argv[2] cm, _ = R.load_counts(folder) auth = R.load_authors(folder)[("GMF50", "GMF45")] theirs = set(auth.index[auth["deg"]]) full = R.GROUPS["GMF50"] + R.GROUPS["GMF45"] out = {"NOTE": "exploratory, not pre-registered", "runs": []} for drop in [None] + full: smp = [x for x in full if x != drop] labels = ["GMF50" if x.startswith("GMF50") else "GMF45" for x in smp] K = cm[smp].values.astype(float); keep = K.sum(1) >= 6; genes = cm.index[keep].values; K = K[keep] s = R.size_factors(K); base = (K / s).mean(1) rec = {"dropped": drop} for v in ("trend", "conservative"): lfc, p, info = R.method_a(K, s, labels, "GMF50", "GMF45", base, v) sel, _, _ = R.call(lfc, p) ours = set(genes[sel]) rec["A_" + v] = int(sel.sum()); rec["A_" + v + "_keeps_of_authors_244"] = len(ours & theirs) out["runs"].append(rec) print(rec) json.dump(out, open(out_path, "w", encoding="utf-8", newline="\n"), indent=1) if __name__ == "__main__": main()