Skip to content

fix: transparently handle regular-gzip (bcftools -O z) VCFs (#32)#107

Closed
jmg421 wants to merge 3 commits into
Bioconductor:develfrom
jmg421:fix/32-bgzf-detection
Closed

fix: transparently handle regular-gzip (bcftools -O z) VCFs (#32)#107
jmg421 wants to merge 3 commits into
Bioconductor:develfrom
jmg421:fix/32-bgzf-detection

Conversation

@jmg421

@jmg421 jmg421 commented Jul 6, 2026

Copy link
Copy Markdown

Problem

Files compressed with bcftools view -O z (or plain gzip) produce regular gzip, not BGZF. htslib's scanBcfHeader requires BGZF and throws [internal] _hts_rewind() failed when given a regular gzip file, making readVcf and scanVcfHeader unusable on such files.

Fix

Two new internal helpers in R/methods-readVcf.R:

  • .is_bgzf(path) — inspects the gzip extra-field sub-field magic bytes (0x42 0x43 = 'BC' at bytes 13–14) to distinguish BGZF from regular gzip.
  • .ensure_bgzf(path) — if a .gz file is not BGZF, transparently re-compresses it to a BGZF tempfile using Rsamtools::bgzip() and returns the temp path.

.ensure_bgzf() is called from:

  1. .checkFile() (used by readVcf) before the TabixFile() call
  2. The scanVcfHeader("character") method before scanBcfHeader()

A message is emitted so users know re-compression occurred.

Tests

Added test_regular_gzip_readVcf() in inst/unitTests/test_readVcf-methods.R which:

  • Builds a real regular-gzip copy of a package VCF
  • Asserts .is_bgzf() returns FALSE for it and TRUE for the original BGZF file
  • Asserts readVcf() succeeds and returns a non-empty CollapsedVCF

All existing test_readVcf-methods.R tests continue to pass.

Closes #32

vjcitn and others added 2 commits July 17, 2026 21:15
Convert \itemize blocks that used \item{label}{desc} syntax to \describe,
and replace empty \item{}{} labels in \describe blocks with the function
signature from the body, resolving all checkRd warnings in isSNV-methods,
PolyPhenDb-class, readVcf-methods, SIFTDb-class, summarizeVariants-methods,
VariantType-class, VCF-class, VcfFile-class, VCFHeader-class, VRanges-class,
and VRangesList-class Rd files.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@jmg421
jmg421 force-pushed the fix/32-bgzf-detection branch from 2b9cbc6 to e9748a2 Compare July 18, 2026 03:17
…ioconductor#32)

.is_bgzf() detects BGZF vs regular gzip via the 'BC' sub-field magic bytes
in the gzip extra header (bytes 13-14 = 0x42 0x43).

.ensure_bgzf() is called from .checkFile() (readVcf) and the scanVcfHeader
character method: if a .gz file is not BGZF it is transparently re-compressed
to a BGZF tempfile so that scanBcfHeader / htslib no longer throws
'[internal] _hts_rewind() failed'.

Adds test_regular_gzip_readVcf() regression test.
@jmg421

jmg421 commented Jul 19, 2026

Copy link
Copy Markdown
Author

Superseded by #112, which adds proper tmpfile cleanup via on.exit and a cleaner .is_bgzf() implementation.

@jmg421 jmg421 closed this Jul 19, 2026
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.

Import Error for bcftools Compressed Files

2 participants