import numpy as np import pandas as pd from scipy import stats from statsmodels.stats.multitest import multipletests from common import RES L = [] rd = lambda f: pd.read_csv(RES / f) def h(title): L.append(f"\n## {title}\n") def t(df, n=60): L.append("```\n" + df.head(n).to_string(index=False) + "\n```") h("Atlas") t(rd("atlas_summary.csv")) a = pd.read_csv(RES / "atlas.csv", index_col=0) L.append(f"MDL2: E_ox {a.loc['YPL270W', 'ox']:.3f}; E_osm {a.loc['YPL270W', 'osm']:.3f}; |D| {a.loc['YPL270W', 'cd']:.3f}") t(rd("abc_cd.csv").sort_values("cd", ascending=False)) h("Conditions") c = rd("conditions.csv") pct = c.severity_frac_z_gt2.rank(pct=True) * 100 L.append(f"hydrogen peroxide conditions: severity {c.severity_frac_z_gt2[c.agent == 'h2o2'].round(3).tolist()}, " f"percentile among 418 conditions {pct[c.agent == 'h2o2'].round(1).tolist()}") base = c[c["class"] == "baseline-only"] L.append(f"conditions outside both classes: {len(base)}; distinct primary compounds {base.compound.str.lower().nunique()}; " f"median severity {base.severity_frac_z_gt2.median():.3f}") h("Agent structure") p = rd("condition_pair_correlations.csv") t(p.groupby(["axis", "kind"]).rho.agg(["size", "median", "min", "max"]).round(3).reset_index()) ae = pd.read_csv(RES / "agent_effects.csv", index_col=0) L.append(f"genome-wide SD of agent-level effects: {ae.std().round(2).to_dict()}") L.append("Spearman correlations between agent-level effects:\n```\n" + ae.corr(method="spearman").round(3).to_string() + "\n```") t(rd("agent_heterogeneity_summary.csv")) rb = pd.read_csv(RES / "agent_robust_cd.csv", index_col=0).n_pairs_top_decile top = a.cd.rank(ascending=False) <= np.ceil(0.1 * len(a)) L.append(f"agent-robust core: {int((rb >= 3).sum())} genes; pooled top-decile genes in the core: " f"{int((top & (rb.reindex(a.index) >= 3)).sum())} of {int(top.sum())}") bal = pd.read_csv(RES / "agent_balanced_effects.csv", index_col=0) L.append(f"agent-balanced versus pooled |D|: Spearman {stats.spearmanr(a.cd, bal.cd_balanced.reindex(a.index), nan_policy='omit').statistic:.3f}") t(rd("leave_one_agent_out.csv").round(3)) h("Reproducibility and sensitivity") t(rd("reproducibility.csv").round(3)) sr = rd("splithalf_random.csv") t(sr.groupby("h2o2_replicates_separated").cd_signed.describe().round(3).reset_index()) t(rd("sensitivity.csv")) t(rd("threshold_sensitivity.csv").round(4)) t(rd("leave_one_condition_out.csv").round(3)) t(rd("toxicity_summary.csv").round(4)) h("Independent replication") t(rd("independent_replication.csv").round(4).assign(p=lambda d: rd("independent_replication.csv").p.map("{:.2e}".format))) t(rd("independent_agent_matrix.csv").round(3)) t(rd("independent_4nqo_dose_series.csv").round(3)) ind = rd("independent_screens.csv") L.append(f"independent screens: {int((~ind.source).sum())} from {ind[~ind.source].paper.nunique()} studies") h("Functional enrichment") e = rd("enrichment_all.csv") for gs in e.gene_set.unique(): x = e[e.gene_set == gs] L.append(f"{gs}: {x.set_size.iloc[0]} genes; {x.terms_tested.iloc[0]} terms tested; {(x.p_bh < 0.05).sum()} with BH-adjusted p < 0.05") t(x[x.p_bh < 0.05][["term", "k", "K", "fold", "p", "p_bh"]].round({"fold": 4}).assign( p=lambda d: d.p.map("{:.2e}".format), p_bh=lambda d: d.p_bh.map("{:.2e}".format))) h("Per-gene inference and reference distribution") t(rd("permutation_mdl2.csv")) t(rd("calibration_summary.csv")) h("Curated phenotype benchmark") bs = rd("benchmark_summary.csv") t(bs.round(4).assign(p_binomial=bs.p_binomial.map("{:.2e}".format), p_slow_growth_bias=bs.p_slow_growth_bias.map("{:.2e}".format))) t(rd("benchmark_terciles.csv").round(3)) t(rd("benchmark_concordance_trend.csv")) t(rd("benchmark_matching.csv").round(3)) t(rd("benchmark_auroc_differences.csv").round(4)) cg = rd("confound_generalize.csv") cg["p_bh"] = multipletests(cg.p, method="fdr_bh")[1] L.append(f"phenotype classes {len(cg)}; slow-growth AUROC > 0.5 in {int((cg.auroc_slowgrowth > 0.5).sum())}; " f"BH-adjusted p < 0.05 in {int((cg.p_bh < 0.05).sum())}") t(cg.sort_values("auroc_slowgrowth", ascending=False).round(4), 45) t(rd("robustness_coupling.csv")) h("ABC transporters") t(rd("abc_paralog_pairs.csv")) st = rd("abc_struct_sim.csv") t(st[st.paralog].round(3)) L.append(f"TM-score median: same subfamily {st[st.same_subfamily].tmscore.median():.3f} ({int(st.same_subfamily.sum())} pairs); " f"different subfamilies {st[~st.same_subfamily].tmscore.median():.3f} ({int((~st.same_subfamily).sum())} pairs)") t(rd("abc_identity_tm_mantel.csv")) t(rd("abc_struct_validation_summary.csv")) ex = rd("experimental_structures.csv") t(ex[["gene", "pdb", "method", "resolution", "coverage", "tm_score_af_vs_experimental"]].round(3)) t(rd("abc_profile_dependence.csv").round(4)) t(rd("abc_gi_matched_sets.csv").round(4)) t(rd("abc_pair_eps.csv")) (RES / "summary_numbers.md").write_text("\n".join(L) + "\n", encoding="utf-8")