Loading...
Loading...
Access ClinPGx pharmacogenomics data (successor to PharmGKB). Query gene-drug interactions, CPIC guidelines, allele functions, for precision medicine and genotype-guided dosing decisions.
npx skill4agent add davila7/claude-code-templates clinpgx-databaseuv pip install requestsBASE_URL = "https://api.clinpgx.org/v1/"import requests
# Get gene details
response = requests.get("https://api.clinpgx.org/v1/gene/CYP2D6")
gene_data = response.json()
# Search for genes by name
response = requests.get("https://api.clinpgx.org/v1/gene",
params={"q": "CYP"})
genes = response.json()# Get drug details
response = requests.get("https://api.clinpgx.org/v1/chemical/PA448515") # Warfarin
drug_data = response.json()
# Search drugs by name
response = requests.get("https://api.clinpgx.org/v1/chemical",
params={"name": "warfarin"})
drugs = response.json()# Get gene-drug pair information
response = requests.get("https://api.clinpgx.org/v1/geneDrugPair",
params={"gene": "CYP2D6", "drug": "codeine"})
pair_data = response.json()
# Get all pairs for a gene
response = requests.get("https://api.clinpgx.org/v1/geneDrugPair",
params={"gene": "CYP2C19"})
all_pairs = response.json()# Get CPIC guideline
response = requests.get("https://api.clinpgx.org/v1/guideline/PA166104939")
guideline = response.json()
# List all CPIC guidelines
response = requests.get("https://api.clinpgx.org/v1/guideline",
params={"source": "CPIC"})
guidelines = response.json()# Get allele information
response = requests.get("https://api.clinpgx.org/v1/allele/CYP2D6*4")
allele_data = response.json()
# Get all alleles for a gene
response = requests.get("https://api.clinpgx.org/v1/allele",
params={"gene": "CYP2D6"})
alleles = response.json()# Get variant information
response = requests.get("https://api.clinpgx.org/v1/variant/rs4244285")
variant_data = response.json()
# Search variants by position (if supported)
response = requests.get("https://api.clinpgx.org/v1/variant",
params={"chromosome": "10", "position": "94781859"})
variants = response.json()# Get clinical annotations
response = requests.get("https://api.clinpgx.org/v1/clinicalAnnotation",
params={"gene": "CYP2D6"})
annotations = response.json()
# Filter by evidence level
response = requests.get("https://api.clinpgx.org/v1/clinicalAnnotation",
params={"evidenceLevel": "1A"})
high_evidence = response.json()# Get drug labels with PGx information
response = requests.get("https://api.clinpgx.org/v1/drugLabel",
params={"drug": "warfarin"})
labels = response.json()
# Filter by regulatory source
response = requests.get("https://api.clinpgx.org/v1/drugLabel",
params={"source": "FDA"})
fda_labels = response.json()# Get pathway information
response = requests.get("https://api.clinpgx.org/v1/pathway/PA146123006") # Warfarin pathway
pathway_data = response.json()
# Search pathways by drug
response = requests.get("https://api.clinpgx.org/v1/pathway",
params={"drug": "warfarin"})
pathways = response.json()# Example: Patient is CYP2C19 *1/*2 (intermediate metabolizer)
response = requests.get("https://api.clinpgx.org/v1/allele/CYP2C19*2")
allele_function = response.json()response = requests.get("https://api.clinpgx.org/v1/geneDrugPair",
params={"gene": "CYP2C19", "drug": "clopidogrel"})
pair_info = response.json()response = requests.get("https://api.clinpgx.org/v1/guideline",
params={"gene": "CYP2C19", "drug": "clopidogrel"})
guideline = response.json()
# Recommendation: Alternative antiplatelet therapy for IM/PMresponse = requests.get("https://api.clinpgx.org/v1/drugLabel",
params={"drug": "clopidogrel"})
label = response.json()pgx_panel = ["CYP2C19", "CYP2D6", "CYP2C9", "TPMT", "DPYD", "SLCO1B1"]all_interactions = {}
for gene in pgx_panel:
response = requests.get("https://api.clinpgx.org/v1/geneDrugPair",
params={"gene": gene})
all_interactions[gene] = response.json()for gene, pairs in all_interactions.items():
for pair in pairs:
if pair.get('cpicLevel'): # Has CPIC guideline
print(f"{gene} - {pair['drug']}: {pair['cpicLevel']}")response = requests.get("https://api.clinpgx.org/v1/chemical",
params={"name": "abacavir"})
drug_id = response.json()[0]['id']response = requests.get("https://api.clinpgx.org/v1/clinicalAnnotation",
params={"drug": drug_id})
annotations = response.json()for annotation in annotations:
if 'HLA' in annotation.get('genes', []):
print(f"Toxicity risk: {annotation['phenotype']}")
print(f"Evidence level: {annotation['evidenceLevel']}")response = requests.get("https://api.clinpgx.org/v1/allele",
params={"gene": "CYP2D6"})
alleles = response.json()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
}# Combine allele frequencies with function to predict phenotypes
phenotype_dist = calculate_phenotype_frequencies(frequency_data)response = requests.get("https://api.clinpgx.org/v1/geneDrugPair",
params={"gene": "TPMT", "drug": "azathioprine"})
pair = response.json()response = requests.get("https://api.clinpgx.org/v1/clinicalAnnotation",
params={"gene": "TPMT", "drug": "azathioprine"})
annotations = response.json()high_quality = [a for a in annotations
if a['evidenceLevel'] in ['1A', '1B', '2A']]pmids = [a['pmid'] for a in high_quality if 'pmid' in a]
# Use PubMed skill to retrieve full citationsimport 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
genes = ["CYP2D6", "CYP2C19", "CYP2C9"]
for gene in genes:
response = rate_limited_request(
"https://api.clinpgx.org/v1/gene/" + 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
gene_data = cached_query(
'cyp2d6_cache.json',
rate_limited_request,
"https://api.clinpgx.org/v1/gene/CYP2D6"
)get_gene_info(gene_symbol)get_drug_info(drug_name)get_gene_drug_pairs(gene, drug)get_cpic_guidelines(gene, drug)get_alleles(gene)get_clinical_annotations(gene, drug, evidence_level)get_drug_labels(drug)search_variants(rsid)export_to_dataframe(data)# Get all CPIC guideline pairs
response = requests.get("https://api.clinpgx.org/v1/geneDrugPair",
params={"cpicLevel": "A"}) # Level A recommendations
actionable_pairs = response.json()patient_genes = {"CYP2C19": "*1/*2", "CYP2D6": "*1/*1", "SLCO1B1": "*1/*5"}
medications = ["clopidogrel", "simvastatin", "escitalopram"]
for med in medications:
for gene in patient_genes:
response = requests.get("https://api.clinpgx.org/v1/geneDrugPair",
params={"gene": gene, "drug": med})
# Check for interactions and dosing guidance# Check for HLA-B*57:01 before abacavir trial
response = requests.get("https://api.clinpgx.org/v1/geneDrugPair",
params={"gene": "HLA-B", "drug": "abacavir"})
pair_info = response.json()
# CPIC: Do not use if HLA-B*57:01 positive