-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCONS
42 lines (37 loc) · 1.12 KB
/
CONS
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
def Consensus(DNAs):
profile = []
for i in range(len(DNAs[0])):
A,C,T,G = 0, 0, 0, 0
for j in range(len(DNAs)):
if DNAs[j][i] == 'A':
A += 1
elif DNAs[j][i] == 'C':
C += 1
elif DNAs[j][i] == 'T':
T += 1
elif DNAs[j][i] == 'G':
G += 1
profile.append([[A,'A'],[C,'C'],[G,'G'],[T,'T']])
consensus = ''
for row in profile:
common = max(row)
consensus += common[1]
print(consensus)
for i in range(4):
record = profile[0][i][1] + ': '
for j in range(len(profile)):
record += str(profile[j][i][0]) + ' '
print(record)
with open('rosalind_cons.txt','r') as file:
content = file.read()
DNAs_number, lines, line_number, DNAs = content.count('>'), content.splitlines(), 0, []
for i in range(DNAs_number):
DNA = ''
line_number += 1
while lines[line_number][0] != '>':
DNA += lines[line_number]
line_number += 1
if line_number+1 > len(lines):
break
DNAs.append(DNA)
Consensus(DNAs)