Clinpgx database

From eric861129/SKILLS_All-in-one · View interactive version

Clinpgx database is an AI agent skill from the GitHub repository eric861129/SKILLS_All-in-one. Access ClinPGx pharmacogenomics data (successor to PharmGKB). Query gene-drug interactions, CPIC guidelines, allele functions, for precision medicine and genotype-guided dosing decisions.

How to use this skill

Skill file

ClinPGx Database

Overview

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.

When to Use This Skill

This skill should be used when:

Installation and Setup

Python API Access

The ClinPGx REST API provides programmatic access to all database resources. Basic setup:

uv pip install requests

API Endpoint

BASE_URL = "https://api.clinpgx.org/v1/"

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 api@clinpgx.org

Core Capabilities

1. Gene Queries

Retrieve gene information including function, clinical annotations, and pharmacogenomic significance:

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()

Key pharmacogenes:

2. Drug and Chemical Queries

Retrieve drug information including pharmacogenomic annotations and mechanisms:

# 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()

Drug categories with pharmacogenomic significance:

3. Gene-Drug Pair Queries

Access curated gene-drug relationships with clinical annotations:

# 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()

Clinical annotation sources:

4. CPIC Guidelines

Access evidence-based clinical practice guidelines:

# 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()

CPIC guideline components:

Example guidelines:

5. Allele and Variant Information

Query allele function and frequency data:

# 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()

Allele information includes:

Phenotype categories:

6. Variant Annotations

Access clinical annotations for specific genetic variants:

# 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()

Variant data includes:

7. Clinical Annotations

Retrieve curated literature annotations (formerly PharmGKB clinical annotations):

# 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()

Evidence levels (from highest to lowest):

8. Drug Labels

Access pharmacogenomic information from drug labels:

# 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()

Label information includes:

9. Pathways

Explore pharmacokinetic and pharmacodynamic pathways:

# 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()

Pathway diagrams show:

Query Workflow

Workflow 1: Clinical Decision Support for Drug Prescription

  1. Identify patient genotype for relevant pharmacogenes:

```python

# Example: Patient is CYP2C19 1/2 (intermediate metabolizer)

response = requests.get("https://api.clinpgx.org/v1/allele/CYP2C19*2")

allele_function = response.json()

```

  1. Query gene-drug pairs for medication of interest:

```python

response = requests.get("https://api.clinpgx.org/v1/geneDrugPair",

params={"gene": "CYP2C19", "drug": "clopidogrel"})

pair_info = response.json()

```

  1. Retrieve CPIC guideline for dosing recommendations:

```python

response = requests.get("https://api.clinpgx.org/v1/guideline",

params={"gene": "CYP2C19", "drug": "clopidogrel"})

guideline = response.json()

# Recommendation: Alternative antiplatelet therapy for IM/PM

```

  1. Check drug label for regulatory guidance:

```python

response = requests.get("https://api.clinpgx.org/v1/drugLabel",

params={"drug": "clopidogrel"})

label = response.json()

```

Workflow 2: Gene Panel Analysis

  1. Get list of pharmacogenes in clinical panel:

```python

pgx_panel = ["CYP2C19", "CYP2D6", "CYP2C9", "TPMT", "DPYD", "SLCO1B1"]

```

  1. For each gene, retrieve all drug interactions:

```python

all_interactions = {}

for gene in pgx_panel:

response = requests.get("https://api.clinpgx.org/v1/geneDrugPair",

params={"gene": gene})

all_interactions[gene] = response.json()

```

  1. Filter for CPIC guideline-level evidence:

```python

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']}")

```

  1. Generate patient report with actionable pharmacogenomic findings.

Workflow 3: Drug Safety Assessment

  1. Query drug for PGx associations:

```python

response = requests.get("https://api.clinpgx.org/v1/chemical",

params={"name": "abacavir"})

drug_id = response.json()[0]['id']

```

  1. Get clinical annotations:

```python

response = requests.get("https://api.clinpgx.org/v1/clinicalAnnotation",

params={"drug": drug_id})

annotations = response.json()

```

  1. Check for HLA associations and toxicity risk:

```python

for annotation in annotations:

if 'HLA' in annotation.get('genes', []):

print(f"Toxicity risk: {annotation['phenotype']}")

print(f"Evidence level: {annotation['evidenceLevel']}")

```

  1. Retrieve screening recommendations from guidelines and labels.

Workflow 4: Research Analysis - Population Pharmacogenomics

  1. Get allele frequencies for population comparison:

```python

response = requests.get("https://api.clinpgx.org/v1/allele",

params={"gene": "CYP2D6"})

alleles = response.json()

```

  1. Extract population-specific frequencies:

```python

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

}

```

  1. Calculate phenotype distributions by population:

```python

# Combine allele frequencies with function to predict phenotypes

phenotype_dist = calculate_phenotype_frequencies(frequency_data)

```

  1. Analyze implications for drug dosing in diverse populations.

Workflow 5: Literature Evidence Review

  1. Search for gene-drug pair:

```python

response = requests.get("https://api.clinpgx.org/v1/geneDrugPair",

params={"gene": "TPMT", "drug": "azathioprine"})

pair = response.json()

```

  1. Retrieve all clinical annotations:

```python

response = requests.get("https://api.clinpgx.org/v1/clinicalAnnotation",

params={"gene": "TPMT", "drug": "azathioprine"})

annotations = response.json()

```

  1. Filter by evidence level and publication date:

```python

high_quality = [a for a in annotations

if a['evidenceLevel'] in ['1A', '1B', '2A']]

```

  1. Extract PMIDs and retrieve full references:

```python

pmids = [a['pmid'] for a in high_quality if 'pmid' in a]

# Use PubMed skill to retrieve full citations

```

Rate Limiting and Best Practices

Rate Limit Compliance

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
genes = ["CYP2D6", "CYP2C19", "CYP2C9"]
for gene in genes:
    response = rate_limited_request(
        "https://api.clinpgx.org/v1/gene/" + gene
    )
    data = response.json()

Error Handling

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)

Caching Results

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"
)

PharmDOG Tool

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:

Resources

scripts/query_clinpgx.py

Python script with ready-to-use functions for common ClinPGx queries:

Consult this script for implementation examples with proper rate limiting and error handling.

references/api_reference.md

Comprehensive API documentation including:

Refer to this document when detailed API information is needed or when constructing complex queries.

Important Notes

Data Sources and Integration

ClinPGx consolidates multiple authoritative sources:

As of July 2025, all PharmGKB URLs redirect to corresponding ClinPGx pages.

Clinical Implementation Considerations

Data Updates

API Stability

Common Use Cases

Pre-emptive Pharmacogenomic Testing

Query all clinically actionable gene-drug pairs to guide panel selection:

# Get all CPIC guideline pairs
response = requests.get("https://api.clinpgx.org/v1/geneDrugPair",
                       params={"cpicLevel": "A"})  # Level A recommendations
actionable_pairs = response.json()

Medication Therapy Management

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:
    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

Clinical Trial Eligibility

Screen for pharmacogenomic contraindications:

# 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

Additional Resources

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.