-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCONS - DNA Consensus and profiling.py
120 lines (99 loc) · 3.24 KB
/
CONS - DNA Consensus and profiling.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#DNA Consensus and profiling
#f = open('input.txt', 'r')
#g = open('output.txt', 'w')
# Modified to run from manual string input over string import from file.
stringlist = [
'ATCCAGCT',
'GGGCAACT',
'ATGGATCT',
'AAGCAACC',
'TTGGAACT',
'ATGCCATT',
'ATGGCACT',
'',
'',
''
]
con = []
def trackall(st):
A = []
C = []
G = []
T = []
counter = 0
stringcount = 1
while counter < len(st[0]):
#initial string check - fills list array
for i in st[counter]:
if i == 'A':
A.insert(counter, 1)
C.insert(counter, 0)
G.insert(counter, 0)
T.insert(counter, 0)
counter += 1
elif i == 'C':
A.insert(counter, 0)
C.insert(counter, 1)
G.insert(counter, 0)
T.insert(counter, 0)
counter += 1
elif i == 'G':
A.insert(counter, 0)
C.insert(counter, 0)
G.insert(counter, 1)
T.insert(counter, 0)
counter += 1
elif i == 'T':
A.insert(counter, 0)
C.insert(counter, 0)
G.insert(counter, 0)
T.insert(counter, 1)
counter += 1
while stringcount < len(st):
# Begin filling in the matrix data
newcount = 0
for x in st[stringcount]:
if x == 'A':
A[newcount] = A[newcount] + 1
counter += 1
newcount += 1
elif x == 'C':
C[newcount] = C[newcount] + 1
counter += 1
newcount += 1
elif x == 'G':
G[newcount] = G[newcount] + 1
counter += 1
newcount += 1
elif x == 'T':
T[newcount] = T[newcount] + 1
counter += 1
newcount += 1
stringcount += 1
#print ('A: ', A)
alist = ' '.join([str(elem) for elem in A])
print('A:', alist)
clist = ' '.join([str(elem) for elem in C])
print('C:', clist)
glist = ' '.join([str(elem) for elem in G])
print('G:', glist)
tlist = ' '.join([str(elem) for elem in T])
print('T:', tlist)
#Select highest figure from each column
ccount = 0
while ccount < len(st[0]):
if (A[ccount] >= C[ccount]) and (A[ccount] >= G[ccount]) and (A[ccount] >= T[ccount]):
con.append('A')
ccount += 1
elif (C[ccount] >= A[ccount]) and (C[ccount] >= G[ccount]) and (C[ccount] >= T[ccount]):
con.append('C')
ccount += 1
elif (G[ccount] >= A[ccount]) and (G[ccount] >= C[ccount]) and (G[ccount] >= T[ccount]):
con.append('G')
ccount += 1
elif (T[ccount] >= A[ccount]) and (T[ccount] >= G[ccount]) and (T[ccount] >= C[ccount]):
con.append('T')
ccount += 1
conlist = ''.join([str(elem) for elem in con])
return conlist
print (trackall(stringlist))