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