Knowledge Graph Tools
Use this skill for building and querying biomedical relationship graphs from public drug-discovery APIs, not for clinical decision-making.
Typical triggers:
- build a knowledge graph seeded from a disease, a drug, or a target list
- find shortest paths from a drug to a disease through intermediate targets and pathways
- identify hub targets that bridge multiple disease areas or drug mechanisms
- expand the neighborhood around a protein to see connected drugs, diseases, and pathways
- merge OpenTargets, ChEMBL, STRING, and Reactome data into one queryable graph
Working Rules
- Every node gets a typed label:
drug, target, disease, or pathway.
- Every edge records its source database and, where available, an evidence score.
- Use canonical identifiers: Ensembl for targets, ChEMBL for drugs, EFO for diseases, Reactome stable IDs for pathways.
- Hub analysis reflects database connectivity, not biological importance; well-studied proteins dominate.
- Shortest-path hypotheses are topological leads, not validated biology.
- Do not claim causal or therapeutic conclusions from graph structure alone.
Environment Check
which python3 || true
python3 - <<'PY'
mods = ["networkx", "requests"]
for name in mods:
try:
__import__(name)
print(f"{name}: ok")
except Exception as exc:
print(f"{name}: missing ({exc})")
PY
If networkx or requests is missing, say so immediately. If network access is blocked, only the query mode on pre-built GraphML files will work.
Bundled Assets
templates/knowledge_graph.py
Build: Disease-Centric Graph
Use templates/knowledge_graph.py --mode build --seed-type disease for:
- fetching disease-associated targets from OpenTargets
- fetching known drugs for those targets from OpenTargets
- adding protein-protein interactions from STRING
- adding pathway membership from Reactome
- assembling typed nodes and edges into a single graph
Quick start:
python3 templates/knowledge_graph.py \
--mode build \
--seed-type disease \
--seed "Crohn's disease" \
--max-targets 30 \
--include-string \
--include-reactome \
--output kg/crohn_graph.graphml \
--summary kg/crohn_summary.json
Deliverables:
- GraphML file with typed nodes (
entity_type) and typed edges (relation, source_db, score)
- summary JSON with node/edge counts by type, top hubs, and data sources queried
Build: Drug-Centric Graph
Use --seed-type drug to start from a drug and expand through its targets:
python3 templates/knowledge_graph.py \
--mode build \
--seed-type drug \
--seed "imatinib" \
--max-targets 20 \
--include-string \
--include-reactome \
--output kg/imatinib_graph.graphml \
--summary kg/imatinib_summary.json
Query: Shortest Path
Use --mode query --query-type shortest-path on an existing GraphML file:
python3 templates/knowledge_graph.py \
--mode query \
--input kg/crohn_graph.graphml \
--query-type shortest-path \
--from-node "CHEMBL941" \
--to-node "EFO_0000384" \
--summary kg/path_result.json
Deliverables:
- summary JSON with path length, node sequence, and edge relations for each step
Query: Hub Analysis
Use --mode query --query-type hubs:
python3 templates/knowledge_graph.py \
--mode query \
--input kg/crohn_graph.graphml \
--query-type hubs \
--top-k 20 \
--summary kg/hub_targets.json
Deliverables:
- summary JSON with top-K nodes ranked by degree and betweenness centrality, with entity type
Query: Neighborhood Expansion
Use --mode query --query-type neighbors:
python3 templates/knowledge_graph.py \
--mode query \
--input kg/crohn_graph.graphml \
--query-type neighbors \
--center-node "ENSG00000141510" \
--radius 2 \
--summary kg/tp53_neighborhood.json
Deliverables:
- summary JSON with subgraph node list, edge list, and entity-type breakdown
Output Expectations
Good answers should mention:
- seed entity and type (drug, disease, or target list)
- which APIs were queried (OpenTargets, ChEMBL, STRING, Reactome)
- graph size: node count by type, edge count by relation type
- for hub queries: top hub identifiers, degrees, and entity types
- for path queries: full path with intermediate nodes and edge types
- identifier schemes used
- where GraphML and JSON were saved
Related Skills
For compound and regulatory database lookups from ChEMBL, openFDA, ClinicalTrials.gov, activate pharma-db-tools.
For target-specific intelligence dossiers, activate target-intelligence-tools.
For drug repurposing hypothesis generation, activate drug-repurposing-tools.
For pathway enrichment from gene lists, activate pathway-enrichment-tools.
For network pharmacology analysis, activate network-pharmacology-tools.
For raw bio database lookups in UniProt, PDB, ClinVar, gnomAD, Reactome, STRING, activate bio-db-tools.
Reference
This skill queries the following public APIs during build mode:
- OpenTargets Platform GraphQL —
https://api.platform.opentargets.org/api/v4/graphql — disease-target associations (associatedTargets), known drugs (knownDrugs), and entity search (platform.opentargets.org)
- ChEMBL REST API —
https://www.ebi.ac.uk/chembl/api/data — molecule search, mechanism-of-action retrieval, and target cross-references (chembl.gitbook.io)
- STRING API v12 —
https://version-12-0.string-db.org/api — protein-protein interaction partners with combined confidence scores (string-db.org)
- Reactome Content Service —
https://reactome.org/ContentService — pathway search by gene symbol with species filter (reactome.org)
- Graph analysis uses networkx —
nx.shortest_path, nx.betweenness_centrality, nx.ego_graph (networkx.org)
- The
target-intelligence-tools skill in this repository served as the reference implementation for API calling patterns, error handling, and identifier resolution.
1---2name: knowledge-graph-tools3description: Drug-discovery knowledge-graph workflow guide for assembling drug-target-disease-pathway relationship graphs from OpenTargets GraphQL, ChEMBL REST, STRING PPI, and Reactome pathway APIs, then running hub detection, shortest-path queries, and neighborhood expansion with networkx. Use when the user asks to build, query, or visualize a biomedical knowledge graph connecting drugs, targets, diseases, and pathways from real public databases without making clinical claims.4---56# Knowledge Graph Tools78Use this skill for building and querying biomedical relationship graphs from public drug-discovery APIs, not for clinical decision-making.910Typical triggers:11- build a knowledge graph seeded from a disease, a drug, or a target list12- find shortest paths from a drug to a disease through intermediate targets and pathways13- identify hub targets that bridge multiple disease areas or drug mechanisms14- expand the neighborhood around a protein to see connected drugs, diseases, and pathways15- merge OpenTargets, ChEMBL, STRING, and Reactome data into one queryable graph1617## Working Rules18191. Every node gets a typed label: `drug`, `target`, `disease`, or `pathway`.202. Every edge records its source database and, where available, an evidence score.213. Use canonical identifiers: Ensembl for targets, ChEMBL for drugs, EFO for diseases, Reactome stable IDs for pathways.224. Hub analysis reflects database connectivity, not biological importance; well-studied proteins dominate.235. Shortest-path hypotheses are topological leads, not validated biology.246. Do not claim causal or therapeutic conclusions from graph structure alone.2526## Environment Check2728```bash29which python3 || true30python3 - <<'PY'31mods = ["networkx", "requests"]32for name in mods:33 try:34 __import__(name)35 print(f"{name}: ok")36 except Exception as exc:37 print(f"{name}: missing ({exc})")38PY39```4041If networkx or requests is missing, say so immediately. If network access is blocked, only the `query` mode on pre-built GraphML files will work.4243## Bundled Assets4445- `templates/knowledge_graph.py`4647## Build: Disease-Centric Graph4849Use `templates/knowledge_graph.py --mode build --seed-type disease` for:50- fetching disease-associated targets from OpenTargets51- fetching known drugs for those targets from OpenTargets52- adding protein-protein interactions from STRING53- adding pathway membership from Reactome54- assembling typed nodes and edges into a single graph5556Quick start:5758```bash59python3 templates/knowledge_graph.py \60 --mode build \61 --seed-type disease \62 --seed "Crohn's disease" \63 --max-targets 30 \64 --include-string \65 --include-reactome \66 --output kg/crohn_graph.graphml \67 --summary kg/crohn_summary.json68```6970Deliverables:71- GraphML file with typed nodes (`entity_type`) and typed edges (`relation`, `source_db`, `score`)72- summary JSON with node/edge counts by type, top hubs, and data sources queried7374## Build: Drug-Centric Graph7576Use `--seed-type drug` to start from a drug and expand through its targets:7778```bash79python3 templates/knowledge_graph.py \80 --mode build \81 --seed-type drug \82 --seed "imatinib" \83 --max-targets 20 \84 --include-string \85 --include-reactome \86 --output kg/imatinib_graph.graphml \87 --summary kg/imatinib_summary.json88```8990## Query: Shortest Path9192Use `--mode query --query-type shortest-path` on an existing GraphML file:9394```bash95python3 templates/knowledge_graph.py \96 --mode query \97 --input kg/crohn_graph.graphml \98 --query-type shortest-path \99 --from-node "CHEMBL941" \100 --to-node "EFO_0000384" \101 --summary kg/path_result.json102```103104Deliverables:105- summary JSON with path length, node sequence, and edge relations for each step106107## Query: Hub Analysis108109Use `--mode query --query-type hubs`:110111```bash112python3 templates/knowledge_graph.py \113 --mode query \114 --input kg/crohn_graph.graphml \115 --query-type hubs \116 --top-k 20 \117 --summary kg/hub_targets.json118```119120Deliverables:121- summary JSON with top-K nodes ranked by degree and betweenness centrality, with entity type122123## Query: Neighborhood Expansion124125Use `--mode query --query-type neighbors`:126127```bash128python3 templates/knowledge_graph.py \129 --mode query \130 --input kg/crohn_graph.graphml \131 --query-type neighbors \132 --center-node "ENSG00000141510" \133 --radius 2 \134 --summary kg/tp53_neighborhood.json135```136137Deliverables:138- summary JSON with subgraph node list, edge list, and entity-type breakdown139140## Output Expectations141142Good answers should mention:143- seed entity and type (drug, disease, or target list)144- which APIs were queried (OpenTargets, ChEMBL, STRING, Reactome)145- graph size: node count by type, edge count by relation type146- for hub queries: top hub identifiers, degrees, and entity types147- for path queries: full path with intermediate nodes and edge types148- identifier schemes used149- where GraphML and JSON were saved150151## Related Skills152153For compound and regulatory database lookups from ChEMBL, openFDA, ClinicalTrials.gov, activate `pharma-db-tools`.154For target-specific intelligence dossiers, activate `target-intelligence-tools`.155For drug repurposing hypothesis generation, activate `drug-repurposing-tools`.156For pathway enrichment from gene lists, activate `pathway-enrichment-tools`.157For network pharmacology analysis, activate `network-pharmacology-tools`.158For raw bio database lookups in UniProt, PDB, ClinVar, gnomAD, Reactome, STRING, activate `bio-db-tools`.159160## Reference161162This skill queries the following public APIs during `build` mode:163- **OpenTargets Platform GraphQL** — `https://api.platform.opentargets.org/api/v4/graphql` — disease-target associations (`associatedTargets`), known drugs (`knownDrugs`), and entity search ([platform.opentargets.org](https://platform.opentargets.org/))164- **ChEMBL REST API** — `https://www.ebi.ac.uk/chembl/api/data` — molecule search, mechanism-of-action retrieval, and target cross-references ([chembl.gitbook.io](https://chembl.gitbook.io/chembl-interface-documentation/web-services))165- **STRING API v12** — `https://version-12-0.string-db.org/api` — protein-protein interaction partners with combined confidence scores ([string-db.org](https://string-db.org/))166- **Reactome Content Service** — `https://reactome.org/ContentService` — pathway search by gene symbol with species filter ([reactome.org](https://reactome.org/))167- Graph analysis uses **networkx** — `nx.shortest_path`, `nx.betweenness_centrality`, `nx.ego_graph` ([networkx.org](https://networkx.org/))168- The `target-intelligence-tools` skill in this repository served as the reference implementation for API calling patterns, error handling, and identifier resolution.