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