-
Notifications
You must be signed in to change notification settings - Fork 0
/
w_1.py
407 lines (350 loc) · 22.9 KB
/
w_1.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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
import copy
import collections
import sys
sys.setrecursionlimit(10000)
def trie_patterns_input(file):
read = open(file)
patterns = []
for line in read:
l = line.strip()
patterns.append(l)
return patterns
def trie_construction(patterns):
G = {}
labels = {}
root = 0
new_node = 0
G[root] = []
labels[root] = []
for pattern in patterns:
current_node = root
for i in range(len(pattern)):
current_symbol = pattern[i]
suc = G[current_node]
for successor_node in suc:
if len(suc) > 0:
index = suc.index(successor_node)
if labels[current_node][index] == current_symbol:
current_node = successor_node
break
else:
new_node += 1
G[new_node] = []
labels[new_node] = []
G[current_node].append(new_node)
labels[current_node].append(current_symbol)
current_node = new_node
return G, labels
def trie_contruction_print(G, labels):
edges = []
file = open('trie_output.txt', 'w')
for node in G:
for i in range(len(G[node])):
line = str(node) + '->' + str(G[node][i]) + ':' + labels[node][i]
file.write(line + '\n')
return edges
def out_degree(G):
out_degrees = {}
for node in G:
out_degrees[node] = len(G[node])
return out_degrees
def in_degree(G):
in_degrees = {}
for node in G:
if node not in in_degrees:
in_degrees[node] = 0
for key in G[node]:
if key not in in_degrees:
in_degrees[key] = 0
for node in G:
for key in G[node]:
in_degrees[key] += 1
return in_degrees
def prefix_trie_matching(text, G, labels, i):
itr = 0
symbol = text[itr]
v = 0
out_degrees = out_degree(G)
while True:
#print(symbol)
#print(itr)
found = 0
w = None
for edge in G[v]:
index = G[v].index(edge)
label = labels[v][index]
if label == symbol:
found = 1
w = edge
break
if out_degrees[v] == 0:
return i
elif found == 1:
itr += 1
symbol = text[itr]
v = w
else:
return 'No matches found'
def trie_matching(text, G, labels):
x = 0
y = len(text)
indices = []
#return G, labels
while True:
match = text[x:y]
#print(match)
rt = prefix_trie_matching(match, G, labels, x)
if isinstance(rt, int):
indices.append(rt)
x += 1
if x == y - 1:
break
return indices
def modified_suffix_trie_construction(text):
trie = {}
root = 0
new_node = 0
trie[root] = []
symbol = {}
symbol[root] = []
position = {}
position[root] = []
leaf_labels = {}
#colors = {}
#index = text.index('#')
for i in range(len(text)):
current_node = root
for j in range(i, len(text)):
current_symbol = text[j]
suc = trie[current_node]
for successor_node in suc:
if len(suc) > 0:
index = suc.index(successor_node)
if symbol[current_node][index] == current_symbol:
current_node = successor_node
break
else:
new_node += 1
trie[new_node] = []
symbol[new_node] = []
trie[current_node].append(new_node)
symbol[current_node].append(current_symbol)
if current_node not in position:
position[current_node] = []
position[current_node].append(j)
current_node = new_node
if len(trie[current_node]) == 0:
leaf_labels[current_node] = i
return trie, symbol, position, leaf_labels
def maximal_non_branching_paths(trie):
out_degrees = out_degree(trie)
in_degrees = in_degree(trie)
paths = []
temp = copy.deepcopy(trie)
for node in trie:
if (in_degrees[node] != 1 and out_degrees[node] != 1) or (in_degrees[node] != out_degrees[node]):
if out_degrees[node] > 0:
visited = copy.deepcopy(trie[node])
while len(visited) > 0:
stack = []
stack.append(node)
edge = visited.pop()
stack.append(edge)
while in_degrees[edge] == out_degrees[edge] == 1:
u = trie[edge][0]
stack.append(u)
edge = u
paths.append(stack)
used = []
cycles = []
for key in temp:
if key not in used:
cycle = []
cycle.append(key)
curr = key
while (in_degrees[curr] == out_degrees[curr] == 1):
u = temp[curr][0]
cycle.append(u)
curr = u
if cycle[0] == cycle[-1]:
cycles.append(cycle)
for i in cycle:
used.append(i)
break
for cycle in cycles:
paths.append(cycle)
return paths
def modified_suffix_tree_construction(trie, symbol, position, leaf_labels, text):
pos = {}
length = {}
new_trie = {}
paths = maximal_non_branching_paths(trie)
#print(trie)
#print(paths)
for path in paths:
#print(path)
x = len(path) - 1
if path[0] not in new_trie:
new_trie[path[0]] = []
new_trie[path[0]].append(path[x])
index = trie[path[0]].index(path[1])
pos[(path[0], path[1])] = position[path[0]][index]
length[(path[0], path[1])] = x + 1
#print(new_trie)
file = open('trie_output.txt', 'w')
patterns = []
for edge in pos:
s = text[pos[edge]: pos[edge] + length[edge] - 1]
file.write(s + '\n')
patterns.append(s)
return patterns, new_trie, pos, length, paths
def longest_repeat(trie):
def dfs(root, label):
if (len(trie[root]) > 1) and (len(patterns[-1]) < len(label)):
patterns.append(label)
for edge in trie[root]:
index = trie[root].index(edge)
s = symbol[root][index]
dfs(edge, label + s)
return None
patterns = ['']
root = 0
dfs(root, '')
return patterns[-1]
def trie_input(file):
read = open(file)
trie = {}
for line in read:
l = line.strip('\n')
l = l.split(' -> ')
if l[1] == '{}':
trie[int(l[0])] = []
else:
x = l[1].split(',')
x = list(map(int, x))
trie[int(l[0])] = x
return trie
def colors_input(file):
read = open(file)
c = {}
for line in read:
l = line.strip('\n')
l = l.split(': ')
c[int(l[0])] = l[1]
return c
def trie_coloring(trie, colors):
while len(trie) != len(colors):
for node in trie:
#print(colors)
if node not in colors:
children = trie[node]
found = 0
for x in children:
if x not in colors:
found = 1
break
if found == 1:
continue
else:
colors_children = list(set([colors[c] for c in children]))
if len(colors_children) == 1:
colors[node] = colors_children[0]
else:
colors[node] = 'purple'
return colors
def longest_shared_substring(trie, symbol, leaf_labels, text):
colors = {}
index = text.index('#')
for leaf in leaf_labels:
if leaf_labels[leaf] <= index:
colors[leaf] = 2
else:
colors[leaf] = 1
def color_node(node):
if node in colors:
return colors[node]
children = trie[node]
color = 0
for child in children:
if child in colors:
color |= colors[child]
else:
color |= color_node(child)
colors[node] = color
return color
for node in trie:
color_node(node)
def dfs(root, label):
if (len(trie[root]) > 1) and (len(patterns[-1]) < len(label)) and (colors[root] == 3):
patterns.append(label)
for edge in trie[root]:
if colors[edge] == 3:
index = trie[root].index(edge)
s = symbol[root][index]
dfs(edge, label + s)
return None
patterns = ['']
root = 0
dfs(root, '')
return patterns[-1]
def shortest_non_shared_substring(text1, text2):
patterns = [text1]
for i in range(len(text1)):
for j in range(i+1, len(text1)):
p = text1[i: j]
if (p not in text2) and (len(p) < len(patterns[-1])):
patterns.append(p)
#print(patterns[-1] in text2)
return patterns[-1]
text1 = 'AAAATAAACAAAGAATTAATCAATGAACTAACCAACGAAGTAAGCAAGGATATACATAGATTTATTCATTGATCTATCCATCGATGTATGCATGGACACAGACTTACTCACTGACCTACCCACCGACGTACGCACGGAGAGTTAGTCAGTGAGCTAGCCAGCGAGGTAGGCAGGGTTTTCTTTGTTCCTTCGTTGCTTGGTCTCTGTCCCTCCGTCGCTCGGTGTGCCTGCGTGGCTGGGCCCCGCCGGCGCGGGGAAACGCGCCATTCTACGTATCGTAAGCTTAAGTCCCAATGCCCACCTCGCTTACCTTGTCAGCTTATTTTTGCTGGATTGAACAGCAAGGCTTTCGATTGAGACTTCAGGCTCTGGCCGATGAATATGTGCGTAGCAAGTAGGTCTGGGTATTGTGGAACCTCAGCTTGACTACTAGAGATACACATCTGCCGAGTGATCGTAGTAGATAAAGTGACAGCGGAAACAGTGATTTTATTCCCGGTAAGCCTGACTGCCCTAACACTGGGCCAGGGTAACCAGTGACATTATACCGGCCTATGGCCATAGCGGTAAGAACAGCACCTGCTAAAAGGTTCGTATATACTGAGCCATCAGGGGGGTACCCCTGTTTCGACCAAAGACAATGGTCTTAATCTCCATGC'
text2 = 'AAAATAAACAAAGAATTAATCAATGAACTAACCAACGAAGTAAGCAAGGATATACATAGATTTATTCATTGATCTATCCATCGATGTATGCATGGACACAGACTTACTCACTGACCTACCCACCGACGTACGCACGGAGAGTTAGTCAGTGAGCTAGCCAGCGAGGTAGGCAGGGTTTTCTTTGTTCCTTCGTTGCTTGGTCTCTGTCCCTCCGTCGCTCGGTGTGCCTGCGTGGCTGGGCCCCGCCGGCGCGGGGAAA'
print(shortest_non_shared_substring(text1, text2))
'''
text = 'TTGAATGACTCCTATAACGAACTTCGACATGGCA$'
trie, symbol, position, leaf_labels = modified_suffix_trie_construction(text)
print(len(leaf_labels))
'''
'''
text1 = 'ACAACCGGTTGGGTTTTCCGGCATCTGACGCGCCCCGCCCGTGAAGGTTTTCTGATTTGATAAGGGTCGATGGCTTAAACATCGCTTAGCATACTGAGCCGTTGGGGATTAAGACCCGTAAACCATGCATTCCTTTAGGGACCGGTGTTGTTTTACGGCGGCGTGCGAGAAAAGGAATAAGGTCAACGCCGAAATTACGAGGTCTAATCCTACGTACGTCTGGGGGTCCTTATTACAAGGAGTAGACTGGCCCCTCACATTGCCTGATGCCCACATGATTGATGACGCGCGCACTGCTTTTGACGGTAGCCACGCCTGGAATCTCGTTGCCGGCGCGCTCTTAAGCGCCGACAGTCCCGTCACATATGCTGATGAAAGCTTTAGAGCTTATAGACATAGCCGGGTACCGCACAGTGTGTCTGCCTCGTAAACTTTTTAGGTCGGGGAGACCTGGTAAGATAGTCGGTCTTCCTTTAGTTTTACCTGAGTGGACCATACTTGTCCTAGTTTTTCTGCGTAGTCTCCCTAATTAAGGTGAGGGGCTTCTGCGTTAGATAAATGCATCTTGTTTTCCAAGAGATATAGTCTCACATTAACGAACTGTCGCCTTAATGTCGTCTGAGATTACCAGGCGGGCCACTCGGCTACGTAATATGGATAGGATTCATACACAAATTATGCAGGCGCGTGCGCAGACTTGGTGCTTTCCCCCAGGAATTACGGCTTGACGAGAGTGATGCTGGATGTCTTAGGCGAGTAAAGGCGAAAGGCCGCAAGGGGTAAACCTGTCTAGAACTGAGCCGACTTACGCTGCGAGCTCCAGAAACCCTTCGCGTACCCATGATTTCATCGTCCTGACTACAGAGTATCGCGTGATAAAGGGCTGGCGACGCAGTCCGCTACGATGAGTGCTGTAATATCTAAATCCCCTCTGTTACAATATCTGAGCACGAGGAGTAAGAGGTCCAGTGTACTATGAAACTTTCTATAGTTTCGTGTG'
text2 = 'GCTTGAGAGACGTACTAACCTTGAACCGAAATGAGTCTCACCCAGTCCTCCCACGTCGGAGAAGGGGGTTGTGATTAGGACCGATGTGAGTACCACATACCTCTGACCATGCCTGCCGTCGTTATGTCCTCTTTGAATCGGAGCTCTAACTGGCCCTTTACTCGAACCCGACAAGGGAGTGCTTTTCTGCTCAAAAGGGAGTACATTGACCCAACCACGTTTGGACAAAAAGACTTGAATGCTACACTTAACCGTTTGAGGCCAACCGGAATCAAAGTCGCTACTCACAGACAAGGGGTACTGCTAATCTCCGGATCCATCGTTTCCACGATTGACAACCGTTCATCGCTTACCGAAGTTCGTGCGTGAAATCCCCAGTCTCAGGTGGTCCCCCCCGGTGGTCTAGCTTTAAGAAGTAAGATATCTACCAGCTTCTGTCGGCTGGCCTACACTATATGATTAACGCATAACATTCTTTGCAAGCGAGAAGATAGAGTATCCCGCTGACCGGCCGCATGGAGTTCTACATATTGCTATCTGTTCCGAGGTCGCGAATGTCCACGGAAGATCAGATCACTGAATTATAATCTGACGCGCGAACCAGGGTACTCTTACATGCCGATCACGTCTTTTTAAACGGTCGGGTTCTCTCGACCTACTCGATAAACTCAGGATTATCGGTGGGCGCTACTTACCCCTCATTTTCGCGGCCTTCGTTGCTCGGAACGCGATAGGAGTACTATGCCACTGAGGTTCAAAGCCATAAGCCGCCCATCGGGCGTCTTGACAGCTACGCGTATTTCAGGGGCCACCATTTGGCCAAGGTTTCTGGTCCCGAGCCCGCACCGACCGAGACTGGAGCCCTTTGATAGGCCTGGAGGATTCATCTGTCGTCTGCCAGCCTGGAAGTCATCTTGATTGAACAACAATACTATCCTCCGTCACATTCACGAACCAGCCTTGTCCTAAGAGCGATTGCTCGCGTTAACGGCCCGATGTC'
text = text1 + '#' + text2 + '$'
trie, symbol, position, leaf_labels= modified_suffix_trie_construction(text)
print(longest_shared_substring(trie, symbol, leaf_labels, text))
'''
'''
file = 'nodes.txt'
trie = trie_input(file)
file = 'colors.txt'
colors = colors_input(file)
colors = tree_coloring(trie, colors)
for key in colors:
print(str(key) + ':' + ' ' + colors[key])
'''
'''
text = 'CAGCCGTGTAGTCAGGTTGGCGCTTGATGTCCCAGGTGCCACGATCGGCGCCTTGTCCTCCTTTCGAGTCGTGAGACTGGTGGACCGTGGACCCTCCTAGGTACAGGACCGTGTACAGTGCTCGGGGCAGGCCCAGCGGAACTCGCAGTGCAATCGCAATCACAAGTTATCAGTAGGTAACAGGACCACAAAGGTGATCCGCTGTGAGGTAACTCAAAACGCCGCGCCTACGGTTATTTATGTCCAATACTAGCTAAGTAGACGTAATCTCCATAGGAGATCCACTCCGAGCTCATACTAAGGCTCAATAAATCGTTTCTACCTGGGGTCATGCCTAGGTCTCACTTCGGACGGCGAGTAAGTGTGTCTTTCATCTGTCTCCTGCCCATAAGGCATGTCACTTATTTATACTTTCTCCCGCGATGACTGGAGGTCGCTCGGTTGGATTAGAGTTTGCACCGGCCAGTTGTTAGCCGTTGCAGGGGTGATTTTCCGCCCATACATGATAAGAGCTTTTAGTGTTACTAGTCTGACTTTTCGTATGCAGTCAGGATTAGCCGATTTTCCGCCCATACATGATAAGAGCTTTTAGTGTTACTAGTCTGACTTTTCGTATGCACTGCGTTCGCCCTACGATCATATTCACTAAAACGTCGTTATCATTATGGACTAGTGGGATTTTCCGCCCATACATGATAAGAGCTTTTAGTGTTACTAGTCTGACTTTTCGTATGCAAGGTGTCTAGTATAGCAGCTAAAGCCGAATCGAGAAGTCAGTCCTCTGCGAATGCTCCAGTACCTGTACCTTGTAATCTTAGTCCACAGCAAGGTCTAGTCTAAGTTGTGTACAGCAAGATTCAACTTACTATTGCCGTTTAGACAAGTGTGACGCCTAAGTTTTGTACCATCAGAAGCGAAAGCACAGCAACACAACATTCAATGGCCGGTTCCACAGGTATATTTCACAACCAGTTCCCTGATCGATCGGTCGTCCGGGCTTCCTTCCTAGTGACGTCGCAACAGGGTTCGCCAGTTGCCGAGCTAACACTTTTGGGGCCTGGGTCAGGATATTTTCCATACGCCCGCTGGGCAGCAGACGCTTCTAAGTATCTTGCACTAGCCGGTACAGTGCCCATAGGGAAGATCAACCCTGGGTGCTCTAGGGATCCATATTCAGTTC$'
trie, symbol, position, leaf_labels = modified_suffix_trie_construction(text)
print(longest_repeat(trie))
'''
'''
text = 'GTCTTGTATCAGCAGGAGAAAACAGCATAATTCCTTAGCATGGTTTTTTCAGGATAGATATAGTTATGGCCAGACCTAAAACGCGGACATAGCCTACCATATATTTTCTCAAGGAGGCAAATTTCTGAGGCACGGCACCGTCCAACGGGTCGGAGGGTCATTCAGAGTTATAGGTAACAACTAATACCTTACGCCGGAACTCGCCTCCATATGAGCTTGGGGCTCGACTCCTAGATTGCGTCCACATCATTGAGCTTACTTGAATAATGTGTCTGGGTAAATCCTGAATCCGGGGCGGCTCCCTCTGATGAGACCAGGTTATCGAGCGCCGACAATTTCACAAACTCAATACCGAATAGTCTCGGATAGGATCAATACTGCTTAAACCAACAACACTCTGGCTGTCTCGACTTAAGACTTTGCGTGGCTTAGGCCGACGGGCGGCTTAGTGTAGCTATATGACTTGATCTAGGTGAATTTGAGACAAATTGGCGCGGCTCAATGCGATACGTTCTATCTTCGTTACGTGCTCCGACTTATCGACGCCCTGCCAAGCGCGGACGAGTACTTGCTATCATACGTTTGATCTGTGTAAAACTGACAAGGAACGCCACACTGGCCTGTAATCATTTGCGTAGATCTCAGGTGGGCCACTCGTATCGCACCTGCACACAATCCGGGACTAGATAGGGCATCACTGATTCGACAAGAACTGTAGGAGCGGCGTATAGGGAGCATACCGGGTCACGCTTTTTCCGAAACTTTCCACCCATGTCTGGTGCTAGAGTCGAGGGGTAGCGGTGGCACCGCTACGATCCAAGCGGATTACTCTCGCTATTACAGATCCAGCGTCCACTATAATGACTTTCTATGAGCCCACGTCAGATGCCGGAAGGCATGAGATGGTTCTGTGAACCTCTCTTACCGTTTTCGAGTACATGGCCTAT$'
trie, symbol, position, leaf_labels = modified_suffix_trie_construction(text)
patterns = modified_suffix_tree_construction(trie, symbol, position, leaf_labels, text)
for pattern in patterns:
print(pattern)
'''
'''
file = 'trie.txt'
patterns = trie_patterns_input(file)
text = 'ATGCGGAACACATGGTCTGTACACGTGTAAGAGTACTTGTTTATTTTCACGCTTTGGATATCGAGTCCTATTCCCCCTCTGCCCACTACAAATTGTCACATTATAACGTGTAATTATAAACAATGAGTTTACTTTAGTGCGTCTTTTGATCCTTAAATCCGCCCAGTCATATGCATGAGCGGAGGACGGCTTGGTACGTAGTGCGCCTCTTAACTTGCGCCAGCGCAGCCGGAAACCCAGTATAAACATCCGCTTCCCTCACTCCGACGGATCTATGGTTATACTAACTAATTGTGGTGTGAGGAGAGCGGGCCCACTGAGTTCCAAACCGCGCCACCTTCTATAATTTTTGATTAGTGAAGGCCCAGCTTTCACTCGATGTACTTTTCCTGTGCACCGCACAAGGCGTTAACAGGTTTGTACCTGCTGGTCTCCTTAAACTCACCGCAGGAGGTCGGCCAAGTGACTGCTAAGCTCTAGGCTCGTGCTATAATAAAGATTGCGACGACAGAGCGCTAACACATCCGGTCAGTCTTCCATAAACCCTGACTCCGGTCCCGAAGGCTTGCGGTCTAATAGGGCCGGCTACTCCTCTCGACCTCGCTCCAGGGACGAAGTGTTAAAGGGGCTACCCAGCTTATGATCCCGTCCGTACTTGGTGGCTACACCGTGGCCTACGGCCGACCGAGACACTACTGATTGTGATTTAAAAATTAGGCCTGGTAGCGTGAACGAGCAGCGGTACCACGAGAGAACAGGGGTGCATCAAGGAAATTAGGCCACACAGTAGGAACTAGCCATATAAGGAGCAACCTATTGTTCCGTCCTTCTGGGCAGCTGGCCTGGTCGGTTTTCATCCGAAACTACAAGGAACCGCTGGAACCGGTAGTTAGTCCCAGGCAGCTGAACTGACCACCGTCTATTGCGGATTAGATGCACTGTCTGTAGCGCCGGGGGGTTACAAGGAACGCGCCAGGATAGAATAGATCCGCTCGAGCGAGAGTACTATTCTCCGTTGTTACTCCCTGCATTATAGCAACGGTGCCTAAAGCAGATGAGACTGATTGCGTGGCGAACGCTTCACACGTTTGGTAAAAGATCCCCCCGGCAAGCTGCACGCCCCGTTTGGCGAACCGACACACAGGAGGAGTTAATTCGAATGTACCGATCAGAACGGCGTGTTTGCATTAACTGCATGATGATTATATAGCTCGTTCAGGGCAGAAACTACTTATGGCATAATATCCTCGCAGAGCAGTTATAATGGCGAGAACACCTGGGTCGTGGTTGGCGATCCTCCCACGTCCAGACTCAAGAAGTCTATCCACTCACAGCTACATTTCGCAACAGGTACCGAACGTGGCCCATGGTACATCAACGAGTGTTGTATCTATATGTACCTACTTTACAGTGAACCTAGCTCTCGACGTGTTGGTCATTTGATAGATGGAATGTAGTGGTACCGATATTATTCCTGCTGGTAGGTAAATTGCGTCAGTTAACTTTTCAATGATAAGCACTACAAGAGCTCTTATCGCTCGCCAGTAAACGCAGAAAAACGAAAGCGCTGATCCGCGACGTGGCATATAATAGCCTAATGCCAAAAGTCCGGTTACATAGCCTGTCCATCACGGCTACGCAGGACTAAGCGGTCTAGATGACAGGAGAAATTCTGTAATGTCTGTGCCGGAGCCGGTTTTCTTAAATTTGTTTCTTTCGTCTATCAGGTGAACGCTTACAACTAGTGGGCCATGCAGAGTGGTCCACATCACACCAGTCTATGGCAGGTATAGCGGTTGGAACTAGATTTATCTCTTTAAAAAAGACAACGGGGGAGTCCCTAAGCCTTCGCACACACGATGACACACGAATAGAACCATTACAGAGGCGAGTCGGATGGCCCTCAAGCGTTTGCGAGGCGAGACGATCTAAGGTAAGTAAAAATACGCATTGCGCCCGGATTATAGCACATCCAGCTCTACTTGAAGGCGCTTAACTCGGCGTATTATAGGTCAATGTTGAATAGATGCCCCAACAAGCAGAATCTAGTCATACACGGACAAATAGTGCTCGCGCCACGGTTTCAGGACGAGGTGTACCCACTTTCACGGTACCACTCAGTTACTGCACCCGCCGCCCGCCGCCGCCGTCGCCAAATGCTTTCTTTTATGGCCCGTACTGATAAATAAAGATCGGATGCTCTGGCGGTCGCCGTCCACAACAGTGATCTTGTGCCACTCCGTCGCAGTCGCGGATGGTAGTCCAGGGCCCGTATACAGCTCTGACAATTCACTCTTTCCACTCTCATGCATTCCCTGGTTAGTGTTACAGAAGCGAGCGCCCGCCGCCCGCCGCCATGGCCAAGCACTCTTCCCACTGGAGGTTGTATACCGACCTTGTTGAAACGTGCGTATAAGCTACAAGTGGTAAACTGGTGCGTTATATGCCACCTACACTTCGACCCGCGGAACTCCTGTGGGATAACTTGAGGTTCGACTGGCGCTCCCTATGTCTTGCAGCGGATAAGTCCGTCGAAGGCGCCCCAGTAGAGGAGACACGAAAGAACCCATGAGATATCTCATCTTTTCTTTGAGAAAGCTGCAAAGGAACCGTTTTGGTATCCGGCCTACAGGCTTGACGATACTATATGCCTACAACCTCTCGTATAGTTGTAACCGGTAAACTGAGAGTGGAAGGCGAGCCTGGCCGAGGGCCGGAGGTGGGCACAATACCGCTAATGCATGGGAGGATAGTTCACGTCAGGGACTTTGGGCTAGCCCATCGTGTTTGTAACCCTTTGGCCCCCTTAGGTCTTCTCTGCGTTAATTAGTCATGAATCTTACTAATTCGCGATTGCACTTGCATCAAACTGGTTGGAATATTCCTGCTGGCTGTGGCCATTACCTAGTACTCCCTTAGACAACGTTACTCTGCTTATTGGGATAGCCCGCTTAAAGCTGGCCATTGCACATCCGTCGGTTCCGACCTCCGACCTCCGAAATTTGGGGGCGAGCGATACATGGGTGAGCATCTGGACCTAGTTCGGTAAGTGTAATTCTACGGCACGGAGCCGGAATCCTCTCTCATTGGGCTACTTTTCGGGGTTGAGGTCAGAATCTCTTGCCGGGGCCTTTGTCGTCCGACTGATGACGAGGACAGGTCTCAGAACACCTTTGTACGCGATCCTATTTGACGTCGCGACTGTATCCGCAGCTACATGATAATGTTTTGTGCTCATTGGTTAGTTAGGCAAACGGGAGGTGGCCGACTAACTTACAGGACGCAAGACATATATGTTACTACTCATGGTTGCAAAGCCATATTCTCAAGTCACCAGCTCGGAAGGGAGTCTTATCAGCCCCAACCGCTAGTCTATAGGTTGACGCTACCCAATGCCAAGCCCGCCTCAGATCTCTGCTCGAAGTGATAGTCCTACGCCTAATCTCTTGGAGGAGCAGGGGGAATGCCCGTACGAGTATATTCACGTCAACGGTTAAGACACGCACGGCTTAACATGCTAACCTAGACTATATTGAAGAATTAAGAGATGGCTAGTTGCAATAAAGAACCGATCGATTAGTTCGGTGCCGTAGTCCTGGAGATCCGCCGTAGTTCGCTTCTGGGTGCCATAGCTTCTTGGTCTAGCGGCTCGTCCCAAAGCCAATACAGTACACCTTGCCAAATAGTAAATAAGTGGATCCAGTCACGCCGAACAGAGAACCCTACCCCCAGTTCGACGGTTCGCGTAGTAAAGAGGTCGCATTCGCCGTCGCTCCTGGGTCATTGACGTAAGCATTAAAGTTAAGTAATACCCTTAACATCTAATACCGTTCTGTGCTCCGTGCAATAGAAACGGGCCGCGAAGTTGTGACATTTGCATACTGGGCCTTAAAGAGTAATTCTGTGAGCGACGAGCCCAGCGGCGCATCTACTGCCGGCCATCTCATTTGTTGGCTATCATCTCACCGTATTGCCCCTGGTTTAGTCGCGCCGGACAACCATGGTGGACTAATTCCCCGGGTGCTGTCTGTATACGGCTTCTCCTTGCCCGACGTGGCTATCCTATTCATATGTTATTGCTTGCCAAGTGCGCGGGCTCGTCACTACCACAATATGTAGTTCCACTGGGTCGCAACAACGCTACTCTTATGTAAGAAATCTTTTTAGTTCAGGAAGCCACGGCCGACCCGGGGGTTAGATGTCCAGGGCCTCACTCATAACGCTCGTACTTTGCGGATTGCGGATTACTACTTTCTCTTTTCCGCGCTACAGTTGCAAGTTAATGATGAATTGAAAGGCGTGTATCATGAGTTGCTACTTTAATTGAGTGGTTTGATGTCAACAGCCCCGGTACGGTCATTCAGCCATAGACTAGCCCGGAGTGTTGCGCGTCTTGCGTAGAATCAGGAGTTCCGTCACCCAGAGGGTGGTACGAGTGATCTATACCTTTCGAGTCTAGTTACCCGACTATCCTCTCCATCTACCCGCCTTATTGCTACGCAGCCGCAGCGATGTGCCTCATGTTACGATCCGTGAGGAGGGTTGGCACAATAATCCTGTGGCGGATATTACCCATAATGGTTAACTTTTACCACGCTGGTCGTCTACTGTTGAAGACCTGGCTGAATTGCTACAAATCTGCTAGGTAGGTGCTATCAGTCTAGTCTTCTACTTTCCTTCTACAACTAGGGGATCCAGCGTATAGCACATCTCATACAAGAATACATGACGACCCCAGACCGTCACGATATCTACTGTATCAATTAATGGCCCGAGTGATATGAAGAGGGAGGTGAACTGCATGTAGTGACGCTGAGATTAGACTCAGCGTACGAGGTGAGCAGTGCACTGTGACGCCTCAACGGGACTCCTTCTGAAGCATATGCAGGGCTAAACTGGGAATATTAATGGTTAGCTGTTAACTACTAACATTCGGTAAGTATGGGTGCCGCAGTACCTGTTGGTGTCGGCGCTATGTTAATACCCGGTGTGCAGAAGGGCTGCGGGGGTGCAATAAGGGGGATTCTCAACCACCTCGCTGTACCTCTTCCTGTGTCCTCGCGGTGTTCTTTTCCCTCGCAATATGTGCCTTCGTGTTCCCCTTAGATTGCGTCGATTGGGGCGGAGTTACCAGGCAAATGCCGGCCCATTATACTACGTTGAACAGCACTTTGACGGATCACTTCAGGAGTAAAAGCTAGCACACGGCGGCCACCAAGAACCGGAAGCAACCTCCCCGCCGATCGACGCGAGCGGACACCCGTATTAATTGGGGCCTTTCGGAATCGCACCGACAGCTGCCGCATTGCGGATTAGAACCCCTTCCCATTTCTACGCTGTAGAATAGTTGCTCCTTATCAAATTTGGCTGTCGGGCCGGTGTCCACCGGGCTACATGTCACACCTATGATGCGTCCATTTAACGTTATAGCACATAGCACATTATTCGATAATCTTCGATAGAACGTCCATCCGACCAGAGAGAACTGGTGGACTGTCGTGGGCCCGTTGCGGATTGCGGATTGGGGATCTATAGCACATAGCACATAAATATTCTTCATATAGCGTAGCTCGAAAGGGCGGTTCTCGAGTCGCTTGACCACAGACTCGTAAGCGTCTATCCCAGCGGTTCGGAAGCGCATCGTTCATCTTAATGGTTGATCCGACCCCGGATTTTCCTCTTGACACACTAGGAGCTGAAGAGCGGGATCGATTGGTTAACGGAGTTTAAAGCGAAACGCACCTTTCAACAACCTGGCCAGACCTTCCATACTACCTCGTACCATACAGCGAATTACATTATAATGTTGTAGGAGAGACGTGCGGACGACGATACGATAGAGGTGTCTAGGACGAGGAGTCGTCTTAGATTACTGGAAAACCACGAAAGGGACGGGGCAAGTGCATCAGTACCGACGTAGTAGTCCTCACAGGATCATATCCCTGGAACCCCCACATGGTAGCACACAATCCAGATCTCGTATCTTGGGCGTACTGAAAAGAGTCGCCAATCATACCGGTGCCAATACCGAAGCTGGCATTGCGGATTCACGTCCTGTGCTTAGCGTTTTGCTGGAAAAAGAGTGTCAAGAACGCAAGCTATTTTAGCAAAATTGAAGTCACACTGTAAGTACTCAGGGTCCAATTCTCCTCGGGTCATTGTTAGGTCGGAAAATGACTGGGACAGGTGGCCGCTATGCTGTCATAGCACCACACAACAGTTGACAGTGCCCCCCGGCGTCGAAGAAGGATGGAGTTGTGGTGCCTAAAAAACTGAGTCCTTTACGCACATTGTTGCTGACATCGGGGGTACTTGATCATCTCATTCTCCCGTTTGGTCGCATATCATACGAAATCGACTTGAGGGATGCCCGAGCTTGTAGCCTTGGTACGACTTGGTAAGCCTAAGACCGCTTTATCGTCCATTGACCTGCTGTGCAATATGACCAGCAGGTCACCGTATCTAAAGACCGGTTACTGTAATTGCGGTCCAAGCCCAAGCCAGGAACGTCCTACACGTGGCTTCTTAACATGTATTCCAACATCTCGTTTTAAAATAACTCAGGTTTTGGATCATGAGGCGGTAGAGTTATCCGGCAGGTAGCTGCTCGACTCGGTCCTCATGAAACATACTGACATCTTGAAGTGTTCCATAAGGCGGACGTATGAAATTCCACTGGTACATATATTGCTTCGAATGCACGCGCGGTATTCAGAAATTTGTTTAACCCAGGATCTTATTTTCGCTAACCGAGAATGCGCGTTTGCCCCTTCTGCTTACGGCAGACTTTACATTTGCAAACCCTGTACTGTGAAGTCGGTAGAGTTCGAATTCGTTGCGAGGACGTGTCAACATTACGCCGGTTTCCACACCTACTGTAATCGAGATACACTACGGATATTTACGGCCGACACAGTCTTTGGATTGGATCCTCTTTATGGTGCAAGTAGGTCGCCTCAATTATAGTATATGACTAGGCCTCAATATGCGTTTCAGCTAAGGTACTCGCTTTGATCATCGTAAGCAGTATGATGAGTCGGTGGTGATCGCCCCGCAAGTAGCTCCAGCAGGAAAGCGCTCACTTGGGGGTGTACGGTCGTCGCTCGCAAACCCACCCGCCAGGAAGTAGCCTGCGGGTGGGGGGGCTGTCCGTAGTTGACAGTTGACAGGCCGTGACAGTTTTCTGTCAACACAATTCTCGCAAACACGCGTAGAACGACTGCGAGCATTGCATAACTTCCCGACCTCCGTTATGCCACCACCGTCTAGCATAAGCTACTAGGCTGCGATTTTGTACGTACTGAAGCGTTACCGACTTGGGGCGGCGGGAGTATGTTACTCAGCGCTTTATTGGCCCAAGCGTAATCGTGATCGTGGGTAAGTGTCAGTTGCTTGCTAGGTAGGCATGCAAAAGTTGAGCAATCACTATTCAGGTGTAGCTGTTGTCGCAGCCTGCTTATCAATGGTACACAAAGTCCCTTGCACGATTATATCCCGCCGCCCGCCGCCTATCGAGCAATCCCGGATTTTTAAATCCGAAAGGAGTTACTCCTGGTGCACATTTTCCATTACTTTGCACCAGTTTGAAGATATAACCGACGGTGCTAGTACTTACAGTAATCGTCCGATGAGTGGTAGATCCAAGGCATTTGACGGGGCAGCAGGGACTCTACGGCCACGGTAGAGGTTGCGAATAGTAGAGACTTCACCTGCGAATCTAAAGACAATAGTGGGTTCATGGTACTTTCACCCTTAAGTTCGGGTTGCGATGATTAGAATTAGGTTATAGGGTGTGGCAGACATGGTGGGGTTCTGAGCTACTTCCACAAATAACTCCAGGACGAGCGTGCTTCCTTGGACTCGTGGCCTTTAGCCAGGACATATGACTGCTTATGCTTCTTTTCGACCAAAGACGGGGTCCAGCCCATGAAATTAGTTATACATAGCACATAAGCTATCCTACAGCACCGGTGAGGAGCATTAAGTTGCCTTTTCGAATCGAGGATTACGCTCGCCAAGTTCCAGCGACTTAGCATTACATATGAAATGGCCAATAATTAATGGTTCCTCATTCCCTCGGCCGCGGTGAACCTCTCTGGGTTCGAACTCGGTCACGTATGTATCTTTTGACAATGATTATGATCCTATGTCTCTGGGGGATAAGCTGACAGCGGGACAATGGATGGGCCTCATCAGCCGCTTTACCAGAGATAGAAATCACACTAGGCTTCCTCTCCACCACCTACTTTATACCGAGCGAGGTAGTATATTGTGGTGCAACGGTTAGCATTGATTTCACAGCAGCGAGGACCCGTTAACTCGGTGGATAGATTAACGTCTAGTCCGACCCCTCCATCGTCGCAGTATTAATAACCCAGTTTTCTTGATTATCCTCGACACGGCGCATTATGTAATGACTTGAAGAGGTGTTCTATGAACACCATCTCACCATATTCCTCGTACACCGATGTGAGATTATTTAGTCGAGGAAGAAATGATAGTTGATGTACGATATATAGCAGACGTAGCCGCAAAATAAGATGAAGGCTTGACCCCCAAGCAATTATCGGTCGTGGGCTCAACCCCGTACCCCAGGCAGGTTTGAAACCGACGGGTAAAATCCCAGCGAGTCCGTACTAGAATACCGCATCTGTGGGGTCCTCTCGTAGCAGTACAATGATCATAGGTAACCGTTACGGTATAGCTTTTCGCGTGCCCGAACTCCGAAGGAACCTGGAGTTTATGACGAAGGCCGGACACAACAAATCTCCGACCCGACCTCCGACCTCCAGTTGACAGCTTGTAGTCTGGCACCTAAGTCTTAGTCATTCCTAGGACTACGGCCGACGACATCTCCGAAGCAGCTAAACATTGGGCCCGTTTTGACTGTTGTATCATACAGTAGGGGAGACAGGTGAAAGGATGGGTTCGGTAGACTAACTTCGCAAACTTGCAACTGGTCCGAACCAGTGCAACTAGGTAGATACCTTAGAAGAAGCACCCCCTGCTTAATGAATGTTAAGAGTGATCTGACCCGCGTCCGTCGGTACAATACCTTACACAGACGACCAATATGTGAGCGGGAGCTAAAGCTGATCCGCTGAGAGTGCTACCCTCCAATTATGTTCCGAACTCTTTGTTTAAGTGAAGCCCCAGCGAGTTATTTGCGAGAGAGCTGGACCTGTGGAAGGAGGTTACATAGGTCCTTATGTCGATCGCCTATCACATCAACAGTTGCAGGTCACGTGGTGTGCAGTCGTCCGAGCATCCCGAGAGAGTCAGGATAAAAAACAGACGTTAATGGTCAACACTAGCCGTACTATCAATGACAGTATTAATGGTTAATGGTTATAATATATACAGACCCGTTCCCGGACGCCGTCGGAGCCGGATAGAGGAGTCACTGCCGGGAACAGCGGGCTACGTCGCGATGGTTTCTCGCCCGCCGCCCTAGTGTGTATTTGTCGATTCAGCCTATTGTGCACCCCGCTGACCTCAGCCAAATTCTTGAGTATCGGCGTCCGCGACTCAAGCTTAAAATGCCAGCTATTCAATGGACAATGGCTTGCCGTGAGCGGTGCAACAACGGCGACACCCAAGGTCGCCAATCGGCCCCAACAGCTCCGGGCTAAGGGCTTGATGGTAACTGGTGGATGTCCGTAGAGGTTTATGAAGGATGAGGGACGTTACTTGGACACAGATGACGGAGAGATAGTATTGGTGCGACCTAATCCGCGAGTTGACAGTTGACAGCAGACGCTCGGCACGCTCAGAAATGCGCATCTCGCTCGAAACA'
G, labels = trie_construction(patterns)
indices = trie_matching(text, G, labels)
for j in indices:
print(j, end = ' ')
print('')
'''
'''
file = 'trie.txt'
patterns = trie_patterns_input(file)
G, labels = trie_construction(patterns)
trie_contruction_print(G, labels)
'''