diff --git a/build_pop.py b/build_pop.py index 1ea4a0b0352ec8c20d30ae65c9cb92238971e51a..795de2692ede285b48992131cbceca82be056ebe 100755 --- a/build_pop.py +++ b/build_pop.py @@ -465,7 +465,7 @@ def generate_samples_fastq(haploid, nb_inds, output_dir, coverage, read_len, ins stderr=open(stderr, "a") if stderr is not None else None) -def confirm(deletions: dict, inversions: dict, variants: dict, printer: Print): +def confirm(deletions: dict, inversions: dict, variants: dict, printer: Print, ask=True): # Deletions: nb_dels = 0 variants_del = sorted(variants["DEL"], key=lambda x: x["min"]) @@ -521,7 +521,9 @@ def confirm(deletions: dict, inversions: dict, variants: dict, printer: Print): printer.out("") # Confirm: - return input("Continue [Y/n]? ") in ["y", "Y", ""] + if ask: + return input("Continue [Y/n]? ") in ["y", "Y", ""] + return True def init(output_dir, force_outputdir, sv_list, nstretches, nb_inds, reference, proba_del, proba_inv, haploid, @@ -599,32 +601,40 @@ def init(output_dir, force_outputdir, sv_list, nstretches, nb_inds, reference, p except Exception: printer.err(traceback.format_exc()) return 1 - if quiet or genotypes is not None or confirm(deletions, inversions, sv_sim.variants, printer): - try: - if genotypes is None: - printer.out("GENERATE SUMMARY VCF FILE...\n") - genotypes_for_inds_DEL, genotypes_for_inds_INV = \ - build_genotypes_vcf_list(deletions, inversions, output_vcf, haploid, force_polymorphism, nb_inds, - tmp_dir, prg_path) - else: - nb_inds, genotypes_for_inds_DEL, genotypes_for_inds_INV = load_genotypes_from_file(genotypes) - if nb_inds < 2: - printer.err("nb-inds must be at least 2") - return 1 - build_fastas_chromosomes(reference, genotypes_for_inds_DEL, genotypes_for_inds_INV, haploid, output_dir, - nb_inds, printer) - printer.out("GENERATE RANDOM READS FOR EACH INDIVIDUAL FROM GENOME...\n") - generate_samples_fastq(haploid, nb_inds, output_dir, coverage, read_len, insert_len_mean, - insert_len_sd, prg_path, threads, stdout, stderr) - printer.out("DONE!\n") - except ExecException as e: - printer.err(e) - return 1 - except Exception: - printer.err(traceback.format_exc()) - return 1 - else: - printer.out("Aborted!\n") + if genotypes is not None: + printer_confirm = printer + if quiet: + with open(os.path.join(output_dir, "confirm.txt"), "w") as log_file: + printer_confirm = Print(stdout=log_file, stderr=stderr) + ok = confirm(deletions, inversions, sv_sim.variants, printer_confirm, False) + else: + ok = confirm(deletions, inversions, sv_sim.variants, printer_confirm) + if ok: + try: + if genotypes is None: + printer.out("GENERATE SUMMARY VCF FILE...\n") + genotypes_for_inds_DEL, genotypes_for_inds_INV = \ + build_genotypes_vcf_list(deletions, inversions, output_vcf, haploid, force_polymorphism, nb_inds, + tmp_dir, prg_path) + else: + nb_inds, genotypes_for_inds_DEL, genotypes_for_inds_INV = load_genotypes_from_file(genotypes) + if nb_inds < 2: + printer.err("nb-inds must be at least 2") + return 1 + build_fastas_chromosomes(reference, genotypes_for_inds_DEL, genotypes_for_inds_INV, haploid, output_dir, + nb_inds, printer) + printer.out("GENERATE RANDOM READS FOR EACH INDIVIDUAL FROM GENOME...\n") + generate_samples_fastq(haploid, nb_inds, output_dir, coverage, read_len, insert_len_mean, + insert_len_sd, prg_path, threads, stdout, stderr) + printer.out("DONE!\n") + except ExecException as e: + printer.err(e) + return 1 + except Exception: + printer.err(traceback.format_exc()) + return 1 + else: + printer.out("Aborted!\n") return 0