def _run_cleanup_pipeline(args): bam_cleanup = _build_wrapper_command(args) procs = {} try: # Update 'procs' and get the last process in the pipeline if args.paired_ended: last_proc = _setup_paired_ended_pipeline(procs, bam_cleanup) else: last_proc = _setup_single_ended_pipeline(procs, bam_cleanup) # Sort, output to stdout (-o) call_sort = ['samtools', 'sort', "-o", "-", args.temp_prefix] procs["sort"] = processes.open_proc(call_sort, stdin=last_proc.stdout, stdout=processes.PIPE, close_fds=True) last_proc.stdout.close() # Update NM and MD tags; output BAM (-b) to stdout call_calmd = ['samtools', 'calmd', '-b', '-', args.fasta] procs["calmd"] = processes.open_proc(call_calmd, stdin=procs["sort"].stdout) procs["sort"].stdout.close() if any(processes.join_procs(procs.values())): return 1 return 0 except: for proc in procs.itervalues(): proc.terminate() raise
def run_batch((args, regions, filename)): setup = setup_batch(args, regions, filename) try: if any(processes.join_procs(setup["procs"].values())): return None return filename except: # Re-wrap exception with full-traceback; otherwise this information # is lost when the exception is retrieved in the main process. raise BatchError(traceback.format_exc()) finally: cleanup_batch(setup)