File size: 2,027 Bytes
6d1bbc7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
62
63
64
65
66
67
68
69
70
71
72
73
"""Run drug name resolution cascade on NegBioDB-CT database.

4-step cascade:
  Step 1: ChEMBL molecule_synonyms exact match
  Step 2: PubChem REST API name lookup
  Step 3: Fuzzy match (Jaro-Winkler > 0.90)
  Step 4: Manual override CSV

Prerequisites:
  - AACT data loaded (scripts_ct/load_aact.py)
  - ChEMBL SQLite downloaded (data/chembl/)

Usage:
    python scripts_ct/resolve_drugs.py [--db DB_PATH] [--skip-pubchem] [--skip-fuzzy]
"""

import argparse
import logging
from pathlib import Path

from negbiodb_ct.drug_resolver import run_drug_resolution
from negbiodb_ct.ct_db import DEFAULT_CT_DB_PATH


def main():
    parser = argparse.ArgumentParser(
        description="Resolve drug intervention names to ChEMBL IDs"
    )
    parser.add_argument(
        "--db", type=str, default=str(DEFAULT_CT_DB_PATH),
        help="Path to CT database (default: data/negbiodb_ct.db)",
    )
    parser.add_argument(
        "--chembl-db", type=str, default=None,
        help="Path to ChEMBL SQLite (default: auto-detect from config)",
    )
    parser.add_argument(
        "--skip-pubchem", action="store_true",
        help="Skip PubChem API step (Step 2)",
    )
    parser.add_argument(
        "--skip-fuzzy", action="store_true",
        help="Skip fuzzy matching step (Step 3)",
    )
    parser.add_argument(
        "--verbose", "-v", action="store_true",
        help="Enable verbose logging",
    )
    args = parser.parse_args()

    logging.basicConfig(
        level=logging.DEBUG if args.verbose else logging.INFO,
        format="%(asctime)s %(name)s %(levelname)s %(message)s",
    )

    chembl_path = Path(args.chembl_db) if args.chembl_db else None

    print("=== Drug Name Resolution ===")
    stats = run_drug_resolution(
        db_path=Path(args.db),
        chembl_db_path=chembl_path,
        skip_pubchem=args.skip_pubchem,
        skip_fuzzy=args.skip_fuzzy,
    )

    print("\n=== Results ===")
    for k, v in stats.items():
        print(f"  {k}: {v}")


if __name__ == "__main__":
    main()