1 // This file is part of the Mussa source distribution.
2 // http://mussa.caltech.edu/
3 // Contact author: Tristan De Buysscher, tristan@caltech.edu
5 // This program and all associated source code files are Copyright (C) 2005
6 // the California Institute of Technology, Pasadena, CA, 91125 USA. It is
7 // under the GNU Public License; please see the included LICENSE.txt
8 // file for more information, or contact Tristan directly.
11 #include "ConnWindow.hh"
12 #include "mussa_exceptions.hh"
18 load_ana_cb(Fl_Button* o, void* v)
20 ConnWindow* T=(ConnWindow*)v;
21 T->real_load_ana_cb();
26 ConnWindow::real_load_ana_cb()
32 cout << "Load! Load! Load, ye yellow-bellied seadogs!\n";
33 //picked_file = fl_file_chooser("Find an Analysis", "", "", 1);
34 picked_file = fl_dir_chooser("Find an Analysis", "", 1);
35 if (picked_file != NULL)
37 a_file_path = picked_file;
38 cout << "doo wah diddy diddy dum diddy doo\n";
39 cout << a_file_path << endl;
42 an_analysis = new Mussa();
44 an_analysis->load(a_file_path);
45 } catch (mussa_load_error e) {
49 //.substr(0,a_file_path.find(".mu")));
51 // relabel window with the analysis name
52 window_name = "Mussa: " + an_analysis->get_name();
53 label((const char*)window_name.c_str());
54 // show the user the analysis
55 conn_box->setup(an_analysis->get_name(), an_analysis->size(),
56 an_analysis->get_window(), &(an_analysis->the_seqs),
57 &(an_analysis->the_paths));
58 conn_box->scale_paths();
64 do_ana_cb(Fl_Button* o, void* v)
66 ConnWindow* T=(ConnWindow*)v;
72 ConnWindow::real_do_ana_cb()
78 picked_file = fl_file_chooser("Analysis Config File", "", "", 1);
79 if (picked_file != NULL)
81 a_file_path = picked_file;
83 an_analysis = new Mussa();
85 an_analysis->load_mupa_file(a_file_path);
86 } catch (mussa_load_error e) {
92 an_analysis->analyze(0, 0, Mussa::TransitiveNway, 0.0);
93 // relabel window with the analysis name
94 window_name = "Mussa: " + an_analysis->get_name();
95 label((const char*)window_name.c_str());
96 // show the user the analysis
97 conn_box->setup(an_analysis->get_name(), an_analysis->size(),
98 an_analysis->get_window(), &(an_analysis->the_seqs),
99 &(an_analysis->the_paths));
100 conn_box->scale_paths();
101 } catch (mussa_analysis_error e) {
110 setup_ana_cb(Fl_Button* o, void* v)
112 ConnWindow* T=(ConnWindow*)v;
113 T->real_setup_ana_cb();
117 ConnWindow::real_setup_ana_cb()
119 an_analysis = new Mussa();
120 setup_win = new SetupWindow(650,700,"Analysis Setup", an_analysis);
122 while(setup_win->visible())
124 cout << "Like a warm summer day\n";
126 if (setup_win->done())
128 // relabel window with the analysis name
129 window_name = "Mussa: " + an_analysis->get_name();
130 label((const char*)window_name.c_str());
131 // is it this easy? what if setup window encounters an error...??
132 conn_box->setup(an_analysis->get_name(), an_analysis->size(),
133 an_analysis->get_window(), &(an_analysis->the_seqs),
134 &(an_analysis->the_paths));
136 conn_box->scale_paths();
142 subana_cb(Fl_Button* o, void* v)
144 ConnWindow* T=(ConnWindow*)v;
149 ConnWindow::real_subana_cb()
153 if (an_analysis == 0 || an_analysis->the_seqs.size() == 0) {
154 fl_message("please load an analysis before creating a subanalysis");
158 sub_analysis = new Mussa();
159 subana_win = new SubAnalysisWindow(500,400,"Sub Analysis Setup", sub_analysis,
160 an_analysis->the_seqs);
162 while(subana_win->visible())
164 cout << "Like a warm summer day\n";
166 if (subana_win->done())
168 subana_name = "SubMussa: " + sub_analysis->get_name();
169 sub_conn_win = new ConnWindow(w(), h(), (const char*) subana_name.c_str());
170 cout << "Like a warm day in may\n";
171 sub_conn_win->add_ana(sub_analysis);
172 //Fl::visual(FL_DOUBLE|FL_INDEX);
173 //sub_conn_box->show();
179 seq_show_cb(Fl_Button* o, void* v)
181 ConnWindow* T=(ConnWindow*)v;
182 T->real_seq_show_cb();
186 ConnWindow::real_seq_show_cb()
188 show_seq_win = new SeqTextWindow(500,400,"Seq Show", an_analysis->the_seqs);
192 seq_win_spawn_cb(Fl_Button* o, void* v)
194 ConnWindow* T=(ConnWindow*)v;
195 T->real_seq_win_spawn_cb();
199 ConnWindow::real_seq_win_spawn_cb()
201 conn_box->spawnSeq();
205 motif_find_cb(Fl_Button* o, void* v)
207 ConnWindow* T=(ConnWindow*)v;
208 T->real_motif_find_cb();
212 ConnWindow::real_motif_find_cb()
214 conn_box->find_motifs();
218 annot_win_cb(Fl_Button* o, void* v)
220 ConnWindow* T=(ConnWindow*)v;
221 T->real_annot_win_cb();
225 ConnWindow::real_annot_win_cb()
227 conn_box->annot_win();
231 // all the crap needed for dealing with the scale bars
233 toggle_scale_bars_cb(Fl_Button* o, void* v)
235 ConnWindow* T=(ConnWindow*)v;
236 T->real_toggle_bars_cb();
240 ConnWindow::real_toggle_bars_cb()
242 conn_box->toggle_bars();
246 set_bar_len_cb(Fl_Input* o, void* v)
248 ConnWindow* T=(ConnWindow*)v;
249 cout << "WAAAAAAAAA\n";
250 T->real_set_bar_len_cb(o);
254 ConnWindow::real_set_bar_len_cb(Fl_Input* o)
258 new_bar_len = atoi(o->value());
259 cout << "new bar len = " << new_bar_len << endl;
260 conn_box->set_bar_interval(new_bar_len);
264 // all the crap needed for dealing with the scale lines
266 toggle_scale_lines_cb(Fl_Button* o, void* v)
268 ConnWindow* T=(ConnWindow*)v;
269 T->real_toggle_lines_cb();
273 ConnWindow::real_toggle_lines_cb()
275 conn_box->toggle_lines();
279 set_line_len_cb(Fl_Input* o, void* v)
281 ConnWindow* T=(ConnWindow*)v;
282 cout << "WAAAAAAAAA\n";
283 T->real_set_line_len_cb(o);
287 ConnWindow::real_set_line_len_cb(Fl_Input* o)
291 new_line_len = atoi(o->value());
292 cout << "new line len = " << new_line_len << endl;
293 conn_box->set_line_interval(new_line_len);
297 // setting new soft threshold
300 set_soft_thres_cb(Fl_Input* o, void* v)
302 ConnWindow* T=(ConnWindow*)v;
303 cout << "WAAAAAAAAA\n";
304 T->real_set_soft_thres_cb(o);
308 ConnWindow::real_set_soft_thres_cb(Fl_Input* o)
312 new_soft_thres = atoi(o->value());
313 cout << "new soft thres = " << new_soft_thres << endl;
315 an_analysis->set_soft_thres(new_soft_thres);
316 an_analysis->set_analysis_mode(Mussa::TransitiveNway);
318 conn_box->scale_paths();
321 // hacked in stuff to save muway files at different thresholds
323 ostringstream append_info;
325 save_path = an_analysis->get_name() + "/"
326 + an_analysis->get_name().substr(0,an_analysis->get_name().find("_t"));
328 append_info << "_t" << new_soft_thres << ".muway";
329 //<< "_w" << an_analysis->window
330 save_path += append_info.str();
331 cout << "saving as: " << save_path << endl;
332 an_analysis->save_muway(save_path);
338 ConnWindow::ConnWindow(int w, int h, const char* title):
339 Fl_Double_Window(w,h,title)
341 int button_len = 120;
342 Fl_Color a_color = fl_rgb_color(150, 200, 255);
347 //fl_color(150,200,255);
352 // create file menu button
353 file_menu = new Fl_Menu_Button(padding, 2, button_len, 30, "Analysis");
354 file_menu->color(FL_WHITE,a_color);
355 file_menu->box(FL_BORDER_BOX);
359 file_menu->add("Do Analysis", 0, (Fl_Callback *) do_ana_cb, this);
360 file_menu->add("Load Analysis", 0, (Fl_Callback *) load_ana_cb, this);
361 file_menu->add("Setup Analysis", 0, (Fl_Callback *) setup_ana_cb, this);
362 file_menu->add("Sub Analysis", 0, (Fl_Callback *) subana_cb, this);
365 view_menu = new Fl_Menu_Button(padding+button_len,2, button_len, 30, "View");
366 view_menu->color(FL_WHITE,a_color);
367 view_menu->box(FL_BORDER_BOX);
369 view_menu->add("Sequence Zoom", 0, (Fl_Callback*) seq_win_spawn_cb, this);
370 view_menu->add("Motif Finder", 0, (Fl_Callback*) motif_find_cb, this);
371 view_menu->add("Annotations", 0, (Fl_Callback*) annot_win_cb, this);
372 view_menu->add("Copy Seq", 0, (Fl_Callback*) seq_show_cb, this);
373 view_menu->add("Toggle Bars", 0, (Fl_Callback*) toggle_scale_bars_cb, this,
374 FL_MENU_TOGGLE|FL_MENU_VALUE);
375 view_menu->add("Toggle Lines", 0, (Fl_Callback*) toggle_scale_lines_cb, this,
376 FL_MENU_TOGGLE|FL_MENU_VALUE);
378 bar_input = new Fl_Input(padding+3*button_len, 2, button_len, 30, "Bar Length (bp)");
379 bar_input->value("");
380 bar_input->when(FL_WHEN_ENTER_KEY);
381 bar_input->callback((Fl_Callback*)set_bar_len_cb, this);
383 line_input = new Fl_Input(padding+5*button_len, 2, button_len, 30, "Line Interval (bp)");
384 line_input->value("");
385 line_input->when(FL_WHEN_ENTER_KEY);
386 line_input->callback((Fl_Callback*)set_line_len_cb, this);
389 thres_input = new Fl_Input(padding+7*button_len, 2, button_len, 30, "Threshold");
390 thres_input->value("");
391 thres_input->when(FL_WHEN_ENTER_KEY);
392 thres_input->callback((Fl_Callback*)set_soft_thres_cb, this);
395 // create the connections box
396 conn_box = new ConnView(padding, padding + 30, w-2*padding, h-2*padding-30);
397 //conn_box = new ConnView(padding, padding, w-2*padding, h-2*padding);
404 ConnWindow::~ConnWindow()
409 ConnWindow::add_ana(Mussa *the_ana)
411 an_analysis = the_ana;
413 // relabel window with the analysis name
414 window_name = "Mussa: " + an_analysis->get_name();
415 label((const char*)window_name.c_str());
417 conn_box->setup(an_analysis->get_name(), an_analysis->size(),
418 an_analysis->get_window(), &(an_analysis->the_seqs),
419 &(an_analysis->the_paths));
420 conn_box->scale_paths();