-
Notifications
You must be signed in to change notification settings - Fork 0
/
Solve the Overlap Graph Problem.py
60 lines (41 loc) · 1.24 KB
/
Solve the Overlap Graph Problem.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
# -*- coding: utf-8 -*-
"""
Created on Tue Dec 25 00:20:52 2018
@author: bjwil
"""
import os
import itertools
os.getcwd()
#os.chdir('C:\\Users\\bjwil\\Bioinformatics')
def window(s, k):
for i in range(1 + len(s) - k):
yield s[i:i+k]
sign = ' -> '
with open ('dataset_198_10.txt', 'r') as in_file:
lines = in_file.read().split()
#s = lines[1]
#k = int(lines[0])
patterns = lines
def Overlap_Graph(patterns):
adjacent_list = {}
final_list = []
for nodes in patterns:
adjacent_list[nodes] = []
for string in adjacent_list:
for node in patterns:
if string[1:] == node[:-1]:
adjacent_list[string].append(node)
for k, v in adjacent_list.items():
if adjacent_list[k]:
final_list.append(str(k) + sign + ', '.join('{}'.format(v) for v in adjacent_list[k]))
#print(str(k) + sign + ', '.join('{}'.format(v) for v in adjacent_list[k]))
return final_list
strings = Overlap_Graph(patterns)
'''
idx = 0
item = lines[0]
while len(lines) > 0:
for idx,item in enumerate(lines[:-1]):
if lines[idx][-len(item)+1:] == lines[idx+1][0:len(item)-1]:
genome_string = genome_string + lines[idx+1][-1]
'''