| import pandas as pd |
|
|
| causal_hits = pd.read_csv("results/fig_SIMS_waterfall.csv") if (Path("results/fig_SIMS_waterfall.csv").exists()) else None |
|
|
| landmark_refs = { |
| "PDR5": "The major yeast multidrug transporter; confers resistance to azoles, cycloheximide, ethanol tolerance (Paulsen et al., Trends Microbiol 1996; Piper et al., Appl Environ Microbiol 1998).", |
| "SNQ2": "Broad-spectrum drug resistance; deletion leads to hypersensitivity to oxidants, ethanol, and xenobiotics (Decottignies et al., EMBO J 1995).", |
| "YOR1": "Oligomycin and multiple toxin resistance, associated with ATPase-dependent efflux (Katzmann et al., Mol Cell Biol 1995).", |
| "ATM1": "Mitochondrial ABC transporter, iron-sulfur cluster export, not classically ethanol but key for oxidative stress resilience (Kispal et al., EMBO J 1999)." |
| } |
|
|
| rows = [] |
| for t, ref in landmark_refs.items(): |
| rows.append({"transporter": t, "supporting_evidence": ref}) |
| lit_check = pd.DataFrame(rows) |
| lit_check.to_csv("results/validation_literature_crosscheck.csv", index=False) |
| lit_check |
|
|
| import json, pandas as pd, numpy as np |
| from pathlib import Path |
|
|
| RES = Path("results"); RES.mkdir(exist_ok=True, parents=True) |
|
|
| s3_path = RES/"causal_section3_snapshot.json" |
| with open(s3_path, "r") as f: |
| s3 = json.load(f) |
|
|
| def _to_scalar(x): |
| """Return a float scalar from x, handling dicts like {'overall': v, ...} or {'ATE': v}.""" |
| if x is None: |
| return np.nan |
| if isinstance(x, (int, float, np.number)): |
| return float(x) |
| if isinstance(x, dict): |
| for k in ["overall", "ATE", "ate", "mean", "Mean", "val", "value"]: |
| if k in x and isinstance(x[k], (int, float, np.number)): |
| return float(x[k]) |
| for v in x.values(): |
| if isinstance(v, (int, float, np.number)): |
| return float(v) |
| return np.nan |
| if isinstance(x, (list, tuple)): |
| for v in x: |
| if isinstance(v, (int, float, np.number)): |
| return float(v) |
| return np.nan |
| return np.nan |
|
|
| ATE_table = s3.get("ATE_table") or {} |
| if not ATE_table and "stress_ate" in s3: |
| ATE_table = {k: v.get("overall", np.nan) for k, v in s3["stress_ate"].items() if isinstance(v, dict)} |
|
|
| anchors = { |
| "PDR5_expr": ("PDR5", "Ethanol/drug tolerance via efflux; KO sensitizes", "positive"), |
| "SNQ2_expr": ("SNQ2", "Oxidant & ethanol hypersensitivity when deleted", "positive"), |
| "YOR1_expr": ("YOR1", "Drug/toxin efflux", "positive or context-specific"), |
| "ATM1_expr": ("ATM1", "Mitochondrial Fe–S export; oxidative resilience", "positive under oxidative"), |
| } |
|
|
| rows=[] |
| for key,(gene,phen,expect) in anchors.items(): |
| val = _to_scalar(ATE_table.get(key, np.nan)) |
| if pd.notna(val): |
| sgn = "positive" if val > 0 else ("negative" if val < 0 else "~0") |
| else: |
| sgn = "~0" |
| note = ( |
| "matches expected direction" |
| if (expect.startswith("positive") and pd.notna(val) and val > 0) |
| or ("context" in expect and pd.notna(val) and val != 0) |
| else ("opposite sign (check stress/context)" if pd.notna(val) and val != 0 else "no effect / not detected") |
| ) |
| rows.append([gene, phen, expect, (float(val) if pd.notna(val) else np.nan), 3, sgn, note]) |
|
|
| df = pd.DataFrame(rows, columns=["gene","phenotype","expected_sign","mean_ATE","n_stresses","ATE_sign","concordance_note"]) |
| out = RES/"validation_lit_crosscheck.csv" |
| df.to_csv(out, index=False) |
| print(" Saved:", out) |
| display(df) |
|
|
| import json, numpy as np, pandas as pd, matplotlib.pyplot as plt, seaborn as sns |
| from pathlib import Path |
|
|
| RES = Path("results"); RES.mkdir(parents=True, exist_ok=True) |
|
|
| |
| def _to_scalar(x): |
| if x is None: return np.nan |
| if isinstance(x, (int,float,np.number)): return float(x) |
| if isinstance(x, dict): |
| for k in ["overall","ATE","ate","mean","Mean","val","value"]: |
| if k in x and isinstance(x[k], (int,float,np.number)): return float(x[k]) |
| |
| for v in x.values(): |
| if isinstance(v, (int,float,np.number)): return float(v) |
| return np.nan |
| if isinstance(x, (list,tuple)): |
| for v in x: |
| if isinstance(v, (int,float,np.number)): return float(v) |
| return np.nan |
| return np.nan |
|
|
| with open(RES/"causal_section3_snapshot.json","r") as f: |
| s3 = json.load(f) |
|
|
| anchors = { |
| "PDR5_expr": "PDR5", |
| "SNQ2_expr": "SNQ2", |
| "YOR1_expr": "YOR1", |
| "ATM1_expr": "ATM1", |
| } |
|
|
| rows = [] |
|
|
| if "stress_ate" in s3: |
| stab = s3["stress_ate"] |
| def _looks_like_transporter_keys(d): |
| ks = list(d.keys())[:5] |
| return any(isinstance(k,str) and k.endswith("_expr") for k in ks) |
| if isinstance(stab, dict) and stab: |
| first = next(iter(stab.values())) |
| if isinstance(first, dict) and _looks_like_transporter_keys(stab): |
| for t, inner in stab.items(): |
| if t not in anchors: continue |
| for stress, val in inner.items(): |
| v = _to_scalar(val) |
| if pd.notna(v): rows.append({"transporter": t, "stress": str(stress), "ATE": v}) |
| elif isinstance(first, dict): |
| for stress, inner in stab.items(): |
| for t, val in inner.items(): |
| if t not in anchors: continue |
| v = _to_scalar(val) |
| if pd.notna(v): rows.append({"transporter": t, "stress": str(stress), "ATE": v}) |
|
|
| if not rows: |
| A = s3.get("ATE_table", {}) |
| for t, g in anchors.items(): |
| v = _to_scalar(A.get(t, np.nan)) |
| if pd.notna(v): |
| rows.append({"transporter": t, "stress": "overall", "ATE": v}) |
|
|
| S = pd.DataFrame(rows) |
|
|
| out_csv = RES/"validation_anchor_per_stress.csv" |
| S.to_csv(out_csv, index=False) |
| print(" Saved:", out_csv) |
| display(S.head(10)) |
|
|
| if not S.empty and S["ATE"].notna().any(): |
| pt = S.pivot_table(index="transporter", columns="stress", values="ATE", aggfunc="mean") |
| pt = pt.dropna(axis=0, how="all").dropna(axis=1, how="all") |
| if pt.size > 0: |
| plt.figure(figsize=(max(6, 1.8 + 0.6*pt.shape[1]), max(2.8, 0.45*pt.shape[0]))) |
| sns.heatmap(pt, annot=True, fmt=".3f", center=0, cmap="coolwarm") |
| plt.title("Per-stress ATEs for anchor genes") |
| plt.tight_layout() |
| plt.savefig(RES/"validation_anchor_per_stress_heatmap.png", dpi=300) |
| plt.show() |
| print(" Saved heatmap →", RES/"validation_anchor_per_stress_heatmap.png") |
| else: |
| print(" No non-NaN cells after pivot; skipping heatmap.") |
| else: |
| print("No per-stress ATEs available; heatmap skipped.") |