Skip to main content

A tool to resolve messy drug names in biomedical datasets to standard identifiers

Project description

Drug Resolver

This package offers a simple way to resolve drug names to their corresponding PubChem entries.

This is useful for identifying unknown drug synonyms or matching drug synonyms across different datasets in an automated way.

Installation

pip install drug-resolver

Usage

from drug_resolver import resolve_drug

d1 = resolve_drug("tetracycline hcl")
print(d1)
"""
ResolvedDrug(
   name='Tetracycline hydrochloride', 
   pubchem_compound_id='54704426', 
   pubchem_substance_id='103591391', 
   smiles='CN(C)C1C(=O)C(C(N)=O)=C(O)C2(O)C(=O)C3=C(O)c4c(O)cccc4C(C)(O)C3CC12.Cl', 
   drug_classes=None, 
   fda_approval=<FDAApprovalStatus.APPROVED: 'APPROVED'>, 
   pubchem_parent_compound_id='54675776')
"""

d2 = resolve_drug("Sumycin")
print(d2)
"""
ResolvedDrug(
    name='Tetracycline', 
    pubchem_compound_id='54675776', 
    pubchem_substance_id='124766046', 
    smiles='CN(C)C1C(=O)C(C(N)=O)=C(O)C2(O)C(=O)C3=C(O)c4c(O)cccc4C(C)(O)C3CC12', 
    drug_classes=frozenset({'Established Pharmacologic Class [EPC] - Tetracycline-class Antimicrobial'}), 
    fda_approval=<FDAApprovalStatus.APPROVED: 'APPROVED'>, 
    pubchem_parent_compound_id=None)
"""

assert d1 == d2 # True

The equality operator between ResolvedDrug objects will return True under the following conditions:

  • The pubchem_compound_id attribute is the same
  • The pubchem_substance_id attribute is the same
  • The smiles strings refer to the same molecule
  • Two compounds share the same pubchem_parent_compound_id or the pubchem_compound_id is the same as the pubchem_parent_compound_id of the other compound.

Caching

You can set the env variable DRUG_RESOLVER_REQUEST_CACHE to a filename. A sqlite database will be created at the filename and all PubChem requests will be cached there. This is useful for avoiding repeated requests to the PubChem API. By default, the cache will be stored in memory and will be lost when the program exits.

Here is an example of the cache works:

(.venv) drug-name-resolver % DRUG_RESOLVER_REQUEST_CACHE=/tmp/test.sqlite3 ipython
Python 3.11.11 (main, Dec  3 2024, 17:20:40) [Clang 16.0.0 (clang-1600.0.26.4)]

In [1]: from drug_resolver import resolve_drug

In [2]: %time d1 = resolve_drug("tetracycline hcl")
CPU times: user 48.1 ms, sys: 10.7 ms, total: 58.8 ms
Wall time: 1.53 s
(.venv)  drug-name-resolver % ls -lh /tmp/test.sqlite3
-rw-r--r--@ 1 quinnj2  wheel   468K Jan 30 14:51 /tmp/test.sqlite3
(.venv) drug-name-resolver % DRUG_RESOLVER_REQUEST_CACHE=/tmp/test.sqlite3 ipython
Python 3.11.11 (main, Dec  3 2024, 17:20:40) [Clang 16.0.0 (clang-1600.0.26.4)]

In [1]: from drug_resolver import resolve_drug

In [2]: %time d1 = resolve_drug("tetracycline hcl")
CPU times: user 24.2 ms, sys: 4.06 ms, total: 28.3 ms
Wall time: 29.3 ms

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

drug_resolver-0.0.5.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

drug_resolver-0.0.5-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file drug_resolver-0.0.5.tar.gz.

File metadata

  • Download URL: drug_resolver-0.0.5.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for drug_resolver-0.0.5.tar.gz
Algorithm Hash digest
SHA256 61cd177bccbe74cc8a23ed415cd132d3e29790ceefa7298be88a91847e574188
MD5 17486d26c52d26cff16f96e8ce7848e6
BLAKE2b-256 b6271c66ffe3fd1bc7dea3e92e6dbc4c768660022958a531d5f2fd79a4df1b46

See more details on using hashes here.

Provenance

The following attestation bundles were made for drug_resolver-0.0.5.tar.gz:

Publisher: release.yml on tansey-lab/drug-resolver

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file drug_resolver-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: drug_resolver-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 9.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for drug_resolver-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 7886e2efb884c592b0cf528f4b42efc9350ed9177527a4a5238c5456d4f0221e
MD5 2665aefa6b185c9fb55decfd14375253
BLAKE2b-256 c4c02baa2914a1dd90dfcd894443b4fe753e2be7d9d09063bb538761f454f5c6

See more details on using hashes here.

Provenance

The following attestation bundles were made for drug_resolver-0.0.5-py3-none-any.whl:

Publisher: release.yml on tansey-lab/drug-resolver

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page