-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcode_slide.py
67 lines (51 loc) · 1.36 KB
/
code_slide.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
import matplotlib
from collections import Counter
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
record = ''
with open(r'D:\annotation\Genetorch-developing\WBcel235_rna .fna', 'r') as f:
file = f.readlines()
for i in file:
if i[0] == '>':
record += '\n'
else:
record += i.split('\n')[0]
record = record.split('\n')
del record[0]
def slide(seq):
record = []
for i in range(len(seq) - 2):
record.append(''.join([seq[i], seq[i + 1], seq[i + 2]]))
return record
code = []
for i in record:
code.extend(slide(i))
graph = dict(Counter(code))
def plot_dict(dict):
dict_sort = sorted(dict.items(), key=lambda item: item[1], reverse=True)
data = list(zip(*dict_sort))
label = data[0]
val = list(data[1])
sumer = sum(val)
val = [n / sumer for n in val]
plt.bar(range(len(val)), val, tick_label=label)
plt.xticks(rotation=75)
plt.show()
# plot_dict(graph)
def exchange(seq):
s = list(seq[:])
a = s[0]
s[0] = s[2]
s[2] = a
return ''.join(s)
graph2 = {}
for k, v in graph.items():
done_list = []
peer = exchange(k)
if peer not in done_list and k not in done_list:
if peer == k:
graph2[k] = v
done_list.append(k)
else:
graph2[k] = v + graph[peer]
done_list.extend([k,peer])