Skip to content

fix(svar2): restore the anchor base in alt_window for empty-ALT deletions - #426

Merged
d-laub merged 1 commit into
mainfrom
fix/svar2-deletion-alt-window
Nov 17, 2026
Merged

d-laub merged 1 commit into
mainfrom
fix/svar2-deletion-alt-window

Conversation

@d-laub

@d-laub d-laub commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator

Bug

On a .svar2-backed dataset, with_seqs("variant-windows", VarWindowOpt(ref="window", alt="window")) returned an alt_window that drops the anchor base of a pure deletion. ref_window kept it:

ref_window  ATG|CTT|TTT
alt_window  ATG||TTT      (expected ATG|C|TTT, which .svar returns)

genoray's svar2 stores an atomized pure deletion at the VCF anchor position with an empty ALT (b""). start/ilen are the same as .svar's GTA>G, so the [start, end) span and ref_window include the anchor. alt_window is assembled as flank5 . alt . flank3, so an empty ALT lost a base. The result matched neither the reconstructed haplotype, which already restores ref[pos] for an empty-ALT deletion, nor the .svar alt window. The docs called the difference a "format convention". This reproduces on main (0.43.1).

Fix

assemble_windows_mode (src/variants/windows.rs) now calls a new anchor_empty_del_alts before assemble_alt_window. For every variant with an empty ALT and ilen < 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 returns None, so there is no copy, which is always the case on .svar. The Python parity oracle (_flat_flanks._anchor_empty_del_alts, used by compute_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-identical ref_window, start and ilen parity with .svar, and it would change the end = start - min(ilen, 0) + 1 window convention that the flank paths share.

Not changed:

  • Bare ALT bytes (RaggedVariants.alt from "variants", and VarWindowOpt(alt="allele")) stay b"" on svar2. That is the stored allele, and the docs now describe it as the only difference.
  • Insertions: the svar2 ALT already includes the anchor (ilen = len(ALT) - 1), so they were not affected.
  • flank_tokens / ref_window read only the reference around the shared span, so they were not affected.
  • The dummy_variant fill is backend-independent (all-unk windows).

Tests

  • New test_svar2_variant_windows_alt_window_matches_svar1[unphased_union=False/True] uses the existing matched .svar/.svar2 fixture (SNP, insertion, dense SNP and GTA>G). It checks that ref_window and alt_window are 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.
  • New test_svar2_variant_windows_dummy_matches_svar1 covers the windows with dummy_variant set.
  • test_svar2_variant_windows_alt_window_decomposition had pinned the buggy decomposition. It now expects the anchor for an empty bare ALT and asserts that the fixture contains one.
  • New Rust unit test test_anchor_empty_del_alts.
  • New strict-xfail test_svar2_flank_tokens_match_svar1 documents a separate gap I found: svar2 returns RaggedVariants for flat "variants" output, so flank_tokens are never produced on svar2. I did not fix that here.
  • On main's kernel (extension rebuilt): the 4 window tests fail with alt_window seq_offsets differ. With the fix: 30 passed and 1 xfailed in tests/dataset/test_svar2_dataset.py.
  • Full pixi run -e dev test: pytest 1332 passed, 52 skipped, 5 xfailed. cargo test --release passes (135 + 4). Ruff check and format are clean, and the docstring-style check passes.

Docs

faq.md, format.md (the section is renamed to ".svar2 pure-deletion ALT bytes") and the genvarloader skill 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_window lacking the anchor will now see one more token per pure-deletion window. Window lengths for those variants change from 2L to 2L + 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

…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
@d-laub
d-laub marked this pull request as ready for review November 17, 2026 23:34
@d-laub
d-laub merged commit 0bfed87 into main Nov 17, 2026
7 of 8 checks passed
@d-laub
d-laub deleted the fix/svar2-deletion-alt-window branch November 17, 2026 23:34
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