Handle recombinant parents given in unaliased form - #319
Open
jchorl wants to merge 1 commit into
Open
Conversation
collapse_barcodes looks up the recombinant parents of a lineage by name in the lineage hierarchy, but pango-designation occasionally specifies them in unaliased form: the parents of XHD are listed as XFG.3.4.1 and XDV.1.5.1.1.8.1, the latter being the unaliased form of NB.1.8.1. Since only lineage names are keys of lineage_data, demixing any sample whose barcodes collapse a group containing XHD failed with KeyError: 'XDV.1.5.1.1.8.1'. Map recombinant parents back to lineage names when the hierarchy is loaded. The KeyError raised when a lineage is missing from the hierarchy entirely was also only caught for reporting, and execution then fell through to use a pango_aliases that was undefined (or left over from the previous group), so a hierarchy behind the barcode file raised UnboundLocalError or silently mislabelled a group. Per-group MRCA resolution now lives in get_group_mrca, and a group that cannot be resolved is grouped into Misc with a warning instead of failing the run. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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
freyja demix --depthcutoff <n>crashes for any sample whose barcodescollapse a group containing XHD:
collapse_barcodeslooks up recombinant parents by lineage name, butpango-designation's
alias_key.jsonlists XHD's parents as["XFG.3.4.1", "XDV.1.5.1.1.8.1"]— the second being the unaliased form ofNB.1.8.1, which is only ever an
alias:value inlineages.yml, never aname:. XHD is the only entry inalias_key.jsonwith this inconsistency(
lineage_notes.txtcorrectly says "Recombinant lineage of XFG.3.4.1,NB.1.8.1"), and it entered the barcodes with the 08_27_2026 update.
Low-coverage samples hit this readily: at
--depthcutoff 1with ~90% of thegenome at zero depth, nearly every barcode column is dropped and thousands
of lineages collapse into multi-class groups.
Changes
so either form resolves.
get_group_mrca(). A group thatcan't be resolved is now grouped into
Miscwith a warning instead ofaborting. The previous
except KeyErrorprinted a message and fellthrough, leaving
pango_aliasesundefined (UnboundLocalError) or stalefrom the previous group, so a hierarchy behind the barcode file was never
actually handled.
get_path_to_root()promoted to module level (was redefined per iteration).testing the code path if pango corrects the XHD entry upstream.
Testing
mainwithKeyError/UnboundLocalError, pass here.test_utilsresults.AI Disclaimer
I hit this issue and had AI help me resolve. I am fairly new to this codebase. If you are uncomfortable with this and don't have time to further investigate, feel free to close.