Create drugbank.py
Browse files- mcp/drugbank.py +28 -0
mcp/drugbank.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# mcp/drugbank.py
|
2 |
+
"""
|
3 |
+
Lightweight DrugBank Open-Data helper.
|
4 |
+
Download the TSV once and keep in /data or load at runtime.
|
5 |
+
"""
|
6 |
+
|
7 |
+
import csv
|
8 |
+
from pathlib import Path
|
9 |
+
from typing import Dict, Optional
|
10 |
+
|
11 |
+
_DATA = Path(__file__).parent / "data" / "drugbank_open_structured_drug_links.tsv"
|
12 |
+
|
13 |
+
def _load_index() -> Dict[str, Dict]:
|
14 |
+
index = {}
|
15 |
+
if not _DATA.exists():
|
16 |
+
raise FileNotFoundError("DrugBank TSV not found – download open data first.")
|
17 |
+
with _DATA.open() as f:
|
18 |
+
reader = csv.DictReader(f, delimiter="\t")
|
19 |
+
for row in reader:
|
20 |
+
name = row["Name"].lower()
|
21 |
+
index[name] = row
|
22 |
+
return index
|
23 |
+
|
24 |
+
_DRUG_INDEX = _load_index()
|
25 |
+
|
26 |
+
def lookup_drug(name: str) -> Optional[Dict]:
|
27 |
+
"""Return DrugBank row dict or None."""
|
28 |
+
return _DRUG_INDEX.get(name.lower())
|