diff --git a/src/lib/run.rs b/src/lib/run.rs index 55ea6c5..f9c8350 100644 --- a/src/lib/run.rs +++ b/src/lib/run.rs @@ -90,6 +90,14 @@ pub fn run(opts: Opts) -> Result<(), anyhow::Error> { filenames(s, &opts.output_dir, &opts.read_structures, &output_types_to_write) .into_iter() .map(|name| { + // Create the output directory. This is important if the output is being written + // to a project-specific directory + if let Some(parent) = name.parent() { + std::fs::create_dir_all(parent).with_context(|| { + format!("Could not create output directory: {:?}", parent) + })?; + } + // Now create the output file File::create(&name) .with_context(|| { format!("Unable to create file: {}", name.to_string_lossy()) diff --git a/src/lib/sample_metadata.rs b/src/lib/sample_metadata.rs index 417c9e5..5f445e1 100644 --- a/src/lib/sample_metadata.rs +++ b/src/lib/sample_metadata.rs @@ -43,7 +43,7 @@ pub struct SampleMetadata { /// The project associated with this the sample #[serde(alias = "Project", rename(serialize = "Project"))] - pub project: Option, + pub project: Option, /// The sanitized `raw_barcode` used for demultiplexing. #[serde(skip)] diff --git a/src/lib/utils.rs b/src/lib/utils.rs index b484086..f583935 100644 --- a/src/lib/utils.rs +++ b/src/lib/utils.rs @@ -76,7 +76,6 @@ pub fn filenames>( Some(project) => output_dir.as_ref().join(project.to_string()), None => output_dir.as_ref().to_path_buf(), }; - std::fs::create_dir_all(&output_dir).unwrap(); for structure in read_structures.iter() { for kind in structure.iter().map(|segment| segment.kind).sorted().dedup() { @@ -367,7 +366,6 @@ mod test { vec::IntoIter, }; - use bstr::BString; use gzp::{BgzfSyncWriter, Compression, MgzipSyncWriter}; use read_structure::{ReadStructure, SegmentType}; @@ -418,7 +416,7 @@ mod test { .unwrap(); // Sample with project - sample.project = Some(BString::from("Project1")); + sample.project = Some(String::from("Project1")); let output_fastqs = filenames(&sample, output_dir, &read_structures, &output_types_to_write); let expected = vec![