-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathanalysis_helpers.py
executable file
·104 lines (74 loc) · 2.81 KB
/
analysis_helpers.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
"""
Various helpers to be used in the analysis module
"""
from helpers import WindowType
def save_cluster(filename, cluster, statistic, wtype):
with open(filename, 'w') as file:
file.write(str(cluster.get_window_statistics(statistic=statistic,
window_type=wtype)))
def save_clusters(clusters, statistic, tips):
for cluster in clusters:
if tips is not None:
wga_file = "cluster_"+str(cluster.cidx) +"_wga_w_" + statistic
no_wga_file = "cluster_"+str(cluster.cidx) +"_no_wga_w_" + statistic
for tip in tips:
wga_file += "_" + tip
no_wga_file += "_" + tip
wga_file += ".txt"
no_wga_file += ".txt"
else:
wga_file = "cluster_"+str(cluster.cidx) +"_wga_w_" + statistic + ".txt"
no_wga_file = "cluster_"+str(cluster.cidx) +"_no_wga_w_" + statistic + ".txt"
save_cluster(filename=wga_file, cluster=cluster,
statistic=statistic, wtype=WindowType.WGA)
save_cluster(filename=no_wga_file, cluster=cluster,
statistic=statistic, wtype=WindowType.NO_WGA)
def save_clusters_gc_content(clusters, tips):
statistic = 'gc'
for cluster in clusters:
if tips is not None:
wga_file = "cluster_"+str(cluster.cidx) +"_wga_w_" + statistic
for tip in tips:
wga_file += "_" + tip
wga_file += ".txt"
else:
wga_file = "cluster_"+str(cluster.cidx) +"_wga_w_" + statistic + ".txt"
save_cluster(filename=wga_file, cluster=cluster,
statistic=statistic, wtype=WindowType.WGA)
def save_windows_statistic(windows, statistic, region_id=None, tips=None):
window_stats = \
[window.get_rd_statistic(statistics=statistic,
name=WindowType.NO_WGA)
for window in windows if not window.is_gap_window()]
if region_id is not None:
filename = "no_wga_windows_" + statistic + "_" + str(region_id)
if tips is not None:
for tip in tips:
filename += "_" + tip
filename += ".txt"
else:
filename = "no_wga_windows_" + statistic
if tips is not None:
for tip in tips:
filename += "_" + tip
filename += ".txt"
with open(filename, 'w') as file:
file.write(str(window_stats))
window_stats = \
[window.get_rd_statistic(statistics=statistic,
name=WindowType.WGA)
for window in windows if not window.is_gap_window()]
if region_id is not None:
filename = "wga_windows_" + statistic + "_" + str(region_id)
if tips is not None:
for tip in tips:
filename += "_" + tip
filename += ".txt"
else:
filename = "wga_windows_" + statistic
if tips is not None:
for tip in tips:
filename += "_" + tip
filename += ".txt"
with open(filename, 'w') as file:
file.write(str(window_stats))