import numpy as np import pandas as pd from scipy import stats from common import RES, hom, axes, centre, effects, sgd_labels THRESHOLDS = [200, 250, 300, 350, 380, 400, 418] base = None rows = [] for t in THRESHOLDS: Z = hom(min_nonmissing=t) ag, ox, os_, ref = axes(Z.columns) Zc = centre(Z) e_ox, e_os = effects(Zc, ox, os_) cd = (e_ox - e_os).abs().dropna() oi, si = np.where(ox)[0], np.where(os_)[0] a = Zc.iloc[:, oi[0::2]].mean(axis=1) - Zc.iloc[:, si[0::2]].mean(axis=1) b = Zc.iloc[:, oi[1::2]].mean(axis=1) - Zc.iloc[:, si[1::2]].mean(axis=1) m = a.notna() & b.notna() if t == 350: base = cd lab = sgd_labels("oxidative") lab = lab[lab.index.isin(e_ox.dropna().index)] conc = (np.sign(e_ox.loc[lab.index]) == -lab).mean() rows.append({"min_nonmissing": t, "genes": len(cd), "splithalf_cd_signed": stats.spearmanr(a[m], b[m]).statistic, "splithalf_cd_abs": stats.spearmanr(a[m].abs(), b[m].abs()).statistic, "oxidative_benchmark_n": len(lab), "oxidative_concordance": conc, "cd": cd}) for r in rows: top_r = set(r["cd"].sort_values(ascending=False).index[: int(np.ceil(0.1 * len(r["cd"])))]) top_b = set(base.sort_values(ascending=False).index[: int(np.ceil(0.1 * len(base)))]) r["top_decile_jaccard_vs_350"] = len(top_r & top_b) / len(top_r | top_b) del r["cd"] out = pd.DataFrame(rows) out.to_csv(RES / "threshold_sensitivity.csv", index=False)