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