Repository navigation
fix(svar2): restore the anchor base in alt_window for empty-ALT deletions - #426
Merged
Merged
Conversation
…ions svar2 stores an atomized pure deletion at the VCF anchor position with an empty ALT, while its [start, end) span (and so ref_window) still covers the anchor. alt_window = flank5 . alt . flank3 therefore dropped the anchor base (ref ATG|CTT|TTT gave alt ATG||TTT instead of ATG|C|TTT), disagreeing with both the reconstructed haplotype and the .svar alt window. assemble_windows_mode now re-inserts the anchor (the first byte of the variant's ref-window span) for empty-ALT variants with ilen < 0 before assembling the alt window; the Python oracle mirrors it. ref_window and alt_window are now byte-identical across .svar and .svar2. Bare ALT bytes (variants output, VarWindowOpt(alt="allele")) are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01X11f2FuuJZe7r98XAAJbui
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.
Bug
On a
.svar2-backed dataset,with_seqs("variant-windows", VarWindowOpt(ref="window", alt="window"))returned analt_windowthat drops the anchor base of a pure deletion.ref_windowkept it:genoray's svar2 stores an atomized pure deletion at the VCF anchor position with an empty ALT (
b"").start/ilenare the same as.svar'sGTA>G, so the[start, end)span andref_windowinclude the anchor.alt_windowis assembled asflank5 . alt . flank3, so an empty ALT lost a base. The result matched neither the reconstructed haplotype, which already restoresref[pos]for an empty-ALT deletion, nor the.svaralt window. The docs called the difference a "format convention". This reproduces onmain(0.43.1).Fix
assemble_windows_mode(src/variants/windows.rs) now calls a newanchor_empty_del_altsbeforeassemble_alt_window. For every variant with an empty ALT andilen < 0, it inserts the anchor, which is the first byte of that variant's ref-window span (rw_data[rw_off[i] + L]). When no variant needs this it returnsNone, so there is no copy, which is always the case on.svar. The Python parity oracle (_flat_flanks._anchor_empty_del_alts, used bycompute_alt_window/compute_windows) mirrors it.I chose this over making the svar2 ref span atomized (dropping the anchor from
ref_window). That alternative would break the existing byte-identicalref_window,startandilenparity with.svar, and it would change theend = start - min(ilen, 0) + 1window convention that the flank paths share.Not changed:
RaggedVariants.altfrom"variants", andVarWindowOpt(alt="allele")) stayb""on svar2. That is the stored allele, and the docs now describe it as the only difference.ilen = len(ALT) - 1), so they were not affected.flank_tokens/ref_windowread only the reference around the shared span, so they were not affected.dummy_variantfill is backend-independent (all-unkwindows).Tests
test_svar2_variant_windows_alt_window_matches_svar1[unphased_union=False/True]uses the existing matched.svar/.svar2fixture (SNP, insertion, dense SNP andGTA>G). It checks thatref_windowandalt_windoware byte-identical across backends, and that on both backends each window equals the FASTA with that single VCF variant applied (ref[s-L:s] . ALT_vcf . ref[e:e+L], OOB padded with N). It also asserts that a deletion, an insertion and an SNV are all present.test_svar2_variant_windows_dummy_matches_svar1covers the windows withdummy_variantset.test_svar2_variant_windows_alt_window_decompositionhad pinned the buggy decomposition. It now expects the anchor for an empty bare ALT and asserts that the fixture contains one.test_anchor_empty_del_alts.test_svar2_flank_tokens_match_svar1documents a separate gap I found: svar2 returnsRaggedVariantsfor flat"variants"output, soflank_tokensare never produced on svar2. I did not fix that here.main's kernel (extension rebuilt): the 4 window tests fail withalt_window seq_offsets differ. With the fix: 30 passed and 1 xfailed intests/dataset/test_svar2_dataset.py.pixi run -e dev test: pytest 1332 passed, 52 skipped, 5 xfailed.cargo test --releasepasses (135 + 4). Ruff check and format are clean, and the docstring-style check passes.Docs
faq.md,format.md(the section is renamed to ".svar2pure-deletion ALT bytes") and thegenvarloaderskill now limit the svar2/svar difference to bare ALT bytes and state that both windows are byte-identical. The changelog is generated from the commit message.Behaviour change
Users who relied on svar2's
alt_windowlacking the anchor will now see one more token per pure-deletion window. Window lengths for those variants change from2Lto2L + 1, the same as on.svar. Downstream workarounds that rebuild the anchor only when the ALT is empty become no-ops.🤖 Generated with Claude Code
https://claude.ai/code/session_01X11f2FuuJZe7r98XAAJbui