Skip to content

Commit

Permalink
Io::is_gzip_path
Browse files Browse the repository at this point in the history
  • Loading branch information
brentp committed Oct 24, 2023
1 parent 2ee4d93 commit 382e2a6
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 36 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/target
.vscode
*.fq
*.fq.gz
3 changes: 1 addition & 2 deletions Cargo.lock

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

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
authors = [
"Nathan Roach <[email protected]>",
"Tim Fennell <[email protected]>",
"Nils Homer <[email protected]>"
"Nils Homer <[email protected]>",
"Brent Pedersen <[email protected]>"
]
name = "fqtk"
version = "0.3.1-rc.1"
Expand Down Expand Up @@ -36,7 +37,7 @@ bstr = "1.0.1"
clap = { version = "4.3.22", features = ["derive"] }
enum_dispatch = "0.3.8"
env_logger = "0.9.3"
fgoxide = "0.3.0"
fgoxide = { git = "https://github.com/brentp/fgoxide", branch = "pub-is-gz" }
flate2 = { version = "1.0.25", features = ["zlib-ng"] } # Force the faster backend that requires a C compiler
itertools = "0.10.5"
log = "0.4.17"
Expand Down
33 changes: 1 addition & 32 deletions src/bin/commands/trimmer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,6 @@ fn create_writer<P: AsRef<Path>>(name: P) -> Result<BufWriter<File>, Error> {
Ok(BufWriter::new(File::create(name)?))
}

fn check_extension(p: &Path) -> bool {
let ext = p.extension().map_or("", |v| v.to_str().unwrap_or(""));
["bgz", "gz"].contains(&ext)
}

impl TrimmerOpts {
fn prepare(&self) -> Result<(Pool, Vec<PooledWriter>, VecOfFqReaders), Error> {
let fgio = Io::new(5, BUFFER_SIZE);
Expand All @@ -130,7 +125,7 @@ impl TrimmerOpts {
.output
.iter()
.map(|p| {
if !check_extension(p) {
if !Io::is_gzip_path(p) {
log::warn!(
"Output file {} does not end with .gz or .bgz. Writing bgzipped output to {} instead.",
p.display(),
Expand Down Expand Up @@ -265,29 +260,3 @@ impl Command for TrimmerOpts {
Ok(())
}
}

#[cfg(test)]
mod tests {
use super::*;
use std::path::PathBuf;

#[test]
fn test_check_extension_gz() {
let path = PathBuf::from("test_file.gz");
assert_eq!(
check_extension(&path),
true,
"The function should return true for .gz extension"
);
}

#[test]
fn test_check_extension_txt() {
let path = PathBuf::from("test_file.txt");
assert_eq!(
check_extension(&path),
false,
"The function should return false for .txt extension"
);
}
}

0 comments on commit 382e2a6

Please sign in to comment.