9 releases

0.3.1 Feb 14, 2023
0.3.0 Feb 12, 2023
0.2.2 Dec 30, 2022
0.2.1 Jun 20, 2021
0.0.3 Sep 2, 2018

#233 in Compression

Download history 372/week @ 2024-07-04 472/week @ 2024-07-11 1158/week @ 2024-07-18 479/week @ 2024-07-25 523/week @ 2024-08-01 443/week @ 2024-08-08 556/week @ 2024-08-15 682/week @ 2024-08-22 503/week @ 2024-08-29 592/week @ 2024-09-05 718/week @ 2024-09-12 1012/week @ 2024-09-19 713/week @ 2024-09-26 878/week @ 2024-10-03 789/week @ 2024-10-10 1062/week @ 2024-10-17

3,573 downloads per month
Used in 7 crates (6 directly)

MIT license

98KB
2K SLoC

bgzip-rs

Build Crates.io Crates.io Crates.io doc-rs

Rust implementation of BGZF

Feature flags

  • rayon: Enable rayon based multi-threaded reader/writer. This is default feature.
  • log: Enable log crate to log warnings. This is default feature.
  • rust_backend: use miniz_oxide crate for flate2 backend. This is default feature.
  • zlib: use zlib for flate2 backend. Please read flate2 description for the detail.
  • zlib-ng: use zlib-ng for flate2 backend. Please read flate2 description for the detail.
  • zlib-ng-compat: Please read flate2 description for the detail.
  • cloudflare_zlib: Please read flate2 description for the detail.
  • libdeflater: use libdeflater instead of flate2 crate.

Write Examples

use bgzip::{BGZFWriter, BGZFError, Compression};
use std::io::{self, Write};
fn main() -> Result<(), BGZFError> {
    let mut write_buffer = Vec::new();
    let mut writer = BGZFWriter::new(&mut write_buffer, Compression::default());
    writer.write_all(b"##fileformat=VCFv4.2\n")?;
    writer.write_all(b"#CHROM\tPOS\tID\tREF\tALT\tQUAL\tFILTER\tINFO\n")?;
    writer.close()?;
    Ok(())
}

Read Examples

use bgzip::{BGZFReader, BGZFError};
use std::io::{self, BufRead};
use std::fs;
fn main() -> Result<(), BGZFError> {
    let mut reader =
        BGZFReader::new(fs::File::open("testfiles/common_all_20180418_half.vcf.gz")?)?;
    let mut line = String::new();
    reader.read_line(&mut line)?;
    assert_eq!("##fileformat=VCFv4.0\n", line);
    reader.bgzf_seek(4210818610)?;
    line.clear();
    reader.read_line(&mut line)?;
    assert_eq!("1\t72700625\trs12116859\tT\tA,C\t.\t.\tRS=12116859;RSPOS=72700625;dbSNPBuildID=120;SSR=0;SAO=0;VP=0x05010008000517053e000100;GENEINFO=LOC105378798:105378798;WGT=1;VC=SNV;SLO;INT;ASP;VLD;G5A;G5;HD;GNO;KGPhase1;KGPhase3;CAF=0.508,.,0.492;COMMON=1;TOPMED=0.37743692660550458,0.00608435270132517,0.61647872069317023\n", line);

    Ok(())
}

Author

Yasunobu OKAMURA

License

MIT

Dependencies

~1.4–2.5MB
~51K SLoC