-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFindChimers.py
More file actions
27 lines (24 loc) · 817 Bytes
/
FindChimers.py
File metadata and controls
27 lines (24 loc) · 817 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from pysam import Samfile
from collections import defaultdict
from glob import glob
from os import path
reads = defaultdict(lambda : [None, None])
seqs = defaultdict(lambda : [None, None])
chimlist = open('chimlist.txt', 'w')
for fname in glob('assigned_*.bam'):
if fname.count('_') > 1:
continue
print fname
samfile = Samfile(fname)
for read in samfile:
qn = read.qname
if reads[qn][read.is_read2] != None:
print qn
assert False
reads[qn][read.is_read2] = fname
seqs[qn][read.is_read2] = read.query
if reads[qn][0] != None and reads[qn][1] != None:
if reads[qn][0] != reads[qn][1]:
chimlist.write("%s\t%s\t%s\n" % (qn, seqs[qn][0], seqs[qn][1]))
del reads[qn]
del seqs[qn]