From b2b76aa20ce73b66c8ca230ed5105a2b6345cec0 Mon Sep 17 00:00:00 2001 From: LaraFuhrmann <55209716+LaraFuhrmann@users.noreply.github.com> Date: Fri, 7 Jun 2024 10:41:32 +0200 Subject: [PATCH] b2w and inference: rerun windows that failed + check if window was processed already before adding process to process list --- viloca/b2w.py | 52 ++++++++++++++++++++++++----------------------- viloca/shotgun.py | 11 ++++++---- 2 files changed, 34 insertions(+), 29 deletions(-) diff --git a/viloca/b2w.py b/viloca/b2w.py index 686a2b8..36bb114 100644 --- a/viloca/b2w.py +++ b/viloca/b2w.py @@ -578,30 +578,31 @@ def build_windows(alignment_file: str, tiling_strategy: TilingStrategy, all_processes = [] for idx, (window_start, window_length, control_window_length) in enumerate(tiling): counter = counter_list[idx] - p = Process( - target=parallel_run_one_window, - args=( - reference_filename, - minimum_reads, - tiling, - region_end, - idx, - window_start, # 1-based - window_length, - control_window_length, - alignment_file, - reference_name, - win_min_ext, - permitted_reads_per_location, - counter, # 0-based - exact_conformance_fix_0_1_basing_in_reads, - indel_map, - max_ins_at_pos, # 0-based - extended_window_mode, - exclude_non_var_pos_threshold, + if not os.path.isfile(f"coverage_{idx}.txt"): + p = Process( + target=parallel_run_one_window, + args=( + reference_filename, + minimum_reads, + tiling, + region_end, + idx, + window_start, # 1-based + window_length, + control_window_length, + alignment_file, + reference_name, + win_min_ext, + permitted_reads_per_location, + counter, # 0-based + exact_conformance_fix_0_1_basing_in_reads, + indel_map, + max_ins_at_pos, # 0-based + extended_window_mode, + exclude_non_var_pos_threshold, + ) ) - ) - all_processes.append(p) + all_processes.append(p) for p in all_processes: p.start() @@ -609,8 +610,9 @@ def build_windows(alignment_file: str, tiling_strategy: TilingStrategy, for p in all_processes: p.join() if p.exitcode != 0: - logging.debug("[b2w] A process was killed. Terminating the program.") - exit(1) + p.start() + logging.debug("[b2w] A process was killed. Terminating the program. Process was restarted.") + #exit(1) logging.debug("[b2w] All processes completed successfully.") diff --git a/viloca/shotgun.py b/viloca/shotgun.py index 95618f2..cac74b1 100644 --- a/viloca/shotgun.py +++ b/viloca/shotgun.py @@ -307,8 +307,10 @@ def win_to_run(alpha_w, seed, inference_type, n_max_haplotypes, n_mfa_starts, un for f1 in file1: winFile, chr1, beg, end, cov = f1.rstrip().split('\t') - j = min(300_000, int(cov) * 15) - rn_list.append((winFile, j, alpha_w, seed, inference_type, n_max_haplotypes, n_mfa_starts, unique_modus, inference_convergence_threshold)) + output_name = output_dir + winFile.split("/")[-1][:-4] + "-" + "cor.fas" + if not os.path.isfile(output_name): + j = min(300_000, int(cov) * 15) + rn_list.append((winFile, j, alpha_w, seed, inference_type, n_max_haplotypes, n_mfa_starts, unique_modus, inference_convergence_threshold)) del end del(beg, chr1) @@ -515,8 +517,9 @@ def main(args): for p in all_processes: p.join() if p.exitcode != 0: - logging.debug("[shotgun] A process was killed. Terminating the program.") - exit(1) + p.start() + logging.debug("[shotgun] A process was killed. Restart process.") + #exit(1) logging.debug("[shotgun] All processes completed successfully.")