-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfourteenth.py
78 lines (55 loc) · 1.39 KB
/
fourteenth.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
with open('rosalind_cons.txt') as f:
data = f.read()
seq = data.split('>Rosalind_')
line = [i.replace('\n','') for i in seq]
dna = []
for i in line:
if i != '':
dna.append(list(i[4:]))
profile = [[None] * len(dna[0]) for i in range(4)]
codon = [0] * 4
def clear_codon(codon):
codon = [0] * 4
return codon
A, C, T, G = 0, 0, 0, 0
for i in range(len(dna[0])):
for j in range(len(dna)):
if dna[j][i] == 'A':
codon[0]+= 1
if dna[j][i] == 'C':
codon[1]+= 1
if dna[j][i] == 'G':
codon[2]+= 1
if dna[j][i] == 'T':
codon[3]+= 1
for j in range(len(profile)):
profile[j][i] = codon[j]
codon = clear_codon(codon)
codon_dict = {
0 : 'A',
1 : 'C',
2 : 'G',
3 : 'T'
}
consensus = ''
def max_index(list):
max = 0
index = 0
for i, j in enumerate(list):
if j >= max:
max = j
index = i
return index
for i in range(len(profile[0])):
temp = []
for j in range(len(profile)):
temp.append(profile[j][i])
consensus+= codon_dict[max_index(temp)]
with open('rosalind_cons_output.txt', 'w') as f:
f.write(consensus)
f.write('\n')
for i in range(len(profile)):
f.write(codon_dict[i]+': ')
for j in profile[i]:
f.write(str(j)+' ')
f.write('\n')