Mercurial > repos > peterjc > mira4_assembler
diff tools/mira4/mira4_make_bam.py @ 21:4abe8d59a438 draft
Uploaded v0.0.4 preview 1; fix getting BAM without MAF
author | peterjc |
---|---|
date | Tue, 28 Oct 2014 08:29:59 -0400 |
parents | 302d13490b23 |
children |
line wrap: on
line diff
--- a/tools/mira4/mira4_make_bam.py Tue Jun 10 10:11:58 2014 -0400 +++ b/tools/mira4/mira4_make_bam.py Tue Oct 28 08:29:59 2014 -0400 @@ -32,6 +32,29 @@ log_handle.write(stdout) return child.returncode +def depad(fasta_file, sam_file, bam_file, log_handle): + log_handle.write("\n================= Converting MIRA assembly from SAM to BAM ===================\n") + #Also doing SAM to (uncompressed) BAM during depad + bam_stem = bam_file + ".tmp" # Have write permissions and want final file in this folder + cmd = 'samtools depad -S -u -T "%s" "%s" | samtools sort - "%s"' % (fasta_file, sam_file, bam_stem) + return_code = run(cmd, log_handle) + if return_code: + return "Error %i from command:\n%s" % (return_code, cmd) + if not os.path.isfile(bam_stem + ".bam"): + return "samtools depad or sort failed to produce BAM file" + + log_handle.write("\n====================== Indexing MIRA assembly BAM file =======================\n") + cmd = 'samtools index "%s.bam"' % bam_stem + return_code = run(cmd, log_handle) + if return_code: + return "Error %i from command:\n%s" % (return_code, cmd) + if not os.path.isfile(bam_stem + ".bam.bai"): + return "samtools indexing of BAM file failed to produce BAI file" + + shutil.move(bam_stem + ".bam", bam_file) + os.remove(bam_stem + ".bam.bai") #Let Galaxy handle that... + + def make_bam(mira_convert, maf_file, fasta_file, bam_file, log_handle): if not os.path.isfile(mira_convert): return "Missing binary %r" % mira_convert @@ -52,30 +75,14 @@ if not os.path.isfile(sam_file): return "Conversion from MIRA to SAM failed" - log_handle.write("\n================= Converting MIRA assembly from SAM to BAM ===================\n") #Also doing SAM to (uncompressed) BAM during depad - bam_stem = bam_file + ".tmp" # Have write permissions and want final file in this folder - cmd = 'samtools depad -S -u -T "%s" "%s" | samtools sort - "%s"' % (fasta_file, sam_file, bam_stem) - return_code = run(cmd, log_handle) - if return_code: - return "Error %i from command:\n%s" % (return_code, cmd) - if not os.path.isfile(bam_stem + ".bam"): - return "samtools depad or sort failed to produce BAM file" + msg = depad(fasta_file, sam_file, bam_file, log_handle) + if msg: + return msg os.remove(sam_file) os.rmdir(tmp_dir) - log_handle.write("\n====================== Indexing MIRA assembly BAM file =======================\n") - cmd = 'samtools index "%s.bam"' % bam_stem - return_code = run(cmd, log_handle) - if return_code: - return "Error %i from command:\n%s" % (return_code, cmd) - if not os.path.isfile(bam_stem + ".bam.bai"): - return "samtools indexing of BAM file failed to produce BAI file" - - shutil.move(bam_stem + ".bam", bam_file) - os.remove(bam_stem + ".bam.bai") #Let Galaxy handle that... - return None #Good :) if __name__ == "__main__":