Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] Add bgzf support #35

Merged
merged 1 commit into from
Sep 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## v0.6.2

- Output BGZF output by default, which can be indexed and queried with tabix
- Read input gzipped files a `MultiGzDecoder` which is more flexible

## v0.6.1

- PGO build fix
Expand Down
30 changes: 28 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ anyhow = "1.0.41"
bstr = "0.2.16"
env_logger = "0.8.4"
flate2 = { version = "1.0", features = ["zlib-ng-compat"], default-features = false }
gzp = {version = "0.7.1", default-features = false, features = ["deflate_zlib_ng"]}
gzp = {version = "0.8.0", default-features = false, features = ["deflate_zlib_ng","libdeflate"]}
grep-cli = "0.1.6"
lazy_static = "1.4.0"
log = "0.4.14"
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ It is meant to be simple and easy to use while exploring datasets.
- Selection of columns by header string literal with the `-F` option, or by regex by setting the `-r` flag
- Input files will be automatically decompressed if their file extension is recognizable and a local binary exists to perform the decompression (similar to ripgrep). See [Decompression](#decompression).
- Output can be gzip compressed using the multi-threaded compressors from [`gzp`](https://github.com/sstadick/gzp) with `-Z` flag
- This gzipped output is in BGZF format and can be indexed and queried with `tabix`
- Exclude fields by index or by header.
- Speed

Expand Down
8 changes: 4 additions & 4 deletions src/lib/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
};
use anyhow::Result;
use bstr::ByteSlice;
use flate2::read::GzDecoder;
use flate2::read::MultiGzDecoder;
use grep_cli::DecompressionReaderBuilder;
use memchr;
use regex::bytes::Regex;
Expand Down Expand Up @@ -103,7 +103,7 @@ impl<'a> CoreConfig<'a> {
.map(|p| p.ends_with(".gz"))
.unwrap_or(false)
{
Box::new(GzDecoder::new(File::open(&path)?))
Box::new(MultiGzDecoder::new(File::open(&path)?))
} else {
Box::new(
DecompressionReaderBuilder::new()
Expand Down Expand Up @@ -371,7 +371,7 @@ where
self.hck_bytes(header.as_bytes(), &mut output)?;
}
let reader: Box<dyn Read> = if self.config.try_decompress {
Box::new(GzDecoder::new(io::stdin()))
Box::new(MultiGzDecoder::new(io::stdin()))
} else {
Box::new(io::stdin())
};
Expand All @@ -389,7 +389,7 @@ where
.map(|p| p.ends_with(".gz"))
.unwrap_or(false)
{
Box::new(GzDecoder::new(File::open(&path)?))
Box::new(MultiGzDecoder::new(File::open(&path)?))
} else {
Box::new(
DecompressionReaderBuilder::new()
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use anyhow::{Context, Error, Result};
use env_logger::Env;
use flate2::Compression;
use grep_cli::stdout;
use gzp::{deflate::Gzip, ZBuilder};
use gzp::{deflate::Bgzf, ZBuilder};
use hcklib::{
core::{Core, CoreConfig, CoreConfigBuilder, HckInput},
field_range::RegexOrStr,
Expand Down Expand Up @@ -194,7 +194,7 @@ fn main() -> Result<()> {
// TODO: Support all flate2 compression targets via enum on `-Z`
let mut writer: Box<dyn Write> = if opts.try_compress {
Box::new(
ZBuilder::<Gzip, _>::new()
ZBuilder::<Bgzf, _>::new()
.compression_level(Compression::new(opts.compression_level))
.num_threads(opts.compression_threads)
.from_writer(writer),
Expand Down