Skip to content

Reorder KEGG compound resolution to check ChEBI/PubChem bulk sources first - #9

Draft
m-crown wants to merge 1 commit into
feature/reference-data-downloadfrom
feature/kegg-bulk-source-priority
Draft

Reorder KEGG compound resolution to check ChEBI/PubChem bulk sources first#9
m-crown wants to merge 1 commit into
feature/reference-data-downloadfrom
feature/kegg-bulk-source-priority

Conversation

@m-crown

@m-crown m-crown commented Aug 9, 2026

Copy link
Copy Markdown
Member

Summary

  • Reorders get_kegg_compound_record's resolution logic to check ChEBI/PubChem's bulk cross-reference data before falling back to a live KEGG structure-fetch call.
  • Investigation found 93.0% of the KEGG COMPOUND catalog already has a structure via ChEBI or PubChem's bulk data; of the naive 7.0% "KEGG-exclusive" remainder, only ~54% (3.76% of the full catalog) are genuine structurally-defined molecules. Reordering cuts roughly 25x the unnecessary live KEGG calls.

Stacked on #8 (feature/reference-data-download) — this PR's diff is scoped to just the KEGG reordering work.

Test plan

  • Confirm get_kegg_compound_record returns identical structures to before for compounds covered by ChEBI/PubChem, sourced without a live KEGG call
  • Confirm live KEGG fallback still triggers correctly for genuinely KEGG-exclusive compounds

🤖 Generated with Claude Code

…first

get_ec_information.py's KEGG-direct compound-structure lookup
(get_kegg_compound_record/get_kegg_compound_smiles) previously ran
unconditionally for every unique KEGG compound code seen across all EC
reactions, hitting rest.kegg.jp once per compound with no rate limiting
of its own (unlike get_kegg_enzymes/get_kegg_reactions, which chunk and
throttle). ChEBI and PubChem resolution ran independently afterward,
meaning every compound got a live KEGG call regardless of whether a
bulk/cheap source already had it.

Per the coverage analysis in docs/cognate_ligands_generation_plan.md
("Question 3": ~93% of KEGG compound codes seen in reactions already have
a structure via ChEBI's bulk file or PubChem's batched CID lookup), moved
the ChEBI and PubChem blocks to run first, then filter the KEGG-direct
lookup to only the compound codes neither of those confirmed resolved.

Deliberately conservative on PubChem: codes are only excluded from the
KEGG-direct fallback after PubChem's own live batched CID->SMILES call
confirms a structure, not just because a CID mapping exists in the bulk
file - avoids any coverage regression for the rare code that has a
mapping but doesn't actually resolve. Net effect on final cognate ligand
coverage: none, by construction - purely a reduction in unnecessary live
KEGG traffic.

Left a second, separate get_kegg_compound_record call site (inside the
PubChem block, fetching full KEGG records just for a display name) alone
- smaller, lower-priority optimization, out of scope here.

Verified via py_compile, a duplication check, and an isolated logic test
against synthetic data mimicking the real post-filter shapes. Not run
against the full live pipeline (requires complete data_dir setup and
hours of upstream KEGG enzyme/reaction fetching before reaching this
code) - see docs/SESSION_HANDOFF.md for what verification was and wasn't
possible in-session.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant