-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_hope.py
95 lines (81 loc) · 1.96 KB
/
plot_hope.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
import sys
import matplotlib.pyplot as plt
from collections import defaultdict
class HomoResult():
def __init__(self, line):
bits = line.split()
self.homo_length = bits[0]
self.base = bits[1]
if bits[2] in ["?", "mm", "skip"]:
self.length = bits[2]
else:
self.length = int(bits[2])
def read_hope_file(file):
data = defaultdict(lambda: defaultdict(list))
with open(file) as fin:
for line in fin.readlines()[1:]:
h = HomoResult(line)
data[h.homo_length][h.base].append(h.length)
return data
def main(args=None):
data = read_hope_file(sys.argv[1])
to_plot = []
labels = []
for length, subd in data.items():
for base, results in subd.items():
labels.append(f"{length}_{base}")
data = []
for i in results:
if isinstance(i, int):
if i > 20:
data.append(21)
else:
data.append(i)
# to_plot.append([i for i in results if isinstance(i, int)])
to_plot.append(data)
# print(labels[0])
# print(to_plot[0][:10])
# ax.boxplot(to_plot, labels=labels)
colours = {
"A": "#CC79A7",
"T": "#E69F00",
"C": "#009E73",
"G": "#0072B2"
}
fig, axs = plt.subplots(7,3, figsize=(8, 10), constrained_layout=True)
i = 0
j = 0
for label, data in zip(labels, to_plot):
ax = axs[i][j]
if j == 2:
i += 1
j = 0
else:
j += 1
homo_length = int(label.split("_")[0])
homo_base = label.split("_")[1]
# fig, ax = plt.subplots()
# fig.set_size_inches(12,8)
ax.set_title(f"length: {homo_length}, base: {homo_base}")
ax.hist(
data,
bins=[i for i in range(-homo_length-1, 23)],
log=True,
align='left',
color=colours[homo_base]
)
plt.savefig(f"{sys.argv[2]}all.png")
plt.close()
# homo_length = int(label.split("_")[0])
# fig, ax = plt.subplots()
# fig.set_size_inches(12,8)
# ax.hist(
# data,
# bins=[i for i in range(-homo_length-1,1)],
# log=True,
# align='right'
# )
# plt.savefig(f"{sys.argv[2]}{label}_deletion.png")
# plt.close()
if __name__ == '__main__':
main()