fix: select VCF output compression by file extension#16
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughAdds a new ChangesExtension-aware VcfWriter for mutate and methylate
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
861c217 to
f7d00e8
Compare
|
@coderabbitai review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/commands/methylate.rs (1)
79-81:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winUpdate the output flag help text to match extension-aware compression.
Line 79 still states BGZF-only output, but this command now writes plain text for non-
.gz/.bgzpaths. Please align the doc string with current behavior.Suggested patch
- /// Output methylation-annotated VCF (BGZF-compressed). + /// Output methylation-annotated VCF. + /// Compression follows the output extension: + /// `.gz`/`.bgz` => BGZF, otherwise plain text.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/commands/methylate.rs` around lines 79 - 81, The doc comment for the output field in the methylate command currently states that output will be BGZF-compressed, but the actual implementation now conditionally compresses based on file extension (.gz or .bgz extensions result in BGZF compression, while other extensions produce plain text output). Update the doc string for the output field to accurately reflect this extension-aware compression behavior instead of unconditionally stating BGZF compression.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@src/commands/methylate.rs`:
- Around line 79-81: The doc comment for the output field in the methylate
command currently states that output will be BGZF-compressed, but the actual
implementation now conditionally compresses based on file extension (.gz or .bgz
extensions result in BGZF compression, while other extensions produce plain text
output). Update the doc string for the output field to accurately reflect this
extension-aware compression behavior instead of unconditionally stating BGZF
compression.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 4ea3914a-b537-495c-9a13-fdc7cafab18c
📒 Files selected for processing (5)
CHANGELOG.mdsrc/commands/methylate.rssrc/commands/mutate.rssrc/vcf/mod.rssrc/vcf/writer.rs
tfenne
left a comment
There was a problem hiding this comment.
Thanks for fixing this. LGTM. I merged your other PR first, so I think this one will need a quick rebase/merge and then we can merge it.
`mutate` always wrote uncompressed text and `methylate` always wrote BGZF, regardless of the output path. noodles' VCF reader picks its codec from the file extension alone (`.gz`/`.bgz` -> BGZF, else plain), never sniffing the magic bytes. So `mutate -o muts.vcf.gz` produced plain text that `simulate` rejected with an opaque BGZF error (you had to re-bgzip the file by hand), and the mirror trap bit `methylate -o meth.vcf`, which wrote a BGZF stream the reader then treated as plain text. Add a `VcfWriter` that picks the codec from the path the same way the reader does -- BGZF when (and only when) it ends in `.gz`/`.bgz`, plain text otherwise -- and route both subcommands through it. The two codecs are enum variants so `close` can call BGZF's consuming `finish` and surface a failed EOF-block write, rather than swallowing it in `Drop`. Output now round-trips through `simulate`/`methylate` regardless of name.
f7d00e8 to
3a3689e
Compare
Summary
holodeck mutate -o muts.vcf.gzwrote plain uncompressed text into a.gz-named file, so piping it straight intoholodeck simulatefailed with an opaqueinvalid BGZF header— you had to re-bgzipthe file by hand first. The mirror trap bitmethylate -o meth.vcf, which always wrote BGZF, producing a BGZF stream the reader then treated as plain text.Root cause: noodles' VCF reader (
vcf::io::reader::Builder::build_from_path) selects its codec from the file extension alone (.gz/.bgz→ BGZF, else plain), never sniffing the magic bytes. The writers didn't honor that convention —mutatenever compressed,methylatealways did.Fix
VcfWriter(src/vcf/writer.rs) picks the codec from the path the same way the reader does: BGZF when (and only when) it ends in.gz/.bgz, plain text otherwise. Modeled onFastqWriter/GoldenBamWriter— aBox<dyn Write>behindnew/close, whereclosedrops the inner writer to flush and emit the BGZF EOF block.mutateandmethylatethrough it.Output now round-trips through
simulate/methylateregardless of name.Test plan
cargo ci-fmtcleancargo ci-lintclean (clippy pedantic,-D warnings)cargo ci-test— full suite passes, including new coverage:writer.rs: extension detection (case-insensitive, final-extension-only);.gz→ gzip magic + trailing BGZF EOF block;.vcf→ uncompressed textmutate.rs:.vcf.gzoutput is real BGZF and reads back throughparse_variants_by_contig(thesimulatepath);.vcfoutput is plain text and also reads backtest_mutate/test_methylate/test_mutate_then_simulateintegration tests unchanged and greenmutate -o muts.vcf.gz→filereportsBGZF→simulate -v muts.vcf.gzsucceeds (33 read pairs) with no manual re-bgzipSummary by CodeRabbit
mutateandmethylatenow automatically choose BGZF compression when the output filename ends with.gzor.bgz(case-insensitive), and write plain text otherwise. This restores compatibility for round-tripping between writers and VCF readers for both compressed and uncompressed outputs..vcf.gzand.vcfoutputs.