PR 4: Ontology resolution stage + CELLxGENE organism wiring - #7
Merged
Conversation
Add the shared `parce/ontology/` stage that grounds free-text design fields to ontology term IDs, the precondition for cross-source linking (ARCHITECTURE §5): - registry.py — Facet → ontology constant (EFO/OBI/PSI-MS, UBERON, MONDO, NCBITaxon, ChEBI, EDAM); pins ontologies, never IDs. - ols.py — OlsClient over OLS4 REST (search + is-a ancestors), injectable HTTP getter, retry-wrapped via sources._retry; CURIE→IRI + double-encoding. - cache.py — ResolutionCache: on-disk JSON, atomic, caches negative results. - layers.py — derive_molecular_layer(): EFO ancestor-label anchors, most-specific-first, UNKNOWN default. Anchors PROVISIONAL (see integration test). - resolver.py — OntologyResolver: cache → OLS exact-then-fuzzy → optional LLM fallback hook (default None, keeps ontology free of agent/Azure). Wire into CellxgeneNormalizer: organism string → NCBITaxon at runtime, replacing the hardcoded _ORGANISM_ONTOLOGY map. Unresolved organisms are skipped, not emitted ungrounded. Add MolecularLayer enum to models (consumed by PR 4b). Decisions: OLS4-only for now (text2term/Zooma deferred to GEO/PR 5); LLM fallback pluggable; anchors keyed by label not ID. Split the original PR 4: the schema change (store EFO assay term + molecular_layer) is now PR 4b. Gates: ruff, ruff format, mypy (no new exemptions), 121 unit tests — all green and hermetic (no .env, no network). No dependency changes. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
mengerj
marked this pull request as ready for review
June 25, 2026 06:11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Scope
Implements PR 4 — Ontology resolver from the roadmap: the shared
parce/ontology/resolution stage plus organism wiring into the CELLxGENEnormalizer. Every source's free-text design fields now resolve to the same
ontology IDs — the precondition for cross-source linking (ARCHITECTURE §5).
Split note: the original PR 4 also bundled the canonical-schema change
(replace free-text
modalitywith an EFOassayterm + a storedmolecular_layerfield). That migration is now PR 4b (new ▶ Next up). Themolecular_layerderivation is implemented here; only its storage on the nodesis deferred.
What's in it
ontology/registry.py—Facet→ ontology constant (EFO/OBI/PSI-MS, UBERON,MONDO, NCBITaxon, ChEBI, EDAM). Pins ontologies, not term IDs.
ontology/ols.py—OlsClientover OLS4 REST (search+is-aancestors),injectable HTTP getter (offline tests), retry-wrapped via
sources._retry.ontology/cache.py—ResolutionCache: on-disk JSON, atomic writes,negative results cached so unresolvable strings aren't re-queried.
ontology/layers.py—derive_molecular_layer(): EFO ancestor-labelanchors, most-specific-first, no-anchor default
UNKNOWN. Anchors areprovisional (unvalidated against live EFO).
ontology/resolver.py—OntologyResolver: cache → OLS exact-then-fuzzy →optional LLM fallback hook (default
None, keepsontologyfree of anyagent/Azure import; PR 5 wires the extraction agent in).models/graph_schema.py— adds theMolecularLayerenum (consumed by PR 4b).normalize/cellxgene.py— grounds the organism string to NCBITaxon at runtime,replacing the hardcoded
_ORGANISM_ONTOLOGYmap. Tissue/disease/assay keep theIDs Census already ships. Unresolved organisms are skipped, not emitted
ungrounded.
Decisions
characteristics_ch1strings appear (resolves an ARCHITECTURE §7 open question).direction preserved.
IDs"). A marked live-OLS integration test is the validation harness; PR 4b must
tighten the labels first.
Verification
All four CI gates pass locally, hermetic (worktree has no
.env, no network):ruff check .— cleanruff format --check .— 40 files formattedmypy src/parce— clean, 24 files, no new exemptionspytest -m "not integration"— 121 passed, 9 deselectedNew offline unit suites: registry, cache, OLS (fake HTTP), layers, resolver
(fake client + real cache on tmp_path). Live-OLS checks are
@pytest.mark.integration(excluded from CI). No dependency changes.🤖 Generated with Claude Code