-
Notifications
You must be signed in to change notification settings - Fork 0
/
GreedyMotif.py
299 lines (241 loc) · 16.4 KB
/
GreedyMotif.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
__author__ = 'Cullin'
import HammingDistance
import sys
import time
import random
random.seed()
from itertools import groupby as g
def most_common_oneliner(L):
return max(g(sorted(L)), key=lambda(x, v):(len(list(v)),-L.index(x)))[0]
def timing(f):
def wrap(*args):
time1 = time.time()
ret = f(*args)
time2 = time.time()
print '%s function took %0.3f ms' % (f.func_name, (time2-time1)*1000.0),args
return ret
return wrap
def find_most_probable_profile_kmer(text,k,profile):
max_prob = 0
ret_kmer = ''
if type(profile) is dict:
profile_dict = profile
else:
profile_dict = dict()
profile_rows = ['A','C','G','T']
for i,base in enumerate(profile_rows):
profile_dict[base] = profile[i]
for i in range(0,len(text) - k + 1):
curr_prob = 1
word = text[i:i+k]
for i,base in enumerate(word):
curr_prob *= profile_dict[base][i]
if curr_prob > max_prob:
max_prob = curr_prob
ret_kmer = word
return ret_kmer
def weighted_choice(choices):
"""
:param choices: dictionary
:return:
"""
total = sum(w for c, w in choices.items())
r = random.uniform(0, total)
upto = 0
for c, w in choices.items():
if upto + w > r:
return c
upto += w
assert False, "Shouldn't get here"
def get_weighted_random_profile_kmer(text,k,profile):
kmer_probs = dict()
for i in range(0,len(text) - k + 1):
curr_prob = 1
word = text[i:i+k]
for i,base in enumerate(word):
curr_prob *= profile[base][i]
kmer_probs[word] = curr_prob
return weighted_choice(kmer_probs)
def create_profile_matrix(motifs):
the_matrix = {'A':[],'C':[],'G':[],'T':[]}
for i in range(0,len(motifs[0])):
curr_column = [motif[i] for motif in motifs]
total = float(len(curr_column))
for base in ['A','C','T','G']:
the_matrix[base].append((curr_column.count(base) + 1) / total)
return the_matrix
def most_common(lst):
return max(set(lst), key=lst.count)
def find_consensus(motifs):
consensus = []
for i in range(0,len(motifs[0])):
column = [motif[i] for motif in motifs]
consensus.append(most_common_oneliner(column))
return ''.join(consensus)
def score_motifs(motifs):
consensus = find_consensus(motifs)
score = 0
for motif in motifs:
score += HammingDistance.calc_dist(consensus,motif)
return score
def greedy_motif_search(dna,k):
best_motifs = []
best_score = sys.maxint
for seq in dna:
best_motifs.append(seq[:k])
first_seq = dna[0]
rest_seq = dna[1:]
for i in range(0,len(first_seq) - k + 1):
kmer = first_seq[i:i+k]
motifs = [kmer]
for seq in rest_seq:
profile_matrix = create_profile_matrix(motifs)
motifs.append(find_most_probable_profile_kmer(seq,k,profile_matrix))
curr_score = score_motifs(motifs)
if curr_score < best_score:
best_motifs = motifs
best_score = curr_score
return best_motifs
def get_rand_substring(string,k):
try:
index = random.choice(range(0,len(string) - k))
except IndexError:
raise Exception('Bad input: %s' % string)
return string[index:index+k]
def randomized_motif_search(dna,k):
import random
random.seed()
best_motifs = []
best_score = sys.maxint
for seq in dna:
word = get_rand_substring(seq,k)
best_motifs.append(word)
while True:
motifs = []
the_matrix = create_profile_matrix(best_motifs)
for seq in dna:
kmer = find_most_probable_profile_kmer(seq,k,the_matrix)
motifs.append(kmer)
curr_score = score_motifs(motifs)
if curr_score < score_motifs(best_motifs):
best_motifs = motifs
best_score = curr_score
else:
return (best_score,best_motifs)
#@timing
def gibbs_sampler(dna,k,n,start_set = None):
best_motifs = []
# Initialize with a given set
if start_set:
best_motifs = start_set
# Initialize best motifs as random kmers
else:
for seq in dna:
word = get_rand_substring(seq,k)
best_motifs.append(word)
# get score
best_score = score_motifs(best_motifs)
# Initialize copy
motifs = [x for x in best_motifs]
# Trial loop
#pdb.set_trace()
for i in range(0,n):
# Pick a dna seq
index = random.choice(range(0,len(dna)-1))
# Remove from motifs at random index
motifs.pop(index)
# get profile matrix
the_matrix = create_profile_matrix(motifs)
# get random wieghted kmer
new_kmer = find_most_probable_profile_kmer(dna[index],k,the_matrix)
#new_kmer = get_weighted_random_profile_kmer(dna[index],k,the_matrix)
# Insert into collection
motifs.insert(index, new_kmer)
curr_score = score_motifs(motifs)
if curr_score < best_score:
best_motifs = motifs
best_score = curr_score
return (best_score,best_motifs)
def main():
x = ['CCCCGCACATCGGAAGCTCGCACGATTGCGAAAAGATGAGCCCCCTGAAGGTCAAAGTTATTTGAGTTCACCCCCCGATAGAAATGTCTTGAGTTTCTAATCCTTTGGCGCTAACCTTGTTATCCGGACGTTAGGATGATAAACTAACTATGGTTCGCTAACCCCCGCACATCGGAA',
'GCTCGCACGATTGCGAAAAGATGAGCCCTGTGATCTAGTCCCGCCTGAAGGTCAAAGTTATTTGAGTTCACCCCCCGATAGAAATGTCTTGAGTTTCTAATCCTTTGGCGCTAACCTTGTTATCCGGACGTTAGGATGATAAACTAACTATGGTTCGCTAACCCCCGCACATCGGAA',
'TTATCCTGGACACTAAACACGGGACCCAAAGGTCCCCACAGTTTTGACTGGACGAAGGGCAACCCCTGCATGGACTGCTCCCCAACTAAGCCTATAAATTGACTGGATAAGAGAGCGAGTCGGCACCCTGCATAATCGGCCTAATGTCGTGTAGTCCCGCTACGCCCCTTGTAATCC',
'AGCGTGTCTACTTGCGAATGATCTCCTAGAGACAACTTCCCCGCCAAGACCCGCTAGGCGCCAAACTCACCCTAACATCCGTTTGCCTAGTCCGTGATGCCTTTGAATGATGGTTAAAGAGCTGCTCGATTCAGAACTACCCTCTGTCCGAGAGTCCCGCAGTAGTTGATACACGGC',
'TAGCTAGGAACCACTAGTCCCGACCCCATTCTCAACGGTCTCGCTCAAGGGGGAGCTTCAACTAGTCTCCTGATAGACCATTTGCATATTTACAGGTCTTTGCGGCCGTAACCTATCGTCCGAATACGTCCTATACGCCGTCGTCAGACGAGTACTGATGTGACTGGGATAGCGACG',
'TTACTCTTTAGTAGGATGAACTTGGAGGAAGAACTAGGTAATGGCGCTTTCTATTGTCCGACAGTCCCGCTTCATTATTAGCAGCGGCCGTTGTATCGCCGACCGACGAACGGGTAGGGCAAGCCTCTGGGTAACGTTATCCGCTACCCTGGCGCCCTTACGAAGTCGTCGACCCAT',
'GGCTACAACTAGAGTATAAGAAGGTGGACGCCTGAGGTCGGCGTTCCTCTGAAGCTTGCTTGAGATTCATTTCGAACCTGTGTTAGATGGGTATCGTCACGTCCGATTATGGGATGGCGGTGTTTTTCTGGACAATATGTCATCACTAGTCCCGGGAGCTGATCTTCGCCATGATCA',
'CCATACGGGCGAAAAGCCGTTTGACACGGCTTGCTGTCGTTCTGCTGCGGCTAAGTAGGTTGCGTCCACTAGTCCGCAAAAAACTCGTGCAGTTGCGAGGGTAGTGGCATCGAAAAATGAGGCTCCCTGAGCACTATTTATATGATGTCTAACAGCGAGCTAGCCGGACGCTTCGGG',
'AGTTACTCTCGATCGGGTTTGCCAGTAATCGGTCAGGTTAGGCCCCTATCGGGGGCTATGGAGATCATCCAGGCATAGTAAACACGCTTGCCTGGCGGAACTATGCAGCAGCACACCTGTCCAGGTGTCCCGTCTGATCTTGCTGACTCATAAATATCTTTGCCGAGTCCCCTCCTT',
'CCGAAGAGACTGAGGCCAAAACGGGGCGGTGCTGTGATTCTTGTGATAGTGGAGATTCCGGTCCCCTGCCACTCGCACTACGGGCTTGGCGTGCCCAGGCCGGGTACGAATACCAAGGATCACCTATTGTCCACTGCCCCCGGAGAAAGGGCGGGGAAAAGGCAATGTCTGCCTAAA',
'GGTTAGCTCTCCTCCGATGACGCACGGCGCAGTAACGTATCGCCTGGGATATCCCCGGCTACGTGGTAGCATCCTCGCGGGGGGGAAGTGTTAGCTAGTCCCGCAATCAAGCCGGGCTACGTCTTACGCTGTAGCTTGATTTAGGCATGATCTGGCGAGACACCCGGTTCAAAGCGC',
'ATATTTAACACTCTGTGCATGGGCTTATACCCGTGTGCGGGGTTGGGCCGGATATTACCTTGTCAACTTTAACTATCCGGACGGTTCGAATTCCACTACTCACTCTGCACCTCGTATCGTGTTCACTGCTCGTAGGTACTTTACCACTCCTGGGGTTCATCCACTAGTCCCTAATGT',
'ACCGAAAATGATATCCCCAGACTCCGATTTGCCTCTGTGTACTAGCTACGCTGTCCATATGTCCCGCTCCATTCAGAAGGTTATCTCTTTCGAGCCCAGGAATCGTTTCCACCAGAGACCTCAAACCGTCCGCAGTAACTACGGCACTAATACATGGATTCAGCTGCACCTACTGTG',
'TTGTCCACTAGTGGGGACTGGGTGCGAGCGCAGTCCTAGAAAACGCGATTCGGGTCACTGAACCGCGAAGAGTGGGCACTACACACCAGTAAACCTTATTAGCGCGAGTATAACCCAACGCAATTATCCTCCATAGGTTGGATGCAGGGTGACCTACAATATAGTTTTCGCTAACTA',
'AAGGTTGTCCACTAAATCCGCGAATAGAATTTACCGATTTCCTAATCCCGAACATACCAACGGCTATCGGTGAATGGTATGATACGCCGGGGCGGGTCCTCCGGAGTTTCATTCATTTCCGCGTCCCATAATTAGCTGGCGGCCTAGAAGCTCAGTAACGCCAAAACTAATTATTTG',
'TTGTCGGAGCACATGACCCGTACCACAGGTGTGCAACACTGGACCAATCTAACGGGTCGTCGAGGACGTGTCCACTAGGAGCGGGGAACCATAACCTTGGCAAGCACTCATCTCTCCACTCGTGAGGCACCCCGGCTGCCCGCCTTGACGCAGCGGGGAGTGTTTAACTCCCGCGAT',
'ATGGTTTAATTGCCAGGTCTCTGCGGACTAGTCCCGTAGATCGTCTGTGACGCCAGGGGGCTCGAGTTCAACGCTAGAGCACGTCTACTACTCCTTCCAGTACATTCTACAGAACCCCATATCGTGCGTGTAAACCCACCCAAGAAATAAGTGGAATACAATAAGGGTTCTCTTAAA',
'GCTCCTGAGATGATGTTTATTCCGGGCGTTATAACAATGGTTACCGGAAGCATAGCTGCGCCGTGCGCGCAGTAACACTTATCACTCGCGGGGGCAACTACGTGTTAGTCAAGGCTTACATGGGTGGCGATCGGCATGTCGTACGTTTGTCTGATAGTCCCGTGGTGCAAGCTCTAG',
'ACTCATCATCAACAAAAGTTGCAGAAGAGGGCAAAACACCACTGAACCAGAGTTTAGATCGTGATGTCCACACCTCCCGCCTCGTCTCGGCGGTCGCCCAGCTGCCCCGGTTGCGCCGCTCAAGAACTCGTATAGGTCAGCATTATAGTCTTGGGTCTCTGGAGATTCGCGGGGTTG',
'GTGTTTAATGTTGACCGACGGAGCTAGCAGCGTCGTAGAAGGTAGCTGAAGTATAGTAACGAGGGCAATTACCCTTTTCGCGACGAATCTGAGCCCTGTCCACTAGTCGTCGGTCATACCAAGCGTGAGATCCCCTCTATCGCCCAGTACGATAGAAACGTCTGATATATTATTATC']
best_score = sys.maxint
best = []
for i in range(0,1000):
temp = randomized_motif_search(x,15)
#print temp
if temp[0] < best_score:
best = temp[1]
best_score = temp[0]
print best_score
for i in best:
print i
if __name__ == '__main__':
#main()
fin = []
for x in range(3):
# z = ['CGCCCCTCTCGGGGGTGTTCAGTAACCGGCCA',
# 'GGGCGAGGTATGTGTAAGTGCCAAGGTGCCAG',
# 'TAGTACCGAGACCGAAAGAAGTATACAGGCGT',
# 'TAGATCAAGTTTCAGGTGCACGTCGGTGAACC',
# 'AATCCACCAGCTCCACGTGCAATGTTGGCCTA']
z = ['TCACAAGAACACTATGGTGAGATTTCGCACGCTGTCCTTCTCGCCAGTTACCTTGGAGTCCAGATCTCCAAACTCCCCGCCCTAACGTCACTTACGATGCCATCGTCGAAACGTGTGGATCCCTTCTTAGGATAGTCCCTTGCGCAGTAGAGGCGGAACTCAGTCCTTGATGATGGGGTTCACACATGCGGGTTATATATTACGGCTGGGGTTTGTGTACCTCACTGTGACTTTTCAAAGGAAAGTAATGTACATTCAACTAACCATCCGCGGTGCCGGGTCCACGTCCTACTCGGCTTCCTCCACAATTTTGGATCACAAGAACACTAT',
'GGTGAGATTTCGCACGCTGTCCTGGCGTTGTTATGTGTTCTCGCCAGTTACCTTGGAGTCCAGATCTCCAAACTCCCCGCCCTAACGTCACTTACGATGCCATCGTCGAAACGTGTGGATCCCTTCTTAGGATAGTCCCTTGCGCAGTAGAGGCGGAACTCAGTCCTTGATGATGGGGTTCACACATGCGGGTTATATATTACGGCTGGGGTTTGTGTACCTCACTGTGACTTTTCAAAGGAAAGTAATGTACATTCAACTAACCATCCGCGGTGCCGGGTCCACGTCCTACTCGGCTTCCTCCACAATTTTGGATCACAAGAACACTAT',
'GAGGATCAATTAAGATCTCTCCCGTCTATCGGTATGTCTTGGGTCACCTTGTTCAGCTTCCAGATATGCAATTTTTGCTTTCGAAACAAAGGTAGAACATCCGGCAGCAGGTTGGGGACGCGATGTGCCGGACGCGTAACCTTATCCCGTAGGGAGATACTCTAGGTCCCAGTACGGATGCAAGGTGAATGCACGGGGCGGCCGGACCTCAACGTCCCAGGCGAGCTAATGCAGTTCGTTGCTACCAGCTGCGACTGTTATGTGTTTTGCTCCGACTAGGGAGGAAAGTTAACTTAGACCAACTTCGTGTCCGTTGGACTTCCAACTCCC',
'CGCGTGCGGTAACTCAACCGTCGCAGGTAGAGTGGTGGATCTGTTCGCTGTACCATTAACTATTCAGTTGAATCGTACTTCCTCATCTCCGACTGAGAGTGGTCGATGACAAAAGAAGAGTTAAATATTGCCCATTGGCAAATAGGCCTAAATAACTGTCAGGGCAGGTGTTTCCCCACCCTTTATGCCCCGATTTAGTGTGCGGTCTGAAAGTACTCCCCTCTAGGACTCATCTGTCCACTCTGTGTCCAGGCATCATCTGAGACCCCGTTGTTGCTGGAGCATTGCAGTGTCACCAATTGGCGCGATCTAGCTATTTTGTCAGAGAAC',
'TCTCGTGAATGTTGCTTGTCACGGTGAAAGGGGGTGCTCGTATGATGACTCCATACCAGAACGAGGCCATCTGTTATGTGCCATCGTGGCTTGAGGTGTAAGTATACTGCCCCTACCCAGCCTTCCCGACTTATAACTAGCCAAGCTGCCACGCTATGCTTAGTTTCTAGCTCTGCCCGTGGGTTATTAGCTTACCGAAAGAGCGCACGTTACAGAGATTTCTCGTAACAACGTCGCAGAAGCATCAGTCGGCAGAGCAGTCTAGAAGACCGTCACTAGGATGGCCAAACGTCTTTTGTGAATGTATATGACCCATGTACGTATATTGCC',
'CCTGGATCGAATATGTGAACTAACGAGAGACGACATATGCCAAACGGGGAAACTAGCGAAACAGTTCGAACTAGATGGGCACTACGCTGGAGTCAACCGCTGGTTACATCAGATTGAAACAGCACCTCCTTGGCAACTCAGACGATTTATACTCGAATCTATCATGGGTTAAGTGGCTTCCTGCATTAACACACTTCGCCCCTACGTGTGCTGCGACGACTCCCCGATTACAGCGGGCACTGCCGACTGCGGCCACGAGTTGCGAAGGACGCGCACCAAGCTTCACCCCTAAATAAAACCTCTATAACCGCCCCGCGCTGGGCCCAGGAG',
'TGACCCTCGAGTGTAGTATCGTGCACATATCGCTAAAGTCAGGTCTCCCAGCTCGTTTGGGTTACTAGCCGATCTATCCGAGCCAAAGGTGATGACGCCAAACACCTGTCTTACACGAAAGATCTGTTATGTTCAACATGTGGGCGTTCGGGGAGCTGCTAATTTGCCATTGCTAAGAGTGCAGTCTGGAGAACCACTACTTGAGCGTAGGAGATTCTACCATCAAGTAAACCAGCGGGATAAAGTATCGTGATGTTCAAAGGCCAACATTGCCAAGCAAGACGTAACTCACATTTGCTCTTGTCCTTGGTCACGGCTAGACCTCCGCTA',
'CAGACACTTCCTACTGCCTTATGTCCATTGTTGTGAACGTCTCTTGCTATGAGCATCTCGGTGAGTTTGTCACGTGTATATCAAGCTTGTAGACTAGGCCCCGTCGCTGGGAGTGCTCTTACGACAACAGACAAACGTGGATCGAGTATGTGGTCATCCAGCAGCCCATCTGCCGAAGCATACATGCTCCTGAAGCCACGGTCCGAACCTACTAATACAGATTGCCCGCGGCCCCCGGCTCCGTCTCGTCCAGTATCAGTTAGGGGGACGCGCAGCATCGACCCAAGGCAGAAAAGAATCGTACCGTAAGCCTTGTGCATATCTCGGGAT',
'CGCATGGAGAGCCCTGGTGAGAAGACGGGGCTTTAATTAGGCGTTGCAAACCGTATAGCGACGTGTAGGGCAGCTTGCTTAGCGCATCCCGCTGTCCAGGGGAATCTCTTGAGATATAGCCTAAGGCGAGATCTAAACCAAAAGAGTCTAGGGCGCAAGGGACTGGAGTCCCGCTAAAAATGGACTTGAATGCGAAGGATCTGTTATGGATCGGCGACGCGCCGAGCGAACGGTATCGGACCAGACTATATTAATTCCAAGTATCGAATCCTATCGTAAGGGGGTGATAATTTTCCGTGTGAAAAAGGCTTTAATCCTTGAATACGGAGC',
'GGGCACTGAAGTTCCAGATAACACCTGGATGGTTTATGTGTGCAGAAAATTCTGCAATTATTTTTGCTGACGCATCCTGCTACGTAGTATCTCCTTTGGTGACCTCATAGTCCACCCCCTCCGGAGGGCCTAGTAAAAAGGTTGACATTGCTCGTCAGTGAAGGGTTAATCTCGCAATCGTTATCTAGTTACAAAGTTGCCGTCAGTTCATTCTAGCCTAACTTCGATGTTCGAAGCGGCGGCCTATTCGACCATCATGTCTTGAGGTCTAAACACCTTTGTGCTGCCTCTGGTATATTGCAGGCTAACGACTAACTTTGGATACCAAAC',
'TTAAACTAGACGAGATAATTAAGAAAGCATTTTTTGGGTTAGATCTACTCTGCGGTTATACCCGTACTACTGATTGACGACCCTGCTAGCGTCCCGCCCTTAAACGTCCGAAGCGAAGGGAGGACGTGGTCGATCAATATCCGAATACGCTATTTTCAGCTTCCGGTGTCAAGTGTATGACCCACTACCGCAATTAAAACTACGCTATTCATTTCTTCACACGCGTTGGATCTGTTATAGAACAATTCCTACTGGCGGCCGAAACACAGGTAATACGATACGCGTTACACCTATACAGTTTAATACTCGACAAGGATGATTGAGGAAGTT',
'TCGAAGTCTCCAGCAGCTAATTGCTAGTAGCAGGATTGGCAGCTGATCTTGTGAGGTGCGTGTGGCCAATGTGGAAGCTCATACTGTGTCACAATCGTAGGAAAAACTCATTTTCTGGACCCGTTAGTTGGATTCATTATGTGTGTACAGTGGATGCTCGACACGTCTGAGGCTAATGCTGATATCTAGCTACGCGACATACAGCACCTGGGTAAGCTTACCTCGGGGATTCTTGTGGGGAGTACAGCGCTCATACAGACTCAGACCTGCTCAGATCGCTGAAATTAATTCCTCGCCTGCAGGGCCGAAGGCCCATGCCCGGTGCGCGGC',
'GCTTGACTCGTGCCGCGGGATCTGACATTCCAGAGATTCCTATGCCCTACGATTTGGTATTGTTATGTGTGCTTGACAGTCCTTGTAGGCATAGCAGGCAGTAATATATACTATGTGTACCAATCACGCAACCTCCGGGTTCACTGGTGTAATGGCTACAGACCACAATGTTTAGCTCATCAATAGACCCGAAATTTTGTGGCGGCGACTCGAGCGCTCCGGTGTGCATCGTCTATCCTGGTACTCTCTAATAGGGCTAAACGGGTCCGCTAGCACGCATCAATCGGGGAGCACGACTACAACGTCACGAGGGGACTTACCAAGGTACGT',
'CGATAGGTTTAACAGGAACTGTTATTTCGGTAAGGCGGACAGGCTGGCTTATAGCATACGGAAGCCGGTAATACAGAAGACAAATTGCAATATGGGTGGTAAGGAGCACACCCGGATTGGTTGGCCTAGACAAAAGATCGGCTTGCGCCTTTTCACAGGCCTTACCTTCCCGTGGATCTGTAGGGTGGTGGTCTTTTTGCTGGTCGGAGGGACTAACGATCTCTAGAAGCCATATCGCAGAGGAGCAGCCGGCCCTCCTCAAGAACGGGACACATCAAAGGTGATGTAACGACTCTACGTTAGGGGAGAGCGCAGGTACTCGAATTGCAT',
'CACCGCAAGGATGAACTTTTCGAGTTCGTCGAAGCTCAGGGCCATTCGTGAATAGAGTACCCGTATCACTCTTCTTATGGTACCGTGGTCAATACCAATTTGACTAGTTCGCTCGCCCCTGTTACGCCCGGGAGTAATTCCCCCTATACGGTAGCTTAGGCCAGATATGCAATGAATCGTGGGCGTGGTGCGTGAGCATGCGTTTCAGTGGATCTGAATTGTGTTAGCTTGACACAATCTTAGGTGTTCGACTCGTTGATACAGGACGATGAAGGCATCTCTAACTCAAAGTTTTTTTACTACTTGGCCTAGGCTTGCTTGGAGGGCGGA',
'AAAGGTGGGCGGAGGGTGTGCACAGTTATATTATAGACCGAGCAGACACTGATCAATTCCATGCAGAAAATAACTATTATTCGTTGATTATTTCACTGGATTCATAAGCAGCTGCCTCCGTGTAAAGGAGCACATTGTGATTGGTAGGTCTCGAGCAGCGGAGCTCTTTTTCACACCTCAGGGTGCAATATATCTTTATGGATCTGTTAATGGACTAACCCTGTCCGCGATTAGGCACAGTAAAAGACTTAATCGAACCTGTTTGAAAATGCGACTGGCCAGGATACGTAACCATTTATTTAGAGATACCAATCGGGCAGACTTCCCCCT',
'CTTATTTGCCCCACCGTTAATGGATGCTGGCCAGTTCGCTAGTTGGCGGTCCGTGTGACGGATATGTCTGTTATGTGGTGTTGAACGGCCGGCCAGTTACCGTTGGCTGCCGTATAGAAGCCGTTTATATCGACTACCGGGCGGGAATACCACTACGGAGGCTGTGCGGGAGCTTGACCTCGATCAAGCTTTCGACATGTCACCTTCACGCAGGGCCAGGGCTGGTGCCGGGACGTGTAAAGGAGAGTAAGTCAGGAAAATCCTTACGGTTCCTCGGGCTACTTGGTTGATACGGGTTCGGGGGTCCTATATCTTTTTTGCCCACGGATG',
'GACATCGTCTTGGGGACCGTATTTAAACTATCATCGATGGAGTATCATGCAAGACTCTAGGCACGGTGCAAGCCTGAGCCGAACTGACCCAAAGTATTAAGCCTCGCGGCTTCCGAACGGTGGGCGGATGTACTCTTTGGATCTTGGATGTGTAGAAGTCCGAACTCTCGAAACTTAGACACCGCGCCTGGATTCCTATTTCCGTCACTCATCGTGAACTTCATTAGAGCTAAGAGGCTCAACCTCTGAGTGGGCGACGGTATGTCTCAAGAATGGTCAGGAACGCGTTACATCCGATATCAACGTATTGTCGCACTGCACCCGCAAAGT',
'GCCCCTAGTATCCCCTTCACAATCATGGCCGTGCACGGACGGATGGAAACGTTATGTGCGTGTGGCCGGGTTCTGGGCATTTGAACCCACGCTGATATCGCTGATTGCGTACGTTCGGGCGCAGAATGTACACTTCCGTTCAACGCCTCATGCCGGGCGGCGAGCGGACATCTACTATTGTGCTACAAGGCGTTTGCTTTCCTATTGCTCGTCGCGTAGAGATGGGGTGGATCTTATGAGCTCCGCGACACTTTAAATTGAGCCAGGGGGTGTCGATCAAATTACAGCATTCTTGAACCGCCACCCCGGTGGCCCTCAGGAATCCCGCCT',
'TCTTGAACTGATCCTGGTACGTAAGTGAAGCCACGCGAAAGTGTAGGTTGGCAGCACTATAATTGGAATCGTTATGTGATCGGGTGCGAAGTGAGTACGGTATAGGGCCCCATGTGAACGAGTACTCTGGGGCACGCAGAAGAAGTCCGAAATCCATGATACTTGTCGCTGCGGGGAGAGTAGATAGCTCTAAAAACTCGTGACGCCCGAGTGACAGAACGCCCAGCCCTAAAGGCAGCCTGTCCGCCTTTAAAACGATATTTACTAGCGCTTACGAGAGCTTAAGTTGGCCTCTGGAACGGTGCACGAGGAATACCCCGCGACTCACAC']
max_score = sys.maxint
for i in range(0,90):
temp = gibbs_sampler(z,15,100)
if temp[0] < max_score:
best = temp[1]
max_score = temp[0]
# if temp[0] <= 9:
# best_1.append(temp[1])
fin.append(gibbs_sampler(z,15,1000,best)[1])
for x in fin:
print 'NEW:'
for i in x:
print i
# actual = []
# for i in range(0,len(fin[0])):
# column = [x[i] for x in fin]
# actual.append(most_common_oneliner(column))
#
# print actual
#print max_score
#for i in best:
# print ir