Skip to content

Commit

Permalink
BAM file processing according to AnnoJ data type.
Browse files Browse the repository at this point in the history
  • Loading branch information
Vipin T. Sreedharan committed May 18, 2012
1 parent b6cd016 commit 2b70955
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions nextgen/AnnoJBAM.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/python
"""
Write a BAM file content to a plain text format.
Usage: python bam_to_txt.py in.bam > out.txt
"""
import re, sys
import pysam

def AnnoJ_BAM(bam_read):
for rec in sam_reader.fetch():
orient=None
for atb in rec.tags:
if atb[0]=='XS':
orient=atb[1]
print rec.qname, orient, rec.pos, rec.qlen, sam_reader.getrname(rec.rname), rec.query

def sort_BAM_TAGS(bam_read):
"""
"""
for line in sys.stdin:
print line.strip('\n\r')
outsam=pysam.Samfile("-", "w", template = bam_read)
for rec in bam_read.fetch():
new_cont=rec.tags
new_cont.insert(0, rec.tags[-1])
new_cont.pop()
rec.tags=new_cont
outsam.write(rec)
outsam.close()

def __main__():

try:
bam_file=sys.argv[1]
except:
print __doc__
sys.exit(1)
sam_reader = pysam.Samfile(bam_file, "rb")
sort_BAM_TAGS(sam_reader)
sam_reader.close()

if __name__=="__main__":__main__()

0 comments on commit 2b70955

Please sign in to comment.