DrugMechDB Query Skill
Search drug mechanism-of-action paths by entity name or ID. Each path is a directed graph: Drug → (intermediates) → Disease, with typed nodes and labeled edges.
Data
- Source:
indication_paths.json
- Path:
resources_metadata/drug_mechanism/DRUGMECHDB/indication_paths.json
- Records: ~4846 mechanism paths, ~32k relationships
Entity auto-detection
| Input pattern |
Detected as |
Example |
DB:DB00619 |
DrugBank ID |
exact on node/graph IDs |
MESH:D015464 |
MESH ID |
exact on node/graph IDs |
UniProt:P00519 |
UniProt protein |
exact on node IDs |
GO:0006915 |
GO term |
exact on node IDs |
CHEBI:*, HP:*, UBERON:*, CL:*, reactome:*, InterPro:*, PR:*, taxonomy:* |
respective types |
exact on node IDs |
| anything else |
free text |
substring match on drug/disease/node names |
API
| Function |
Signature |
Returns |
load(path) |
path to JSON |
list[dict] — full database |
build_index(db) |
loaded db |
(by_id, by_name, by_drug, by_disease) dicts for O(1) lookup |
search(db, entity, index=None) |
single query string |
list[dict] — matching paths |
search_batch(db, entities, index=None) |
list of query strings |
dict[str, list[dict]] |
summarize(paths, entity) |
search results |
compact multi-line text |
to_json(paths) |
search results |
list of flat dicts (id, drug, disease, nodes, links) |
Node types (14)
BiologicalProcess, Cell, CellularComponent, ChemicalSubstance, Disease, Drug, GeneFamily, GrossAnatomicalStructure, MacromolecularComplex, MolecularActivity, OrganismTaxon, Pathway, PhenotypicFeature, Protein
Quick usage
import drugmechdb_query as dq
db = dq.load() # uses default DATA_PATH
idx = dq.build_index(db) # optional, recommended for repeated queries
# Single query — by name or ID
paths = dq.search(db, "imatinib", idx)
paths = dq.search(db, "UniProt:P00519", idx)
paths = dq.search(db, "MESH:D003920", idx)
print(dq.summarize(paths, "imatinib"))
# Batch query
results = dq.search_batch(db, ["metformin", "MESH:D003920", "asthma"], idx)
for entity, paths in results.items():
print(dq.summarize(paths, entity))
# JSON export
print(dq.to_json(paths))
Output structure per path
graph: { _id, drug, disease, drugbank, drug_mesh, disease_mesh }
nodes: [{ id, label, name }, ...]
links: [{ source, target, key }, ...]
key examples: decreases activity of, causes, positively regulates, treats, increases expression of, etc. (66 relation types total).
1---2name: drugmechdb-query3description: Query the DrugMechDB drug mechanism-of-action database. Use whenever the user asks about drug mechanisms, drug-to-disease paths, biological targets of a drug, or wants to look up any biomedical entity (drug name, protein, disease, DrugBank ID, MESH ID, UniProt ID, GO term, etc.) in DrugMechDB.4---5
6# DrugMechDB Query Skill
7
8Search drug mechanism-of-action paths by entity name or ID. Each path is a directed graph: Drug → (intermediates) → Disease, with typed nodes and labeled edges.
9
10## Data
11
12- **Source**: `indication_paths.json`
13- **Path**: `resources_metadata/drug_mechanism/DRUGMECHDB/indication_paths.json`
14- **Records**: ~4846 mechanism paths, ~32k relationships
15
16## Entity auto-detection
17
18| Input pattern | Detected as | Example |
19|---|---|---|
20| `DB:DB00619` | DrugBank ID | exact on node/graph IDs |
21| `MESH:D015464` | MESH ID | exact on node/graph IDs |
22| `UniProt:P00519` | UniProt protein | exact on node IDs |
23| `GO:0006915` | GO term | exact on node IDs |
24| `CHEBI:*`, `HP:*`, `UBERON:*`, `CL:*`, `reactome:*`, `InterPro:*`, `PR:*`, `taxonomy:*` | respective types | exact on node IDs |
25| anything else | free text | substring match on drug/disease/node names |
26
27## API
28
29| Function | Signature | Returns |
30|---|---|---|
31| `load(path)` | path to JSON | `list[dict]` — full database |
32| `build_index(db)` | loaded db | `(by_id, by_name, by_drug, by_disease)` dicts for O(1) lookup |
33| `search(db, entity, index=None)` | single query string | `list[dict]` — matching paths |
34| `search_batch(db, entities, index=None)` | list of query strings | `dict[str, list[dict]]` |
35| `summarize(paths, entity)` | search results | compact multi-line text |
36| `to_json(paths)` | search results | list of flat dicts (id, drug, disease, nodes, links) |
37
38## Node types (14)
39
40BiologicalProcess, Cell, CellularComponent, ChemicalSubstance, Disease, Drug, GeneFamily, GrossAnatomicalStructure, MacromolecularComplex, MolecularActivity, OrganismTaxon, Pathway, PhenotypicFeature, Protein
41
42## Quick usage
43
44```python
45import drugmechdb_query as dq
46
47db = dq.load() # uses default DATA_PATH
48idx = dq.build_index(db) # optional, recommended for repeated queries
49
50# Single query — by name or ID
51paths = dq.search(db, "imatinib", idx)
52paths = dq.search(db, "UniProt:P00519", idx)
53paths = dq.search(db, "MESH:D003920", idx)
54print(dq.summarize(paths, "imatinib"))
55
56# Batch query
57results = dq.search_batch(db, ["metformin", "MESH:D003920", "asthma"], idx)
58for entity, paths in results.items():
59 print(dq.summarize(paths, entity))
60
61# JSON export
62print(dq.to_json(paths))
63```
64
65## Output structure per path
66
67```
68graph: { _id, drug, disease, drugbank, drug_mesh, disease_mesh }
69nodes: [{ id, label, name }, ...]
70links: [{ source, target, key }, ...]
71```
72
73`key` examples: `decreases activity of`, `causes`, `positively regulates`, `treats`, `increases expression of`, etc. (66 relation types total).