45743721f9a0bbc9e7690fa69b349bbf497fbbcb
[mussa.git] / mussa_gui_conn_window.cc
1 //  This file is part of the Mussa source distribution.
2 //  http://mussa.caltech.edu/
3 //  Contact author: Tristan  De Buysscher, tristan@caltech.edu
4
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.
9
10
11 #include "mussa_gui_conn_window.hh"
12
13 #include <iostream>
14 using namespace std;
15
16 void
17 load_ana_cb(Fl_Button* o, void* v)
18 {
19   ConnWindow* T=(ConnWindow*)v;
20   T->real_load_ana_cb();
21 }
22
23
24 void
25 ConnWindow::real_load_ana_cb()
26 {
27   char *picked_file;
28   string a_file_path;
29   string err_msg;
30
31   cout << "Load!  Load!  Load, ye yellow-bellied seadogs!\n";
32   //picked_file = fl_file_chooser("Find an Analysis", "", "", 1);
33   picked_file = fl_dir_chooser("Find an Analysis", "", 1);
34   if (picked_file != NULL)
35   {
36     a_file_path = picked_file;
37     cout << "doo wah diddy diddy dum diddy doo\n";
38     cout << a_file_path << endl;
39
40     // load the analysis
41     an_analysis = new Mussa();
42     err_msg = an_analysis->load(a_file_path);
43     //.substr(0,a_file_path.find(".mu")));
44
45     if (err_msg == "")
46     {
47       // relabel window with the analysis name
48       window_name = "Mussa: " + an_analysis->ana_name;
49       label((const char*)window_name.c_str());
50       // show the user the analysis
51       conn_box->setup(an_analysis->ana_name, an_analysis->seq_num, 
52                       an_analysis->window, &(an_analysis->the_Seqs), 
53                       &(an_analysis->the_paths));
54       conn_box->scale_paths();
55     }
56     else
57     {
58       fl_alert(err_msg.c_str());
59       cout << err_msg << endl;
60     }
61   }
62 }
63
64
65 void
66 do_ana_cb(Fl_Button* o, void* v)
67 {
68   ConnWindow* T=(ConnWindow*)v;
69   T->real_do_ana_cb();
70 }
71
72
73 void
74 ConnWindow::real_do_ana_cb()
75 {
76   char *picked_file;
77   string a_file_path;
78   string err_msg;
79
80   picked_file = fl_file_chooser("Analysis Config File", "", "", 1);
81   if (picked_file != NULL)
82   {
83     a_file_path = picked_file;
84
85     an_analysis = new Mussa();
86     err_msg = an_analysis->load_mupa_file(a_file_path);
87
88     if (err_msg == "")
89     {
90       err_msg = an_analysis->analyze(0, 0, 't', 0.0);
91     }
92
93     if (err_msg == "")
94     {
95       // relabel window with the analysis name
96       window_name = "Mussa: " + an_analysis->ana_name;
97       label((const char*)window_name.c_str());
98       // show the user the analysis
99       conn_box->setup(an_analysis->ana_name, an_analysis->seq_num, 
100                       an_analysis->window, &(an_analysis->the_Seqs), 
101                       &(an_analysis->the_paths));
102       conn_box->scale_paths();
103     }
104     else
105     {
106       fl_alert(err_msg.c_str());
107       cout << err_msg;
108     }
109   }
110 }
111
112
113 void
114 setup_ana_cb(Fl_Button* o, void* v)
115 {
116   ConnWindow* T=(ConnWindow*)v;
117   T->real_setup_ana_cb();
118 }
119
120 void
121 ConnWindow::real_setup_ana_cb()
122 {
123   an_analysis = new Mussa();
124   setup_win = new SetupWindow(650,700,"Analysis Setup", an_analysis);
125
126   while(setup_win->visible())
127     Fl::wait(.1);
128   cout << "Like a warm summer day\n";
129
130   if (setup_win->done())
131   {
132     // relabel window with the analysis name
133     window_name = "Mussa: " + an_analysis->ana_name;
134     label((const char*)window_name.c_str());
135     // is it this easy?  what if setup window encounters an error...??
136     conn_box->setup(an_analysis->ana_name, an_analysis->seq_num, 
137                     an_analysis->window, &(an_analysis->the_Seqs), 
138                     &(an_analysis->the_paths));
139
140     conn_box->scale_paths();
141   }
142 }
143
144
145 void
146 subana_cb(Fl_Button* o, void* v)
147 {
148   ConnWindow* T=(ConnWindow*)v;
149   T->real_subana_cb();
150 }
151
152 void
153 ConnWindow::real_subana_cb()
154 {
155   string subana_name;
156
157   sub_analysis = new Mussa();
158   subana_win = new SubanaWindow(500,400,"Sub Analysis Setup", sub_analysis,
159                                 an_analysis->the_Seqs);
160
161   while(subana_win->visible())
162     Fl::wait(.1);
163   cout << "Like a warm summer day\n";
164
165   if (subana_win->done())
166   {
167     subana_name = "SubMussa: " + sub_analysis->ana_name; 
168     sub_conn_win = new ConnWindow(w(), h(), (const char*) subana_name.c_str());
169     cout << "Like a warm day in may\n";
170     sub_conn_win->add_ana(sub_analysis);
171     //Fl::visual(FL_DOUBLE|FL_INDEX);
172     //sub_conn_box->show();
173   }
174 }
175
176
177 void
178 seq_show_cb(Fl_Button* o, void* v)
179 {
180   ConnWindow* T=(ConnWindow*)v;
181   T->real_seq_show_cb();
182 }
183
184 void
185 ConnWindow::real_seq_show_cb()
186 {
187   show_seq_win = new SeqTextWin(500,400,"Seq Show", an_analysis->the_Seqs);
188 }
189
190 void
191 seq_win_spawn_cb(Fl_Button* o, void* v)
192 {
193   ConnWindow* T=(ConnWindow*)v;
194   T->real_seq_win_spawn_cb();
195 }
196
197 void
198 ConnWindow::real_seq_win_spawn_cb()
199 {
200   conn_box->spawnSeq();
201 }
202
203 void
204 motif_find_cb(Fl_Button* o, void* v)
205 {
206   ConnWindow* T=(ConnWindow*)v;
207   T->real_motif_find_cb();
208 }
209
210 void
211 ConnWindow::real_motif_find_cb()
212 {
213   conn_box->find_motifs();
214 }
215
216 void
217 annot_win_cb(Fl_Button* o, void* v)
218 {
219   ConnWindow* T=(ConnWindow*)v;
220   T->real_annot_win_cb();
221 }
222
223 void
224 ConnWindow::real_annot_win_cb()
225 {
226   conn_box->annot_win();
227 }
228
229
230 // all the crap needed for dealing with the scale bars
231 void
232 toggle_scale_bars_cb(Fl_Button* o, void* v)
233 {
234   ConnWindow* T=(ConnWindow*)v;
235   T->real_toggle_bars_cb();
236 }
237
238 void
239 ConnWindow::real_toggle_bars_cb()
240 {
241   conn_box->toggle_bars();
242 }
243
244 void
245 set_bar_len_cb(Fl_Input* o, void* v)
246 {
247   ConnWindow* T=(ConnWindow*)v;
248   cout << "WAAAAAAAAA\n";
249   T->real_set_bar_len_cb(o);
250 }
251
252 void
253 ConnWindow::real_set_bar_len_cb(Fl_Input* o)
254 {
255   int new_bar_len;
256  
257   new_bar_len = atoi(o->value());
258   cout << "new bar len = " << new_bar_len << endl;
259   conn_box->set_bar_interval(new_bar_len);
260 }
261
262
263 // all the crap needed for dealing with the scale lines
264 void
265 toggle_scale_lines_cb(Fl_Button* o, void* v)
266 {
267   ConnWindow* T=(ConnWindow*)v;
268   T->real_toggle_lines_cb();
269 }
270
271 void
272 ConnWindow::real_toggle_lines_cb()
273 {
274   conn_box->toggle_lines();
275 }
276
277 void
278 set_line_len_cb(Fl_Input* o, void* v)
279 {
280   ConnWindow* T=(ConnWindow*)v;
281   cout << "WAAAAAAAAA\n";
282   T->real_set_line_len_cb(o);
283 }
284
285 void
286 ConnWindow::real_set_line_len_cb(Fl_Input* o)
287 {
288   int new_line_len;
289  
290   new_line_len = atoi(o->value());
291   cout << "new line len = " << new_line_len << endl;
292   conn_box->set_line_interval(new_line_len);
293 }
294
295
296 // setting new soft threshold
297
298 void
299 set_soft_thres_cb(Fl_Input* o, void* v)
300 {
301   ConnWindow* T=(ConnWindow*)v;
302   cout << "WAAAAAAAAA\n";
303   T->real_set_soft_thres_cb(o);
304 }
305
306 void
307 ConnWindow::real_set_soft_thres_cb(Fl_Input* o)
308 {
309   int new_soft_thres;
310  
311   new_soft_thres = atoi(o->value());
312   cout << "new soft thres = " << new_soft_thres << endl;
313
314   an_analysis->set_soft_thres(new_soft_thres);
315   an_analysis->set_ana_mode('t');
316   an_analysis->nway();
317   conn_box->scale_paths();
318   conn_box->redraw();
319
320   // hacked in stuff to save muway files at different thresholds
321   string save_path;
322   ostringstream append_info;
323
324   save_path = an_analysis->ana_name + "/"
325     + an_analysis->ana_name.substr(0,an_analysis->ana_name.find("_t"));
326   append_info.str("");
327   append_info << "_t" << new_soft_thres << ".muway";
328   //<<  "_w" << an_analysis->window
329   save_path += append_info.str();
330   cout << "saving as: " << save_path << endl;
331   an_analysis->save_muway(save_path);
332 }
333
334
335
336
337 ConnWindow::ConnWindow(int w, int h, const char* title):
338   Fl_Double_Window(w,h,title)
339 {
340   int button_len = 120;
341   Fl_Color a_color = fl_rgb_color(150, 200, 255);
342
343   padding = 5;
344
345   begin();
346   //fl_color(150,200,255);
347   color(FL_WHITE);
348   resizable(this);
349
350  
351   // create file menu button
352   file_menu = new Fl_Menu_Button(padding, 2, button_len, 30, "Analysis");
353   file_menu->color(FL_WHITE,a_color);
354   file_menu->box(FL_BORDER_BOX);
355   file_menu->clear();
356
357   // add menu items
358   file_menu->add("Do Analysis", 0, (Fl_Callback *) do_ana_cb, this);
359   file_menu->add("Load Analysis", 0, (Fl_Callback *) load_ana_cb, this);
360   file_menu->add("Setup Analysis", 0, (Fl_Callback *) setup_ana_cb, this);
361   file_menu->add("Sub Analysis", 0, (Fl_Callback *) subana_cb, this);
362
363
364   view_menu = new Fl_Menu_Button(padding+button_len,2, button_len, 30, "View");
365   view_menu->color(FL_WHITE,a_color);
366   view_menu->box(FL_BORDER_BOX);
367   view_menu->clear();
368   view_menu->add("Sequence Zoom", 0, (Fl_Callback*) seq_win_spawn_cb, this);
369   view_menu->add("Motif Finder", 0, (Fl_Callback*) motif_find_cb, this);
370   view_menu->add("Annotations", 0, (Fl_Callback*) annot_win_cb, this);
371   view_menu->add("Copy Seq", 0, (Fl_Callback*) seq_show_cb, this);
372   view_menu->add("Toggle Bars", 0, (Fl_Callback*) toggle_scale_bars_cb, this, 
373                  FL_MENU_TOGGLE|FL_MENU_VALUE);
374   view_menu->add("Toggle Lines", 0, (Fl_Callback*) toggle_scale_lines_cb, this,
375                  FL_MENU_TOGGLE|FL_MENU_VALUE);
376
377   bar_input = new Fl_Input(padding+3*button_len, 2, button_len, 30, "Bar Length (bp)");
378   bar_input->value("");
379   bar_input->when(FL_WHEN_ENTER_KEY);
380   bar_input->callback((Fl_Callback*)set_bar_len_cb, this);
381
382   line_input = new Fl_Input(padding+5*button_len, 2, button_len, 30, "Line Interval (bp)");
383   line_input->value("");
384   line_input->when(FL_WHEN_ENTER_KEY);
385   line_input->callback((Fl_Callback*)set_line_len_cb, this);
386
387
388   thres_input = new Fl_Input(padding+7*button_len, 2, button_len, 30, "Threshold");
389   thres_input->value("");
390   thres_input->when(FL_WHEN_ENTER_KEY);
391   thres_input->callback((Fl_Callback*)set_soft_thres_cb, this);
392
393
394   // create the connections box
395   conn_box = new ConnView(padding, padding + 30, w-2*padding, h-2*padding-30);
396   //conn_box = new ConnView(padding, padding, w-2*padding, h-2*padding);
397
398   end();
399   show();
400 }
401
402
403 ConnWindow::~ConnWindow()
404 {}
405
406
407 void
408 ConnWindow::add_ana(Mussa *the_ana)
409 {
410   an_analysis = the_ana;
411
412   // relabel window with the analysis name
413   window_name = "Mussa: " + an_analysis->ana_name;
414   label((const char*)window_name.c_str());
415
416   conn_box->setup(an_analysis->ana_name, an_analysis->seq_num, 
417                   an_analysis->window, &(an_analysis->the_Seqs), 
418                   &(an_analysis->the_paths));
419   conn_box->scale_paths();
420 }