9 print('Usage:',sys
.argv
[0],'<bam file> <output prefix>',file=sys
.stderr
,flush
=True);
12 outPrefix
= sys
.argv
[2]
13 if os
.path
.dirname(outPrefix
): os
.makedirs(os
.path
.dirname(outPrefix
), exist_ok
=True)
14 uniqBamName
= ''.join((outPrefix
,'.uniq.bam'))
15 multiBamName
= ''.join((outPrefix
,'.multi.bam'))
16 nfoName
= ''.join((outPrefix
,'.info'))
17 readCnt
= {'Uniq':0, 'Multi':0, 'Secondary':0, 'Total':0}
19 with pysam
.AlignmentFile(bamFile
, "rb", threads
=4) as samIn
:
20 uniqBam
= pysam
.AlignmentFile(uniqBamName
, "wb", template
=samIn
,threads
=4)
21 multiBam
= pysam
.AlignmentFile(multiBamName
, "wb", template
=samIn
,threads
=4)
27 elif not aln
.is_secondary
:
31 readCnt
['Secondary'] += 1
35 with
open(nfoName
,'w') as nfo
:
36 nfo
.write(str(readCnt
))
38 if __name__
== "__main__":
39 main() # ./separateSTARbam.py Aligned.sortedByCoord.out.bam Separated &