Skip to content

ontologies: NCBITaxon .owl/.db version-alignment gate (completes #604)#607

Merged
realmarcin merged 3 commits into
masterfrom
feat/ncbitaxon-db-version-pin
Jul 22, 2026
Merged

ontologies: NCBITaxon .owl/.db version-alignment gate (completes #604)#607
realmarcin merged 3 commits into
masterfrom
feat/ncbitaxon-db-version-pin

Conversation

@realmarcin

Copy link
Copy Markdown
Collaborator

Completes the remaining piece of #604 (NCBITaxon .db release pinning; the GO portion + version-gate framework shipped in #606).

Problem

metatraits/lpsn/bacdive resolve taxa against the OAK-fetched ncbitaxon.db (whose release is whatever OAK last downloaded), while the NCBITaxon transform emits nodes from ncbitaxon.owl. Nothing pinned the two to the same release, so a drifted OAK cache could resolve lookups against different taxa than the transform emitted.

Change

  • assert_ncbitaxon_version_alignment(db_path) — compares ncbitaxon.owl's versionIRI release with the db's owl:versionInfo (read via a tiny SemSQL query, _ncbitaxon_db_release) and fails loudly on mismatch; KG_NCBITAXON_VERSION_CHECK=warn downgrades to a warning. No-op when either stamp is unreadable (fail-safe — only two readable-but-different stamps trip it).
  • Generalized _obo_release_from_head to match NCBITaxon's versionIRI form (ncbitaxon/DATE/, which has no releases/ segment, unlike GO).
  • Factored the shared strictness resolution into _version_check_strict (used by both gates).
  • Wired into metatraits _ensure_ncbitaxon_db_ready (both the happy-path and cache-repair success branches — the pre-flight validation that all consumers rely on).

Verification

  • Current sources both 2026-05-13 → gate passes silently (verified).
  • 7 new tests (owl/db release parsing, aligned / mismatch / env-warn / missing-stamp); GO gate + its 11 tests unchanged. CI-ruff (0.15.22) clean.

With this, #604 is fully addressed — both GO and NCBITaxon .owl/.db alignment are now gated.

🤖 Generated with Claude Code

Completes the remaining piece of #604. metatraits/lpsn/bacdive do label +
lineage lookups against the OAK-fetched ncbitaxon.db (whose release is
whatever OAK last downloaded), while the NCBITaxon transform emits nodes from
ncbitaxon.owl — nothing pinned the two to the same release.

- assert_ncbitaxon_version_alignment(db_path): compares ncbitaxon.owl's
  versionIRI release with the db's owl:versionInfo (via _ncbitaxon_db_release,
  a small SemSQL query) and fails loudly on mismatch; KG_NCBITAXON_VERSION_CHECK
  =warn downgrades to a warning. No-op when either stamp is unreadable.
- Generalized _obo_release_from_head to also match NCBITaxon's versionIRI form
  (`ncbitaxon/DATE/`, no `releases/` segment).
- Factored the strictness resolution shared with the GO gate into
  _version_check_strict.
- Wired the gate into metatraits `_ensure_ncbitaxon_db_ready` (both the
  happy-path and cache-repair success branches).

Verified on the current sources: ncbitaxon.owl and ncbitaxon.db are both
2026-05-13 → gate passes silently. 7 new tests (owl/db release parsing,
aligned/mismatch/env-warn/missing-stamp); GO gate unchanged (11 tests).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 22, 2026 01:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR completes the NCBITaxon half of #604 by adding a version-alignment gate that detects when the NCBITaxon OWL used by the ontologies transform and the SemSQL SQLite DB used for downstream lookups are from different releases, preventing silent drift across ontology artifacts.

Changes:

  • Extends _obo_release_from_head() to also parse NCBITaxon-style versionIRI stamps (.../ncbitaxon/YYYY-MM-DD/... without a releases/ segment).
  • Adds assert_ncbitaxon_version_alignment() (+ shared _version_check_strict() helper) and wires the NCBITaxon gate into metatraits’ _ensure_ncbitaxon_db_ready().
  • Adds a new focused test suite covering OWL/db release parsing and strict vs warn/no-op behaviors.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
kg_microbe/utils/ontology_utils.py Adds strictness resolution helper, extends OWL release parsing, and introduces NCBITaxon .owl/.db alignment gate + DB release reader.
kg_microbe/transform_utils/metatraits/metatraits.py Calls the new NCBITaxon alignment gate during metatraits’ DB preflight validation/repair.
tests/test_ncbitaxon_version_alignment.py New tests for NCBITaxon OWL/db stamp parsing and alignment gate behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +129 to +132
row = conn.execute(
"SELECT value FROM statements WHERE predicate = 'owl:versionInfo' "
"AND value IS NOT NULL LIMIT 1"
).fetchone()
Comment thread kg_microbe/utils/ontology_utils.py Outdated
Comment on lines +147 to +150
metatraits/lpsn/bacdive do label + lineage lookups against ``ncbitaxon.db``
(an OAK-fetched prebuilt SemSQL DB whose release is whatever OAK last
downloaded), while the NCBITaxon transform output is built from
``ncbitaxon.owl``. If the two are different releases, lookups can resolve
Comment thread kg_microbe/utils/ontology_utils.py Outdated
Comment on lines +167 to +169
f"NCBITaxon source version mismatch: ncbitaxon.owl={owl_release} vs "
f"ncbitaxon.db={db_release}. metatraits/lpsn/bacdive look taxa up in "
"ncbitaxon.db while the transform emits nodes from ncbitaxon.owl; the "
Addresses PR #607 review:
- #1 (MEDIUM): the gate only ran under `if use_mp:` — so sequential metatraits
  (METATRAITS_MULTIPROCESSING=false / single worker) skipped it entirely.
  Moved the alignment call to run unconditionally in run() (no-ops if the DB
  isn't materialized yet), keeping the MP-only cache-repair pre-flight as-is.
- #2 (MEDIUM): default the NCBITaxon gate to WARN, not raise — the OAK cache
  and the pinned ncbitaxon.owl legitimately drift (OAK auto-refreshes) and
  NCBITaxon labels/lineage are stable, so a mismatch is worth surfacing loudly
  but not aborting a previously-green run. KG_NCBITAXON_VERSION_CHECK=strict
  (or strict=True) opts back into fail-loud. _version_check_strict grew a
  per-gate default_strict; GO stays strict.
- #3 (LOW/MED): target the ontology node in the versionInfo query
  (`subject LIKE '%ncbitaxon%'`) instead of relying on a single row.
- #4 (LOW): correct the docstring/message — only metatraits invokes the gate
  (not lpsn/bacdive).
- Tests: default-warn, env-strict-upgrade, subject-targeting (decoy row), and
  corrupt-db→None (21 total; GO's 11 unchanged).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@realmarcin

Copy link
Copy Markdown
Collaborator Author

Review addressed. #1 (MEDIUM, the important one) — the gate only ran under if use_mp:, skipping sequential metatraits; moved it to run unconditionally in run() (no-ops if the db isn't materialized yet). #2 (MEDIUM) — NCBITaxon now defaults to warn (the OAK cache vs pinned ncbitaxon.owl legitimately drift, and labels/lineage are stable), with KG_NCBITAXON_VERSION_CHECK=strict to opt into fail-loud; GO stays strict. #3 — versionInfo query now targets the ontology subject (subject LIKE '%ncbitaxon%') + a decoy-row test. #4 — docstring/message corrected (only metatraits invokes it). Added subject-targeting, corrupt-db→None, default-warn and env-strict tests (21 total). Confirmed non-issues from review: regex has no GO regression, exception handling is adequate, symlink read works, _version_check_strict refactor is behavior-preserving. #5 (dead if not NCBITAXON_SOURCE guard) left as harmless defensive parity with the GO gate.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@realmarcin
realmarcin merged commit f31bd66 into master Jul 22, 2026
3 checks passed
@realmarcin
realmarcin deleted the feat/ncbitaxon-db-version-pin branch July 22, 2026 01:16
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.

2 participants