massive code move
[mussa.git] / gui / SetupWindow.cxx
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 "SetupWindow.hh"
12 #include "mussa_class.hh"
13 #include <iostream>
14 #include <FL/Fl_File_Chooser.H>
15
16 using namespace std;
17
18 bool
19 SetupWindow::done()
20 {
21   return all_done;
22 }
23
24
25 void
26 do_analysis_cb(Fl_Button* o, void* v)
27 {
28   SetupWindow* T=(SetupWindow*)v;
29   T->real_do_analysis();
30 }
31
32
33 // passes the parameters to the mussa class object and orders it to run
34 void
35 SetupWindow::real_do_analysis()
36 {
37   int i;
38   string err_msg;
39
40   // <-- need a check here to make sure all vars have a valid value
41
42   an_analysis->clear();
43   an_analysis->set_name(ana_name);
44   an_analysis->set_seq_num(seq_num);
45   an_analysis->set_window(window);
46   an_analysis->set_threshold(threshold);
47
48   for(i=0; i < seq_num; i++)
49     an_analysis->set_seq_info(seq_files[i], annot_files[i], fasta_indices[i],
50                               sub_seq_starts[i], sub_seq_ends[i]);
51
52   err_msg = an_analysis->analyze(0,0, 't', 0.0);
53   //cout << "Feel the tribal beat\n";
54   if (!(err_msg == ""))
55   {
56     //fl_alert(err_msg.c_str());
57     cout << err_msg;
58   }
59
60   all_done = true;
61
62   hide();
63 }
64
65
66 void
67 choose_seq_file_cb(Fl_Button* o, void* v)
68 {
69   seq_data_instance * blah = (seq_data_instance *) v;
70   SetupWindow* T= blah->sw_ptr;
71   T->real_choose_seq_file_cb(blah->index);
72 }
73
74
75 void
76 SetupWindow::real_choose_seq_file_cb(int i)
77 {
78   char *picked_file;
79   string a_file_path;
80
81   picked_file = fl_file_chooser("Find an Analysis", "", "", 1);
82   a_file_path = picked_file;
83   seq_files[i] = a_file_path;
84   seq_inputs[i]->value((const char *)picked_file);
85 }
86
87
88 void
89 seq_file_in_cb(Fl_Input* o, void* v)
90
91   seq_data_instance * blah = (seq_data_instance *) v;
92   SetupWindow* T= blah->sw_ptr;
93   T->real_seq_file_in_cb(o,blah->index);
94 }
95
96
97 void
98 SetupWindow::real_seq_file_in_cb(Fl_Input* o, int i)
99 {
100   seq_files[i] = o->value();
101   // leaving this as a reminder that bools will need to be set to determine
102   // if all needed fields have been filled with some value before an analysis
103   // is attempted
104   //(*the_motifs)[i].dirty = true;
105 }
106
107 //char *picked_file;
108 //picked_file = fl_file_chooser("Find an Analysis", "", "", 1);
109
110 // *** Annot file selection
111
112 void
113 choose_annot_file_cb(Fl_Button* o, void* v)
114 {
115   seq_data_instance * blah = (seq_data_instance *) v;
116   SetupWindow* T= blah->sw_ptr;
117   T->real_choose_annot_file_cb(blah->index);
118 }
119
120
121 void
122 SetupWindow::real_choose_annot_file_cb(int i)
123 {
124   char *picked_file;
125   string a_file_path;
126
127   picked_file = fl_file_chooser("Find an Analysis", "", "", 1);
128   a_file_path = picked_file;
129   annot_files[i] = a_file_path;
130   annot_inputs[i]->value((const char *)picked_file);
131 }
132
133 void
134 annot_file_in_cb(Fl_Input* o, void* v)
135
136   seq_data_instance * blah = (seq_data_instance *) v;
137   SetupWindow* T= blah->sw_ptr;
138   T->real_annot_file_in_cb(o,blah->index);
139 }
140
141 void
142 SetupWindow::real_annot_file_in_cb(Fl_Input* o, int i)
143 {
144   annot_files[i] = o->value();
145 }
146
147
148 // *** fasta index selection
149
150 void
151 fa_index_in_cb(Fl_Input* o, void* v)
152
153   seq_data_instance * blah = (seq_data_instance *) v;
154   SetupWindow* T= blah->sw_ptr;
155   T->real_fa_index_in_cb(o,blah->index);
156 }
157
158 void
159 SetupWindow::real_fa_index_in_cb(Fl_Input* o, int i)
160 {
161   fasta_indices[i] = atoi(o->value());
162 }
163
164 // *** subsequence start select
165
166 void
167 sub_start_in_cb(Fl_Input* o, void* v)
168
169   seq_data_instance * blah = (seq_data_instance *) v;
170   SetupWindow* T= blah->sw_ptr;
171   T->real_sub_start_in_cb(o,blah->index);
172 }
173
174 void
175 SetupWindow::real_sub_start_in_cb(Fl_Input* o, int i)
176 {
177   sub_seq_starts[i] = atoi(o->value());
178 }
179
180 // *** subsequence end select
181
182 void
183 sub_end_in_cb(Fl_Input* o, void* v)
184
185   seq_data_instance * blah = (seq_data_instance *) v;
186   SetupWindow* T= blah->sw_ptr;
187   T->real_sub_end_in_cb(o,blah->index);
188 }
189
190 void
191 SetupWindow::real_sub_end_in_cb(Fl_Input* o, int i)
192 {
193   sub_seq_ends[i] = atoi(o->value());
194
195 }
196
197 // *** input analysis name
198
199 void
200 set_ana_name_cb(Fl_Input* o, void* v)
201 {
202   SetupWindow* T=(SetupWindow*)v;
203   T->real_set_ana_name_cb(o);
204 }
205
206 void
207 SetupWindow::real_set_ana_name_cb(Fl_Input* o)
208 {
209   ana_name = o->value();
210 }
211
212 // *** input window size
213
214 void
215 set_win_size_cb(Fl_Input* o, void* v)
216 {
217   SetupWindow* T=(SetupWindow*)v;
218   T->real_set_win_size_cb(o);
219 }
220
221 void
222 SetupWindow::real_set_win_size_cb(Fl_Input* o)
223 {
224   window = atoi(o->value());
225 }
226
227 // *** input threshold
228
229 void
230 set_threshold_cb(Fl_Input* o, void* v)
231 {
232   SetupWindow* T=(SetupWindow*)v;
233   T->real_set_threshold_cb(o);
234 }
235
236 void
237 SetupWindow::real_set_threshold_cb(Fl_Input* o)
238 {
239   threshold = atoi(o->value());
240 }
241
242 void
243 set_seq_num_cb(Fl_Input* o, void* v)
244 {
245   SetupWindow* T=(SetupWindow*)v;
246   T->real_set_seq_num_cb(o);
247 }
248
249 // *** input number of sequences, add appropriate inputs for each sequence
250
251 void
252 SetupWindow::real_set_seq_num_cb(Fl_Input* o)
253 {
254   int i;
255
256   seq_num = atoi(o->value());
257   seq_inputs.clear();
258   annot_inputs.clear();
259
260   seq_scroll = new Fl_Scroll(5,80,w()-10,h()-115);
261   seq_scroll->color(FL_WHITE);
262
263   for (i = 0; i < seq_num; i++)
264   {
265     seq_files.push_back("");
266     annot_files.push_back("");
267     fasta_indices.push_back(1);
268     sub_seq_starts.push_back(0);
269     sub_seq_ends.push_back(0);
270     add_seq_input(i);
271   }
272   seq_scroll->box(FL_DOWN_FRAME);
273   add(seq_scroll);
274   redraw();
275 }
276
277
278 SetupWindow::SetupWindow(int w, int h, const char* title, Mussa *the_analysis):Fl_Window(w,h,title)
279 {
280   color(FL_WHITE);
281
282   an_analysis = the_analysis;
283   all_done = false;
284
285   begin();
286
287   name_input = new Fl_Input(110, 10, w-120, 30, "Analysis Name ");
288   name_input->value("");
289   //name_input->when(FL_WHEN_ENTER_KEY);
290   name_input->box(FL_BORDER_BOX);
291   name_input->callback((Fl_Callback*)set_ana_name_cb, this);
292
293   // add in radio buttons for win_append and thres_append eventually
294   win_append = true;
295   thres_append = true;
296
297   win_input = new Fl_Input(65,45,100,30, "Window ");
298   win_input->value("");
299   win_input->callback((Fl_Callback*)set_win_size_cb, this);
300
301   thres_input = new Fl_Input(250,45,100,30, "Threshold ");
302   thres_input->value("");
303   thres_input->callback((Fl_Callback*)set_threshold_cb, this);
304
305   seq_num_input = new Fl_Input(430,45,100, 30, "Seq Num ");
306   seq_num_input->value("");
307   seq_num_input->callback((Fl_Callback*)set_seq_num_cb, this);
308
309   // button to launch the analysis
310   test = new Fl_Button(w-100,h-30,100,30,"Do Analysis");
311   test->callback((Fl_Callback*)do_analysis_cb, this);
312
313   // test button to make sure setup data is being stored
314   test = new Fl_Button(w-200,h-30,100,30,"show setup");
315   test->callback((Fl_Callback*)print_cb, this);
316
317   // generic input, keeping around as template for future additions
318   //_input = new Fl_Input(0, , 30, "");
319   //_input->value("");
320   //_input->when(FL_WHEN_ENTER_KEY);
321   //_input->callback((Fl_Callback*)set__cb, this);
322
323   end();
324   //resizable(this);
325   show();
326 }
327
328
329 SetupWindow::~SetupWindow(){}
330
331
332 void
333 SetupWindow::add_seq_input(int i)
334 {
335   Fl_Input *fasta_input, *start_input, *end_input;
336   Fl_Button *seq_browse, *annot_browse;
337
338
339   // this remembers what seq index each input is associated with
340   seq_data_instance * something;
341   something = new seq_data_instance;
342   something->sw_ptr = this;
343   something->index = i;
344
345
346   // setup sequence file input for text input or file browsing
347   seq_inputs.push_back(new Fl_Input(55, 85+(i*105), w()-165, 30, "seq "));
348   seq_inputs[i]->value("");
349   seq_inputs[i]->callback((Fl_Callback*)seq_file_in_cb, (void*) something);
350
351   seq_browse = new Fl_Button(w()-105, 85+(i*105), 80, 30, "Browse");
352   seq_browse->callback((Fl_Callback*)choose_seq_file_cb, (void*) something);
353
354   // setup annotation file input for text input or file browsing
355   annot_inputs.push_back(new Fl_Input(55, 120+(i*105), w()-165, 30, "annot "));
356   annot_inputs[i]->value("");
357   annot_inputs[i]->callback((Fl_Callback*)annot_file_in_cb,(void*)something);
358
359   annot_browse = new Fl_Button(w()-105, 120+(i*105), 80, 30, "Browse");
360   annot_browse->callback((Fl_Callback*)choose_annot_file_cb, (void*)something);
361
362   // index of fasta seq wanted if more than 1 seq in file
363   fasta_input = new Fl_Input(90, 155+(i*105), 50, 30, "fasta index");
364   fasta_input->value("");
365   fasta_input->callback((Fl_Callback*)fa_index_in_cb, (void*) something);
366
367   // subsequence select, index of first bp wanted
368   start_input = new Fl_Input(225, 155+(i*105), 50, 30, "start index");
369   start_input->value("");
370   start_input->callback((Fl_Callback*)sub_start_in_cb, (void*) something);
371
372   // subsequence select, index of last bp wanted
373   end_input = new Fl_Input(355, 155+(i*105), 50, 30, "end index");
374   end_input->value("");
375   end_input->callback((Fl_Callback*)sub_end_in_cb, (void*) something);
376
377   seq_scroll->add(seq_inputs[i]);
378   seq_scroll->add(seq_browse);
379   seq_scroll->add(annot_inputs[i]);
380   seq_scroll->add(annot_browse);
381   seq_scroll->add(fasta_input);
382   seq_scroll->add(start_input);
383   seq_scroll->add(end_input);
384 }
385
386 /*
387   cout << "fee\n";
388   cout << "fie\n";
389   cout << "foe\n";
390   cout << "fum\n";
391 */
392
393 void SetupWindow::print_cb(Fl_Button* o, void* v)
394 {
395   SetupWindow* T=(SetupWindow*)v;
396   T->print_cb_real(o,v);
397 }
398
399
400 void SetupWindow::print_cb_real(Fl_Button* , void*)
401 {
402   cout << "ana_name: " << ana_name << endl;
403   cout << "win: " << window << endl;
404   cout << "thres: " << threshold << endl;
405   cout << "seq_num: " << seq_num << endl;
406   //cout << "win_add: " << win_append << end;
407   //cout << "thres_add: " << thres_append << endl;
408
409   int i;
410
411   
412
413   for (i = 0; i < seq_num; i++)
414   {
415     cout << seq_files[i] << endl; 
416     cout << annot_files[i] << endl;
417     cout << "fasta: " << fasta_indices[i];
418     cout << " start: " << sub_seq_starts[i];
419     cout << " end: " << sub_seq_ends[i] << endl;
420     cout << "blargle!\n";
421   }
422   cout << "end of inputs\n" << endl;
423 }