diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000000000000000000000000000000000000..bed0738c7eeb449bca98b5d2f33c89a1ee56349a --- /dev/null +++ b/.gitattributes @@ -0,0 +1,60 @@ +*.7z filter=lfs diff=lfs merge=lfs -text +*.arrow filter=lfs diff=lfs merge=lfs -text +*.avro filter=lfs diff=lfs merge=lfs -text +*.bin filter=lfs diff=lfs merge=lfs -text +*.bz2 filter=lfs diff=lfs merge=lfs -text +*.ckpt filter=lfs diff=lfs merge=lfs -text +*.ftz filter=lfs diff=lfs merge=lfs -text +*.gz filter=lfs diff=lfs merge=lfs -text +*.h5 filter=lfs diff=lfs merge=lfs -text +*.joblib filter=lfs diff=lfs merge=lfs -text +*.lfs.* filter=lfs diff=lfs merge=lfs -text +*.lz4 filter=lfs diff=lfs merge=lfs -text +*.mds filter=lfs diff=lfs merge=lfs -text +*.mlmodel filter=lfs diff=lfs merge=lfs -text +*.model filter=lfs diff=lfs merge=lfs -text +*.msgpack filter=lfs diff=lfs merge=lfs -text +*.npy filter=lfs diff=lfs merge=lfs -text +*.npz filter=lfs diff=lfs merge=lfs -text +*.onnx filter=lfs diff=lfs merge=lfs -text +*.ot filter=lfs diff=lfs merge=lfs -text +*.parquet filter=lfs diff=lfs merge=lfs -text +*.pb filter=lfs diff=lfs merge=lfs -text +*.pickle filter=lfs diff=lfs merge=lfs -text +*.pkl filter=lfs diff=lfs merge=lfs -text +*.pt filter=lfs diff=lfs merge=lfs -text +*.pth filter=lfs diff=lfs merge=lfs -text +*.rar filter=lfs diff=lfs merge=lfs -text +*.safetensors filter=lfs diff=lfs merge=lfs -text +saved_model/**/* filter=lfs diff=lfs merge=lfs -text +*.tar.* filter=lfs diff=lfs merge=lfs -text +*.tar filter=lfs diff=lfs merge=lfs -text +*.tflite filter=lfs diff=lfs merge=lfs -text +*.tgz filter=lfs diff=lfs merge=lfs -text +*.wasm filter=lfs diff=lfs merge=lfs -text +*.xz filter=lfs diff=lfs merge=lfs -text +*.zip filter=lfs diff=lfs merge=lfs -text +*.zst filter=lfs diff=lfs merge=lfs -text +*tfevents* filter=lfs diff=lfs merge=lfs -text +# Audio files - uncompressed +*.pcm filter=lfs diff=lfs merge=lfs -text +*.sam filter=lfs diff=lfs merge=lfs -text +*.raw filter=lfs diff=lfs merge=lfs -text +# Audio files - compressed +*.aac filter=lfs diff=lfs merge=lfs -text +*.flac filter=lfs diff=lfs merge=lfs -text +*.mp3 filter=lfs diff=lfs merge=lfs -text +*.ogg filter=lfs diff=lfs merge=lfs -text +*.wav filter=lfs diff=lfs merge=lfs -text +# Image files - uncompressed +*.bmp filter=lfs diff=lfs merge=lfs -text +*.gif filter=lfs diff=lfs merge=lfs -text +*.png filter=lfs diff=lfs merge=lfs -text +*.tiff filter=lfs diff=lfs merge=lfs -text +# Image files - compressed +*.jpg filter=lfs diff=lfs merge=lfs -text +*.jpeg filter=lfs diff=lfs merge=lfs -text +*.webp filter=lfs diff=lfs merge=lfs -text +# Video files - compressed +*.mp4 filter=lfs diff=lfs merge=lfs -text +*.webm filter=lfs diff=lfs merge=lfs -text diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..5a5054513b6bcf2f34516d7cf613ed80b8c9f9fc --- /dev/null +++ b/.gitignore @@ -0,0 +1,58 @@ +# Data directories (large, downloaded) +data/ +exports/ + +# Experiment results & runtime logs (generated, large) +results/ +logs/ + +# Database files +*.db +*.sqlite +*.sqlite3 + +# Python +__pycache__/ +*.py[cod] +*$py.class +*.egg-info/ +*.egg +dist/ +build/ +.eggs/ + +# Virtual environments +.venv/ +venv/ + +# Environment variables +.env + +# OS +.DS_Store + +# IDE +.idea/ +.vscode/ + +# Claude Code local settings (contain tool permissions and local paths) +.claude/ + +# Testing +.pytest_cache/ +.coverage +htmlcov/ + +# Internal planning documents (not for public release) +research/ +NeurIPS_DB_Track_Research.md + +# Binary files (PDFs) — not suitable for git/HuggingFace datasets +paper/main.pdf +paper/*.aux +paper/*.bbl +paper/*.blg +paper/*.log +paper/*.out +paper/missfont.log +paper/figures/*.pdf diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..b76b760be7bd0408dc0d8fc428ba2fe0109a54b3 --- /dev/null +++ b/LICENSE @@ -0,0 +1,27 @@ +Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) + +Copyright (c) 2026 James Jang + +You are free to: + Share — copy and redistribute the material in any medium or format + Adapt — remix, transform, and build upon the material for any purpose, even commercially + +Under the following terms: + Attribution — You must give appropriate credit, provide a link to the license, + and indicate if changes were made. You may do so in any reasonable manner, but + not in any way that suggests the licensor endorses you or your use. + + ShareAlike — If you remix, transform, or build upon the material, you must + distribute your contributions under the same license as the original. + + No additional restrictions — You may not apply legal terms or technological + measures that legally restrict others from doing anything the license permits. + +Full license text: https://creativecommons.org/licenses/by-sa/4.0/legalcode + +--- + +Note on upstream licenses: +- ChEMBL (v36) data is CC BY-SA 3.0, which requires CC BY-SA 4.0 for derived works. +- All other upstream sources (PubChem, AACT, HuRI, etc.) are Public Domain or + permissively licensed (CC BY, Apache 2.0, MIT), compatible with CC BY-SA 4.0. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..573996685f810a0b42c1f152cefcf20c564802d8 --- /dev/null +++ b/Makefile @@ -0,0 +1,180 @@ +# NegBioDB Pipeline Makefile + +.PHONY: setup db test clean \ + ge-db ge-download-depmap ge-load-depmap ge-load-rnai ge-export ge-all ge-clean ge-test + +# === Week 1: Scaffolding === + +setup: + uv venv + uv sync --all-extras + mkdir -p data exports + +db: setup + uv run python -c "from negbiodb.db import create_database; create_database()" + +test: setup + uv run pytest tests/ -v + +clean: + rm -f data/negbiodb.db + rm -rf exports/* __pycache__ .pytest_cache + find . -name "*.pyc" -delete 2>/dev/null || true + +# === Week 2: Data Download === + +.PHONY: download download-pubchem download-chembl download-bindingdb download-davis + +download-pubchem: setup + uv run python scripts/download_pubchem.py + +download-chembl: setup + uv run python scripts/download_chembl.py + +download-bindingdb: setup + uv run python scripts/download_bindingdb.py + +download-davis: setup + uv run python scripts/download_davis.py + +download: download-pubchem download-chembl download-bindingdb download-davis + +# === ETL: Load Sources === + +.PHONY: load-davis load-chembl load-pubchem load-bindingdb load-all + +load-davis: db download-davis + uv run python scripts/load_davis.py + +load-chembl: db download-chembl + uv run python scripts/load_chembl.py + +load-pubchem: db download-pubchem + uv run python scripts/load_pubchem.py + +load-bindingdb: db download-bindingdb + uv run python scripts/load_bindingdb.py + +load-all: load-davis load-chembl load-pubchem load-bindingdb + +# ============================================================ +# Clinical Trial Failure Domain +# ============================================================ + +.PHONY: ct-db ct-download ct-load-aact ct-classify ct-resolve ct-outcomes ct-all ct-clean + +ct-db: setup + uv run python -c "from negbiodb_ct.ct_db import create_ct_database; create_ct_database()" + +ct-download-aact: setup + uv run python scripts_ct/download_aact.py + +ct-download-opentargets: setup + uv run python scripts_ct/download_opentargets.py + +ct-download-cto: setup + uv run python scripts_ct/download_cto.py + +ct-download-shi-du: setup + uv run python scripts_ct/download_shi_du.py + +ct-download: ct-download-opentargets ct-download-cto ct-download-shi-du + @echo "NOTE: AACT requires --url flag. Run: make ct-download-aact" + +ct-load-aact: ct-db + uv run python scripts_ct/load_aact.py + +ct-classify: ct-load-aact + uv run python scripts_ct/classify_failures.py + +ct-resolve: ct-load-aact + uv run python scripts_ct/resolve_drugs.py + +ct-outcomes: ct-classify + uv run python scripts_ct/load_outcomes.py + +ct-all: ct-db ct-load-aact ct-classify ct-resolve ct-outcomes + @echo "CT pipeline complete." + +ct-clean: + rm -f data/negbiodb_ct.db + @echo "CT database removed." + +ct-test: setup + uv run pytest tests/test_ct_db.py tests/test_etl_aact.py tests/test_etl_classify.py tests/test_drug_resolver.py tests/test_etl_outcomes.py -v + +# ============================================================ +# Protein-Protein Interaction Negative Domain +# ============================================================ + +.PHONY: ppi-db ppi-download ppi-load-huri ppi-load-intact ppi-load-humap ppi-load-string ppi-all ppi-clean ppi-test + +ppi-db: setup + uv run python -c "from negbiodb_ppi.ppi_db import create_ppi_database; create_ppi_database()" + +ppi-download-huri: setup + uv run python scripts_ppi/download_huri.py + +ppi-download-intact: setup + uv run python scripts_ppi/download_intact.py + +ppi-download-humap: setup + uv run python scripts_ppi/download_humap.py + +ppi-download-string: setup + uv run python scripts_ppi/download_string.py + +ppi-download-biogrid: setup + uv run python scripts_ppi/download_biogrid.py + +ppi-download: ppi-download-huri ppi-download-intact ppi-download-humap ppi-download-string ppi-download-biogrid + +ppi-load-huri: ppi-db ppi-download-huri + uv run python scripts_ppi/load_huri.py + +ppi-load-intact: ppi-db ppi-download-intact + uv run python scripts_ppi/load_intact.py + +ppi-load-humap: ppi-db ppi-download-humap + uv run python scripts_ppi/load_humap.py + +ppi-load-string: ppi-db ppi-download-string + uv run python scripts_ppi/load_string.py + +ppi-all: ppi-db ppi-load-huri ppi-load-intact ppi-load-humap ppi-load-string + @echo "PPI pipeline complete." + +ppi-clean: + rm -f data/negbiodb_ppi.db + @echo "PPI database removed." + +ppi-test: setup + uv run pytest tests/test_ppi_db.py tests/test_protein_mapper.py tests/test_etl_huri.py tests/test_etl_intact.py tests/test_etl_humap.py tests/test_etl_string.py -v + +# === GE/DepMap Domain === + +ge-db: + uv run python -c "from negbiodb_depmap.depmap_db import init_db; init_db()" + @echo "GE database initialized." + +ge-download-depmap: + uv run python scripts_depmap/download_depmap.py + +ge-load-depmap: ge-db ge-download-depmap + uv run python scripts_depmap/load_depmap.py + +ge-load-rnai: ge-db ge-download-depmap + uv run python scripts_depmap/load_rnai.py + +ge-export: ge-db + uv run python scripts_depmap/export_ge_ml_dataset.py + +ge-all: ge-db ge-load-depmap ge-load-rnai ge-export + @echo "GE pipeline complete." + +ge-clean: + rm -f data/negbiodb_depmap.db + @echo "GE database removed." + +ge-test: setup + uv run pytest tests/test_ge_db.py tests/test_ge_features.py tests/test_etl_depmap.py tests/test_etl_rnai.py tests/test_ge_export.py -v diff --git a/PATCH_NOTES_2026-03-10.md b/PATCH_NOTES_2026-03-10.md new file mode 100644 index 0000000000000000000000000000000000000000..696b5d304556f9987f6382b238fa57e16bae6dea --- /dev/null +++ b/PATCH_NOTES_2026-03-10.md @@ -0,0 +1,330 @@ +# Patch Notes: Experiment Pipeline Fixes + +Date: 2026-03-10 + +## Scope + +This patch fixes experiment orchestration bugs found during review across: + +- `src/negbiodb/export.py` +- `scripts/train_baseline.py` +- `scripts/prepare_exp_data.py` +- `scripts/collect_results.py` +- `tests/test_pipeline_scripts.py` + +## Bugs Fixed + +### 1. Split export row fanout with multiple split versions + +Problem: +- `export_negative_dataset()` joined split columns by `split_strategy`. +- If `random_v2` or another later split definition existed for the same strategy, + the export query could duplicate rows. + +Fix: +- Export now resolves a single latest `split_id` per strategy before joining + `split_assignments`. +- Cold split integrity checks were aligned to use the latest split definition too. +- Split selection now prefers explicit version semantics (`version` column and `_vN` + suffixes) rather than raw insertion order. + +Impact: +- Prevents silent corruption of `negbiodb_dti_pairs.parquet` when new split versions are added. + +### 2. Incomplete graph cache silently degrading GraphDTA/DrugBAN + +Problem: +- Existing `graph_cache.pt` files could be incomplete. +- Missing SMILES fell through to placeholder graphs during batching. +- When no cache existed, train fold could save a train-only cache that val/test later reused. + +Fix: +- Added `_prepare_graph_cache()` in `train_baseline.py`. +- The cache is now built or backfilled against the full dataset parquet before folds are created. +- `DTIDataset._load_graphs()` also backfills missing SMILES if a partial cache path is still passed in. + +Impact: +- Prevents valid molecules from silently training/evaluating as dummy graphs. + +### 3. Training run outputs overwriting each other + +Problem: +- Output directories were keyed only by `model/split/negative`. +- Different datasets or seeds could overwrite prior runs. + +Fix: +- Run names now include `dataset` and `seed`. +- Added `_build_run_name()` helper to keep naming deterministic and testable. + +Impact: +- Balanced vs. realistic and multi-seed runs can now coexist safely. + +### 3b. Unsupported realistic Exp 1 controls now fail fast + +Problem: +- `uniform_random` and `degree_matched` controls did not have realistic dataset variants. +- The CLI still accepted `--dataset realistic` for those negatives, which mislabeled balanced-control runs as realistic. + +Fix: +- Removed those unsupported mappings from `train_baseline.py`. +- The CLI now rejects realistic random-control combinations explicitly. + +Impact: +- Prevents mislabeled Exp 1 results from being written to disk and summarized later. + +### 4. Invalid DDB CLI combinations + +Problem: +- `ddb` was exposed as a negative source even though it is a split mode. +- Commands like `--split random --negative ddb` were accepted. + +Fix: +- Removed `ddb` from `--negative` choices. +- Added explicit validation so DDB is only valid for `split=ddb`, `negative=negbiodb`, + and `dataset=balanced`. + +Impact: +- Reduces mislabeled experiment runs and ambiguous result directories. + +### 5. `prepare_exp_data.py --skip-exp4` still required the pairs parquet + +Problem: +- Input validation always required `exports/negbiodb_dti_pairs.parquet`, + even when Exp 4 was being skipped. + +Fix: +- Conditionalized required inputs so the large pairs parquet is only required when Exp 4 runs. +- Added defensive deduplication and `many_to_one` merge validation in `prepare_exp4_ddb()`. + +Impact: +- Exp 1 preparation can now run independently. + +### 6. Result collection mixed datasets and hid seed information + +Problem: +- `collect_results.py` dropped `dataset` and `seed` from Table 1 output. +- Exp 1 summary selected the first matching row instead of grouping safely. + +Fix: +- Table output now preserves `dataset` and `seed`. +- Exp 1 summary is now grouped by dataset and averages only across seeds present in all compared negative conditions. + +Impact: +- Prevents balanced/realistic runs from being conflated in downstream summaries. + +### 6b. Result collection now supports explicit dataset/seed filters + +Problem: +- `collect_results.py` previously aggregated every run under `results/baselines/`. +- As more experiments accumulate, paper tables can accidentally mix exploratory and final runs. + +Fix: +- Added `--dataset` and repeatable `--seed` filters to `collect_results.py`. +- Added repeatable `--model`, `--split`, and `--negative` filters too. +- The command now fails fast if filters remove all rows. +- Added optional `--aggregate-seeds` output that writes `table1_aggregated.csv` + with mean/std over seeds. +- Added `table1_aggregated.md` with human-readable `mean +/- std` formatting. + +Impact: +- Makes paper/report generation reproducible from an explicit run subset. +- Adds a paper-friendly seed-aggregated summary without removing access to raw runs. + +### 7. SLURM submission metadata aligned with current run naming + +Problem: +- SLURM job names and log file names did not include dataset or seed. +- Submission wrappers relied on implicit defaults instead of exporting `DATASET` and `SEED` explicitly. + +Fix: +- Updated SLURM wrapper scripts to include dataset and seed in job/log naming. +- Submission wrappers now export `DATASET` and `SEED` explicitly to the training job. +- Training job logging now prints seed together with model/split/negative/dataset. + +Impact: +- Makes cluster logs line up with the run directories and result-collection filters. + +### 7b. SLURM submission scripts now support seed sweeps + +Problem: +- Multi-seed experiments required manual resubmission or manual editing of shell scripts. + +Fix: +- Added `SEEDS="42 43 44"` style support to SLURM submission wrappers. +- Added optional `MODELS`, `SPLITS`, and `NEGATIVES` filters to `submit_all.sh`. +- Default behavior remains `SEEDS=42`, preserving the prior single-seed workflow. + +Impact: +- Makes it straightforward to launch reproducible seed sweeps that match `collect_results.py --seed ...`. +- Makes selective experiment submission possible without editing shell scripts. + +### 7c. Added Cayuga SSH helper wrappers for remote submission and monitoring + +Problem: +- The documented Cayuga workflow relies on SSH ControlMaster and non-interactive remote commands. +- Reconstructing the exact remote submit/monitor commands by hand is error-prone. + +Fix: +- Added `slurm/remote_submit_cayuga.sh` to call `submit_all.sh` remotely via `ssh ${HPC_LOGIN:-cayuga-login1}`. +- Added `slurm/remote_monitor_cayuga.sh` to inspect `squeue` and recent log files remotely. +- Made SLURM binary paths overridable via `SBATCH_BIN` / `SQUEUE_BIN`. + +Impact: +- Makes the repository align directly with the Cayuga SSH workflow documented in the lab notes. + +## Regression Tests Added + +Added `tests/test_pipeline_scripts.py` covering: + +- export uses latest split version without row duplication +- `prepare_exp_data.py --skip-exp4` no longer requires the pairs parquet +- run names include dataset and seed +- invalid DDB dataset resolution is rejected +- unsupported realistic random-control runs are rejected +- `train_baseline.py` rejects `split=ddb` with `dataset=realistic` +- `train_baseline.py` writes results into a dataset+seed-qualified run directory +- graph cache backfills missing SMILES +- result collection preserves dataset/seed and groups Exp 1 summaries by dataset using matched seeds only +- result collection can filter by dataset and seed before building tables +- result collection can also filter by model, split, and negative source +- result collection can optionally write seed-aggregated tables +- result collection writes both aggregated CSV and aggregated Markdown summaries +- SLURM job/log names now include dataset and seed, matching run output naming +- SLURM submission wrappers support multi-seed sweeps via the `SEEDS` environment variable +- `submit_all.sh` can filter submitted experiments by model, split, and negative source +- Added remote Cayuga SSH helper scripts for submission and monitoring + +## Verification + +Commands run: + +```bash +uv run pytest tests/test_export.py -q +uv run pytest tests/test_pipeline_scripts.py -q +``` + +Observed results: + +- `tests/test_export.py`: 52 passed +- `tests/test_pipeline_scripts.py`: 17 passed, 1 skipped + +Skip reason: +- the graph cache backfill test is skipped when `torch` is unavailable in the environment + +## Follow-up + +Recommended next step: + +- add one end-to-end script test that exercises `train_baseline.py` CLI with heavy training + functions mocked out, to lock down argument validation and results writing behavior together + +## Lessons Learned (2026-03-12) + +### 1. Exp 4 must be defined as a full-task split, not a negative-only transform + +What we learned: +- Treating DDB as "only reassign negatives while positives keep `split_random`" weakens the claim. +- That setup mixes split bias with class-specific handling and no longer measures the benchmark-level effect of node-degree bias. + +Decision: +- Exp 4 is now defined as a **full-task degree-balanced split on merged M1 balanced data**. +- Positives and negatives must be reassigned together under the same `split_degree_balanced` policy. + +Operational rule: +- Any future regeneration of `exports/negbiodb_m1_balanced_ddb.parquet` must be done from the merged M1 benchmark, not by patching only the negative subset. + +### 2. Eval-only rewrites can make stale checkpoints look fresh + +What we learned: +- Using `results.json` modification time alone is not a reliable freshness signal. +- `eval_checkpoint.py` can rewrite results for an old checkpoint and make a stale run appear newly generated. + +Decision: +- Freshness checks must use training artifacts first (`best.pt`, `last.pt`, `training_log.csv`) and only fall back to `results.json` if no training artifacts exist. + +Operational rule: +- Any future result filtering or release packaging should treat checkpoint/log timestamps as the source of truth for run freshness. + +### 3. DDB benchmark regeneration invalidates prior DDB model results + +What we learned: +- Once `exports/negbiodb_m1_balanced_ddb.parquet` changes, all prior `*_ddb_*` model results become semantically stale even if files still parse. +- Silent reuse of those results is more dangerous than having missing rows. + +Decision: +- `collect_results.py` now excludes stale DDB runs by default when they are older than the current DDB parquet. + +Operational rule: +- After any future DDB regeneration, immediately retrain the DDB model trio before producing paper tables. + +### 4. Remote HPC execution can drift from local fixes + +What we learned: +- The Cayuga working directory is effectively a deployed copy, not a git-controlled checkout. +- Local fixes do not automatically exist on the remote side, so "submitted successfully" does not imply "submitted the corrected code." + +Decision: +- Before remote submission, explicitly sync changed code or regenerate artifacts in place on Cayuga. +- For large derived files, remote regeneration is usually safer than bulk transfer. + +Operational rule: +- Prefer: + 1. sync small code/script changes + 2. regenerate derived artifacts on Cayuga + 3. then submit jobs + +### 5. Submission wrappers need shell syntax coverage, not just static review + +What we learned: +- `slurm/submit_all.sh` still contained loop-closing bugs after functional edits. +- These did not surface until the exact submission path was exercised on the remote cluster. + +Decision: +- Shell wrappers should be syntax-checked with `bash -n` whenever edited. + +Operational rule: +- For any future SLURM wrapper change: + - run `bash -n