-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathids.py
61 lines (50 loc) · 1.92 KB
/
ids.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
import common
created_motifs_by_far = []
global_counter = 0
answers = []
destoryers = []
def IDS(state, goal, limit=100, stop=False):
global global_counter
all_neighbors = []
for motif in state:
all_neighbors.append(create_neighbor_motifs(motif))
all_neighbors = [item for sublist in all_neighbors for item in sublist]
for motif in all_neighbors:
print('Checking ' + motif + '...', end='\r')
if common.is_motif_valid(motif) == False:
all_neighbors.remove(motif)
if motif not in destoryers:
destoryers.append(motif)
elif len(motif) == limit:
answers.append(motif)
common.print_success(motif + ' is a valid motif.')
global_counter += 1
if len(all_neighbors[0]) < limit:
IDS(all_neighbors, goal, limit, True)
return
def discover_motifs(length, desired_hamming_distance):
starter_motifs = create_neighbor_motifs(None)
IDS(starter_motifs, desired_hamming_distance, length)
def create_neighbor_motifs(motif):
neighbor_motifs = []
if motif is None:
motif = ''
for i in range(0, len(common.motif_characters)):
should_pass = True
neighbor_motif = motif + common.motif_characters[i]
if any(destroyer in motif for destroyer in destoryers):
should_pass = False
if should_pass == True:
neighbor_motifs.append(neighbor_motif)
return neighbor_motifs
def handled_previously(motif):
return motif in created_motifs_by_far
st = common.start_time()
discover_motifs(common.input_motif_length, common.input_hamming_distance)
if global_counter > 0:
common.print_success(str(global_counter) + ' motif with the length of ' +
str(common.input_motif_length) + ' found.')
else:
common.print_error('No motifs with length of ' +
str(common.input_motif_length) + ' were found.')
common.end_time(st)