gloome 2.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- gloome/__init__.py +0 -0
- gloome/__main__.py +6 -0
- gloome/config.py +387 -0
- gloome/consts.py +250 -0
- gloome/services/__init__.py +0 -0
- gloome/services/service_functions.py +434 -0
- gloome/tree/__init__.py +0 -0
- gloome/tree/node.py +505 -0
- gloome/tree/npencoder.py +33 -0
- gloome/tree/tree.py +1283 -0
- gloome/utils.py +42 -0
- gloome-2.0.0.dist-info/METADATA +148 -0
- gloome-2.0.0.dist-info/RECORD +16 -0
- gloome-2.0.0.dist-info/WHEEL +5 -0
- gloome-2.0.0.dist-info/entry_points.txt +2 -0
- gloome-2.0.0.dist-info/top_level.txt +1 -0
gloome/__init__.py
ADDED
|
File without changes
|
gloome/__main__.py
ADDED
gloome/config.py
ADDED
|
@@ -0,0 +1,387 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import traceback
|
|
3
|
+
|
|
4
|
+
from sys import exit
|
|
5
|
+
from typing import Dict
|
|
6
|
+
|
|
7
|
+
from gloome.utils import *
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class Config:
|
|
11
|
+
def __init__(self, **attributes):
|
|
12
|
+
self.MODE = MODE[3:4]
|
|
13
|
+
self.COMMAND_LINE = COMMAND_LINE
|
|
14
|
+
|
|
15
|
+
self.RESULTS_DIR = RESULTS_DIR
|
|
16
|
+
self.LOGS_DIR = LOGS_DIR
|
|
17
|
+
|
|
18
|
+
self.IN_DIR = IN_DIR
|
|
19
|
+
self.OUT_DIR = OUT_DIR
|
|
20
|
+
self.RESULTS_URL = RESULTS_URL
|
|
21
|
+
self.LOG_URL = LOG_URL
|
|
22
|
+
|
|
23
|
+
self.ACTIONS = ACTIONS
|
|
24
|
+
self.VALIDATION_ACTIONS = VALIDATION_ACTIONS
|
|
25
|
+
self.DEFAULT_ACTIONS = DEFAULT_ACTIONS
|
|
26
|
+
self.MAIN_ACTIONS = MAIN_ACTIONS
|
|
27
|
+
|
|
28
|
+
self.CURRENT_ARGS = DEFAULT_ARGUMENTS
|
|
29
|
+
|
|
30
|
+
self.CALCULATED_ARGS = CALCULATED_ARGS
|
|
31
|
+
|
|
32
|
+
self.WEBSERVER_NAME_CAPITAL = WEBSERVER_NAME_CAPITAL
|
|
33
|
+
|
|
34
|
+
self.PROCESS_ID = None
|
|
35
|
+
self.MSA_FILE = None
|
|
36
|
+
self.TREE_FILE = None
|
|
37
|
+
self.JOB_LOGGER = None
|
|
38
|
+
|
|
39
|
+
self.USAGE = USAGE
|
|
40
|
+
|
|
41
|
+
if attributes:
|
|
42
|
+
for key, value in attributes.items():
|
|
43
|
+
if key == 'PROCESS_ID':
|
|
44
|
+
self.change_process_id(value)
|
|
45
|
+
else:
|
|
46
|
+
setattr(self, key, value)
|
|
47
|
+
if len(self.COMMAND_LINE) > 4 and self.COMMAND_LINE[1].startswith('-') and self.COMMAND_LINE[3].startswith(
|
|
48
|
+
'-'):
|
|
49
|
+
self.parse_arguments()
|
|
50
|
+
|
|
51
|
+
if not self.PROCESS_ID:
|
|
52
|
+
self.change_process_id(get_new_process_id())
|
|
53
|
+
|
|
54
|
+
def change_process_id(self, process_id: str):
|
|
55
|
+
self.PROCESS_ID = process_id
|
|
56
|
+
|
|
57
|
+
self.RESULTS_DIR = RESULTS_DIR
|
|
58
|
+
self.LOGS_DIR = LOGS_DIR
|
|
59
|
+
|
|
60
|
+
self.OUT_DIR = self.OUT_DIR.joinpath(self.PROCESS_ID)
|
|
61
|
+
check_dir(self.OUT_DIR)
|
|
62
|
+
self.IN_DIR = self.IN_DIR.joinpath(self.PROCESS_ID)
|
|
63
|
+
|
|
64
|
+
self.CALCULATED_ARGS.file_path = self.OUT_DIR
|
|
65
|
+
|
|
66
|
+
self.RESULTS_URL = f'{self.RESULTS_URL}/{self.PROCESS_ID}'
|
|
67
|
+
log_file_for_url = str(self.LOGS_DIR.joinpath(self.PROCESS_ID + '.log')).replace('/', '%2F')
|
|
68
|
+
self.LOG_URL = parse.urljoin(self.LOG_URL, f'get_file?file_path={log_file_for_url}&mode=view')
|
|
69
|
+
self.JOB_LOGGER = get_job_logger(f'{process_id}', self.LOGS_DIR)
|
|
70
|
+
|
|
71
|
+
def check_and_set_input_and_output_variables(self):
|
|
72
|
+
"""get variables from input arguments and fill out the Variable Class properties"""
|
|
73
|
+
if len(self.COMMAND_LINE) < 5:
|
|
74
|
+
print('\tAt least two required parameters --msa_file --tree_file', self.USAGE, sep='\n')
|
|
75
|
+
exit()
|
|
76
|
+
|
|
77
|
+
if len(self.COMMAND_LINE) > 4 and self.COMMAND_LINE[1].startswith('-') and self.COMMAND_LINE[3].startswith('-'):
|
|
78
|
+
if not self.check_arguments_for_errors():
|
|
79
|
+
for error_type, error in self.CALCULATED_ARGS.err_list:
|
|
80
|
+
print(f'{error_type}: {error}')
|
|
81
|
+
print(self.USAGE)
|
|
82
|
+
exit()
|
|
83
|
+
|
|
84
|
+
def get_selected_files(self) -> Dict[str, bool]:
|
|
85
|
+
selected_files = {'file_interactive_tree_html': self.CURRENT_ARGS.file_interactive_tree_html,
|
|
86
|
+
'file_newick_tree_png': self.CURRENT_ARGS.file_newick_tree_png,
|
|
87
|
+
'file_table_of_nodes_tsv': self.CURRENT_ARGS.file_table_of_nodes_tsv,
|
|
88
|
+
'file_probability_per_pos_per_branches_tsv':
|
|
89
|
+
self.CURRENT_ARGS.file_probability_per_pos_per_branches_tsv,
|
|
90
|
+
'file_table_of_branches_tsv': self.CURRENT_ARGS.file_table_of_branches_tsv,
|
|
91
|
+
'file_log_likelihood_tsv': self.CURRENT_ARGS.file_log_likelihood_tsv,
|
|
92
|
+
'file_table_of_attributes_tsv': self.CURRENT_ARGS.file_table_of_attributes_tsv,
|
|
93
|
+
'file_phylogenetic_tree_nwk': self.CURRENT_ARGS.file_phylogenetic_tree_nwk}
|
|
94
|
+
return selected_files
|
|
95
|
+
|
|
96
|
+
def get_form_data(self) -> Dict[str, Union[str, int]]:
|
|
97
|
+
form_data = {'msaText': self.CALCULATED_ARGS.msa,
|
|
98
|
+
'newickText': self.CALCULATED_ARGS.newick_text,
|
|
99
|
+
'isOptimizePi': int(self.CURRENT_ARGS.is_optimize_pi),
|
|
100
|
+
'isOptimizePiAverage': int(self.CURRENT_ARGS.is_optimize_pi_average),
|
|
101
|
+
'isOptimizeAlpha': int(self.CURRENT_ARGS.is_optimize_alpha),
|
|
102
|
+
'isOptimizeBL': int(self.CURRENT_ARGS.is_optimize_bl),
|
|
103
|
+
'isDoNotUseEMail': int(self.CURRENT_ARGS.is_do_not_use_e_mail),
|
|
104
|
+
'fileInteractiveTreeHtml': int(self.CURRENT_ARGS.file_interactive_tree_html),
|
|
105
|
+
'fileNewickTreePng': int(self.CURRENT_ARGS.file_newick_tree_png),
|
|
106
|
+
'fileTableOfNodesTsv': int(self.CURRENT_ARGS.file_table_of_nodes_tsv),
|
|
107
|
+
'fileProbabilityPerPosPerBranchesTsv':
|
|
108
|
+
int(self.CURRENT_ARGS.file_probability_per_pos_per_branches_tsv),
|
|
109
|
+
'fileTableOfBranchesTsv': int(self.CURRENT_ARGS.file_table_of_branches_tsv),
|
|
110
|
+
'fileLogLikelihoodTsv': int(self.CURRENT_ARGS.file_log_likelihood_tsv),
|
|
111
|
+
'fileTableOfAttributesTsv': int(self.CURRENT_ARGS.file_table_of_attributes_tsv),
|
|
112
|
+
'filePhylogeneticTreeNwk': int(self.CURRENT_ARGS.file_phylogenetic_tree_nwk),
|
|
113
|
+
'coefficientBL': self.CURRENT_ARGS.coefficient_bl,
|
|
114
|
+
'pi1': self.CURRENT_ARGS.pi_1,
|
|
115
|
+
'alpha': self.CURRENT_ARGS.alpha,
|
|
116
|
+
'categoriesQuantity': self.CURRENT_ARGS.categories_quantity,
|
|
117
|
+
'eMail': self.CURRENT_ARGS.e_mail}
|
|
118
|
+
return form_data
|
|
119
|
+
|
|
120
|
+
def execute_action(self, func, *args, **kwargs):
|
|
121
|
+
try:
|
|
122
|
+
val = func(*args, **kwargs)
|
|
123
|
+
if val:
|
|
124
|
+
self.JOB_LOGGER.info(f'\n\tSuccessfully Command \'{func.__name__}\' executed successfully. -> {val}\n')
|
|
125
|
+
except ValueError:
|
|
126
|
+
format_exc = f'{traceback.format_exc()}'
|
|
127
|
+
self.JOB_LOGGER.info(f'Failed to execute the command \'{func.__name__}\' -> {format_exc}')
|
|
128
|
+
self.CALCULATED_ARGS.err_list.append((f'Failed to execute the command \'{func.__name__}\'', format_exc))
|
|
129
|
+
|
|
130
|
+
def execute_calculation(self):
|
|
131
|
+
if not self.CALCULATED_ARGS.err_list and self.DEFAULT_ACTIONS.get('calculate_tree', False):
|
|
132
|
+
self.execute_action(self.ACTIONS.calculate_tree, self.CALCULATED_ARGS.newick_tree)
|
|
133
|
+
if not self.CALCULATED_ARGS.err_list and self.DEFAULT_ACTIONS.get('calculate_ancestral_sequence', False):
|
|
134
|
+
self.execute_action(self.ACTIONS.calculate_ancestral_sequence, self.CALCULATED_ARGS.newick_tree)
|
|
135
|
+
if not self.CALCULATED_ARGS.err_list and self.DEFAULT_ACTIONS.get('execute_all_actions', False):
|
|
136
|
+
self.execute_action(self.ACTIONS.execute_all_actions, file_path=self.OUT_DIR, create_new_file=True,
|
|
137
|
+
form_data=self.get_form_data(), newick_tree=self.CALCULATED_ARGS.newick_tree,
|
|
138
|
+
with_internal_nodes=self.CURRENT_ARGS.with_internal_nodes,
|
|
139
|
+
log_file=self.JOB_LOGGER.handlers[-1].baseFilename, actions=self.MAIN_ACTIONS,
|
|
140
|
+
selected_files=self.get_selected_files())
|
|
141
|
+
if not self.CALCULATED_ARGS.err_list:
|
|
142
|
+
self.execute_action(self.ACTIONS.recompile_json, output_file=self.OUT_DIR.joinpath('result.json'),
|
|
143
|
+
process_id=self.PROCESS_ID, create_link=False)
|
|
144
|
+
|
|
145
|
+
def check_arguments_for_errors(self) -> bool:
|
|
146
|
+
if self.TREE_FILE.is_file():
|
|
147
|
+
with open(self.TREE_FILE, 'r') as f:
|
|
148
|
+
if self.VALIDATION_ACTIONS.get('del_bootstrap_values', False):
|
|
149
|
+
self.CALCULATED_ARGS.newick_text = self.ACTIONS.del_bootstrap_values(f.read().strip())
|
|
150
|
+
else:
|
|
151
|
+
self.CALCULATED_ARGS.newick_text = f.read().strip()
|
|
152
|
+
else:
|
|
153
|
+
self.CALCULATED_ARGS.err_list.append((f'The File does not exist',
|
|
154
|
+
f'File "{self.TREE_FILE}" does not exist '))
|
|
155
|
+
|
|
156
|
+
if self.MSA_FILE.is_file():
|
|
157
|
+
with open(self.MSA_FILE, 'r') as f:
|
|
158
|
+
self.CALCULATED_ARGS.msa = f.read().strip()
|
|
159
|
+
else:
|
|
160
|
+
self.CALCULATED_ARGS.err_list.append((f'The File does not exist',
|
|
161
|
+
f'File "{self.MSA_FILE}" does not exist '))
|
|
162
|
+
|
|
163
|
+
if not self.CALCULATED_ARGS.err_list and self.VALIDATION_ACTIONS.get('check_data', False):
|
|
164
|
+
self.CALCULATED_ARGS.err_list += self.ACTIONS.check_data(self.CALCULATED_ARGS.newick_text,
|
|
165
|
+
self.CALCULATED_ARGS.msa,
|
|
166
|
+
self.CURRENT_ARGS.categories_quantity,
|
|
167
|
+
self.CURRENT_ARGS.alpha,
|
|
168
|
+
self.CURRENT_ARGS.pi_1,
|
|
169
|
+
self.CURRENT_ARGS.coefficient_bl,
|
|
170
|
+
self.CURRENT_ARGS.e_mail,
|
|
171
|
+
self.CURRENT_ARGS.is_optimize_pi,
|
|
172
|
+
self.CURRENT_ARGS.is_optimize_pi_average,
|
|
173
|
+
self.CURRENT_ARGS.is_optimize_alpha,
|
|
174
|
+
self.CURRENT_ARGS.is_optimize_bl,
|
|
175
|
+
self.CURRENT_ARGS.is_do_not_use_e_mail,
|
|
176
|
+
self.CURRENT_ARGS.file_interactive_tree_html,
|
|
177
|
+
self.CURRENT_ARGS.file_newick_tree_png,
|
|
178
|
+
self.CURRENT_ARGS.file_table_of_nodes_tsv,
|
|
179
|
+
self.CURRENT_ARGS.file_probability_per_pos_per_branches_tsv,
|
|
180
|
+
self.CURRENT_ARGS.file_table_of_branches_tsv,
|
|
181
|
+
self.CURRENT_ARGS.file_log_likelihood_tsv,
|
|
182
|
+
self.CURRENT_ARGS.file_table_of_attributes_tsv,
|
|
183
|
+
self.CURRENT_ARGS.file_phylogenetic_tree_nwk)
|
|
184
|
+
|
|
185
|
+
if not self.CALCULATED_ARGS.err_list and self.VALIDATION_ACTIONS.get('set_root', False):
|
|
186
|
+
try:
|
|
187
|
+
self.CALCULATED_ARGS.newick_text = self.ACTIONS.set_root(self.CALCULATED_ARGS.newick_text)
|
|
188
|
+
except ValueError:
|
|
189
|
+
self.CALCULATED_ARGS.err_list.append((f'TREE error', f'Failed to set root.'))
|
|
190
|
+
|
|
191
|
+
if not self.CALCULATED_ARGS.err_list and self.VALIDATION_ACTIONS.get('check_tree', False):
|
|
192
|
+
try:
|
|
193
|
+
self.CALCULATED_ARGS.newick_tree = self.ACTIONS.check_tree(self.CALCULATED_ARGS.newick_text)
|
|
194
|
+
except ValueError:
|
|
195
|
+
self.CALCULATED_ARGS.err_list.append((f'TREE error', f'Wrong Phylogenetic tree format.'))
|
|
196
|
+
|
|
197
|
+
if not self.CALCULATED_ARGS.err_list and self.DEFAULT_ACTIONS.get('set_tree_data', False):
|
|
198
|
+
try:
|
|
199
|
+
self.ACTIONS.set_tree_data(self.CALCULATED_ARGS.newick_tree, msa=self.CALCULATED_ARGS.msa,
|
|
200
|
+
categories_quantity=self.CURRENT_ARGS.categories_quantity,
|
|
201
|
+
alpha=self.CURRENT_ARGS.alpha, pi_1=self.CURRENT_ARGS.pi_1,
|
|
202
|
+
coefficient_bl=self.CURRENT_ARGS.coefficient_bl,
|
|
203
|
+
is_optimize_pi=self.CURRENT_ARGS.is_optimize_pi,
|
|
204
|
+
is_optimize_pi_average=self.CURRENT_ARGS.is_optimize_pi_average,
|
|
205
|
+
is_optimize_alpha=self.CURRENT_ARGS.is_optimize_alpha,
|
|
206
|
+
is_optimize_bl=self.CURRENT_ARGS.is_optimize_bl)
|
|
207
|
+
except ValueError:
|
|
208
|
+
self.CALCULATED_ARGS.err_list.append((f'MSA error',
|
|
209
|
+
f'Wrong MSA format. Please provide MSA in FASTA format.'))
|
|
210
|
+
|
|
211
|
+
if not self.CALCULATED_ARGS.err_list and (self.CURRENT_ARGS.is_optimize_pi_average or
|
|
212
|
+
self.CURRENT_ARGS.is_optimize_pi):
|
|
213
|
+
try:
|
|
214
|
+
self.CURRENT_ARGS.pi_1 = self.CALCULATED_ARGS.newick_tree.pi_1
|
|
215
|
+
except ValueError:
|
|
216
|
+
self.CALCULATED_ARGS.err_list.append((f'Strange error',
|
|
217
|
+
f'Strange error.'))
|
|
218
|
+
|
|
219
|
+
if not self.CALCULATED_ARGS.err_list and self.CURRENT_ARGS.is_optimize_alpha:
|
|
220
|
+
try:
|
|
221
|
+
self.CURRENT_ARGS.alpha = self.CALCULATED_ARGS.newick_tree.alpha
|
|
222
|
+
except ValueError:
|
|
223
|
+
self.CALCULATED_ARGS.err_list.append((f'Strange error',
|
|
224
|
+
f'Strange error.'))
|
|
225
|
+
|
|
226
|
+
if not self.CALCULATED_ARGS.err_list and self.CURRENT_ARGS.is_optimize_bl:
|
|
227
|
+
try:
|
|
228
|
+
self.CURRENT_ARGS.coefficient_bl = self.CALCULATED_ARGS.newick_tree.coefficient_bl
|
|
229
|
+
except ValueError:
|
|
230
|
+
self.CALCULATED_ARGS.err_list.append((f'Strange error',
|
|
231
|
+
f'Strange error.'))
|
|
232
|
+
|
|
233
|
+
if self.CALCULATED_ARGS.err_list:
|
|
234
|
+
self.JOB_LOGGER.info(f'Error list: \n{self.CALCULATED_ARGS.err_list}')
|
|
235
|
+
else:
|
|
236
|
+
self.JOB_LOGGER.info(f'Verification completed successfully\n')
|
|
237
|
+
|
|
238
|
+
return not self.CALCULATED_ARGS.err_list
|
|
239
|
+
|
|
240
|
+
def enable_default_actions(self):
|
|
241
|
+
self.DEFAULT_ACTIONS.update({
|
|
242
|
+
'calculate_tree': False,
|
|
243
|
+
'calculate_ancestral_sequence': False,
|
|
244
|
+
'execute_all_actions': False
|
|
245
|
+
})
|
|
246
|
+
self.MAIN_ACTIONS.update({
|
|
247
|
+
'compute_likelihood_of_tree': False,
|
|
248
|
+
'draw_tree': False,
|
|
249
|
+
'create_all_file_types': False
|
|
250
|
+
})
|
|
251
|
+
|
|
252
|
+
if 'compute_likelihood_of_tree' in self.MODE:
|
|
253
|
+
self.DEFAULT_ACTIONS.update({'execute_all_actions': True})
|
|
254
|
+
self.MAIN_ACTIONS.update({'compute_likelihood_of_tree': True})
|
|
255
|
+
if 'draw_tree' in self.MODE:
|
|
256
|
+
self.DEFAULT_ACTIONS.update({'calculate_tree': True,
|
|
257
|
+
'calculate_ancestral_sequence': True,
|
|
258
|
+
'execute_all_actions': True})
|
|
259
|
+
self.MAIN_ACTIONS.update({'draw_tree': True})
|
|
260
|
+
if 'create_all_file_types' in self.MODE:
|
|
261
|
+
self.DEFAULT_ACTIONS.update({'calculate_tree': True,
|
|
262
|
+
'calculate_ancestral_sequence': True,
|
|
263
|
+
'execute_all_actions': True})
|
|
264
|
+
self.MAIN_ACTIONS.update({'create_all_file_types': True})
|
|
265
|
+
if 'execute_all_actions' in self.MODE:
|
|
266
|
+
self.DEFAULT_ACTIONS.update({'calculate_tree': True,
|
|
267
|
+
'calculate_ancestral_sequence': True,
|
|
268
|
+
'execute_all_actions': True})
|
|
269
|
+
self.MAIN_ACTIONS.update({'compute_likelihood_of_tree': True,
|
|
270
|
+
'draw_tree': True,
|
|
271
|
+
'create_all_file_types': True})
|
|
272
|
+
|
|
273
|
+
def parse_arguments(self):
|
|
274
|
+
"""parse arguments and fill out the relevant Variable Class properties"""
|
|
275
|
+
parser = argparse.ArgumentParser(prog=self.WEBSERVER_NAME_CAPITAL, description='GLOOME',
|
|
276
|
+
usage='%(prog)s [options]')
|
|
277
|
+
parser.add_argument('--msa_file', dest='msa_file', type=str, required=True,
|
|
278
|
+
help=f'Specify the msa filepath (required).')
|
|
279
|
+
parser.add_argument('--tree_file', dest='tree_file', type=str, required=True,
|
|
280
|
+
help=f'Specify the newick filepath (required).')
|
|
281
|
+
parser.add_argument('--out_dir', dest='out_dir', type=str, required=False, default=self.OUT_DIR,
|
|
282
|
+
help=f'Specify the outdir path (optional).')
|
|
283
|
+
parser.add_argument('--process_id', dest='process_id', type=str, required=False, default=self.PROCESS_ID,
|
|
284
|
+
help=f'Specify a process ID or it will be generated automatically (optional).')
|
|
285
|
+
parser.add_argument('--mode', dest='mode', required=False, action="extend", nargs="+", type=str,
|
|
286
|
+
help=f'Execution mode style (optional). Possible options: ("draw_tree", '
|
|
287
|
+
f'"compute_likelihood_of_tree", "create_all_file_types", "execute_all_actions"). '
|
|
288
|
+
f'Default is {self.MODE[3:4]}.')
|
|
289
|
+
parser.add_argument('--with_internal_nodes', dest='with_internal_nodes', type=int, required=False,
|
|
290
|
+
default=self.CURRENT_ARGS.with_internal_nodes, help=f'Specify the tree has internal nodes '
|
|
291
|
+
f'(optional). Default is {self.CURRENT_ARGS.with_internal_nodes}.')
|
|
292
|
+
parser.add_argument('--categories_quantity', dest='categories_quantity', type=int, required=False,
|
|
293
|
+
default=int(self.CURRENT_ARGS.categories_quantity), help=f'Specify categories quantity '
|
|
294
|
+
f'(optional). Default is {int(self.CURRENT_ARGS.categories_quantity)}.')
|
|
295
|
+
parser.add_argument('--alpha', dest='alpha', type=float, required=False, default=self.CURRENT_ARGS.alpha,
|
|
296
|
+
help=f'Specify alpha (optional). Default is {self.CURRENT_ARGS.alpha}.')
|
|
297
|
+
parser.add_argument('--pi_1', dest='pi_1', type=float, required=False, default=self.CURRENT_ARGS.pi_1,
|
|
298
|
+
help=f'Specify pi_1 (optional). Default is {self.CURRENT_ARGS.pi_1}.')
|
|
299
|
+
parser.add_argument('--coefficient_bl', dest='coefficient_bl', type=float, required=False,
|
|
300
|
+
help=f'Specify coefficient_bl (optional). Default is {self.CURRENT_ARGS.coefficient_bl}.',
|
|
301
|
+
default=self.CURRENT_ARGS.coefficient_bl)
|
|
302
|
+
parser.add_argument('--e_mail', dest='e_mail', type=str, required=False,
|
|
303
|
+
help=f'Specify e_mail (technical parameter, do not change).',
|
|
304
|
+
default=self.CURRENT_ARGS.e_mail)
|
|
305
|
+
parser.add_argument('--is_optimize_pi', dest='is_optimize_pi', type=int, required=False,
|
|
306
|
+
help=f'Specify is_optimize_pi (optional). Default is '
|
|
307
|
+
f'{int(self.CURRENT_ARGS.is_optimize_pi)}.', default=int(self.CURRENT_ARGS.is_optimize_pi))
|
|
308
|
+
parser.add_argument('--is_optimize_pi_average', dest='is_optimize_pi_average', type=int, required=False,
|
|
309
|
+
help=f'Specify is_optimize_pi_average (optional). Default is '
|
|
310
|
+
f'{int(self.CURRENT_ARGS.is_optimize_pi_average)}.',
|
|
311
|
+
default=int(self.CURRENT_ARGS.is_optimize_pi_average))
|
|
312
|
+
parser.add_argument('--is_optimize_alpha', dest='is_optimize_alpha', type=int, required=False,
|
|
313
|
+
help=f'Specify is_optimize_alpha (optional). Default is '
|
|
314
|
+
f'{int(self.CURRENT_ARGS.is_optimize_alpha)}.',
|
|
315
|
+
default=int(self.CURRENT_ARGS.is_optimize_alpha))
|
|
316
|
+
parser.add_argument('--is_optimize_bl', dest='is_optimize_bl', type=int, required=False,
|
|
317
|
+
help=f'Specify is_optimize_bl (optional). Default is '
|
|
318
|
+
f'{int(self.CURRENT_ARGS.is_optimize_bl)}.', default=int(self.CURRENT_ARGS.is_optimize_bl))
|
|
319
|
+
parser.add_argument('--is_do_not_use_e_mail', dest='is_do_not_use_e_mail', type=int, required=False,
|
|
320
|
+
help=f'Specify is_do_not_use_e_mail (technical parameter, do not change).',
|
|
321
|
+
default=int(self.CURRENT_ARGS.is_do_not_use_e_mail))
|
|
322
|
+
parser.add_argument('--file_interactive_tree_html', dest='file_interactive_tree_html', type=int, required=False,
|
|
323
|
+
help=f'Specify file_interactive_tree_html (optional). Default is '
|
|
324
|
+
f'{int(self.CURRENT_ARGS.file_interactive_tree_html)}.',
|
|
325
|
+
default=int(self.CURRENT_ARGS.file_interactive_tree_html))
|
|
326
|
+
parser.add_argument('--file_newick_tree_png', dest='file_newick_tree_png', type=int, required=False,
|
|
327
|
+
help=f'Specify file_newick_tree_png (optional). Default is '
|
|
328
|
+
f'{int(self.CURRENT_ARGS.file_newick_tree_png)}.',
|
|
329
|
+
default=int(self.CURRENT_ARGS.file_newick_tree_png))
|
|
330
|
+
parser.add_argument('--file_table_of_nodes_tsv', dest='file_table_of_nodes_tsv', type=int, required=False,
|
|
331
|
+
help=f'Specify file_table_of_nodes_tsv (optional). Default is '
|
|
332
|
+
f'{int(self.CURRENT_ARGS.file_table_of_nodes_tsv)}.',
|
|
333
|
+
default=int(self.CURRENT_ARGS.file_table_of_nodes_tsv))
|
|
334
|
+
parser.add_argument('--file_probability_per_pos_per_branches_tsv', type=int, required=False,
|
|
335
|
+
dest='file_probability_per_pos_per_branches_tsv', help=f'Specify '
|
|
336
|
+
f'file_probability_per_pos_per_branches_tsv (optional). Default is '
|
|
337
|
+
f'{int(self.CURRENT_ARGS.file_probability_per_pos_per_branches_tsv)}.',
|
|
338
|
+
default=int(self.CURRENT_ARGS.file_probability_per_pos_per_branches_tsv))
|
|
339
|
+
parser.add_argument('--file_table_of_branches_tsv', dest='file_table_of_branches_tsv', type=int, required=False,
|
|
340
|
+
help=f'Specify file_table_of_branches_tsv (optional). Default is '
|
|
341
|
+
f'{int(self.CURRENT_ARGS.file_table_of_branches_tsv)}.',
|
|
342
|
+
default=int(self.CURRENT_ARGS.file_table_of_branches_tsv))
|
|
343
|
+
parser.add_argument('--file_log_likelihood_tsv', dest='file_log_likelihood_tsv', type=int, required=False,
|
|
344
|
+
help=f'Specify file_log_likelihood_tsv (optional). Default is '
|
|
345
|
+
f'{int(self.CURRENT_ARGS.file_log_likelihood_tsv)}.',
|
|
346
|
+
default=int(self.CURRENT_ARGS.file_log_likelihood_tsv))
|
|
347
|
+
parser.add_argument('--file_table_of_attributes_tsv', dest='file_table_of_attributes_tsv', type=int,
|
|
348
|
+
required=False, help=f'Specify file_table_of_attributes_tsv (optional). Default is '
|
|
349
|
+
f'{int(self.CURRENT_ARGS.file_table_of_attributes_tsv)}.',
|
|
350
|
+
default=int(self.CURRENT_ARGS.file_table_of_attributes_tsv))
|
|
351
|
+
parser.add_argument('--file_phylogenetic_tree_nwk', dest='file_phylogenetic_tree_nwk', type=int,
|
|
352
|
+
required=False, help=f'Specify file_phylogenetic_tree_nwk (optional). Default is '
|
|
353
|
+
f'{int(self.CURRENT_ARGS.file_phylogenetic_tree_nwk)}.',
|
|
354
|
+
default=int(self.CURRENT_ARGS.file_phylogenetic_tree_nwk))
|
|
355
|
+
|
|
356
|
+
args = parser.parse_args()
|
|
357
|
+
|
|
358
|
+
for arg_name, arg_value in vars(args).items():
|
|
359
|
+
if arg_value is not None:
|
|
360
|
+
if arg_name == 'process_id':
|
|
361
|
+
if arg_value != self.PROCESS_ID:
|
|
362
|
+
self.change_process_id(arg_value)
|
|
363
|
+
elif arg_name == 'mode':
|
|
364
|
+
setattr(self, arg_name.upper(), arg_value)
|
|
365
|
+
elif arg_name in ('msa_file', 'tree_file', 'out_dir'):
|
|
366
|
+
setattr(self, arg_name.upper(), Path(arg_value))
|
|
367
|
+
elif arg_name in ('with_internal_nodes', 'is_optimize_pi', 'is_optimize_pi_average',
|
|
368
|
+
'is_optimize_alpha', 'is_optimize_bl', 'is_do_not_use_e_mail',
|
|
369
|
+
'file_interactive_tree_html', 'file_newick_tree_png', 'file_table_of_nodes_tsv',
|
|
370
|
+
'file_probability_per_pos_per_branches_tsv', 'file_table_of_branches_tsv',
|
|
371
|
+
'file_log_likelihood_tsv', 'file_table_of_attributes_tsv',
|
|
372
|
+
'file_phylogenetic_tree_nwk'):
|
|
373
|
+
if hasattr(self.CURRENT_ARGS, arg_name):
|
|
374
|
+
setattr(self.CURRENT_ARGS, arg_name, bool(arg_value))
|
|
375
|
+
else:
|
|
376
|
+
if hasattr(self, arg_name.upper()):
|
|
377
|
+
setattr(self, arg_name.upper(), arg_value)
|
|
378
|
+
if hasattr(self.CURRENT_ARGS, arg_name):
|
|
379
|
+
setattr(self.CURRENT_ARGS, arg_name, arg_value)
|
|
380
|
+
|
|
381
|
+
self.enable_default_actions()
|
|
382
|
+
|
|
383
|
+
return args
|
|
384
|
+
|
|
385
|
+
@staticmethod
|
|
386
|
+
def get_new_process_id():
|
|
387
|
+
return f'{round(time())}{randint(1000, 9999)}'
|
gloome/consts.py
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
from sys import argv
|
|
2
|
+
from typing import List, Tuple, Union
|
|
3
|
+
from types import FunctionType, MethodType
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from urllib import parse
|
|
6
|
+
from importlib.resources import files
|
|
7
|
+
|
|
8
|
+
from gloome.tree.tree import Tree
|
|
9
|
+
from gloome.services.service_functions import check_data, execute_all_actions, recompile_json, del_bootstrap_values
|
|
10
|
+
|
|
11
|
+
MODE = ['draw_tree', 'compute_likelihood_of_tree', 'create_all_file_types', 'execute_all_actions']
|
|
12
|
+
IS_PRODUCTION = True
|
|
13
|
+
MAX_CONTENT_LENGTH = 16 * 1000 * 1000 * 1000
|
|
14
|
+
PREFIX = '/'
|
|
15
|
+
APPLICATION_ROOT = PREFIX
|
|
16
|
+
DEBUG = not IS_PRODUCTION
|
|
17
|
+
|
|
18
|
+
PREFERRED_URL_SCHEME = 'https'
|
|
19
|
+
WEBSERVER_NAME_CAPITAL = 'Gloome'
|
|
20
|
+
WEBSERVER_NAME = 'gloome.tau.ac.il'
|
|
21
|
+
WEBSERVER_URL = f'{PREFERRED_URL_SCHEME}://{WEBSERVER_NAME}'
|
|
22
|
+
RESULTS_URL = parse.urljoin(WEBSERVER_URL, 'results')
|
|
23
|
+
LOG_URL = WEBSERVER_URL
|
|
24
|
+
|
|
25
|
+
WEBSERVER_TITLE = '<b>GLOOME Server - Gain Loss Mapping Engine</b>'
|
|
26
|
+
MODULE_LOAD = 'module load mamba/mamba-1.5.8'
|
|
27
|
+
|
|
28
|
+
GLOOME = Path('/gloome')
|
|
29
|
+
BIN_DIR = GLOOME if GLOOME.exists() else Path.cwd()
|
|
30
|
+
RESULTS_DIR = BIN_DIR.joinpath('results')
|
|
31
|
+
IN_DIR = RESULTS_DIR.joinpath('in')
|
|
32
|
+
OUT_DIR = RESULTS_DIR.joinpath('out')
|
|
33
|
+
LOGS_DIR = BIN_DIR.joinpath('logs')
|
|
34
|
+
TMP_DIR = BIN_DIR.joinpath('tmp')
|
|
35
|
+
|
|
36
|
+
ENVIRONMENT_DIR = BIN_DIR.joinpath('gloome_env2')
|
|
37
|
+
ENVIRONMENT_ACTIVATE = f'mamba activate {ENVIRONMENT_DIR}'
|
|
38
|
+
|
|
39
|
+
GLOOME_DIR = files('gloome')
|
|
40
|
+
DATA_DIR = GLOOME_DIR.joinpath('data')
|
|
41
|
+
INITIAL_DATA_DIR = DATA_DIR.joinpath('initial_data')
|
|
42
|
+
|
|
43
|
+
MSA_FILE_NAME = 'msa_file.msa'
|
|
44
|
+
TREE_FILE_NAME = 'tree_file.tree'
|
|
45
|
+
|
|
46
|
+
REQUEST_WAITING_TIME = 20
|
|
47
|
+
REQUESTS_NUMBER = 24 * 60 * 60 * 3 / REQUEST_WAITING_TIME
|
|
48
|
+
|
|
49
|
+
UNDER_CONSTRUCTION = False
|
|
50
|
+
SECRET_KEY = ''
|
|
51
|
+
TOKEN = ''
|
|
52
|
+
PARTITION = ''
|
|
53
|
+
USE_OLD_SUBMITER = 0
|
|
54
|
+
|
|
55
|
+
LOGIN_NODE_URLS = ''
|
|
56
|
+
USER_NAME = ''
|
|
57
|
+
USER_ID = ''
|
|
58
|
+
USER_PASSWORD = ''
|
|
59
|
+
ADMIN_EMAIL = ''
|
|
60
|
+
SMTP_SERVER = ''
|
|
61
|
+
SMTP_PORT = 0
|
|
62
|
+
REPORT_RECEIVERS = []
|
|
63
|
+
|
|
64
|
+
DEV_EMAIL = ''
|
|
65
|
+
ADMIN_USER_NAME = ''
|
|
66
|
+
ADMIN_PASSWORD = ''
|
|
67
|
+
SEND_EMAIL_DIR_IBIS = ''
|
|
68
|
+
OWNER_EMAIL = ''
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
class Actions:
|
|
72
|
+
|
|
73
|
+
def __init__(self, **attributes):
|
|
74
|
+
if attributes:
|
|
75
|
+
for key, value in attributes.items():
|
|
76
|
+
if type(value) in (FunctionType, MethodType):
|
|
77
|
+
setattr(self, key, value)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
class CalculatedArgs:
|
|
81
|
+
err_list: List[Union[Tuple[str, ...], str]]
|
|
82
|
+
|
|
83
|
+
def __init__(self, **attributes):
|
|
84
|
+
self.err_list = []
|
|
85
|
+
if attributes:
|
|
86
|
+
for key, value in attributes.items():
|
|
87
|
+
setattr(self, key, value)
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
class DefaultArgs:
|
|
91
|
+
def __init__(self, **attributes):
|
|
92
|
+
if attributes:
|
|
93
|
+
for key, value in attributes.items():
|
|
94
|
+
setattr(self, key, value)
|
|
95
|
+
|
|
96
|
+
def get(self, attribute_name, default=None):
|
|
97
|
+
if hasattr(self, attribute_name):
|
|
98
|
+
return getattr(self, attribute_name)
|
|
99
|
+
else:
|
|
100
|
+
return default
|
|
101
|
+
|
|
102
|
+
def update(self, *args, **kwargs) -> None:
|
|
103
|
+
if kwargs:
|
|
104
|
+
for key, value in kwargs.items():
|
|
105
|
+
setattr(self, key, value)
|
|
106
|
+
if args:
|
|
107
|
+
for arg in args:
|
|
108
|
+
if isinstance(arg, dict):
|
|
109
|
+
for key, value in arg.items():
|
|
110
|
+
setattr(self, key, value)
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
COMMAND_LINE = argv
|
|
114
|
+
|
|
115
|
+
DEFAULT_FORM_ARGUMENTS = {
|
|
116
|
+
'categories_quantity': 4,
|
|
117
|
+
'alpha': 0.5,
|
|
118
|
+
'pi_1': 0.5,
|
|
119
|
+
'coefficient_bl': 1.0,
|
|
120
|
+
'e_mail': '',
|
|
121
|
+
'is_optimize_pi': True,
|
|
122
|
+
'is_optimize_pi_average': False,
|
|
123
|
+
'is_optimize_alpha': True,
|
|
124
|
+
'is_optimize_bl': True,
|
|
125
|
+
'is_do_not_use_e_mail': True,
|
|
126
|
+
'file_interactive_tree_html': False,
|
|
127
|
+
'file_newick_tree_png': False,
|
|
128
|
+
'file_table_of_nodes_tsv': True,
|
|
129
|
+
'file_probability_per_pos_per_branches_tsv': True,
|
|
130
|
+
'file_table_of_branches_tsv': True,
|
|
131
|
+
'file_log_likelihood_tsv': True,
|
|
132
|
+
'file_table_of_attributes_tsv': True,
|
|
133
|
+
'file_phylogenetic_tree_nwk': True
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
DEFAULT_ARGUMENTS = DefaultArgs(**{
|
|
137
|
+
'with_internal_nodes': True,
|
|
138
|
+
'sep': '\t'
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
DEFAULT_ARGUMENTS.update(DEFAULT_FORM_ARGUMENTS)
|
|
142
|
+
|
|
143
|
+
ACTIONS = Actions(**{
|
|
144
|
+
'del_bootstrap_values': del_bootstrap_values,
|
|
145
|
+
'check_data': check_data,
|
|
146
|
+
'set_root': Tree.get_root_by_midpoint,
|
|
147
|
+
'check_tree': Tree.rename_nodes,
|
|
148
|
+
'set_tree_data': Tree.set_tree_data,
|
|
149
|
+
'calculate_tree': Tree.calculate_tree,
|
|
150
|
+
'calculate_ancestral_sequence': Tree.calculate_ancestral_sequence,
|
|
151
|
+
'execute_all_actions': execute_all_actions,
|
|
152
|
+
'recompile_json': recompile_json
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
VALIDATION_ACTIONS = {
|
|
156
|
+
'del_bootstrap_values': True,
|
|
157
|
+
'check_data': True,
|
|
158
|
+
'set_root': True,
|
|
159
|
+
'check_tree': True
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
DEFAULT_ACTIONS = {
|
|
163
|
+
'set_tree_data': True,
|
|
164
|
+
'calculate_tree': False,
|
|
165
|
+
'calculate_ancestral_sequence': False,
|
|
166
|
+
'execute_all_actions': False
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
MAIN_ACTIONS = {'compute_likelihood_of_tree': False,
|
|
170
|
+
'draw_tree': False,
|
|
171
|
+
'create_all_file_types': False}
|
|
172
|
+
|
|
173
|
+
CALCULATED_ARGS = CalculatedArgs(**{
|
|
174
|
+
'file_path': None,
|
|
175
|
+
'newick_text': None,
|
|
176
|
+
'msa': None,
|
|
177
|
+
'newick_tree': None
|
|
178
|
+
})
|
|
179
|
+
|
|
180
|
+
USAGE = '''\tRequired parameters:
|
|
181
|
+
\t\t--msa_file <type=str>
|
|
182
|
+
\t\t\tSpecify the msa filepath.
|
|
183
|
+
\t\t--tree_file <type=str>
|
|
184
|
+
\t\t\tSpecify the newick filepath.
|
|
185
|
+
\tOptional parameters:
|
|
186
|
+
\t\t--out_dir <type=str>
|
|
187
|
+
\t\t\tSpecify the outdir path.
|
|
188
|
+
\t\t--process_id <type=str>
|
|
189
|
+
\t\t\tSpecify a process ID or it will be generated automatically.
|
|
190
|
+
\t\t--mode <type=str>
|
|
191
|
+
\t\t\tExecution mode style. Possible options: ('draw_tree', 'compute_likelihood_of_tree',
|
|
192
|
+
\t\t\t'create_all_file_types', 'execute_all_actions'). Default is 'execute_all_actions'.
|
|
193
|
+
\t\t--with_internal_nodes <type=int>
|
|
194
|
+
\t\t\tSpecify the tree has internal nodes. Default is 1.
|
|
195
|
+
\t\t--categories_quantity <type=int>
|
|
196
|
+
\t\t\tSpecify categories quantity. Default is 4.
|
|
197
|
+
\t\t--alpha <type=float>
|
|
198
|
+
\t\t\tSpecify alpha. Default is 0.5.
|
|
199
|
+
\t\t--pi_1 <type=float>
|
|
200
|
+
\t\t\tSpecify pi_1. Default is 0.5.
|
|
201
|
+
\t\t--coefficient_bl <type=float>
|
|
202
|
+
\t\t\tSpecify coefficient_bl. Default is 1.0.
|
|
203
|
+
\t\t--is_optimize_pi <type=int>
|
|
204
|
+
\t\t\tSpecify is_optimize_pi. Default is 1.
|
|
205
|
+
\t\t--is_optimize_pi_average <type=int>
|
|
206
|
+
\t\t\tSpecify is_optimize_pi_average. Default is 0.
|
|
207
|
+
\t\t--is_optimize_alpha <type=int>
|
|
208
|
+
\t\t\tSpecify is_optimize_alpha. Default is 1.
|
|
209
|
+
\t\t--is_optimize_bl <type=int>
|
|
210
|
+
\t\t\tSpecify is_optimize_bl. Default is 1.
|
|
211
|
+
\t\t--file_interactive_tree_html <type=int>
|
|
212
|
+
\t\t\tSpecify file_interactive_tree_html. Default is 0.
|
|
213
|
+
\t\t--file_newick_tree_png <type=int>
|
|
214
|
+
\t\t\tSpecify file_newick_tree_png. Default is 0.
|
|
215
|
+
\t\t--file_table_of_nodes_tsv <type=int>
|
|
216
|
+
\t\t\tSpecify file_table_of_nodes_tsv. Default is 1.
|
|
217
|
+
\t\t--file_probability_per_pos_per_branches_tsv
|
|
218
|
+
\t\t\tSpecify file_probability_per_pos_per_branches_tsv. Default is 1.
|
|
219
|
+
\t\t--file_table_of_branches_tsv <type=int>
|
|
220
|
+
\t\t\tSpecify file_table_of_branches_tsv. Default is 1.
|
|
221
|
+
\t\t--file_log_likelihood_tsv <type=int>
|
|
222
|
+
\t\t\tSpecify file_log_likelihood_tsv. Default is 1.
|
|
223
|
+
\t\t--file_table_of_attributes_tsv <type=int>
|
|
224
|
+
\t\t\tSpecify file_table_of_attributes_tsv. Default is 1.
|
|
225
|
+
\t\t--file_phylogenetic_tree_nwk <type=int>
|
|
226
|
+
\t\t\tSpecify file_phylogenetic_tree_nwk. Default is 1.
|
|
227
|
+
\t\t--e_mail <type=str>
|
|
228
|
+
\t\t\tSpecify e_mail (technical parameter, do not change).
|
|
229
|
+
\t\t--is_do_not_use_e_mail <type=int>
|
|
230
|
+
\t\t\tSpecify is_do_not_use_e_mail (technical parameter, do not change).'''
|
|
231
|
+
|
|
232
|
+
MENU = ({'name': 'Home', 'url': 'index',
|
|
233
|
+
'submenu': ()
|
|
234
|
+
},
|
|
235
|
+
{'name': 'Overview', 'url': 'overview',
|
|
236
|
+
'submenu': ()
|
|
237
|
+
},
|
|
238
|
+
{'name': 'Faq', 'url': 'faq',
|
|
239
|
+
'submenu': ()
|
|
240
|
+
},
|
|
241
|
+
{'name': 'Gallery', 'url': 'gallery',
|
|
242
|
+
'submenu': ()
|
|
243
|
+
},
|
|
244
|
+
{'name': 'Source code', 'url': 'source_code',
|
|
245
|
+
'submenu': ()
|
|
246
|
+
},
|
|
247
|
+
{'name': 'Citing & credits', 'url': 'citing_and_credits',
|
|
248
|
+
'submenu': ()
|
|
249
|
+
}
|
|
250
|
+
)
|
|
File without changes
|