fix: handle compound ontology ids in translate()#33
Merged
jkobject merged 1 commit intoMay 20, 2026
Merged
Conversation
translate() resolved each ontology id with a single `.filter(ontology_id=...).one()` call. CellxGene records multi-ethnic donors with comma-joined ids (e.g. "HANCESTRO:0005,HANCESTRO:0008"), which match no single term, so `.one()` raised ObjectDoesNotExist and aborted the whole run. Add a `_lookup_name` helper that splits comma-joined ids, resolves each part, and rejoins the names. It uses `.one_or_none()` so a genuinely unknown id degrades to None instead of raising. All four branches of translate() now go through the helper; return types are unchanged. Adds tests/test_translate.py covering single, compound, unknown, and mixed ids with a mock registry (no ontology DB needed). Refs jkobject/scPRINT#49
3 tasks
jkobject
pushed a commit
to cantinilab/scPRINT
that referenced
this pull request
May 20, 2026
make_adata calls translate() to fill the cosmetic conv_* columns with human-readable names. translate() can raise on ids it cannot resolve (e.g. comma-joined CellxGene ethnicity terms a model may predict), which aborts the entire prediction/embedding run. Wrap the translate() calls so an unresolved id warns and skips the conv_* column instead of crashing. The actual predictions (pred_*) are unaffected. The root cause is also fixed upstream in scdataloader's translate() (jkobject/scDataLoader#33); this keeps scPRINT robust regardless of the installed scdataloader version. Closes #49
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #33 +/- ##
==========================================
+ Coverage 48.09% 48.91% +0.81%
==========================================
Files 10 10
Lines 1969 1977 +8
==========================================
+ Hits 947 967 +20
+ Misses 1022 1010 -12 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This was referenced May 20, 2026
This was referenced May 20, 2026
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.
Problem
translate()resolves each ontology id with a single.filter(ontology_id=...).one()call. CellxGene records multi-ethnic donors with comma-joined ids, e.g.self_reported_ethnicity_ontology_term_id = "HANCESTRO:0005,HANCESTRO:0008". That string matches no single ontology term, so.one()raisesObjectDoesNotExistand the whole run aborts.This is what scPRINT users hit in jkobject/scPRINT#49 — a model that predicts ethnicity emits compound labels (they were in the training vocabulary), and
translate()crashes the entire embedding run on them.Fix
Add a
_lookup_name(obj, ontology_id)helper that:"HANCESTRO:0005,HANCESTRO:0008"→"European,African");.one_or_none()so a genuinely unknown id degrades toNoneinstead of raising.All four branches of
translate()(str / dict / set / list) now go through the helper. Return types and shapes are unchanged — only two behaviour changes, both strict improvements: compound ids resolve instead of crashing, and unknown ids returnNoneinstead of raising.Tests
Adds
tests/test_translate.py— covers single, compound, unknown, mixed, and whitespace cases using a mock registry, so it runs without a populated ontology database. (.one_or_none()is confirmed present in the pinnedlamindb==2.1.1.)Refs jkobject/scPRINT#49