Datasets:
Add MirrorPeptidizer benchmark (D/L comparison, new targets, ablation, figure data, SI)
0613483 verified Download scripts/export_figure_data.py from dahuilangda/MirrorPeptidizer: direct link, hf CLI and curl.
- Browser
- Download file 4.58 kB
-
https://huggingface.co/datasets/dahuilangda/MirrorPeptidizer/resolve/main/scripts/export_figure_data.py
- Command line
-
hf download hf://datasets/dahuilangda/MirrorPeptidizer/scripts/export_figure_data.py
-
curl -L -o export_figure_data.py https://huggingface.co/datasets/dahuilangda/MirrorPeptidizer/resolve/main/scripts/export_figure_data.py
4.58 kB
| """Export all plotting CSVs for each figure into benchmark/figure_data/.""" | |
| from pathlib import Path | |
| import pandas as pd | |
| import numpy as np | |
| import shutil | |
| BENCH = Path(__file__).resolve().parents[1] | |
| FIGDATA = BENCH / "figure_data" | |
| FIGDATA.mkdir(exist_ok=True) | |
| TARGETS = ["PDL1", "MDM2", "IL23R"] | |
| def main(): | |
| # ── fig_ablation_bo_tradeoff ── | |
| ablation = pd.read_csv(BENCH / "ablation" / "ablation_summary_pose_filtered.csv") | |
| ablation.to_csv(FIGDATA / "fig_ablation_bo_tradeoff_ablation_summary.csv", index=False) | |
| tradeoff = pd.read_csv(BENCH / "ablation" / "ablation_tradeoff_pose_filtered.csv") | |
| tradeoff.to_csv(FIGDATA / "fig_ablation_bo_tradeoff_tradeoff.csv", index=False) | |
| bad = pd.read_csv(BENCH / "buried_pose_inventory.csv") | |
| # Ablation Tier-1 reuses the dl D-peptide designs, so the ablation bad-pose | |
| # counts are the D_peptide buried poses per core target. | |
| bad_ab = bad[bad["peptide_mode"] == "D_peptide"] | |
| bad_counts = ( | |
| bad_ab.groupby("target") | |
| .size() | |
| .reindex(TARGETS, fill_value=0) | |
| .rename("n_bad_poses") | |
| .reset_index() | |
| ) | |
| bad_counts.to_csv(FIGDATA / "fig_ablation_bo_tradeoff_bad_pose_counts.csv", index=False) | |
| print( | |
| f"fig_ablation: {len(ablation)} summary rows + " | |
| f"{len(tradeoff)} trade-off rows + {len(bad_counts)} pose counts" | |
| ) | |
| # ── fig_dl_score_distribution ── | |
| for t in TARGETS: | |
| for m in ["D_peptide", "L_peptide"]: | |
| src = BENCH / "dl_downsampled" / f"{t}_{m}_filtered.csv" | |
| dst = FIGDATA / f"fig_dl_score_dist_{t}_{m}.csv" | |
| shutil.copy2(src, dst) | |
| from scipy import stats as sp_stats | |
| rows = [] | |
| for t in TARGETS: | |
| d = pd.read_csv(FIGDATA / f"fig_dl_score_dist_{t}_D_peptide.csv") | |
| l = pd.read_csv(FIGDATA / f"fig_dl_score_dist_{t}_L_peptide.csv") | |
| ks, p = sp_stats.ks_2samp(d["score"], l["score"]) | |
| rows.append( | |
| { | |
| "target": t, | |
| "n": len(d), | |
| "D_median": d["score"].median(), | |
| "L_median": l["score"].median(), | |
| "D_mean": d["score"].mean(), | |
| "L_mean": l["score"].mean(), | |
| "KS_stat": ks, | |
| "KS_p": p, | |
| } | |
| ) | |
| pd.DataFrame(rows).to_csv(FIGDATA / "fig_dl_score_dist_summary.csv", index=False) | |
| print("fig_dl_score_dist: 6 CSVs + summary") | |
| # ── fig_dl_sequence_comparison (t-SNE top-100) ── | |
| from sklearn.decomposition import PCA | |
| from sklearn.manifold import TSNE | |
| AAS = list("ACDEFGHIKLMNPQRSTVWY") | |
| TOP_N = 100 | |
| aa2i = {a: i for i, a in enumerate(AAS)} | |
| def onehot(seqs, max_len): | |
| vecs = [] | |
| for s in seqs: | |
| v = np.zeros(max_len * len(AAS)) | |
| for pos, aa in enumerate(str(s)): | |
| if aa in aa2i: | |
| v[pos * len(AAS) + aa2i[aa]] = 1.0 | |
| vecs.append(v) | |
| return np.array(vecs) | |
| for t in TARGETS: | |
| d_df = pd.read_csv(FIGDATA / f"fig_dl_score_dist_{t}_D_peptide.csv") | |
| l_df = pd.read_csv(FIGDATA / f"fig_dl_score_dist_{t}_L_peptide.csv") | |
| d_top = d_df.nsmallest(TOP_N, "score").drop_duplicates("sequence").copy() | |
| l_top = l_df.nsmallest(TOP_N, "score").drop_duplicates("sequence").copy() | |
| ml = max(d_top["sequence"].str.len().max(), l_top["sequence"].str.len().max()) | |
| dv = onehot(d_top["sequence"], ml) | |
| lv = onehot(l_top["sequence"], ml) | |
| X = np.vstack([dv, lv]) | |
| npc = min(50, X.shape[1], X.shape[0] - 1) | |
| Xp = PCA(n_components=npc, random_state=42).fit_transform(X) | |
| Xt = TSNE( | |
| n_components=2, perplexity=30, random_state=42, | |
| learning_rate="auto", init="pca", | |
| ).fit_transform(Xp) | |
| nd = len(dv) | |
| d_out = d_top[["sequence", "score", "length", "pose"]].copy() | |
| d_out["tsne_1"] = Xt[:nd, 0] | |
| d_out["tsne_2"] = Xt[:nd, 1] | |
| d_out["type"] = "D" | |
| l_out = l_top[["sequence", "score", "length", "pose"]].copy() | |
| l_out["tsne_1"] = Xt[nd:, 0] | |
| l_out["tsne_2"] = Xt[nd:, 1] | |
| l_out["type"] = "L" | |
| combined = pd.concat([d_out, l_out], ignore_index=True) | |
| combined.to_csv(FIGDATA / f"fig_dl_tsne_{t}.csv", index=False) | |
| print(f"fig_dl_tsne_{t}: {nd} D + {len(l_out)} L = {len(combined)} rows") | |
| print(f"\nAll figure data saved to {FIGDATA}/") | |
| for f in sorted(FIGDATA.iterdir()): | |
| print(f" {f.name} ({f.stat().st_size/1024:.1f} KB)") | |
| if __name__ == "__main__": | |
| main() | |