BULMA / scripts /data_curation /build_causal_table.py
HarriziSaad's picture
Update scripts/data_curation/build_causal_table.py
09a67b6 verified
import numpy as np
import pandas as pd
from pathlib import Path
SEED = 17
DATA_PROC = Path("data/processed")
DATA_PROC.mkdir(parents=True, exist_ok=True)
def build_causal_table(transporters: list, seed: int = SEED, n: int = 6000) -> pd.DataFrame:
rng = np.random.default_rng(seed)
df = pd.DataFrame({
"outcome": rng.normal(0, 1, n),
"ethanol_pct": rng.choice([0, 4, 6, 8, 10], n),
"ROS": rng.gamma(2.0, 0.7, n),
"PDR1_reg": rng.normal(0, 1, n),
"YAP1_reg": rng.normal(0, 1, n),
"H2O2_uM": rng.choice([0, 100, 200, 400], n),
"NaCl_mM": rng.choice([0, 200, 400, 800], n),
"batch": rng.choice(["GSE_A", "GSE_B", "GSE_C"], n),
"accession": rng.choice(["GSE102475", "GSE73316", "GSE40356"], n),
"sample_id": [f"S{i:05d}" for i in range(n)],
"normalized": True,
})
for t in transporters:
expr = rng.normal(0, 1, n)
if t == "ATM1":
df["outcome"] += 0.08 * expr
if t == "SNQ2":
df["outcome"] -= 0.05 * expr
df[f"{t}_expr"] = expr
core = ["outcome", "ethanol_pct", "ROS", "PDR1_reg", "YAP1_reg",
"H2O2_uM", "NaCl_mM", "batch", "accession", "sample_id", "normalized"]
expr_cols = [f"{t}_expr" for t in transporters]
return df[core + expr_cols]
if __name__ == "__main__":
import sys
sys.path.insert(0, str(Path(__file__).parent.parent.parent))
from scripts.compute_embeddings_protein import CANON_GENES as TRANSPORTERS
df = build_causal_table(TRANSPORTERS, seed=SEED)
df.to_csv(DATA_PROC / "causal_table.csv", index=False)
print(f"✅ causal_table.csv shape={df.shape} NaNs={df.isna().any().any()}")