PharmGKB / ClinPGx Query Skill
Queries two complementary APIs:
- ClinPGx API (
api.clinpgx.org/v1) — gene, chemical, variant detail
- CPIC API (
api.cpicpgx.org/v1) — gene-drug pairs, CPIC guideline levels (PostgREST)
Auto-detects input entity type by pattern:
| Input Pattern |
Detected As |
Data Sources |
PA128 |
ClinPGx accession |
gene or chemical detail + CPIC pairs |
rs4244285 |
dbSNP rsID |
variant lookup |
CYP2D6 |
gene symbol (uppercase, 2-15 chars) |
gene detail + CPIC pairs |
| anything else |
drug / free text |
chemical detail + CPIC pairs |
API
| Function |
Input |
Returns |
search(entity) |
single entity string |
dict with genes, chemicals, variants, cpic_pairs, related |
search_batch(entities) |
list of entity strings |
dict[str → search result] |
summarize(result, entity) |
search result + label |
compact text (one line per hit) |
to_json(result) |
search result |
indented JSON string |
search_gene(symbol) |
gene symbol |
list of gene dicts (ClinPGx) |
search_drug(name) |
drug name |
list of chemical dicts (ClinPGx) |
search_variant(rsid) |
rsID string |
list of variant dicts (ClinPGx) |
get_cpic_pairs_by_gene(symbol) |
gene symbol |
list of pair dicts (CPIC pair_view) |
get_cpic_pairs_by_drug(name) |
drug name |
list of pair dicts (CPIC pair_view) |
Usage
See if __name__ == "__main__" block in 49_PHARMGKB_CLINPGX.py for runnable
examples covering: gene symbol, drug name, rsID, ClinPGx accession, batch
search, and JSON output.
Key Fields
Gene (ClinPGx): id, symbol, name, hasCpicGuideline
Chemical (ClinPGx): id, name, types
Variant (ClinPGx): id, symbol, genes, location
CPIC Pair (pair_view): genesymbol, drugname, cpiclevel (A/B/C/D),
clinpgxlevel (evidence), pgxtesting, guidelinename
Data Sources
- ClinPGx (Stanford / NIH) — https://www.clinpgx.org/ — REST JSON, no key, ≤2 req/s, CC BY-SA 4.0
- CPIC API — https://api.cpicpgx.org/ — PostgREST, no key — gene-drug guideline pairs
- Note: PharmGKB was subsumed by ClinPGx (July 2025). CPIC API remains at
api.cpicpgx.org.
1---2name: pharmgkb-clinpgx3description: Query ClinPGx (PharmGKB) and CPIC for pharmacogenomics data. Use whenever the user asks about gene-drug interactions, pharmacogenomics clinical annotations, drug-metabolizing enzymes, CPIC guidelines, or variant-level PGx evidence for any gene symbol, drug name, rsID, or ClinPGx accession.4---5
6# PharmGKB / ClinPGx Query Skill
7
8Queries two complementary APIs:
9
10- **ClinPGx API** (`api.clinpgx.org/v1`) — gene, chemical, variant detail
11- **CPIC API** (`api.cpicpgx.org/v1`) — gene-drug pairs, CPIC guideline levels (PostgREST)
12
13Auto-detects input entity type by pattern:
14
15| Input Pattern | Detected As | Data Sources |
16|---|---|---|
17| `PA128` | ClinPGx accession | gene or chemical detail + CPIC pairs |
18| `rs4244285` | dbSNP rsID | variant lookup |
19| `CYP2D6` | gene symbol (uppercase, 2-15 chars) | gene detail + CPIC pairs |
20| anything else | drug / free text | chemical detail + CPIC pairs |
21
22## API
23
24| Function | Input | Returns |
25|---|---|---|
26| `search(entity)` | single entity string | dict with `genes`, `chemicals`, `variants`, `cpic_pairs`, `related` |
27| `search_batch(entities)` | list of entity strings | dict[str → search result] |
28| `summarize(result, entity)` | search result + label | compact text (one line per hit) |
29| `to_json(result)` | search result | indented JSON string |
30| `search_gene(symbol)` | gene symbol | list of gene dicts (ClinPGx) |
31| `search_drug(name)` | drug name | list of chemical dicts (ClinPGx) |
32| `search_variant(rsid)` | rsID string | list of variant dicts (ClinPGx) |
33| `get_cpic_pairs_by_gene(symbol)` | gene symbol | list of pair dicts (CPIC `pair_view`) |
34| `get_cpic_pairs_by_drug(name)` | drug name | list of pair dicts (CPIC `pair_view`) |
35
36## Usage
37
38See `if __name__ == "__main__"` block in `49_PHARMGKB_CLINPGX.py` for runnable
39examples covering: gene symbol, drug name, rsID, ClinPGx accession, batch
40search, and JSON output.
41
42## Key Fields
43
44**Gene** (ClinPGx): `id`, `symbol`, `name`, `hasCpicGuideline`
45
46**Chemical** (ClinPGx): `id`, `name`, `types`
47
48**Variant** (ClinPGx): `id`, `symbol`, `genes`, `location`
49
50**CPIC Pair** (`pair_view`): `genesymbol`, `drugname`, `cpiclevel` (A/B/C/D),
51`clinpgxlevel` (evidence), `pgxtesting`, `guidelinename`
52
53## Data Sources
54
55- **ClinPGx** (Stanford / NIH) — https://www.clinpgx.org/ — REST JSON, no key, ≤2 req/s, CC BY-SA 4.0
56- **CPIC API** — https://api.cpicpgx.org/ — PostgREST, no key — gene-drug guideline pairs
57- **Note**: PharmGKB was subsumed by ClinPGx (July 2025). CPIC API remains at `api.cpicpgx.org`.