Skip to content

Commit

Permalink
fix: ignore gz suffix when naming output
Browse files Browse the repository at this point in the history
  • Loading branch information
mbhall88 committed Dec 14, 2023
1 parent 2b63599 commit c558ce7
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,11 @@ fn main() -> Result<()> {
_ => {}
}

// create a temporary output directory
let tmpdir = tempfile::tempdir().context("Failed to create temporary output directory")?;
// create a temporary output directory in the current directory and don't delete it
let tmpdir = tempfile::Builder::new()
.prefix("nohuman")
.tempdir_in(std::env::current_dir().unwrap())
.context("Failed to create temporary directory")?;
let outfile = if input.len() == 2 {
tmpdir.path().join("kraken_out#.fq")
} else {
Expand All @@ -158,15 +161,27 @@ fn main() -> Result<()> {
if input.len() == 2 {
let out1 = args.out1.unwrap_or_else(|| {
let parent = input[0].parent().unwrap();
// get the part of the file name before the extension
let fname = input[0].file_stem().unwrap();
// get the part of the file name before the extension.
// if the file is compressed, the extension will be .gz, we want to remove this first before getting the file stem
let fname = if input[0].extension().unwrap_or_default() == "gz" {
let no_ext = input[0].with_extension("");
no_ext.file_stem().unwrap().to_owned()
} else {
input[0].file_stem().unwrap().to_owned()
};
let fname = format!("{}.nohuman.fq", fname.to_string_lossy());
parent.join(fname)
});
let out2 = args.out2.unwrap_or_else(|| {
let parent = input[1].parent().unwrap();
// get the part of the file name before the extension
let fname = input[1].file_stem().unwrap();
// get the part of the file name before the extension.
// if the file is compressed, the extension will be .gz, we want to remove this first before getting the file stem
let fname = if input[1].extension().unwrap_or_default() == "gz" {
let no_ext = input[1].with_extension("");
no_ext.file_stem().unwrap().to_owned()
} else {
input[1].file_stem().unwrap().to_owned()
};
let fname = format!("{}.nohuman.fq", fname.to_string_lossy());
parent.join(fname)
});
Expand All @@ -179,8 +194,14 @@ fn main() -> Result<()> {
} else {
let out1 = args.out1.unwrap_or_else(|| {
let parent = input[0].parent().unwrap();
// get the part of the file name before the extension
let fname = input[0].file_stem().unwrap();
// get the part of the file name before the extension.
// if the file is compressed, the extension will be .gz, we want to remove this first before getting the file stem
let fname = if input[0].extension().unwrap_or_default() == "gz" {
let no_ext = input[0].with_extension("");
no_ext.file_stem().unwrap().to_owned()
} else {
input[0].file_stem().unwrap().to_owned()
};
let fname = format!("{}.nohuman.fq", fname.to_string_lossy());
parent.join(fname)
});
Expand Down

0 comments on commit c558ce7

Please sign in to comment.