Skip to content

Commit

Permalink
review fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
nh13 committed Nov 15, 2022
1 parent 80cf25f commit 5fc25d3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
8 changes: 8 additions & 0 deletions src/lib/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion src/lib/sample_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub struct SampleMetadata {

/// The project associated with this the sample
#[serde(alias = "Project", rename(serialize = "Project"))]
pub project: Option<BString>,
pub project: Option<String>,

/// The sanitized `raw_barcode` used for demultiplexing.
#[serde(skip)]
Expand Down
4 changes: 1 addition & 3 deletions src/lib/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ pub fn filenames<P: AsRef<Path>>(
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() {
Expand Down Expand Up @@ -367,7 +366,6 @@ mod test {
vec::IntoIter,
};

use bstr::BString;
use gzp::{BgzfSyncWriter, Compression, MgzipSyncWriter};
use read_structure::{ReadStructure, SegmentType};

Expand Down Expand Up @@ -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![
Expand Down

0 comments on commit 5fc25d3

Please sign in to comment.