Skip to content

Commit 8589859

Browse files
committed
fix(chimeric): create output parent directory before writing
The chimeric output writer constructs its path as <outFileNamePrefix>/Chimeric.out.junction, treating the prefix as a directory regardless of whether it ends in `/`. In two-pass mode the chim writer fires before any other output creates that directory, so the file open fails with "No such file or directory" and the entire run aborts. Call create_dir_all on the parent of the chim output path before opening the file. Without two-pass mode the bug was masked because another output writer happened to create the dir first. Fixes #35
1 parent 70be24d commit 8589859

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

src/chimeric/output.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ impl ChimericJunctionWriter {
2525
let mut path = PathBuf::from(prefix);
2626
path.push("Chimeric.out.junction");
2727

28+
if let Some(parent) = path.parent()
29+
&& !parent.as_os_str().is_empty()
30+
{
31+
std::fs::create_dir_all(parent).map_err(|e| Error::io(e, parent))?;
32+
}
33+
2834
let file = File::create(&path).map_err(|e| Error::io(e, &path))?;
2935

3036
let writer = BufWriter::new(file);
@@ -287,6 +293,30 @@ mod tests {
287293
assert!(path.exists());
288294
}
289295

296+
#[test]
297+
fn test_chimeric_junction_writer_creates_missing_parent() {
298+
// Regression test for #35: when --twopassMode Basic is combined with
299+
// --chimSegmentMin > 0 and --outFileNamePrefix doesn't end in `/`, the
300+
// chim writer fires before any other output writer creates the parent
301+
// directory. The writer must create the parent itself.
302+
let dir = tempdir().unwrap();
303+
let prefix_path = dir.path().join("sample.");
304+
let prefix = prefix_path.to_str().unwrap();
305+
306+
assert!(!prefix_path.exists(), "parent dir should not exist yet");
307+
308+
let writer = ChimericJunctionWriter::new(prefix);
309+
assert!(
310+
writer.is_ok(),
311+
"writer should create missing parent dir, got: {:?}",
312+
writer.err()
313+
);
314+
315+
let mut path = PathBuf::from(prefix);
316+
path.push("Chimeric.out.junction");
317+
assert!(path.exists(), "chim output file should exist at {:?}", path);
318+
}
319+
290320
#[test]
291321
fn test_write_inter_chromosomal() {
292322
let dir = tempdir().unwrap();

0 commit comments

Comments
 (0)