Skip to main content

scigantic-comptox

CI PyPI PyPI - Python Version License

Query EPA's CompTox Chemicals Dashboard from Python. Two halves, and only one of them needs anything from you:

  • ToxCast bioactivity, from a public S3 mirror over DuckDB. No API key, no download, no local database.
  • Live Chemical/Hazard/Exposure lookups, over EPA's own CCTE REST API. Optional, and requires your own EPA API key.
import scigantic_comptox as comptox

df = comptox.bioactivity(dtxsid="DTXSID7020182", hitc=1.0)

That query runs against s3://scigantic-comptox over DuckDB's httpfs extension.

Installation

$ pip install scigantic-comptox

What's in the bioactivity mirror

Every row is the winning dose-response model plus hit-call for one (chemical, ToxCast assay endpoint) pair, from EPA's invitrodb v4.3 mc5-6_winning_model_fits summary tier: AC50, potency, top, confidence bounds, and hitc/hitcall (active/inactive/ambiguous). This is the same level of detail as PubChem's own concise BioAssay tables, deliberately not the raw well-level plate reads or the full set of losing candidate curve models EPA also publishes (mc4_all_model_fits) -- that table is what makes EPA's own "summary" download 7GB instead of the ~600MB actually mirrored here; almost nobody needs the losing models, they need the winner.

comptox.bioactivity(aeid=1114, limit=5)

A real data-quality issue is handled for you. EPA's export uses the literal string "NA" for missing values in several columns (including dsstox_substance_id), not a real SQL NULL -- filtering with IS NOT NULL silently misses these. bioactivity() normalizes this (NULLIF(..., 'NA')) so a real NULL check works as expected; it also casts columns EPA ships as text purely because of those "NA" strings (ac50, bmd, top, and others) to real DOUBLEs. Use bioactivity_raw() if you want EPA's exact upstream types instead.

PubChem cross-reference

EPA publishes a per-assay-endpoint PubChem CID cross-reference alongside each invitrodb release. This wraps the consolidated version of that file:

comptox.pubchem_bridge(dtxsid="DTXSID7020182")

Pairs naturally with scigantic-pubchem's own BioAssay/gene/protein coverage.

What's not mirrored (yet)

DSSTox bulk chemical structures aren't mirrored -- EPA's bulk distribution for that turned out to be a large, unstructured institutional drive rather than a clean single file. comptox.releases() reports this plainly (structures: False) rather than silently missing the data. For now, chemical structure lookup by DTXSID goes through the live REST half below, the same place EPA's own client gets it from.

The live REST half: bring your own EPA API key

EPA's CCTE API needs one, and deliberately doesn't hand out a shared one: their own docs describe it as "an individual API key" that "uniquely identifies the user," issued by emailing ccte_api@epa.gov rather than self-serve signup. EPA's own reference client, ctx-python, never embeds a key either. This package follows the same rule -- no key ships with it, and none is proxied on your behalf.

$ export COMPTOX_API_KEY=your-key-here
comptox.chemical_detail("DTXSID7020182")
comptox.hazard_toxval("DTXSID7020182")
comptox.exposure_httk("DTXSID7020182")

Calling any of these without a key raises MissingApiKeyError with a link to how to get one, not a bare 401. Requests are retried with backoff on 429/5xx, and responses are cached for 30 days by default (the opposite default from the mirror half's caching, see below) -- EPA's API has no documented rate limit, but it's still a live government service, not an unlimited public mirror, so repeatedly re-fetching the same lookup in a loop is worth avoiding by default.

Endpoint coverage here is intentionally a starting set (one real, verified path per microservice), not a full reimplementation of ctx-python -- that package already covers Chemical/Exposure/Hazard comprehensively. This package's actual differentiator is the bioactivity mirror above, which ctx-python doesn't cover at all.

Working offline (mirror half)

Off by default, since zero setup is the whole point of the mirror:

comptox.enable_cache()
df = comptox.pubchem_bridge()  # downloads the file once, then reads from disk

Downloads to ~/.cache/scigantic-comptox (override with enable_cache(cache_dir=...) or the SCIGANTIC_COMPTOX_CACHE environment variable). Concurrent callers racing the first download of the same file wait for it rather than each downloading their own copy.

connect(), query(), and bioactivity() don't participate in this (registering the underlying views eagerly would mean the first call for any release downloads the full ~600MB regardless of what the query actually touches); use comptox.cache_resolve("v4_3/derived/pubchem_bridge.parquet") to cache a specific file yourself.

The live REST half has its own separate cache, ON by default (comptox.disable_ctx_cache() to turn it off) -- see above for why the two halves use opposite defaults.

What's mirrored

comptox.releases()
release bioactivity pubchem bridge structures
v4_3 yes yes no

This table isn't hardcoded. releases() reads a small manifest published alongside each mirror run.

Command line

$ scigantic-comptox info
$ scigantic-comptox query "SELECT count(*) FROM bioactivity" --release v4_3

License

MIT-0. See LICENSE. This covers the code in this package only.

Data license

EPA's invitrodb v4.3 (ToxCast bioactivity data) is CC0 -- public domain, no attribution or share-alike terms to track. A courtesy citation is appreciated, not required: Filer, D.L. et al. (2017), tcpl: the ToxCast pipeline for high-throughput screening data, Bioinformatics, doi:10.1093/bioinformatics/btw680.

Download files

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

Source Distribution

scigantic_comptox-0.1.0.tar.gz (23.0 kB view details)

Uploaded Source

Built Distribution

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

scigantic_comptox-0.1.0-py3-none-any.whl (21.5 kB view details)

Uploaded Python 3

File details

Details for the file scigantic_comptox-0.1.0.tar.gz.

File metadata

  • Download URL: scigantic_comptox-0.1.0.tar.gz
  • Upload date:
  • Size: 23.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.11.16

File hashes

Hashes for scigantic_comptox-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b53cea967b68b5d18496e7555751c94b9856c233368f3220bf08ad1bfa0696d1
MD5 ff5cd7b341ff644d30231b854ee4107c
BLAKE2b-256 c9fa1fc108cd751050d2f15848dc1e770e21050406baf0855cf69a81b26f37a4

See more details on using hashes here.

File details

Details for the file scigantic_comptox-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for scigantic_comptox-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0326df8b4aa8193479114a8b2994dc0ba6eec89318a27e88b6c9c5d3e0e67fbc
MD5 6b81a2606bda194220560ae548a89ba4
BLAKE2b-256 f1e9a9fd02770df93c0df333c335007263cf3fc0ae134edf66e4d7c944f2b791

See more details on using hashes here.

Release history Release notifications | RSS feed

0.3.0

2 files

0.2.0

2 files

0.1.1

2 files

This release

0.1.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page