Skip to content
Open
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
26 changes: 26 additions & 0 deletions src/chimeric/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ impl ChimericJunctionWriter {
pub fn new(prefix: &str) -> Result<Self, Error> {
let path = PathBuf::from(format!("{prefix}Chimeric.out.junction"));

if let Some(parent) = path.parent()
&& !parent.as_os_str().is_empty()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What’s this for? How can a path have "" as parent?

{
std::fs::create_dir_all(parent).map_err(|e| Error::io(e, parent))?;
}

let file = File::create(&path).map_err(|e| Error::io(e, &path))?;

let writer = BufWriter::new(file);
Expand Down Expand Up @@ -254,6 +260,26 @@ mod tests {
);
}

#[test]
fn test_chimeric_junction_writer_creates_missing_parent() {
let dir = tempdir().unwrap();
let prefix = format!("{}/sample/", dir.path().display());
let prefix_path = PathBuf::from(&prefix);

assert!(!prefix_path.exists(), "parent dir should not exist yet");

let writer = ChimericJunctionWriter::new(&prefix);
assert!(
writer.is_ok(),
"writer should create missing parent dir, got: {:?}",
writer.err()
);

let mut path = prefix_path.clone();
path.push("Chimeric.out.junction");
assert!(path.exists(), "chim output file should exist at {path:?}");
}

#[test]
fn test_write_inter_chromosomal() {
use cigar::op::{Kind, Op};
Expand Down
Loading