lorapop / code /work /hv_candidates.py
bryan7264's picture
Add files using upload-large-folder tool
36357ab verified
Raw History Blame Contribute Delete
1.49 kB
# MIT License, Bryan Cheng, 2026.
"""How many same-module high-variance controls exist under different 'non-associated' rules (D-033 support)."""
import json, os, sys
import numpy as np
sys.path.insert(0, ".")
from src.analysis.scan import bh
EST = ["naive", "pc", "mm_f", "mm_fd", "wf_d", "wf_r", "dup_afe"]
d = "results/scans/qwen05"
loci = json.load(open(f"{d}/loci.json")); prim = json.load(open(f"{d}/primary_traits.json"))["primary"]
plan = json.load(open("results/interventions/plan_qwen05_full.json"))
P = np.stack([np.load(f"{d}/{t}.npz")["p"][:, 1] for t in prim]); P = np.where(np.isfinite(P), P, 1.0)
real = np.array([not l["module"].startswith("presence") for l in loci]); P[:, :, ~real] = 1.0
tested = {x["locus_idx"] for x in plan["directions"] if x["kind"] == "locus" and x.get("source")}
mods_t = {loci[j]["module"] for j in tested}
for name, ests in [("all7", EST), ("pop4", ["naive", "pc", "mm_f", "mm_fd"]), ("mm2", ["mm_f", "mm_fd"]), ("mmfd", ["mm_fd"])]:
ei = [EST.index(e) for e in ests]
fdr = np.zeros(len(loci), bool)
for e in ei:
for ti in range(len(prim)):
fdr |= bh(P[ti, e]) & real
pm = P[:, ei].min((0, 1)) * len(prim) * len(ei)
for thr in (0.5, 0.05):
ok = real & ~fdr & (pm > thr)
nm = sum(any(ok[k] for k, x in enumerate(loci) if x["module"] == m and k not in tested) for m in mods_t)
print(name, "bonf>", thr, "candidates", int(ok.sum()), "tested modules with a control", nm, "of", len(mods_t))