Repository navigation
feat(svar2): flat "variants" output with ride-along flank_tokens - #428
Merged
Merged
Conversation
On a .svar2-backed dataset, with_seqs("variants").with_output_format("flat")
silently returned RaggedVariants, so flank_tokens were never produced. Svar2Haps
now honors `flat`: it decodes the block once (shared `_decode_variants`, the same
read-bound decode the ragged path uses) and runs the shared variants-mode
assemble_variant_buffers kernel over the decoded arrays via an identity gather,
returning FlatVariants with flank_tokens, as SVAR1's get_variants_flat does.
Flat output matches .svar field for field (alt, start, ilen when requested,
store INFO/FORMAT fields, flank_tokens) except the documented bare-ALT
convention: a pure deletion's alt is b"" on .svar2. start/ilen are identical
(the deletion starts at the anchor), so the flank span and flank_tokens are
byte-identical without re-anchoring. Flank tokens stay reference-oriented on
negative strands; alt is RC'd by the caller, as for .svar.
Ragged svar2 "variants" output also silently ignored dummy_variant; it now
fills empty groups like .svar (routed through the flat fill + to_ragged).
The strict xfail test_svar2_flank_tokens_match_svar1 is now a real test, plus
.svar vs .svar2 flat parity tests over phased/unphased_union, dummy_variant,
var_fields, minus strand, multi-contig, store fields, the buffered dataloader,
and the max_jitter>0 guard.
Closes #427
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X11f2DWnh5PcaTMo2g6JQT
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.
Closes #427
Problem
On a
.svar2-backed dataset,with_seqs("variants").with_output_format("flat")returnedRaggedVariantsand never raised, so the ride-alongflank_tokenswere never produced.Design
Svar2Haps.__call__now honorsflatforvariants. A new_decode_variantsholds the existing read-bound decode and contig-group stitching, and the ragged and flat outputs both wrap its result.assemble_variant_bufferskernel that.svar'sget_variants_flatuses, over the decoded arrays through an identity gather. It returnsFlatVariants(alt,start,ilenwhen requested, store INFO/FORMAT fields) plusflank_tokens. No Rust changes..svar2a pure deletion'saltisb""(.svarkeeps the anchor).start/ilenare identical on both backends because the deletion starts at the anchor, so the flank span[start, start - min(ilen,0) + 1)and thereforeflank_tokensare byte-identical. Unlikealt_window, no re-anchoring is needed. Flank tokens stay reference-oriented on minus strands.altis reverse-complemented by the caller, as for.svar..svar2variantsoutput ignoreddummy_variantwithout raising. It now fills empty groups the way.svardoes.Supported / raises
.svar: phased,unphased_union,dummy_variant,var_fields(with and withoutilen, plus store INFO/FORMAT fields), minus strand, multi-contig,var_filter="exonic", andto_dataloader(mode="buffered" | "double_buffered").max_jitter>0orjitter>0still raisesNotImplementedError(right-clip). Spliced variants still require ragged output (ValueError, same as.svar).Tests
test_svar2_flank_tokens_match_svar1is now a regular test..svarand.svar2flat output (12-way parametrization: union × dummy × var_fields, on a mixed-strand bed), minus-strand RC, multi-contig, store fields vs ragged, buffered dataloader, the jitter guard, and raggeddummy_variantparity.pixi run -e dev test: 1352 passed, 52 skipped, 4 xfailed.cargo testpasses. ruff, ruff format, pyrefly, and the docstring check are clean.Perf
1kg test data (100 × 10 kb regions, 5 samples, about 14.8k variants,
L=16):.svar2flat output takes 4.8 ms against 1.6 ms for.svar..svar2ragged without flanks takes 3.5 ms. On rows where both backends return the same variants,flank_tokensare identical. The 6 of 1000 rows that differ come from variants.svarincludes up to 55 bp past the region end. That difference already shows up in ragged output, so it is not related to this PR.Docs
faq.md,format.md(svar2 supported list and pure-deletion section), andskills/genvarloader/SKILL.md.🤖 Generated with Claude Code
https://claude.ai/code/session_01X11f2DWnh5PcaTMo2g6JQT