1 // This file is part of the Mussa source distribution.
2 // http://mussa.caltech.edu/
3 // Contact author: Tristan De Buysscher, tristan@caltech.edu
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.
11 #include "gui/SetupWindow.hpp"
12 #include "alg/mussa.hpp"
13 #include "mussa_exceptions.hpp"
15 #include <FL/Fl_File_Chooser.H>
27 do_analysis_cb(Fl_Button* o, void* v)
29 SetupWindow* T=(SetupWindow*)v;
30 T->real_do_analysis();
34 // passes the parameters to the mussa class object and orders it to run
36 SetupWindow::real_do_analysis()
41 // <-- need a check here to make sure all vars have a valid value
44 an_analysis->set_name(analysis_name);
45 an_analysis->set_window(window);
46 an_analysis->set_threshold(threshold);
48 for(i=0; i < seq_num; i++) {
49 an_analysis->load_sequence(seq_files[i], annot_files[i], fasta_indices[i],
50 sub_seq_starts[i], sub_seq_ends[i]);
54 an_analysis->analyze();
55 } catch (mussa_analysis_error e) {
66 choose_seq_file_cb(Fl_Button* o, void* v)
68 seq_data_instance * blah = (seq_data_instance *) v;
69 SetupWindow* T= blah->sw_ptr;
70 T->real_choose_seq_file_cb(blah->index);
75 SetupWindow::real_choose_seq_file_cb(int i)
80 picked_file = fl_file_chooser("Find an Analysis", "", "", 1);
81 a_file_path = picked_file;
82 seq_files[i] = a_file_path;
83 seq_inputs[i]->value((const char *)picked_file);
88 seq_file_in_cb(Fl_Input* o, void* v)
90 seq_data_instance * blah = (seq_data_instance *) v;
91 SetupWindow* T= blah->sw_ptr;
92 T->real_seq_file_in_cb(o,blah->index);
97 SetupWindow::real_seq_file_in_cb(Fl_Input* o, int i)
99 seq_files[i] = o->value();
100 // leaving this as a reminder that bools will need to be set to determine
101 // if all needed fields have been filled with some value before an analysis
103 //(*the_motifs)[i].dirty = true;
107 //picked_file = fl_file_chooser("Find an Analysis", "", "", 1);
109 // *** Annot file selection
112 choose_annot_file_cb(Fl_Button* o, void* v)
114 seq_data_instance * blah = (seq_data_instance *) v;
115 SetupWindow* T= blah->sw_ptr;
116 T->real_choose_annot_file_cb(blah->index);
121 SetupWindow::real_choose_annot_file_cb(int i)
126 picked_file = fl_file_chooser("Find an Analysis", "", "", 1);
127 a_file_path = picked_file;
128 annot_files[i] = a_file_path;
129 annot_inputs[i]->value((const char *)picked_file);
133 annot_file_in_cb(Fl_Input* o, void* v)
135 seq_data_instance * blah = (seq_data_instance *) v;
136 SetupWindow* T= blah->sw_ptr;
137 T->real_annot_file_in_cb(o,blah->index);
141 SetupWindow::real_annot_file_in_cb(Fl_Input* o, int i)
143 annot_files[i] = o->value();
147 // *** fasta index selection
150 fa_index_in_cb(Fl_Input* o, void* v)
152 seq_data_instance * blah = (seq_data_instance *) v;
153 SetupWindow* T= blah->sw_ptr;
154 T->real_fa_index_in_cb(o,blah->index);
158 SetupWindow::real_fa_index_in_cb(Fl_Input* o, int i)
160 fasta_indices[i] = atoi(o->value());
163 // *** subsequence start select
166 sub_start_in_cb(Fl_Input* o, void* v)
168 seq_data_instance * blah = (seq_data_instance *) v;
169 SetupWindow* T= blah->sw_ptr;
170 T->real_sub_start_in_cb(o,blah->index);
174 SetupWindow::real_sub_start_in_cb(Fl_Input* o, int i)
176 sub_seq_starts[i] = atoi(o->value());
179 // *** subsequence end select
182 sub_end_in_cb(Fl_Input* o, void* v)
184 seq_data_instance * blah = (seq_data_instance *) v;
185 SetupWindow* T= blah->sw_ptr;
186 T->real_sub_end_in_cb(o,blah->index);
190 SetupWindow::real_sub_end_in_cb(Fl_Input* o, int i)
192 sub_seq_ends[i] = atoi(o->value());
196 // *** input analysis name
199 set_ana_name_cb(Fl_Input* o, void* v)
201 SetupWindow* T=(SetupWindow*)v;
202 T->real_set_ana_name_cb(o);
206 SetupWindow::real_set_ana_name_cb(Fl_Input* o)
208 analysis_name = o->value();
211 // *** input window size
214 set_win_size_cb(Fl_Input* o, void* v)
216 SetupWindow* T=(SetupWindow*)v;
217 T->real_set_win_size_cb(o);
221 SetupWindow::real_set_win_size_cb(Fl_Input* o)
223 window = atoi(o->value());
226 // *** input threshold
229 set_threshold_cb(Fl_Input* o, void* v)
231 SetupWindow* T=(SetupWindow*)v;
232 T->real_set_threshold_cb(o);
236 SetupWindow::real_set_threshold_cb(Fl_Input* o)
238 threshold = atoi(o->value());
242 set_seq_num_cb(Fl_Input* o, void* v)
244 SetupWindow* T=(SetupWindow*)v;
245 T->real_set_seq_num_cb(o);
248 // *** input number of sequences, add appropriate inputs for each sequence
251 SetupWindow::real_set_seq_num_cb(Fl_Input* o)
255 seq_num = atoi(o->value());
257 annot_inputs.clear();
259 seq_scroll = new Fl_Scroll(5,80,w()-10,h()-115);
260 seq_scroll->color(FL_WHITE);
262 for (i = 0; i < seq_num; i++)
264 seq_files.push_back("");
265 annot_files.push_back("");
266 fasta_indices.push_back(1);
267 sub_seq_starts.push_back(0);
268 sub_seq_ends.push_back(0);
271 seq_scroll->box(FL_DOWN_FRAME);
277 SetupWindow::SetupWindow(int w, int h, const char* title, Mussa *the_analysis):Fl_Window(w,h,title)
281 an_analysis = the_analysis;
286 name_input = new Fl_Input(110, 10, w-120, 30, "Analysis Name ");
287 name_input->value("");
288 //name_input->when(FL_WHEN_ENTER_KEY);
289 name_input->box(FL_BORDER_BOX);
290 name_input->callback((Fl_Callback*)set_ana_name_cb, this);
292 // add in radio buttons for win_append and thres_append eventually
296 win_input = new Fl_Input(65,45,100,30, "Window ");
297 win_input->value("");
298 win_input->callback((Fl_Callback*)set_win_size_cb, this);
300 thres_input = new Fl_Input(250,45,100,30, "Threshold ");
301 thres_input->value("");
302 thres_input->callback((Fl_Callback*)set_threshold_cb, this);
304 seq_num_input = new Fl_Input(480,45,100, 30, "Number of Seqs");
305 seq_num_input->value("");
306 seq_num_input->callback((Fl_Callback*)set_seq_num_cb, this);
308 // button to launch the analysis
309 test = new Fl_Button(w-100,h-30,100,30,"Do Analysis");
310 test->callback((Fl_Callback*)do_analysis_cb, this);
312 // test button to make sure setup data is being stored
313 test = new Fl_Button(w-200,h-30,100,30,"show setup");
314 test->callback((Fl_Callback*)print_cb, this);
316 // generic input, keeping around as template for future additions
317 //_input = new Fl_Input(0, , 30, "");
319 //_input->when(FL_WHEN_ENTER_KEY);
320 //_input->callback((Fl_Callback*)set__cb, this);
328 SetupWindow::~SetupWindow(){}
332 SetupWindow::add_seq_input(int i)
334 Fl_Input *fasta_input, *start_input, *end_input;
335 Fl_Button *seq_browse, *annot_browse;
338 // this remembers what seq index each input is associated with
339 seq_data_instance * something;
340 something = new seq_data_instance;
341 something->sw_ptr = this;
342 something->index = i;
345 // setup sequence file input for text input or file browsing
346 seq_inputs.push_back(new Fl_Input(55, 85+(i*105), w()-165, 30, "seq "));
347 seq_inputs[i]->value("");
348 seq_inputs[i]->callback((Fl_Callback*)seq_file_in_cb, (void*) something);
350 seq_browse = new Fl_Button(w()-105, 85+(i*105), 80, 30, "Browse");
351 seq_browse->callback((Fl_Callback*)choose_seq_file_cb, (void*) something);
353 // setup annotation file input for text input or file browsing
354 annot_inputs.push_back(new Fl_Input(55, 120+(i*105), w()-165, 30, "annot "));
355 annot_inputs[i]->value("");
356 annot_inputs[i]->callback((Fl_Callback*)annot_file_in_cb,(void*)something);
358 annot_browse = new Fl_Button(w()-105, 120+(i*105), 80, 30, "Browse");
359 annot_browse->callback((Fl_Callback*)choose_annot_file_cb, (void*)something);
361 // index of fasta seq wanted if more than 1 seq in file
362 fasta_input = new Fl_Input(90, 155+(i*105), 50, 30, "fasta index");
363 fasta_input->value("");
364 fasta_input->callback((Fl_Callback*)fa_index_in_cb, (void*) something);
366 // subsequence select, index of first bp wanted
367 start_input = new Fl_Input(225, 155+(i*105), 50, 30, "start index");
368 start_input->value("");
369 start_input->callback((Fl_Callback*)sub_start_in_cb, (void*) something);
371 // subsequence select, index of last bp wanted
372 end_input = new Fl_Input(355, 155+(i*105), 50, 30, "end index");
373 end_input->value("");
374 end_input->callback((Fl_Callback*)sub_end_in_cb, (void*) something);
376 seq_scroll->add(seq_inputs[i]);
377 seq_scroll->add(seq_browse);
378 seq_scroll->add(annot_inputs[i]);
379 seq_scroll->add(annot_browse);
380 seq_scroll->add(fasta_input);
381 seq_scroll->add(start_input);
382 seq_scroll->add(end_input);
392 void SetupWindow::print_cb(Fl_Button* o, void* v)
394 SetupWindow* T=(SetupWindow*)v;
395 T->print_cb_real(o,v);
399 void SetupWindow::print_cb_real(Fl_Button* , void*)
401 cout << "analysis_name: " << analysis_name << endl;
402 cout << "win: " << window << endl;
403 cout << "thres: " << threshold << endl;
404 cout << "seq_num: " << seq_num << endl;
405 //cout << "win_add: " << win_append << end;
406 //cout << "thres_add: " << thres_append << endl;
412 for (i = 0; i < seq_num; i++)
414 cout << seq_files[i] << endl;
415 cout << annot_files[i] << endl;
416 cout << "fasta: " << fasta_indices[i];
417 cout << " start: " << sub_seq_starts[i];
418 cout << " end: " << sub_seq_ends[i] << endl;
419 cout << "blargle!\n";
421 cout << "end of inputs\n" << endl;