def merge_bam_files(bam_files, work_dir, config): """Merge multiple BAM files from a sample into a single BAM for processing. """ out_file = os.path.join(work_dir, os.path.basename(bam_files[0])) if not os.path.exists(out_file): picard = PicardRunner(config["program"]["picard"]) with utils.curdir_tmpdir() as tmp_dir: opts = [("OUTPUT", out_file), ("SORT_ORDER", "coordinate"), ("TMP_DIR", tmp_dir)] for b in bam_files: opts.append(("INPUT", b)) picard.run("MergeSamFiles", opts) return out_file
def do_work(ref, cur_fastq, config, config_file): picard = PicardRunner(config["program"]["picard"]) align_dir = config["align_dir"] if not os.path.exists(align_dir): os.makedirs(align_dir) fastq_one, fastq_two = _get_align_files(cur_fastq, config) base = "%s-%s" % (cur_fastq["name"], os.path.basename(ref)) align_file = bowtie_to_sam(fastq_one, fastq_two, ref, base, align_dir, config) bam_file = sam_to_bam(align_file, fastq_one, fastq_two, ref, config_file) picard.run_fn("picard_index", bam_file) bed_file = bam_to_bed(bam_file) if fastq_two is not None: inferred_bed = generate_inferred_coverage(bam_file) generate_bigwig(inferred_bed, ref, picard) else: generate_bigwig(bed_file, ref, picard) return cur_fastq["name"], bed_file