File size: 2,366 Bytes
504d922
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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())