-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCORR.py
executable file
·33 lines (29 loc) · 881 Bytes
/
CORR.py
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
26
27
28
29
30
31
32
33
#!/usr/bin/env python
import sys
from collections import Counter
from Bio.Seq import Seq
def hamm(s1, s2):
return sum([int(a != b) for a, b in zip(s1, s2)])
if __name__ == '__main__':
ss = sys.stdin.read().strip().split('\n')
c = Counter()
for s in ss:
src = str(Seq(s).reverse_complement())
if src in c:
c[src] += 1
else:
c[s] += 1
good, bad = [], []
for k, v in c.viewitems():
if v >= 2:
good.append(k)
else:
bad.append(k)
for b in bad:
try:
gi = [hamm(g, b) for g in good].index(1)
print('%s->%s' % (b, good[gi]))
except ValueError:
brc = str(Seq(b).reverse_complement())
grci = [hamm(g, brc) for g in good].index(1)
print('%s->%s' % (b, str(Seq(good[grci]).reverse_complement())))