File size: 802 Bytes
c5b2751
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# mcp/drugbank.py
"""
Lightweight DrugBank Open-Data helper.
Download the TSV once and keep in /data or load at runtime.
"""

import csv
from pathlib import Path
from typing import Dict, Optional

_DATA = Path(__file__).parent / "data" / "drugbank_open_structured_drug_links.tsv"

def _load_index() -> Dict[str, Dict]:
    index = {}
    if not _DATA.exists():
        raise FileNotFoundError("DrugBank TSV not found – download open data first.")
    with _DATA.open() as f:
        reader = csv.DictReader(f, delimiter="\t")
        for row in reader:
            name = row["Name"].lower()
            index[name] = row
    return index

_DRUG_INDEX = _load_index()

def lookup_drug(name: str) -> Optional[Dict]:
    """Return DrugBank row dict or None."""
    return _DRUG_INDEX.get(name.lower())