Skip to content

DRAFT: CHEBI-route related_ingredients suggester (issue #30, pending MIM#119)#215

Closed
realmarcin wants to merge 1 commit into
mainfrom
feat/draft-ingredient-suggester
Closed

DRAFT: CHEBI-route related_ingredients suggester (issue #30, pending MIM#119)#215
realmarcin wants to merge 1 commit into
mainfrom
feat/draft-ingredient-suggester

Conversation

@realmarcin

Copy link
Copy Markdown
Contributor

⚠️ DRAFT — do not merge until MediaIngredientMech#119 confirms the CHEBI route (ask c).
Everything is implemented, tested, and green; this is parked ready to finalize.

Context

The ingredient analog of the media suggester (#211), built now so it lands the
moment MIM confirms. It links via the ingredient's CHEBI term
(RelatedIngredient.chebi_term) — the "CHEBI route" — which needs no
MediaIngredientMech:NNNNNN id (the schema pattern MIM doesn't use; see MIM#119).

What

  • cross_repo_environment.py: IngredientHit + mim_ingredients_by_environment()
    (byte-prefiltered; chebi_id set only when the MIM identifier is a CHEBI CURIE),
    plus get_chebi_adapter() and a shared _cached_oak_adapter() helper.
  • scripts/suggest_related_ingredients.py + just suggest-related-ingredients:
    for each community, matches environment_term against MIM environmental_context
    and emits related_ingredients blocks:
    • chebi_term with the canonical ChEBI label (resolved from the local ChEBI
      sqlite — not MIM's free-text name) so the id↔label gate stays green;
    • shared_environment_term (the ENVO join key);
    • skips already-linked CHEBI ids, generic environments, and records whose
      canonical label can't be resolved (reported, not silently dropped);
    • --subsumption supported; suggestion-only, prints a DRAFT banner.
  • Tests: test_suggest_related_ingredients.py + a mim_ingredients_by_environment
    case (fake OAK adapters, offline).

Verified

An emitted block LinkML-validates in a real record — Sulfur (CHEBI:26833, label
"sulfur atom") for a hot-spring phototrophic mat community
, keyed on shared
ENVO:00000051.

Honest yield

~3 CHEBI-identified MIM env-context ingredients today, so immediate output is tiny.
The tool scales as MIM populates environmental_context (the field it committed to
in MIM#1). This PR is about having the capability ready, not bulk output.

Before finalizing

  • MIM#119 ask (c): confirm citing the ingredient's CHEBI: id is an acceptable
    cross-repo link. If yes → mark ready, merge. If MIM prefers MIM:<name> → add a
    mim_id field and emit that instead (small change).

Verification

  • just test229 passed (+6)
  • just lint — black + ruff + mypy clean

🤖 Generated with Claude Code

…MIM#119)

The ingredient analog of the media suggester, ready to finalize once MIM confirms
the CHEBI route (MediaIngredientMech#119 ask c). For each community, matches
environment_term against MIM environmental_context and emits RelatedIngredient
blocks via the ingredient's CHEBI term — no MediaIngredientMech:NNNNNN id needed.

- cross_repo_environment.py: IngredientHit + mim_ingredients_by_environment()
  (chebi_id set only when the MIM identifier is a CHEBI CURIE); get_chebi_adapter()
  and a shared _cached_oak_adapter() helper.
- scripts/suggest_related_ingredients.py + `just suggest-related-ingredients`:
  emits chebi_term + shared_environment_term (+ preferred_term); resolves the
  CANONICAL ChEBI label (not MIM's free-text name) so the id-label gate stays green;
  skips/reports records with an unresolvable label; supports --subsumption; skips
  already-linked CHEBI ids and generic environments. Suggestion-only. Prints a
  DRAFT banner.
- tests/test_suggest_related_ingredients.py + a mim_ingredients_by_environment case.

Verified an emitted block LinkML-validates in a real record (Sulfur CHEBI:26833 for
a hot-spring mat community, keyed on ENVO:00000051). Current yield is tiny (~3
CHEBI-identified MIM env ingredients today); scales as MIM populates
environmental_context.

Held as a DRAFT PR — do not merge until MIM#119 confirms the CHEBI route.

229 tests pass; lint clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@realmarcin
realmarcin force-pushed the feat/draft-ingredient-suggester branch from 046a482 to 5eda920 Compare July 19, 2026 23:26
realmarcin added a commit that referenced this pull request Jul 20, 2026
MIM#119 (now closed as answered) settled the two blockers: MediaIngredientMech:NNNNNN
is vestigial (drop it), and the equivalence-safe join is the ingredient's CHEBI term
from MIM's SSSOM skos:exactMatch rows — NOT the record identifier field, NOT
close/narrowMatch (which would generalise). Coverage is 10 environmental_context
records, not ~44.

Rebuilt the suggester (supersedes draft PR #215) on that basis:
- cross_repo_environment.py: mim_exactmatch_chebi() parses the SSSOM (skipping the #
  preamble; keeps only skos:exactMatch → CHEBI:); mim_ingredients_by_environment()
  joins each environmental_context record (MIM:<file-stem> subject) to it and scans
  data/ingredients/ (not the repo root — MIM keeps multi-MB aggregate dumps under
  data/curated/ that would blow up YAML parsing). + get_chebi_adapter/_cached_oak_adapter.
- scripts/suggest_related_ingredients.py + `just suggest-related-ingredients`: emits
  RelatedIngredient with chebi_term (CANONICAL ChEBI label, not MIM's free-text name,
  so the id-label gate stays green) + shared_environment_term; env keys are
  environment_term + modeled_environment; --subsumption supported; skips already-linked
  CHEBI ids, generic envs, and unresolved labels (reported). Not a draft.
- tests: SSSOM join (exactMatch/narrowMatch/non-CHEBI filtering) + suggester helpers.

Verified: real run emits Sulfur (CHEBI:26833, "sulfur atom") for the hot-spring mat
community (exact ENVO:00000051 match); block LinkML-validates. Yield is 1 today —
data-limited by MIM's 10 context records, correct and scales. 254 tests pass; lint clean.

Follow-up (NEXT_TASKS): drop the vestigial ^MediaIngredientMech:\d{6}$ pattern from
RelatedIngredient.mediaingredientmech_id.

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

Copy link
Copy Markdown
Contributor Author

Superseded by #220, which rebuilds the ingredient suggester on MIM#119's resolution (CHEBI route via SSSOM skos:exactMatch, not the record identifier field). Closing this draft.

@realmarcin realmarcin closed this Jul 20, 2026
realmarcin added a commit that referenced this pull request Jul 20, 2026
…#220)

MIM#119 (now closed as answered) settled the two blockers: MediaIngredientMech:NNNNNN
is vestigial (drop it), and the equivalence-safe join is the ingredient's CHEBI term
from MIM's SSSOM skos:exactMatch rows — NOT the record identifier field, NOT
close/narrowMatch (which would generalise). Coverage is 10 environmental_context
records, not ~44.

Rebuilt the suggester (supersedes draft PR #215) on that basis:
- cross_repo_environment.py: mim_exactmatch_chebi() parses the SSSOM (skipping the #
  preamble; keeps only skos:exactMatch → CHEBI:); mim_ingredients_by_environment()
  joins each environmental_context record (MIM:<file-stem> subject) to it and scans
  data/ingredients/ (not the repo root — MIM keeps multi-MB aggregate dumps under
  data/curated/ that would blow up YAML parsing). + get_chebi_adapter/_cached_oak_adapter.
- scripts/suggest_related_ingredients.py + `just suggest-related-ingredients`: emits
  RelatedIngredient with chebi_term (CANONICAL ChEBI label, not MIM's free-text name,
  so the id-label gate stays green) + shared_environment_term; env keys are
  environment_term + modeled_environment; --subsumption supported; skips already-linked
  CHEBI ids, generic envs, and unresolved labels (reported). Not a draft.
- tests: SSSOM join (exactMatch/narrowMatch/non-CHEBI filtering) + suggester helpers.

Verified: real run emits Sulfur (CHEBI:26833, "sulfur atom") for the hot-spring mat
community (exact ENVO:00000051 match); block LinkML-validates. Yield is 1 today —
data-limited by MIM's 10 context records, correct and scales. 254 tests pass; lint clean.

Follow-up (NEXT_TASKS): drop the vestigial ^MediaIngredientMech:\d{6}$ pattern from
RelatedIngredient.mediaingredientmech_id.

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@realmarcin
realmarcin deleted the feat/draft-ingredient-suggester branch July 20, 2026 18:19
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