| from __future__ import annotations |
|
|
| import argparse |
| import json |
| import tarfile |
| import urllib.request |
| from pathlib import Path |
| import sys |
|
|
| ROOT = Path(__file__).resolve().parents[1] |
| if str(ROOT) not in sys.path: |
| sys.path.insert(0, str(ROOT)) |
|
|
| from docking_pipeline.validation import validate_dud |
|
|
|
|
| def _resolve_data_dir(data_dir: str, download_url: str | None) -> str: |
| path = Path(data_dir) |
| if path.exists() or not download_url: |
| return str(path) |
| path.mkdir(parents=True, exist_ok=True) |
| archive = path / Path(download_url).name |
| urllib.request.urlretrieve(download_url, archive) |
| with tarfile.open(archive, "r:*") as tar: |
| tar.extractall(path) |
| children = [p for p in path.iterdir() if p.is_dir()] |
| return str(children[0] if len(children) == 1 else path) |
|
|
|
|
| def main() -> int: |
| parser = argparse.ArgumentParser(description="Run rDock DUD enrichment workflow for one system") |
| parser.add_argument("--data-dir", required=True, help="Directory containing DUD_rDock_TestSet systems") |
| parser.add_argument("--system", help="System ID, e.g. hivpr") |
| parser.add_argument("--out", required=True) |
| parser.add_argument("--n-runs", type=int, default=100) |
| parser.add_argument("--jobs", default="auto") |
| parser.add_argument("--cpu-fraction", type=float, default=0.85) |
| parser.add_argument("--download-if-missing", action="store_true") |
| parser.add_argument("--list-systems", action="store_true") |
| parser.add_argument("--download-url", help="Optional DUD_rDock_TestSet tar.gz URL to fetch when --data-dir is absent") |
| args = parser.parse_args() |
| from docking_pipeline.validation import discover_validation_systems, ensure_validation_data |
|
|
| data_dir = ensure_validation_data( |
| _resolve_data_dir(args.data_dir, args.download_url if args.download_if_missing else None), |
| "dud", |
| args.download_url, |
| args.download_if_missing, |
| ) |
| if args.list_systems: |
| print(json.dumps([s.__dict__ for s in discover_validation_systems(data_dir, "dud")], indent=2)) |
| else: |
| if not args.system: |
| raise SystemExit("--system is required unless --list-systems is used") |
| print(json.dumps(validate_dud(data_dir, args.system, args.out, n_runs=args.n_runs, jobs=args.jobs), indent=2)) |
| return 0 |
|
|
|
|
| if __name__ == "__main__": |
| raise SystemExit(main()) |
|
|