| 1 | bgzip-rs |
| 2 | ======== |
| 3 | |
| 4 | [](https://github.com/informationsea/bgzip-rs/actions/workflows/build.yml) |
| 5 | [](https://crates.io/crates/bgzip) |
| 6 | [](https://crates.io/crates/bgzip) |
| 7 | [](https://crates.io/crates/bgzip) |
| 8 | [](https://docs.rs/bgzip) |
| 9 | |
| 10 | Rust implementation of BGZF |
| 11 | |
| 12 | Feature flags |
| 13 | ------------- |
| 14 | |
| 15 | * `rayon`: Enable [rayon](https://github.com/rayon-rs/rayon) based multi-threaded reader/writer. This is default feature. |
| 16 | * `log`: Enable [log](https://github.com/rust-lang/log) crate to log warnings. This is default feature. |
| 17 | * `rust_backend`: use [miniz_oxide](https://crates.io/crates/miniz_oxide) crate for [flate2](https://github.com/rust-lang/flate2-rs) backend. This is default feature. |
| 18 | * `zlib`: use `zlib` for flate2 backend. Please read [flate2](https://github.com/rust-lang/flate2-rs) description for the detail. |
| 19 | * `zlib-ng`: use `zlib-ng` for flate2 backend. Please read [flate2](https://github.com/rust-lang/flate2-rs) description for the detail. |
| 20 | * `zlib-ng-compat`: Please read [flate2](https://github.com/rust-lang/flate2-rs) description for the detail. |
| 21 | * `cloudflare_zlib`: Please read [flate2](https://github.com/rust-lang/flate2-rs) description for the detail. |
| 22 | * `libdeflater`: use [libdeflater](https://github.com/adamkewley/libdeflater) instead of [flate2](https://github.com/rust-lang/flate2-rs) crate. |
| 23 | |
| 24 | Write Examples |
| 25 | -------- |
| 26 | ```rust |
| 27 | use bgzip::{BGZFWriter, BGZFError, Compression}; |
| 28 | use std::io::{self, Write}; |
| 29 | fn main() -> Result<(), BGZFError> { |
| 30 | let mut write_buffer = Vec::new(); |
| 31 | let mut writer = BGZFWriter::new(&mut write_buffer, Compression::default()); |
| 32 | writer.write_all(b"##fileformat=VCFv4.2\n")?; |
| 33 | writer.write_all(b"#CHROM\tPOS\tID\tREF\tALT\tQUAL\tFILTER\tINFO\n")?; |
| 34 | writer.close()?; |
| 35 | Ok(()) |
| 36 | } |
| 37 | ``` |
| 38 | |
| 39 | Read Examples |
| 40 | -------- |
| 41 | ```rust |
| 42 | use bgzip::{BGZFReader, BGZFError}; |
| 43 | use std::io::{self, BufRead}; |
| 44 | use std::fs; |
| 45 | fn main() -> Result<(), BGZFError> { |
| 46 | let mut reader = |
| 47 | BGZFReader::new(fs::File::open("testfiles/common_all_20180418_half.vcf.gz")?)?; |
| 48 | let mut line = String::new(); |
| 49 | reader.read_line(&mut line)?; |
| 50 | assert_eq!("##fileformat=VCFv4.0\n", line); |
| 51 | reader.bgzf_seek(4210818610)?; |
| 52 | line.clear(); |
| 53 | reader.read_line(&mut line)?; |
| 54 | 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); |
| 55 | |
| 56 | Ok(()) |
| 57 | } |
| 58 | ``` |
| 59 | |
| 60 | Author |
| 61 | ------ |
| 62 | |
| 63 | Yasunobu OKAMURA |
| 64 | |
| 65 | License |
| 66 | ------- |
| 67 | |
| 68 | MIT |
| 69 |