Skip to content

fix(chimeric): create output parent directory before writing#37

Open
pinin4fjords wants to merge 2 commits into
scverse:mainfrom
pinin4fjords:fix/chim-parent-dir-create
Open

fix(chimeric): create output parent directory before writing#37
pinin4fjords wants to merge 2 commits into
scverse:mainfrom
pinin4fjords:fix/chim-parent-dir-create

Conversation

@pinin4fjords
Copy link
Copy Markdown

Summary

rustar-aligner --chimSegmentMin > 0 combined with --twopassMode Basic aborts the run when --outFileNamePrefix doesn't end in /:

[INFO  rustar_aligner] Chimeric detection enabled (chimSegmentMin=12)
Error: I/O error: No such file or directory (os error 2) (SAMPLE./Chimeric.out.junction)

The chim writer constructs its path as <prefix>/Chimeric.out.junction (treating --outFileNamePrefix as a directory, per the existing behaviour tracked in #26). In two-pass mode the chim writer fires before any other output writer creates that directory, so the File::create call fails. Without two-pass mode the bug is masked because another output writer incidentally creates the dir first.

Fix

Call std::fs::create_dir_all on the parent of the chim output path before opening the file. Minimal, scoped fix - does not change the existing prefix-as-dir behaviour (that's left to #26).

Test plan

  • New unit test asserts the chim writer succeeds when the parent dir doesn't exist
  • Existing tests pass
  • cargo build
  • cargo clippy --all-targets -- -D warnings
  • cargo fmt --check

After the fix, rustar-aligner --chimSegmentMin 12 --twopassMode Basic --outFileNamePrefix sample. ... completes and writes sample./Chimeric.out.junction (with 14-column content matching STAR's format).

Fixes #35

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 scverse#35
@pinin4fjords
Copy link
Copy Markdown
Author

Verified the fix end-to-end on macOS/aarch64 with the binary built from 8589859.

Ran the exact failure mode from the issue (PE + --twopassMode Basic + --chimSegmentMin 12 + bare-dot --outFileNamePrefix RUS.) against the yeast test inputs:

[INFO  rustar_aligner] Writing pass 1 junctions to RUS./SJ.pass1.out.tab
[INFO  rustar_aligner] Pass 1 discovered 16 novel junctions
...
[INFO  rustar_aligner::stats] Total mapped: 42631 (85.26%)
[INFO  rustar_aligner] Wrote RUS./Log.final.out
[INFO  rustar_aligner] Alignment complete!

$ ls RUS./
Aligned.out.bam
Aligned.toTranscriptome.out.bam
Chimeric.out.junction
Log.final.out
SJ.out.tab
SJ.pass1.out.tab

Pre-fix the same invocation crashed before any output was written:

[INFO  rustar_aligner] Chimeric detection enabled (chimSegmentMin=12)
Error: I/O error: No such file or directory (os error 2) (RUS./Chimeric.out.junction)

After the fix the run completes cleanly, the parent dir is created by create_dir_all, and Chimeric.out.junction lands alongside the other outputs. LGTM from the consumer side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--chimSegmentMin > 0 + --twopassMode Basic aborts the run when --outFileNamePrefix doesn't end in /

1 participant