
Primekg
- 871 installs
- 32.7k repo stars
- Updated August 3, 2026
- k-dense-ai/scientific-agent-skills
PrimeKG is an agent skill that queries the Precision Medicine Knowledge Graph integrating 20+ biomedical databases with 100,000+ nodes and 4 million edges for developers building AI-powered drug-discovery and biomedical
About
PrimeKG is an agent skill for the Precision Medicine Knowledge Graph originally from Harvard MIMS (skill metadata version 1.0) that unifies over 20 primary databases and scientific literature into one biomedical graph. The graph contains over 100,000 nodes and 4 million edges across 29 relationship types, including drug-target, disease-gene, and phenotype-disease associations. Developers reach for PrimeKG when agent or backend workflows need to search genes, proteins, drugs, diseases, and phenotypes or traverse multiscale biological relationships during precision-medicine research. Key capabilities include node search, relationship lookup, and structured queries across integrated biomedical entities.
- Query a knowledge graph with over 100000 nodes and 4 million edges
- Search nodes for genes, proteins, drugs, diseases and phenotypes
- Retrieve direct neighbors and clinical evidence associations
- Analyze local disease context and identify drug-disease paths for repurposing
- Programmatic access via query_primekg.py with local kg.csv storage
Primekg by the numbers
- 871 all-time installs (skills.sh)
- +39 installs in the week ending Aug 5, 2026 (Skillselion tracking)
- Ranked #1,262 of 16,546 AI & Agent Building skills by installs in the Skillselion catalog
- Data as of Aug 5, 2026 (Skillselion catalog sync)
npx skills add https://github.com/k-dense-ai/scientific-agent-skills --skill primekgAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 871 |
|---|---|
| repo stars | ★ 32.7k |
| Last updated | August 3, 2026 |
| Repository | k-dense-ai/scientific-agent-skills ↗ |
How do you query a biomedical knowledge graph for drug targets?
Query a biomedical knowledge graph for genes, drugs, diseases and phenotypes during AI-powered research and drug discovery workflows.
Who is it for?
Developers building biomedical research or drug-discovery agents who need programmatic access to an integrated precision-medicine knowledge graph.
Skip if: Developers who only need general web search or non-biomedical knowledge bases without structured drug-target or disease-gene graph data.
When should I use this skill?
The user needs to search genes, drugs, diseases, phenotypes, or traverse biomedical relationships in the PrimeKG knowledge graph.
What you get
Knowledge-graph node matches, relationship paths, and structured query results for genes, drugs, diseases, and phenotypes.
- graph node results
- relationship path outputs
- structured biomedical query responses
By the numbers
- 100,000+ nodes and 4 million edges across 29 relationship types
- Integrates 20+ primary biomedical databases
- Skill metadata version 1.0 from K-Dense Inc.
Files
PrimeKG Knowledge Graph Skill
Overview
PrimeKG is a precision medicine knowledge graph that integrates over 20 primary databases and high-quality scientific literature into a single resource. It contains over 100,000 nodes and 4 million edges across 29 relationship types, including drug-target, disease-gene, and phenotype-disease associations.
Key capabilities:
- Search for nodes (genes, proteins, drugs, diseases, phenotypes)
- Retrieve direct neighbors (associated entities and clinical evidence)
- Analyze local disease context (related genes, drugs, phenotypes)
- Identify drug-disease paths (potential repurposing opportunities)
Data access: Programmatic access via query_primekg.py. Data is stored at C:\Users\eamon\Documents\Data\PrimeKG\kg.csv.
When to Use This Skill
This skill should be used when:
- Knowledge-based drug discovery: Identifying targets and mechanisms for diseases.
- Drug repurposing: Finding existing drugs that might have evidence for new indications.
- Phenotype analysis: Understanding how symptoms/phenotypes relate to diseases and genes.
- Multiscale biology: Bridging the gap between molecular targets (genes) and clinical outcomes (diseases).
- Network pharmacology: Investigating the broader network effects of drug-target interactions.
Core Workflow
1. Search for Entities
Find identifiers for genes, drugs, or diseases.
from scripts.query_primekg import search_nodes
# Search for Alzheimer's disease nodes
results = search_nodes("Alzheimer", node_type="disease")
# Returns: [{"id": "EFO_0000249", "type": "disease", "name": "Alzheimer's disease", ...}]2. Get Neighbors (Direct Associations)
Retrieve all connected nodes and relationship types.
from scripts.query_primekg import get_neighbors
# Get all neighbors of a specific disease ID
neighbors = get_neighbors("EFO_0000249")
# Returns: List of neighbors like {"neighbor_name": "APOE", "relation": "disease_gene", ...}3. Analyze Disease Context
A high-level function to summarize associations for a disease.
from scripts.query_primekg import get_disease_context
# Comprehensive summary for a disease
context = get_disease_context("Alzheimer's disease")
# Access: context['associated_genes'], context['associated_drugs'], context['phenotypes']Relationship Types in PrimeKG
The graph contains several key relationship types including:
protein_protein: Physical PPIsdrug_protein: Drug target/mechanism associationsdisease_gene: Genetic associationsdrug_disease: Indications and contraindicationsdisease_phenotype: Clinical signs and symptomsgwas: Genome-wide association studies evidence
Best Practices
1. Use specific IDs: When using get_neighbors, ensure you have the correct ID from search_nodes. 2. Context first: Use get_disease_context for a broad overview before diving into specific genes or drugs. 3. Filter relationships: Use the relation_type filter in get_neighbors to focus on specific evidence (e.g., only drug_protein). 4. Multiscale integration: Combine with OpenTargets for deeper genetic evidence or Semantic Scholar for the latest literature context.
Resources
Scripts
scripts/query_primekg.py: Core functions for searching and querying the knowledge graph.
Data Path
- Data:
/mnt/c/Users/eamon/Documents/Data/PrimeKG/kg.csv - Total nodes: ~129,000
- Total edges: ~4,000,000
- Database: CSV-based, optimized for pandas querying.
import pandas as pd
import os
import json
from typing import List, Dict, Optional, Union
# Default data path
DATA_PATH = "/mnt/c/Users/eamon/Documents/Data/PrimeKG/kg.csv"
def _load_kg():
"""Internal helper to load the KG efficiently."""
if not os.path.exists(DATA_PATH):
raise FileNotFoundError(f"PrimeKG data not found at {DATA_PATH}. Please ensure the file is downloaded.")
# For very large files, we might want to use a database or specialized graph library.
# For now, we'll use pandas for simplicity but with low_memory=True.
return pd.read_csv(DATA_PATH, low_memory=True)
def search_nodes(name_query: str, node_type: Optional[str] = None) -> List[Dict]:
"""
Search for nodes in PrimeKG by name and optionally type.
Args:
name_query: String to search for in node names.
node_type: Optional type of node (e.g., 'gene/protein', 'drug', 'disease').
Returns:
List of matching nodes with their metadata.
"""
kg = _load_kg()
# Check both x and y columns for unique nodes
x_nodes = kg[['x_id', 'x_type', 'x_name', 'x_source']].drop_duplicates()
x_nodes.columns = ['id', 'type', 'name', 'source']
y_nodes = kg[['y_id', 'y_type', 'y_name', 'y_source']].drop_duplicates()
y_nodes.columns = ['id', 'type', 'name', 'source']
nodes = pd.concat([x_nodes, y_nodes]).drop_duplicates()
mask = nodes['name'].str.contains(name_query, case=False, na=False)
if node_type:
mask &= (nodes['type'] == node_type)
results = nodes[mask].head(20).to_dict(orient='records')
return results
def get_neighbors(node_id: Union[str, int], relation_type: Optional[str] = None) -> List[Dict]:
"""
Get all direct neighbors of a specific node.
Args:
node_id: The ID of the node (e.g., NCBI Gene ID or ChEMBL ID).
relation_type: Optional filter for specific relationship types.
Returns:
List of neighbors and the relationship metadata.
"""
kg = _load_kg()
node_id = str(node_id)
mask_x = (kg['x_id'].astype(str) == node_id)
mask_y = (kg['y_id'].astype(str) == node_id)
if relation_type:
mask_x &= (kg['relation'] == relation_type)
mask_y &= (kg['relation'] == relation_type)
neighbors_x = kg[mask_x][['relation', 'display_relation', 'y_id', 'y_type', 'y_name', 'y_source']]
neighbors_x.columns = ['relation', 'display_relation', 'neighbor_id', 'neighbor_type', 'neighbor_name', 'neighbor_source']
neighbors_y = kg[mask_y][['relation', 'display_relation', 'x_id', 'x_type', 'x_name', 'x_source']]
neighbors_y.columns = ['relation', 'display_relation', 'neighbor_id', 'neighbor_type', 'neighbor_name', 'neighbor_source']
results = pd.concat([neighbors_x, neighbors_y]).to_dict(orient='records')
return results
def find_paths(start_node_id: str, end_node_id: str, max_depth: int = 2) -> List[List[Dict]]:
"""
Find paths between two nodes (e.g., Drug to Disease) up to a certain depth.
Note: Simple BFS implementation.
"""
kg = _load_kg()
start_node_id = str(start_node_id)
end_node_id = str(end_node_id)
# Simplified path finding for depth 1 and 2
# Depth 1
direct = kg[((kg['x_id'].astype(str) == start_node_id) & (kg['y_id'].astype(str) == end_node_id)) |
((kg['y_id'].astype(str) == start_node_id) & (kg['x_id'].astype(str) == end_node_id))]
paths = []
for _, row in direct.iterrows():
paths.append([row.to_dict()])
if max_depth >= 2:
# Find neighbors of start
n1_x = kg[kg['x_id'].astype(str) == start_node_id]
n1_y = kg[kg['y_id'].astype(str) == start_node_id]
# This is computationally expensive in pure pandas for a large KG.
# Implementation skipped for brevity in this MVP, but suggested for full version.
pass
return paths
def get_disease_context(disease_name: str) -> Dict:
"""
Analyze the local graph around a disease: associated genes, drugs, and phenotypes.
"""
results = search_nodes(disease_name, node_type='disease')
if not results:
return {"error": "Disease not found"}
disease_id = results[0]['id']
neighbors = get_neighbors(disease_id)
summary = {
"disease_info": results[0],
"associated_genes": [n for n in neighbors if n['neighbor_type'] == 'gene/protein'],
"associated_drugs": [n for n in neighbors if n['neighbor_type'] == 'drug'],
"phenotypes": [n for n in neighbors if n['neighbor_type'] == 'phenotype'],
"related_diseases": [n for n in neighbors if n['neighbor_type'] == 'disease']
}
return summary
Related skills
FAQ
How large is the PrimeKG knowledge graph?
PrimeKG contains over 100,000 nodes and 4 million edges across 29 relationship types. The graph integrates more than 20 primary biomedical databases and literature sources for multiscale precision-medicine queries.
What entities can PrimeKG search?
PrimeKG supports searching nodes and relationships for genes, proteins, drugs, diseases, phenotypes, and related biomedical entities. Relationship types include drug-target, disease-gene, and phenotype-disease associations.