-
Notifications
You must be signed in to change notification settings - Fork 12
/
flcallback.cc
370 lines (367 loc) · 9.91 KB
/
flcallback.cc
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
#include "flnjtree_ui.h"
#include "flglobal.h"
// PHYML window
void cb_phyml(Fl_Widget *w, void *global)
{
FNglobal *g = (FNglobal*)global;
fl_message("If you use PHYML in your work, please cite its paper:\n\nGuindon S. and Gascuel O. (2003) A simple, fast, and accurate algorithm to\n estimate large phylogenies by maximum likelihood. Syst Biol, 52(5), 696-704");
int n = 0;
for (int i = 0; i < FN_N_SPACE; ++i)
if (g->workspace[i]->get_tree()) ++n;
if (n) g->phyml->has_tree->activate();
else g->phyml->has_tree->deactivate();
g->phyml_w->show();
}
void cb_phyml_inv(Fl_Widget *w, void *global)
{
FNglobal *g = (FNglobal*)global;
if (g->phyml->is_inv->value()) g->phyml->i_inv->deactivate();
else g->phyml->i_inv->activate();
}
void cb_phyml_alpha(Fl_Widget *w, void *global)
{
FNglobal *g = (FNglobal*)global;
if (g->phyml->is_alpha->value()) g->phyml->i_alpha->deactivate();
else g->phyml->i_alpha->activate();
}
void cb_phyml_has_tree(Fl_Widget *w, void *global)
{
FNglobal *g = (FNglobal*)global;
if (g->phyml->has_tree->value()) g->phyml->i_tree->activate();
else g->phyml->i_tree->deactivate();
}
void cb_phyml_tstv(Fl_Widget *w, void *global)
{
FNglobal *g = (FNglobal*)global;
if (g->phyml->is_tstv->value())
g->phyml->i_tstv->deactivate();
else g->phyml->i_tstv->activate();
}
void cb_phyml_n_cat(Fl_Widget *w, void *global)
{
FNglobal *g = (FNglobal*)global;
int n_cat = atoi(g->phyml->i_num_cat->value());
if (n_cat == 1) {
g->phyml->is_alpha->deactivate();
g->phyml->i_alpha->deactivate();
} else {
g->phyml->is_alpha->activate();
if (g->phyml->is_alpha->value() == 0)
g->phyml->i_alpha->activate();
}
}
void cb_phyml_type(Fl_Widget *w, void *global)
{
FNglobal *g =(FNglobal*)global;
Fl_Choice *c = (Fl_Choice*)w;
if (c->value() == 0) { // nucleotide
g->phyml->i_model->clear();
g->phyml->i_model->menu(menu_phyml_nt_model);
g->phyml->i_model->redraw();
g->phyml->is_tstv->activate();
if (g->phyml->is_tstv->value() == 0)
g->phyml->i_tstv->activate();
} else if (c->value() == 1) {
g->phyml->i_model->clear();
g->phyml->i_model->menu(menu_phyml_aa_model);
g->phyml->i_model->redraw();
g->phyml->is_tstv->deactivate();
g->phyml->i_tstv->deactivate();
}
}
void cb_phyml_browse(Fl_Widget *w, void *global)
{
FNglobal *g = (FNglobal*)global;
g->fc_phyml_aln->show();
while (g->fc_phyml_aln->visible()) Fl::check();
if (g->fc_phyml_aln->value())
g->phyml->i_alignment->value(g->fc_phyml_aln->value());
g->phyml->i_alignment->redraw();
}
void cb_phyml_tree(Fl_Widget *w, void *global)
{
if (!fl_ask("Building ML tree is usually very slow.\nFLtreeBeST might not respond for a long time.\nBe patient, or explicitly kill the program.")) {
return;
}
FNglobal *g = (FNglobal*)global;
if (g->phyml->has_tree->value() && g->workspace[g->phyml->i_tree->value()]->get_tree() == 0) {
fl_alert("No tree is found in workspace %s.", g->workspace[g->phyml->i_tree->value()]);
return;
}
g->active_ws()->set_tree(g->phyml->do_phyml());
g->active_ws()->redraw();
g->phyml->has_tree->activate();
}
// BUILD window and miscellaneous
void cb_build(Fl_Widget *w, void *global)
{
FNglobal *g = (FNglobal*)global;
int n = 0;
for (int i = 0; i < FN_N_SPACE; ++i)
if (g->workspace[i]->get_tree()) ++n;
if (n) g->build->is_cons->activate();
else g->build->is_cons->deactivate();
g->build_w->show();
}
void cb_merge(Fl_Widget *w, void *global)
{
FNglobal *g = (FNglobal*)global;
g->merge_w->show();
}
void cb_compare(Fl_Widget *w, void *global)
{
FNglobal *g = (FNglobal*)global;
g->compare_w->show();
}
void cb_backtrans(Fl_Widget *w, void *global)
{
FNglobal *g = (FNglobal*)global;
g->backtrans_w->show();
}
void cb_close_build(Fl_Widget *w, void *global)
{
FNglobal *g = (FNglobal*)global;
g->build_w->hide();
}
void cb_close_phyml(Fl_Widget *w, void *global)
{
FNglobal *g = (FNglobal*)global;
g->phyml_w->hide();
}
void cb_close_merge(Fl_Widget *w, void *global)
{
FNglobal *g = (FNglobal*)global;
g->merge_w->hide();
}
void cb_close_backtrans(Fl_Widget *w, void *global)
{
FNglobal *g = (FNglobal*)global;
g->backtrans_w->hide();
}
void cb_close_compare(Fl_Widget *w, void *global)
{
FNglobal *g = (FNglobal*)global;
g->compare_w->hide();
}
void cb_build_tree(Fl_Widget *w, void *global)
{
FNglobal *g = (FNglobal*)global;
if (g->build->is_cons->value() && g->workspace[g->build->i_cons_tree->value()]->get_tree() == 0) {
fl_alert("No tree is found in workspace %s.", g->workspace[g->build->i_cons_tree->value()]);
return;
}
g->active_ws()->set_tree(g->build->build());
g->active_ws()->redraw();
g->build->is_cons->activate();
}
void cb_toggle_cons(Fl_Widget *w, void *global)
{
FNglobal *g = (FNglobal*)global;
if (g->build->is_cons->value())
g->build->i_cons_tree->activate();
else g->build->i_cons_tree->deactivate();
}
void cb_do_backtrans(Fl_Widget *w, void *global)
{
FNglobal *g = (FNglobal*)global;
g->backtrans->backtrans();
g->backtrans_w->hide();
}
void cb_merge_tree(Fl_Widget *w, void *global)
{
FNglobal *g = (FNglobal*)global;
g->active_ws()->set_tree(g->merge->merge());
g->active_ws()->redraw();
g->merge_w->hide();
}
void cb_compare_tree(Fl_Widget *w, void *global)
{
FNglobal *g = (FNglobal*)global;
g->compare->compare();
g->active_ws()->redraw();
g->compare_w->hide();
}
void cb_prev(Fl_Widget *w, void *global)
{
FNglobal *g = (FNglobal*)global;
g->tabs->value(g->workspace[g->change_ws(-1)]->parent()->parent());
Fl::flush();
}
void cb_next(Fl_Widget *w, void *global)
{
FNglobal *g = (FNglobal*)global;
g->tabs->value(g->workspace[g->change_ws(+1)]->parent()->parent());
Fl::flush();
}
void cb_update_buttons(Fl_Widget *w, void *global)
{
FNglobal *g = (FNglobal*)global;
Workspace *ws = g->active_ws();
int n = 0;
if (g->prev_tab == g->tabs->value()) return;
g->prev_tab = g->tabs->value();
for (int i = 0; i < FN_N_SPACE; ++i)
if (g->workspace[i]->get_tree()) ++n;
if (ws->get_tree()) {
g->b_save->activate();
g->b_expt->activate();
g->b_root->activate();
g->b_order->activate();
g->b_comp->activate();
} else {
g->b_save->deactivate();
g->b_expt->deactivate();
g->b_root->deactivate();
g->b_order->deactivate();
g->b_comp->deactivate();
}
if (n >= 2) g->b_merge->activate();
else g->b_merge->deactivate();
g->b_spec->value(ws->get_pp()->show_spec);
g->b_real->value(ws->get_pp()->is_real);
Fl::flush();
}
void cb_open(Fl_Widget *w, void *global)
{
FNglobal *g = (FNglobal*)global;
g->fc_nhx->show();
while (g->fc_nhx->visible()) Fl::check();
if (g->fc_nhx->value()) {
FILE *fp = fopen(g->fc_nhx->value(), "r");
if (fp) {
g->active_ws()->set_tree(fp);
fclose(fp);
g->active_ws()->redraw();
}
}
}
void cb_save(Fl_Widget *w, void *global)
{
FNglobal *g = (FNglobal*)global;
g->fc_save->show();
while (g->fc_save->visible()) Fl::check();
if (g->fc_save->value())
g->active_ws()->save_nhx(g->fc_save->value());
}
void cb_expt(Fl_Widget *w, void *global)
{
FNglobal *g = (FNglobal*)global;
g->fc_eps->show();
while (g->fc_eps->visible()) Fl::check();
if (g->fc_eps->value())
g->active_ws()->export_eps(g->fc_eps->value());
}
void cb_root(Fl_Widget *w, void *global)
{
FNglobal *g = (FNglobal*)global;
g->active_ws()->root_tree();
g->active_ws()->redraw();
}
void cb_browse(Fl_Widget *w, void *global)
{
FNglobal *g = (FNglobal*)global;
g->fc_aln->show();
while (g->fc_aln->visible()) Fl::check();
if (g->fc_aln->value())
g->build->i_alignment->value(g->fc_aln->value());
g->build->i_alignment->redraw();
}
void cb_browse_aa_aln(Fl_Widget *w, void *global)
{
FNglobal *g = (FNglobal*)global;
g->fc_aa_aln->show();
while (g->fc_aa_aln->visible()) Fl::check();
if (g->fc_aa_aln->value())
g->backtrans->i_aa_aln->value(g->fc_aa_aln->value());
g->backtrans->i_aa_aln->redraw();
}
void cb_browse_nt_seq(Fl_Widget *w, void *global)
{
FNglobal *g = (FNglobal*)global;
g->fc_nt_seq->show();
while (g->fc_nt_seq->visible()) Fl::check();
if (g->fc_nt_seq->value())
g->backtrans->i_nt_seq->value(g->fc_nt_seq->value());
g->backtrans->i_nt_seq->redraw();
}
void cb_browse_nt_aln(Fl_Widget *w, void *global)
{
FNglobal *g = (FNglobal*)global;
g->fc_nt_aln->show();
while (g->fc_nt_aln->visible()) Fl::check();
if (g->fc_nt_aln->value())
g->backtrans->i_nt_aln->value(g->fc_nt_aln->value());
g->backtrans->i_nt_aln->redraw();
}
void cb_type(Fl_Widget *w, void *global)
{
FNglobal *g =(FNglobal*)global;
Fl_Choice *c = (Fl_Choice*)w;
if (c->value() == 1) { // nucleotide
g->build->i_dist_type->clear();
g->build->i_dist_type->menu(menu_nt_type);
g->build->i_dist_type->redraw();
} else if (c->value() == 0) {
g->build->i_dist_type->clear();
g->build->i_dist_type->menu(menu_aa_type);
g->build->i_dist_type->redraw();
}
}
void cb_zoom_in_x(Fl_Widget *w, void *global)
{
FNglobal *g =(FNglobal*)global;
Workspace *ws = g->active_ws();
ws->size(ws->w()+100, ws->h());
ws->redraw();
}
void cb_zoom_out_x(Fl_Widget *w, void *global)
{
FNglobal *g =(FNglobal*)global;
Workspace *ws = g->active_ws();
ws->size(ws->w()-100, ws->h());
ws->redraw();
}
void cb_zoom_in_y(Fl_Widget *w, void *global)
{
FNglobal *g =(FNglobal*)global;
Workspace *ws = g->active_ws();
ws->size(ws->w(), ws->h()+100);
ws->redraw();
}
void cb_zoom_out_y(Fl_Widget *w, void *global)
{
FNglobal *g =(FNglobal*)global;
Workspace *ws = g->active_ws();
ws->size(ws->w(), ws->h()-100);
ws->redraw();
}
void cb_small_font(Fl_Widget *w, void *global)
{
FNglobal *g =(FNglobal*)global;
g->active_ws()->change_font_size(-1);
g->active_ws()->redraw();
}
void cb_large_font(Fl_Widget *w, void *global)
{
FNglobal *g =(FNglobal*)global;
g->active_ws()->change_font_size(+1);
g->active_ws()->redraw();
}
void cb_spec(Fl_Widget *w, void *global)
{
FNglobal *g =(FNglobal*)global;
g->active_ws()->toggle_spec();
g->active_ws()->redraw();
}
void cb_real(Fl_Widget *w, void *global)
{
FNglobal *g =(FNglobal*)global;
g->active_ws()->toggle_real();
g->active_ws()->redraw();
}
void cb_order(Fl_Widget *w, void *global)
{
FNglobal *g =(FNglobal*)global;
g->active_ws()->order_tree();
g->active_ws()->redraw();
}