-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcons.py
52 lines (48 loc) · 902 Bytes
/
cons.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/env
from rosa_util import *
#superstring from FASTA
def cons(seq):
nucl = ['A','C','G','T']
cons = ''
A = []
C = []
G = []
T = []
for i in range(len(seq[0])):
a = 0
c = 0
g = 0
t = 0
for s in seq:
if s[i] == 'A':
a += 1
elif s[i] == 'C':
c += 1
elif s[i] == 'G':
g += 1
elif s[i] == 'T':
t += 1
mode = max(a,c,g,t)
if a == mode:
cons += 'A'
elif c == mode:
cons += 'C'
elif g == mode:
cons += 'G'
elif t == mode:
cons += 'T'
A.append(a)
C.append(c)
G.append(g)
T.append(t)
#print cons
writeResult(cons+'\n')
aa = 'A: '+' '.join(str(x) for x in A)+'\n'
cc = 'C: '+' '.join(str(x) for x in C)+'\n'
gg = 'G: '+' '.join(str(x) for x in G)+'\n'
tt = 'T: '+' '.join(str(x) for x in T)+'\n'
#print aa,cc,gg,tt
writeResult(aa+cc+gg+tt)
if __name__ == '__main__':
f = readFASTA('data/rosalind_cons.txt')
cons(f[1])