Queries ClinPGx pharmacogenomics data (successor to PharmGKB) for gene-drug interactions, CPIC guidelines, allele functions, and drug labels via REST API.
How this skill is triggered — by the user, by Claude, or both
Slash command
/alterlab-writing-tools:alterlab-clinpgxThis skill is limited to the following tools:
The summary Claude sees in its skill listing — used to decide when to auto-load this skill
ClinPGx (Clinical Pharmacogenomics Database) is a comprehensive resource for clinical pharmacogenomics information, successor to PharmGKB. It consolidates data from PharmGKB, CPIC, and PharmCAT, providing curated information on how genetic variation affects medication response. Access gene-drug pairs, clinical guidelines, allele functions, and drug labels for precision medicine applications.
ClinPGx (Clinical Pharmacogenomics Database) is a comprehensive resource for clinical pharmacogenomics information, successor to PharmGKB. It consolidates data from PharmGKB, CPIC, and PharmCAT, providing curated information on how genetic variation affects medication response. Access gene-drug pairs, clinical guidelines, allele functions, and drug labels for precision medicine applications.
This skill should be used when:
The ClinPGx REST API provides programmatic access to all database resources. Basic setup:
uv pip install requests
BASE_URL = "https://api.clinpgx.org/v1/data/"
Important: ClinPGx resources are addressed by ClinPGx accession IDs in the path (e.g. gene CYP2D6 = PA128, CYP2C9 = PA126), not by gene symbols or rsIDs. To resolve a symbol or rsID, query the collection endpoint with parameters (e.g. GET /v1/data/gene?symbol=CYP2D6, GET /v1/data/variant?symbol=rs4244285) and read the accession ID from the response.
Rate Limits:
Authentication: Not required for basic access
Data License: Creative Commons Attribution-ShareAlike 4.0 International License
For substantial API use, notify the ClinPGx team at [email protected]
Retrieve gene information including function, clinical annotations, and pharmacogenomic significance:
import requests
# Resolve a gene symbol to its ClinPGx record (accession ID is in the response)
response = requests.get("https://api.clinpgx.org/v1/data/gene",
params={"symbol": "CYP2D6"})
genes = response.json()
# Get gene details directly by accession ID (CYP2D6 = PA128)
response = requests.get("https://api.clinpgx.org/v1/data/gene/PA128")
gene_data = response.json()
Key pharmacogenes:
Retrieve drug information including pharmacogenomic annotations and mechanisms:
# Get drug details by ClinPGx accession ID
response = requests.get("https://api.clinpgx.org/v1/data/chemical/PA448515") # Warfarin
drug_data = response.json()
# Search drugs by name
response = requests.get("https://api.clinpgx.org/v1/data/chemical",
params={"name": "warfarin"})
drugs = response.json()
Drug categories with pharmacogenomic significance:
Access curated gene-drug relationships with clinical annotations. There is no single gene-drug-pair endpoint in the public API; derive pairs from guideline annotations, or use the pair report endpoint when you have both object accession IDs:
# Derive gene-drug relationships from guideline annotations
response = requests.get("https://api.clinpgx.org/v1/data/guidelineAnnotation",
params={"relatedChemicals.symbol": "codeine"})
guideline_annotations = response.json()
# Pair report endpoint (requires accession IDs for both objects)
# /report/pair/{firstObjId}/{secondObjId}/{resultType}
response = requests.get(
"https://api.clinpgx.org/v1/report/pair/PA128/PA449088/guidelineAnnotation"
)
pair_report = response.json()
Clinical annotation sources:
Access evidence-based clinical practice guidelines:
# Get a guideline annotation by accession ID
response = requests.get("https://api.clinpgx.org/v1/data/guidelineAnnotation/PA166104939")
guideline = response.json()
# List guideline annotations from a given source
response = requests.get("https://api.clinpgx.org/v1/data/guidelineAnnotation",
params={"source": "CPIC"})
guidelines = response.json()
CPIC guideline components:
Example guidelines:
Query allele function and frequency data. The public ClinPGx API does not expose a dedicated /allele resource. Star-allele definitions, functional status, and population frequencies are maintained by PharmVar (https://www.pharmvar.org/); allele-level clinical implications are surfaced through guideline annotations:
# Allele function / phenotype implications come through guideline annotations
response = requests.get("https://api.clinpgx.org/v1/data/guidelineAnnotation",
params={"relatedGenes.symbol": "CYP2D6"})
guideline_annotations = response.json()
# For canonical star-allele definitions and frequencies, use PharmVar:
# https://www.pharmvar.org/gene/CYP2D6
Allele information (via PharmVar / guideline annotations) includes:
Phenotype categories:
Access clinical annotations for specific genetic variants:
# Resolve an rsID to its ClinPGx variant record (accession ID is in the response)
response = requests.get("https://api.clinpgx.org/v1/data/variant",
params={"symbol": "rs4244285"})
variants = response.json()
# Then fetch the full record directly by its accession ID, e.g.:
# requests.get(f"https://api.clinpgx.org/v1/data/variant/{variants[0]['id']}")
Variant data includes:
Retrieve curated literature annotations (formerly PharmGKB clinical annotations). These are served by the annotation collections summaryAnnotation, variantAnnotation, and dataAnnotation depending on annotation type:
# Get summary (clinical) annotations related to a gene
response = requests.get("https://api.clinpgx.org/v1/data/summaryAnnotation",
params={"relatedGenes.symbol": "CYP2D6"})
annotations = response.json()
# Variant-level annotations
response = requests.get("https://api.clinpgx.org/v1/data/variantAnnotation",
params={"relatedGenes.symbol": "CYP2D6"})
variant_annotations = response.json()
Confirm the exact query parameter names and any evidence-level filters against the live OpenAPI spec before relying on them in production.
Evidence levels (from highest to lowest):
Access pharmacogenomic information from drug labels:
# Get drug labels with PGx information
response = requests.get("https://api.clinpgx.org/v1/data/label",
params={"relatedChemicals.symbol": "warfarin"})
labels = response.json()
# Filter by regulatory source
response = requests.get("https://api.clinpgx.org/v1/data/label",
params={"source": "FDA"})
fda_labels = response.json()
Label information includes:
Explore pharmacokinetic and pharmacodynamic pathways:
# Get pathway information by accession ID
response = requests.get("https://api.clinpgx.org/v1/data/pathway/PA146123006") # Warfarin pathway
pathway_data = response.json()
# Search pathways related to a drug
response = requests.get("https://api.clinpgx.org/v1/data/pathway",
params={"relatedChemicals.symbol": "warfarin"})
pathways = response.json()
Pathway diagrams show:
Identify patient genotype for relevant pharmacogenes:
# Example: Patient is CYP2C19 *1/*2 (intermediate metabolizer)
# Star-allele function/definitions come from PharmVar (no /allele resource in the API):
# https://www.pharmvar.org/gene/CYP2C19
Find guideline annotations for the medication of interest:
response = requests.get("https://api.clinpgx.org/v1/data/guidelineAnnotation",
params={"relatedChemicals.symbol": "clopidogrel"})
guideline_annotations = response.json()
# Recommendation: Alternative antiplatelet therapy for IM/PM
Check drug label for regulatory guidance:
response = requests.get("https://api.clinpgx.org/v1/data/label",
params={"relatedChemicals.symbol": "clopidogrel"})
label = response.json()
Get list of pharmacogenes in clinical panel:
pgx_panel = ["CYP2C19", "CYP2D6", "CYP2C9", "TPMT", "DPYD", "SLCO1B1"]
For each gene, retrieve its guideline annotations:
all_interactions = {}
for gene in pgx_panel:
response = requests.get("https://api.clinpgx.org/v1/data/guidelineAnnotation",
params={"relatedGenes.symbol": gene})
all_interactions[gene] = response.json()
Review the guideline annotations returned for each gene:
for gene, annotations in all_interactions.items():
for ann in annotations:
print(f"{gene}: {ann.get('name')}")
Generate patient report with actionable pharmacogenomic findings.
Query drug for PGx associations:
response = requests.get("https://api.clinpgx.org/v1/data/chemical",
params={"name": "abacavir"})
drug_id = response.json()[0]['id']
Get summary annotations:
response = requests.get("https://api.clinpgx.org/v1/data/summaryAnnotation",
params={"relatedChemicals.symbol": "abacavir"})
annotations = response.json()
Check for HLA associations and toxicity risk:
for annotation in annotations:
if 'HLA' in annotation.get('genes', []):
print(f"Toxicity risk: {annotation.get('phenotype')}")
Retrieve screening recommendations from guidelines and labels.
Get allele frequencies for population comparison. The ClinPGx API has no /allele resource; allele definitions and population frequencies are obtained from PharmVar (https://www.pharmvar.org/), which offers its own download/API:
# e.g. PharmVar gene page / downloads for CYP2D6 star-allele frequencies
# https://www.pharmvar.org/gene/CYP2D6
alleles = [] # populate from PharmVar data
Extract population-specific frequencies from the PharmVar records:
populations = ['European', 'African', 'East Asian', 'Latino']
frequency_data = {}
for allele in alleles:
allele_name = allele['name']
frequency_data[allele_name] = {
pop: allele.get(f'{pop}_frequency', 'N/A')
for pop in populations
}
Calculate phenotype distributions by population:
# Combine allele frequencies with function to predict phenotypes
phenotype_dist = calculate_phenotype_frequencies(frequency_data)
Analyze implications for drug dosing in diverse populations.
Find guideline annotations for the gene-drug relationship:
response = requests.get("https://api.clinpgx.org/v1/data/guidelineAnnotation",
params={"relatedGenes.symbol": "TPMT"})
guideline_annotations = response.json()
Retrieve all summary annotations:
response = requests.get("https://api.clinpgx.org/v1/data/summaryAnnotation",
params={"relatedGenes.symbol": "TPMT"})
annotations = response.json()
Filter by the annotation's level-of-evidence field (confirm field name against the OpenAPI spec):
high_quality = [a for a in annotations
if a.get('levelOfEvidence') in ['1A', '1B', '2A']]
Extract PMIDs and retrieve full references:
pmids = [a['pmid'] for a in high_quality if 'pmid' in a]
# Use PubMed skill to retrieve full citations
import time
def rate_limited_request(url, params=None, delay=0.5):
"""Make API request with rate limiting (2 req/sec max)"""
response = requests.get(url, params=params)
time.sleep(delay) # Wait 0.5 seconds between requests
return response
# Use in loops (resolve each gene symbol via the collection endpoint)
genes = ["CYP2D6", "CYP2C19", "CYP2C9"]
for gene in genes:
response = rate_limited_request(
"https://api.clinpgx.org/v1/data/gene", params={"symbol": gene}
)
data = response.json()
def safe_api_call(url, params=None, max_retries=3):
"""API call with error handling and retries"""
for attempt in range(max_retries):
try:
response = requests.get(url, params=params, timeout=10)
if response.status_code == 200:
return response.json()
elif response.status_code == 429:
# Rate limit exceeded
wait_time = 2 ** attempt # Exponential backoff
print(f"Rate limit hit. Waiting {wait_time}s...")
time.sleep(wait_time)
else:
response.raise_for_status()
except requests.exceptions.RequestException as e:
print(f"Attempt {attempt + 1} failed: {e}")
if attempt == max_retries - 1:
raise
time.sleep(1)
import json
from pathlib import Path
def cached_query(cache_file, api_func, *args, **kwargs):
"""Cache API results to avoid repeated queries"""
cache_path = Path(cache_file)
if cache_path.exists():
with open(cache_path) as f:
return json.load(f)
result = api_func(*args, **kwargs)
with open(cache_path, 'w') as f:
json.dump(result, f, indent=2)
return result
# Usage (CYP2D6 = accession PA128)
gene_data = cached_query(
'cyp2d6_cache.json',
rate_limited_request,
"https://api.clinpgx.org/v1/data/gene/PA128"
)
PharmDOG (formerly DDRx) is ClinPGx's clinical decision support tool for interpreting pharmacogenomic test results:
Key features:
Access: Available at https://www.clinpgx.org/pharmacogenomic-decision-support
Use cases:
Python script with ready-to-use functions for common ClinPGx queries:
get_gene_info(gene_symbol) - Retrieve gene detailsget_drug_info(drug_name) - Get drug informationget_gene_drug_pairs(gene, drug) - Query gene-drug interactionsget_cpic_guidelines(gene, drug) - Retrieve CPIC guidelinesget_alleles(gene) - Get all alleles for a geneget_clinical_annotations(gene, drug, evidence_level) - Query literature annotationsget_drug_labels(drug) - Retrieve pharmacogenomic drug labelssearch_variants(rsid) - Search by variant rsIDexport_to_dataframe(data) - Convert results to pandas DataFrameConsult this script for implementation examples with proper rate limiting and error handling.
Comprehensive API documentation including:
Refer to this document when detailed API information is needed or when constructing complex queries.
ClinPGx consolidates multiple authoritative sources:
As of July 2025, all PharmGKB URLs redirect to corresponding ClinPGx pages.
Query all clinically actionable gene-drug pairs to guide panel selection:
# List CPIC guideline annotations and derive the actionable gene-drug pairs from them
response = requests.get("https://api.clinpgx.org/v1/data/guidelineAnnotation",
params={"source": "CPIC"})
guideline_annotations = response.json()
Review patient medications against known genotypes:
patient_genes = {"CYP2C19": "*1/*2", "CYP2D6": "*1/*1", "SLCO1B1": "*1/*5"}
medications = ["clopidogrel", "simvastatin", "escitalopram"]
for med in medications:
response = requests.get("https://api.clinpgx.org/v1/data/guidelineAnnotation",
params={"relatedChemicals.symbol": med})
guideline_annotations = response.json()
# Cross-reference returned annotations against patient_genes for dosing guidance
Screen for pharmacogenomic contraindications:
# Check for HLA-B*57:01 guidance before abacavir trial
response = requests.get("https://api.clinpgx.org/v1/data/guidelineAnnotation",
params={"relatedChemicals.symbol": "abacavir"})
guideline_annotations = response.json()
# CPIC: Do not use if HLA-B*57:01 positive
npx claudepluginhub alterlab-ieu/alterlab-academic-skills --plugin alterlab-visualizationQueries ClinPGx pharmacogenomics data for gene-drug interactions, CPIC guidelines, allele functions, and drug labels to support precision medicine and genotype-guided dosing decisions.
Researches pharmacogenomics data: drug-gene interactions, CPIC guidelines, PharmGKB annotations, FDA labeling, and variant interpretation for clinical PGx reports.
Queries ClinPGx (PharmGKB) and CPIC APIs for pharmacogenomic annotations, dosing guidelines, gene-drug pairs, variant-drug associations, drug labels, and PGx pathways.