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->set_seq_info(seq_files[i], annot_files[i], fasta_indices[i],
50 sub_seq_starts[i], sub_seq_ends[i]);
53 an_analysis->analyze();
54 } catch (mussa_analysis_error e) {
65 choose_seq_file_cb(Fl_Button* o, void* v)
67 seq_data_instance * blah = (seq_data_instance *) v;
68 SetupWindow* T= blah->sw_ptr;
69 T->real_choose_seq_file_cb(blah->index);
74 SetupWindow::real_choose_seq_file_cb(int i)
79 picked_file = fl_file_chooser("Find an Analysis", "", "", 1);
80 a_file_path = picked_file;
81 seq_files[i] = a_file_path;
82 seq_inputs[i]->value((const char *)picked_file);
87 seq_file_in_cb(Fl_Input* o, void* v)
89 seq_data_instance * blah = (seq_data_instance *) v;
90 SetupWindow* T= blah->sw_ptr;
91 T->real_seq_file_in_cb(o,blah->index);
96 SetupWindow::real_seq_file_in_cb(Fl_Input* o, int i)
98 seq_files[i] = o->value();
99 // leaving this as a reminder that bools will need to be set to determine
100 // if all needed fields have been filled with some value before an analysis
102 //(*the_motifs)[i].dirty = true;
106 //picked_file = fl_file_chooser("Find an Analysis", "", "", 1);
108 // *** Annot file selection
111 choose_annot_file_cb(Fl_Button* o, void* v)
113 seq_data_instance * blah = (seq_data_instance *) v;
114 SetupWindow* T= blah->sw_ptr;
115 T->real_choose_annot_file_cb(blah->index);
120 SetupWindow::real_choose_annot_file_cb(int i)
125 picked_file = fl_file_chooser("Find an Analysis", "", "", 1);
126 a_file_path = picked_file;
127 annot_files[i] = a_file_path;
128 annot_inputs[i]->value((const char *)picked_file);
132 annot_file_in_cb(Fl_Input* o, void* v)
134 seq_data_instance * blah = (seq_data_instance *) v;
135 SetupWindow* T= blah->sw_ptr;
136 T->real_annot_file_in_cb(o,blah->index);
140 SetupWindow::real_annot_file_in_cb(Fl_Input* o, int i)
142 annot_files[i] = o->value();
146 // *** fasta index selection
149 fa_index_in_cb(Fl_Input* o, void* v)
151 seq_data_instance * blah = (seq_data_instance *) v;
152 SetupWindow* T= blah->sw_ptr;
153 T->real_fa_index_in_cb(o,blah->index);
157 SetupWindow::real_fa_index_in_cb(Fl_Input* o, int i)
159 fasta_indices[i] = atoi(o->value());
162 // *** subsequence start select
165 sub_start_in_cb(Fl_Input* o, void* v)
167 seq_data_instance * blah = (seq_data_instance *) v;
168 SetupWindow* T= blah->sw_ptr;
169 T->real_sub_start_in_cb(o,blah->index);
173 SetupWindow::real_sub_start_in_cb(Fl_Input* o, int i)
175 sub_seq_starts[i] = atoi(o->value());
178 // *** subsequence end select
181 sub_end_in_cb(Fl_Input* o, void* v)
183 seq_data_instance * blah = (seq_data_instance *) v;
184 SetupWindow* T= blah->sw_ptr;
185 T->real_sub_end_in_cb(o,blah->index);
189 SetupWindow::real_sub_end_in_cb(Fl_Input* o, int i)
191 sub_seq_ends[i] = atoi(o->value());
195 // *** input analysis name
198 set_ana_name_cb(Fl_Input* o, void* v)
200 SetupWindow* T=(SetupWindow*)v;
201 T->real_set_ana_name_cb(o);
205 SetupWindow::real_set_ana_name_cb(Fl_Input* o)
207 analysis_name = o->value();
210 // *** input window size
213 set_win_size_cb(Fl_Input* o, void* v)
215 SetupWindow* T=(SetupWindow*)v;
216 T->real_set_win_size_cb(o);
220 SetupWindow::real_set_win_size_cb(Fl_Input* o)
222 window = atoi(o->value());
225 // *** input threshold
228 set_threshold_cb(Fl_Input* o, void* v)
230 SetupWindow* T=(SetupWindow*)v;
231 T->real_set_threshold_cb(o);
235 SetupWindow::real_set_threshold_cb(Fl_Input* o)
237 threshold = atoi(o->value());
241 set_seq_num_cb(Fl_Input* o, void* v)
243 SetupWindow* T=(SetupWindow*)v;
244 T->real_set_seq_num_cb(o);
247 // *** input number of sequences, add appropriate inputs for each sequence
250 SetupWindow::real_set_seq_num_cb(Fl_Input* o)
254 seq_num = atoi(o->value());
256 annot_inputs.clear();
258 seq_scroll = new Fl_Scroll(5,80,w()-10,h()-115);
259 seq_scroll->color(FL_WHITE);
261 for (i = 0; i < seq_num; i++)
263 seq_files.push_back("");
264 annot_files.push_back("");
265 fasta_indices.push_back(1);
266 sub_seq_starts.push_back(0);
267 sub_seq_ends.push_back(0);
270 seq_scroll->box(FL_DOWN_FRAME);
276 SetupWindow::SetupWindow(int w, int h, const char* title, Mussa *the_analysis):Fl_Window(w,h,title)
280 an_analysis = the_analysis;
285 name_input = new Fl_Input(110, 10, w-120, 30, "Analysis Name ");
286 name_input->value("");
287 //name_input->when(FL_WHEN_ENTER_KEY);
288 name_input->box(FL_BORDER_BOX);
289 name_input->callback((Fl_Callback*)set_ana_name_cb, this);
291 // add in radio buttons for win_append and thres_append eventually
295 win_input = new Fl_Input(65,45,100,30, "Window ");
296 win_input->value("");
297 win_input->callback((Fl_Callback*)set_win_size_cb, this);
299 thres_input = new Fl_Input(250,45,100,30, "Threshold ");
300 thres_input->value("");
301 thres_input->callback((Fl_Callback*)set_threshold_cb, this);
303 seq_num_input = new Fl_Input(480,45,100, 30, "Number of Seqs");
304 seq_num_input->value("");
305 seq_num_input->callback((Fl_Callback*)set_seq_num_cb, this);
307 // button to launch the analysis
308 test = new Fl_Button(w-100,h-30,100,30,"Do Analysis");
309 test->callback((Fl_Callback*)do_analysis_cb, this);
311 // test button to make sure setup data is being stored
312 test = new Fl_Button(w-200,h-30,100,30,"show setup");
313 test->callback((Fl_Callback*)print_cb, this);
315 // generic input, keeping around as template for future additions
316 //_input = new Fl_Input(0, , 30, "");
318 //_input->when(FL_WHEN_ENTER_KEY);
319 //_input->callback((Fl_Callback*)set__cb, this);
327 SetupWindow::~SetupWindow(){}
331 SetupWindow::add_seq_input(int i)
333 Fl_Input *fasta_input, *start_input, *end_input;
334 Fl_Button *seq_browse, *annot_browse;
337 // this remembers what seq index each input is associated with
338 seq_data_instance * something;
339 something = new seq_data_instance;
340 something->sw_ptr = this;
341 something->index = i;
344 // setup sequence file input for text input or file browsing
345 seq_inputs.push_back(new Fl_Input(55, 85+(i*105), w()-165, 30, "seq "));
346 seq_inputs[i]->value("");
347 seq_inputs[i]->callback((Fl_Callback*)seq_file_in_cb, (void*) something);
349 seq_browse = new Fl_Button(w()-105, 85+(i*105), 80, 30, "Browse");
350 seq_browse->callback((Fl_Callback*)choose_seq_file_cb, (void*) something);
352 // setup annotation file input for text input or file browsing
353 annot_inputs.push_back(new Fl_Input(55, 120+(i*105), w()-165, 30, "annot "));
354 annot_inputs[i]->value("");
355 annot_inputs[i]->callback((Fl_Callback*)annot_file_in_cb,(void*)something);
357 annot_browse = new Fl_Button(w()-105, 120+(i*105), 80, 30, "Browse");
358 annot_browse->callback((Fl_Callback*)choose_annot_file_cb, (void*)something);
360 // index of fasta seq wanted if more than 1 seq in file
361 fasta_input = new Fl_Input(90, 155+(i*105), 50, 30, "fasta index");
362 fasta_input->value("");
363 fasta_input->callback((Fl_Callback*)fa_index_in_cb, (void*) something);
365 // subsequence select, index of first bp wanted
366 start_input = new Fl_Input(225, 155+(i*105), 50, 30, "start index");
367 start_input->value("");
368 start_input->callback((Fl_Callback*)sub_start_in_cb, (void*) something);
370 // subsequence select, index of last bp wanted
371 end_input = new Fl_Input(355, 155+(i*105), 50, 30, "end index");
372 end_input->value("");
373 end_input->callback((Fl_Callback*)sub_end_in_cb, (void*) something);
375 seq_scroll->add(seq_inputs[i]);
376 seq_scroll->add(seq_browse);
377 seq_scroll->add(annot_inputs[i]);
378 seq_scroll->add(annot_browse);
379 seq_scroll->add(fasta_input);
380 seq_scroll->add(start_input);
381 seq_scroll->add(end_input);
391 void SetupWindow::print_cb(Fl_Button* o, void* v)
393 SetupWindow* T=(SetupWindow*)v;
394 T->print_cb_real(o,v);
398 void SetupWindow::print_cb_real(Fl_Button* , void*)
400 cout << "analysis_name: " << analysis_name << endl;
401 cout << "win: " << window << endl;
402 cout << "thres: " << threshold << endl;
403 cout << "seq_num: " << seq_num << endl;
404 //cout << "win_add: " << win_append << end;
405 //cout << "thres_add: " << thres_append << endl;
411 for (i = 0; i < seq_num; i++)
413 cout << seq_files[i] << endl;
414 cout << annot_files[i] << endl;
415 cout << "fasta: " << fasta_indices[i];
416 cout << " start: " << sub_seq_starts[i];
417 cout << " end: " << sub_seq_ends[i] << endl;
418 cout << "blargle!\n";
420 cout << "end of inputs\n" << endl;