-
Notifications
You must be signed in to change notification settings - Fork 0
/
GASM.py
executable file
·36 lines (32 loc) · 1.02 KB
/
GASM.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
34
35
36
#!/usr/bin/env python
import sys
from itertools import chain
from Bio.Seq import Seq
def flatten(listOfLists):
"Flatten one level of nesting"
return chain.from_iterable(listOfLists)
if __name__ == '__main__':
ss = sys.stdin.read().strip().split('\n')
ss_rc = [str(Seq(s).reverse_complement()) for s in ss]
n = len(ss)
l = len(ss[0])
for k in range(l-1, 1, -1):
db = dict(flatten([[(s[i:i+k], s[i+1:i+k+1]) for i in range(l-k)] for s in ss]))
db_rc = dict(flatten([[(s[i:i+k], s[i+1:i+k+1]) for i in range(l-k)] for s in ss_rc]))
f = km = db.iterkeys().next()
s = ''
while True:
if km in db:
s += km[-1]
km = db.pop(km)
if km == f:
print s
sys.exit()
elif km in db_rc:
s += km[-1]
km = db_rc.pop(km)
if km == f:
print s
sys.exit()
else:
break