|
|
| 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) |
|
|
| CONDITIONS = ["YPD", "YPD+EtOH_4pct", "YPD+H2O2_100uM"] |
|
|
|
|
| def build_labels(transporters: list, compounds: list, seed: int = SEED) -> pd.DataFrame: |
| """ |
| Parameters |
| ---------- |
| transporters : list of (name, ...) or plain name strings |
| compounds : list of (name, smiles, class) tuples |
| """ |
| rng = np.random.default_rng(seed) |
| rows = [] |
|
|
| for t in transporters: |
| t_name = t if isinstance(t, str) else t[0] |
| base = 0.03 |
| if t_name in ("PDR5", "SNQ2", "YOR1", "PDR15"): base = 0.06 |
| if t_name == "ATM1": base = 0.05 |
|
|
| for c_name, c_smi, c_cls in compounds: |
| p = base |
| if t_name in ("PDR5", "SNQ2") and c_cls in ("aromatic", "heterocycle"): p *= 2.5 |
| if t_name == "ATM1" and c_name in ("H2O2", "ETHANOL"): p *= 3.0 |
| if t_name == "YOR1" and c_cls == "alcohol": p *= 1.8 |
|
|
| for assay in ("A1", "A2"): |
| rows.append({ |
| "transporter": t_name, |
| "compound": c_name, |
| "y": int(rng.random() < min(p, 0.5)), |
| "assay_id": assay, |
| "condition": rng.choice(CONDITIONS), |
| "concentration": rng.choice(["1uM", "10uM", "50uM", "100uM"]), |
| "replicate": int(rng.integers(1, 4)), |
| "media": rng.choice(["YPD", "SD"]), |
| }) |
|
|
| return pd.DataFrame(rows) |
|
|
|
|
| if __name__ == "__main__": |
| P = pd.read_csv(DATA_PROC / "protein.csv") |
| L = pd.read_csv(DATA_PROC / "ligand.csv") |
|
|
| transporters = P["transporter"].tolist() |
| compounds = list(zip(L["compound"], L.get("smiles", L["compound"]), |
| L.get("class", ["unknown"] * len(L)))) |
|
|
| Y = build_labels(transporters, compounds, seed=SEED) |
| Y.to_csv(DATA_PROC / "labels.csv", index=False) |
| print(f"labels.csv shape={Y.shape} pos_rate={Y.y.mean():.3f} NaNs={Y.isna().any().any()}") |
|
|