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