Fuzzy term lookup for ClinPGx/PharmGKB: drugs and variants, via the PharmGKB and RxNorm APIs
Project description
clinpgx-term-lookup
Fuzzy term lookup for ClinPGx / PharmGKB: take a free-text drug or variant term and resolve it to its ClinPGx record.
It is API-only — no local data files to download. Lookups are served by the public PharmGKB and RxNorm APIs, so results stay current and the package stays small. An internet connection is required at lookup time.
Installation
pip install clinpgx-term-lookup
Usage
Drugs
from clinpgx_term_lookup import DrugLookup
results = DrugLookup().search("warfarin")
for r in results:
print(r.name, r.id, r.url, r.score, r.source)
The drug lookup:
- Tries an exact PharmGKB chemical name match.
- On a miss, fuzzy-matches the term with RxNorm's
approximateTermendpoint, resolves it to its ingredient (so brand names likeTylenolmap toacetaminophen), and re-queries PharmGKB by that name. - On a miss, returns the RxNorm result itself as a fallback (with
source="rxnorm").
So misspellings (warfarn) and trade names (tylenol) both resolve to the
right PharmGKB chemical.
Variants
from clinpgx_term_lookup import VariantLookup
VariantLookup().search("rs1234") # rsID -> variant endpoint
VariantLookup().search("CYP2C19*2") # star allele -> haplotype endpoint
Terms starting with rs are looked up as rsIDs; everything else is treated as
a star allele.
Result objects
Both lookups return a list of Pydantic models with these fields:
| Field | Description |
|---|---|
raw_input |
The original query string |
id |
PharmGKB accession ID (or RXN<rxcui>) |
name |
The matched name |
url |
Link to the ClinPGx (or RxNorm) record |
score |
0–1 fuzzy similarity to the query |
source |
"pharmgkb" or "rxnorm" |
Command line
clinpgx-term-lookup warfarin --type drug
clinpgx-term-lookup rs1234 --type variant
Output is JSON. Use --top-k and --threshold to tune results.
License
MIT. Note that lookups query the PharmGKB and RxNorm APIs; their data is subject to their respective terms of use.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file clinpgx_term_lookup-0.1.0.tar.gz.
File metadata
- Download URL: clinpgx_term_lookup-0.1.0.tar.gz
- Upload date:
- Size: 8.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
de90c9901ea3a332ee69c4a6da6f1b7764930e2dbdaf74767b78f5ca5b1187f7
|
|
| MD5 |
f1e719c0d86b3393b6081eb8cea6a6c2
|
|
| BLAKE2b-256 |
d78e497d87a60ba76560f3b462f2c75127605683d32d420bf11c8734312ba7db
|
File details
Details for the file clinpgx_term_lookup-0.1.0-py3-none-any.whl.
File metadata
- Download URL: clinpgx_term_lookup-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0397a65bb57093634a9d734ea9f0de2af1bbb372fe79193dbe206fcf45a3a3b4
|
|
| MD5 |
26873aaa3533d0ae96b5236f7e65b00c
|
|
| BLAKE2b-256 |
f759e793a86eea0d48025b75f1f5f752961d43eff5a91146e0a37f1dff43881c
|