Skip to content

Commit

Permalink
Add option to force mapAD to overwrite existing output files
Browse files Browse the repository at this point in the history
  • Loading branch information
jch-13 committed Jul 12, 2024
1 parent 3e4cf61 commit 2b0a7c7
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/distributed/dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ pub struct Dispatcher<'a, 'b> {
reads_path: &'b Path,
reference_path: &'b Path,
out_file_path: &'b Path,
force_overwrite: bool,
alignment_parameters: &'a AlignmentParameters,
connections: HashMap<Token, Connection>,
accept_connections: bool,
Expand All @@ -68,6 +69,7 @@ impl<'a, 'b> Dispatcher<'a, 'b> {
reads_path: &'b str,
reference_path: &'b str,
out_file_path: &'b str,
force_overwrite: bool,
alignment_parameters: &'a AlignmentParameters,
) -> Result<Self> {
let reads_path = Path::new(reads_path);
Expand All @@ -83,6 +85,7 @@ impl<'a, 'b> Dispatcher<'a, 'b> {
reads_path,
reference_path: Path::new(reference_path),
out_file_path,
force_overwrite,
alignment_parameters,
connections: HashMap::new(),
accept_connections: true,
Expand Down Expand Up @@ -122,7 +125,10 @@ impl<'a, 'b> Dispatcher<'a, 'b> {
OpenOptions::new()
.read(false)
.write(true)
.create_new(true)
// If .create_new(true) is set, .create() and .truncate() are ignored
.create_new(!self.force_overwrite)
.create(true)
.truncate(true)
.open(self.out_file_path)?,
);

Expand Down
9 changes: 9 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,12 @@ fn define_cli() -> ArgMatches {
.help("Abort alignment when stack size limit is reached instead of trying to recover.")
.action(ArgAction::SetTrue)
)
.arg(
Arg::new("force_overwrite")
.long("force_overwrite")
.help(format!("Force {CRATE_NAME} to overwrite the output BAM file."))
.action(ArgAction::SetTrue)
)
)
.subcommand(
Command::new("worker")
Expand Down Expand Up @@ -315,6 +321,7 @@ fn start_mapper(map_matches: &ArgMatches, _seed: u64) {
let out_file_path = map_matches
.get_one::<String>("output")
.expect("Presence is ensured by CLI definition");
let force_overwrite = map_matches.get_flag("force_overwrite");

let num_threads = *map_matches
.get_one("num_threads")
Expand All @@ -335,6 +342,7 @@ fn start_mapper(map_matches: &ArgMatches, _seed: u64) {
reads_path,
reference_path,
out_file_path,
force_overwrite,
&alignment_parameters,
)
.and_then(|mut dispatcher| dispatcher.run(port))
Expand All @@ -343,6 +351,7 @@ fn start_mapper(map_matches: &ArgMatches, _seed: u64) {
reads_path,
reference_path,
out_file_path,
force_overwrite,
&alignment_parameters,
)
} {
Expand Down
6 changes: 5 additions & 1 deletion src/map/mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ pub fn run(
reads_path: &str,
reference_path: &str,
out_file_path: &str,
force_overwrite: bool,
alignment_parameters: &AlignmentParameters,
) -> Result<()> {
let reads_path = Path::new(reads_path);
Expand Down Expand Up @@ -87,7 +88,10 @@ pub fn run(
OpenOptions::new()
.read(false)
.write(true)
.create_new(true)
// If .create_new(true) is set, .create() and .truncate() are ignored
.create_new(!force_overwrite)
.create(true)
.truncate(true)
.open(out_file_path)?,
);

Expand Down
2 changes: 2 additions & 0 deletions tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ fn integration_1_local() {
env.input_bam_path.to_str().unwrap(),
env.test_genome_path.to_str().unwrap(),
output_bam_path_local.to_str().unwrap(),
false,
&env.alignment_parameters,
)
.unwrap();
Expand All @@ -196,6 +197,7 @@ fn integration_1_distributed() {
env.input_bam_path.to_str().unwrap(),
env.test_genome_path.to_str().unwrap(),
output_bam_path_distr_clone.to_str().unwrap(),
false,
&env.alignment_parameters,
)
.unwrap();
Expand Down

0 comments on commit 2b0a7c7

Please sign in to comment.