| name | drugbank-database |
| description | Programmatic access to DrugBank drug and target data; use when you need to download, parse, and analyze DrugBank XML for properties, interactions, pathways, and pharmacology. |
| license | MIT |
| author | AIPOCH |
Source: https://github.com/aipoch/medical-research-skills
When to Use
- You need to extract structured drug properties (e.g., identifiers, synonyms, ATC codes) from DrugBank XML for downstream analysis.
- You want to build and analyze drug–drug interaction (DDI) networks from DrugBank interaction records.
- You are mapping drugs to targets (proteins/genes) to support target discovery, mechanism-of-action analysis, or enrichment workflows.
- You need to connect drugs to pathways and pharmacology annotations for systems pharmacology or knowledge graph construction.
- You want to generate tabular datasets (CSV/Parquet) from DrugBank for use in notebooks, dashboards, or ML pipelines.
Key Features
- Programmatic download of DrugBank releases via
drugbank-downloader (requires DrugBank access).
- XML parsing and traversal using
lxml for reliable extraction of nested DrugBank entities.
- Data wrangling into
pandas DataFrames for filtering, joining, and export.
- Network construction and analysis with
networkx (e.g., DDI graphs, drug–target bipartite graphs).
- Optional cheminformatics support with
rdkit for structure-based processing (e.g., SMILES/InChI handling when present).
Dependencies
drugbank-downloader (version varies by your environment)
lxml>=4.9
pandas>=2.0
networkx>=3.0
rdkit>=2022.09 (optional; required only for structure/chemistry workflows)
Example Usage
"""
End-to-end example:
1) Parse a local DrugBank XML file
2) Extract a minimal drug table
3) Extract drug-drug interactions
4) Build a DDI graph
Prerequisites:
- You must obtain DrugBank XML via your DrugBank account/license.
- Place the XML file at ./drugbank.xml (or update the path).
"""
from lxml import etree
import pandas as pd
import networkx as nx
DRUGBANK_XML_PATH = "./drugbank.xml"
NS = {"db": "http://www.drugbank.ca"}
tree = etree.parse(DRUGBANK_XML_PATH)
root = tree.getroot()
drugs = []
for drug in root.xpath("//db:drug", namespaces=NS):
drugbank_id = drug.xpath("string(db:drugbank-id[@primary='true'])", namespaces=NS).strip()
name = drug.xpath("string(db:name)", namespaces=NS).strip()
drug_type = drug.get("type", "").strip()
smiles = drug.xpath(
"string(db:calculated-properties/db:property[db:kind='SMILES']/db:value)",
namespaces=NS,
).strip()
drugs.append(
{
"drugbank_id": drugbank_id,
"name": name,
"type": drug_type,
"smiles": smiles or None,
}
)
drugs_df = pd.DataFrame(drugs).dropna(subset=["drugbank_id"])
print("Drugs:", len(drugs_df))
print(drugs_df.head())
interactions = []
for drug in root.xpath("//db:drug", namespaces=NS):
src_id = drug.xpath(, namespaces=NS).strip()
src_name = drug.xpath(, namespaces=NS).strip()
ddi drug.xpath(, namespaces=NS):
tgt_id = ddi.xpath(, namespaces=NS).strip()
tgt_name = ddi.xpath(, namespaces=NS).strip()
description = ddi.xpath(, namespaces=NS).strip()
src_id tgt_id:
interactions.append(
{
: src_id,
: src_name,
: tgt_id,
: tgt_name,
: description ,
}
)
ddi_df = pd.DataFrame(interactions)
(, (ddi_df))
(ddi_df.head())
G = nx.from_pandas_edgelist(
ddi_df,
source=,
target=,
edge_attr=[],
create_using=nx.Graph(),
)
(, G.number_of_nodes())
(, G.number_of_edges())
top_degree = (G.degree, key= x: x[], reverse=)[:]
top_degree_df = pd.DataFrame(top_degree, columns=[, ]).merge(
drugs_df[[, ]],
on=,
how=,
)
(top_degree_df)
Implementation Details