Skip to content

Use zflate instead of libdeflate for BGZF, sort runs and indexes - #35

Open
DylanCosto wants to merge 1 commit into
mainfrom
deps/zflate
Open

DylanCosto wants to merge 1 commit into
mainfrom
deps/zflate

Conversation

@DylanCosto

Copy link
Copy Markdown
Owner

Replaces the libdeflater (C libdeflate) dependency with zflate 1.0.0, a pure-Rust port of libdeflate, everywhere bonefish compresses or decompresses DEFLATE:

  • BGZF input: dorado BAM (BamFastq, header/@RG reading, BAM detection) and bgzipped FASTQ/FASTA (BgzfParallel)
  • the sorter's level-1 temporary runs (write and read back)
  • sorted BAM output and its BAI/CSI index
  • the BGZF and gzip helpers in parser_stress.rs

Plain (non-BGZF) gzip input still goes through flate2/zlib-rs.

--sort-level is now checked to be 0-12 (clap range on the CLI, and SortedBamWriter::new for library callers), so a bad level is an error instead of a panic in a compression thread. SortConfig.level stays i32.

Build: a build without jemalloc/mimalloc no longer needs a C compiler (cargo tree -i cc is empty on default features). The bioconda recipe still needs one for jemalloc. zflate needs Rust 1.91+; CI uses stable and the Dockerfile 1.98.

Verification

Against a build of main (b44551d), same flags (--release --features jemalloc), 24 threads, GRCh38 no-alt:

check result
genome-wide HG001 sample (BGZF FASTQ) → SAM, @PG removed 9bc7ff3e9f498cc1530b2b1d78c47e10, same as v0.4.0
same → sorted BAM (default level 6) identical records and header; samtools quickcheck ok; 465 bytes smaller
BAI region queries (8 regions + unmapped *) bonefish's index = main's = samtools index's
dorado BAM (160k reads, MM/ML tags) → SAM with -y identical
dorado BAM → sorted BAM records match its sorted SAM
CSI index (689 Mbp fused chr1-3 contig) identical records; region and * queries = samtools index -c
--sort-level 0, 1, 12 valid BAMs, same records
--sort-level 13, -1 rejected with a clap error, no panic
CPU time, FASTQ → sorted BAM (3 alternating runs) 636.8 vs 637.1 CPU-s (unchanged)
  • cargo test --release --locked --features jemalloc with BONEFISH_REQUIRE_SIMD=avx2,avx512bw,avx512vl,avx512vbmi: 212 passed, 0 failed, 5 ignored (as on main)
  • scripts/validation unit tests, verify_evidence.py, verify_clean_dp_evidence.py: pass
  • cargo clippy --all-targets: no warnings
  • cargo check --all-targets for aarch64-unknown-linux-gnu and aarch64-apple-darwin: clean (not run on arm64 hardware; CI's arm runners cover that)

- bonefish-core depends on zflate 1.0.0 (pure-Rust port of libdeflate) in place of
  libdeflater: BGZF input (dorado BAM, bgzipped FASTQ), the sorter's level-1 runs, sorted BAM
  output and BAI/CSI indexes. Tests' BGZF and gzip helpers use it too. A build without
  jemalloc or mimalloc no longer needs a C compiler; zflate needs Rust 1.91 or newer.
- --sort-level is checked to be 0-12 (clap range, and SortedBamWriter::new for library
  callers) instead of panicking in a compression thread.

Output identical: genome-wide sample SAM 9bc7ff3e...; sorted BAM records from FASTQ and from
dorado BAM input; BAI and CSI (689 Mbp contig) region and unmapped queries agree with
samtools' own indexes; levels 0, 1 and 12 give the same records. CPU time unchanged; the
genome-wide BAM is 465 bytes smaller at level 6. cargo test --release --features jemalloc
(AVX2/AVX-512 required) and the validation scripts pass; arm64 Linux and macOS type-check.
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