[project @ 13]
[mussa.git] / mussa_gui_subana.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_subana.hh"
12
13
14 void
15 do_subana_cb(Fl_Button* o, void* v)
16 {
17   SubanaWindow* T=(SubanaWindow*)v;
18   T->real_do_subana();
19 }
20
21
22 // passes the parameters to the mussa class object and orders it to run
23 void
24 SubanaWindow::real_do_subana()
25 {
26   int i;
27   string a_sequence, err_msg;
28
29   // <-- need a check here to make sure all vars have a valid value
30
31   an_analysis->clear();
32   an_analysis->set_name(ana_name);
33   an_analysis->set_seq_num(seq_num);
34   an_analysis->set_window(window);
35   an_analysis->set_threshold(threshold);
36
37   for(i=0; i < seq_num; i++)
38   {
39     a_sequence = the_Seqs[i].seq();
40     cout << a_sequence.length() << endl;
41     a_sequence = a_sequence.substr(sub_seq_starts[i],
42                                    sub_seq_ends[i] - sub_seq_starts[i] );
43     cout << a_sequence.length() << endl;
44     an_analysis->add_a_seq(a_sequence);
45   }
46
47   err_msg = an_analysis->analyze(0,0, 't', 0.0);
48
49   cout << "Feel the tribal beat\n";
50   if (!(err_msg == ""))
51   {
52     //fl_alert(err_msg.c_str());
53     cout << err_msg;
54   }
55
56   all_done = true;
57
58   hide();
59 }
60
61
62
63 // *** subsequence start select
64
65 void
66 sub_start_in_cb1(Fl_Input* o, void* v)
67
68   sub_seq_data_instance * blah = (sub_seq_data_instance *) v;
69   SubanaWindow* T= blah->sw_ptr;
70   T->real_sub_start_in_cb(o,blah->index);
71 }
72
73 void
74 SubanaWindow::real_sub_start_in_cb(Fl_Input* o, int i)
75 {
76   sub_seq_starts[i] = atoi(o->value());
77 }
78
79 // *** subsequence end select
80
81 void
82 sub_end_in_cb1(Fl_Input* o, void* v)
83
84   sub_seq_data_instance * blah = (sub_seq_data_instance *) v;
85   SubanaWindow* T= blah->sw_ptr;
86   T->real_sub_end_in_cb(o,blah->index);
87 }
88
89 void
90 SubanaWindow::real_sub_end_in_cb(Fl_Input* o, int i)
91 {
92   sub_seq_ends[i] = atoi(o->value());
93
94 }
95
96 // *** input analysis name
97
98 void
99 set_ana_name_cb1(Fl_Input* o, void* v)
100 {
101   SubanaWindow* T=(SubanaWindow*)v;
102   T->real_set_ana_name_cb(o);
103 }
104
105 void
106 SubanaWindow::real_set_ana_name_cb(Fl_Input* o)
107 {
108   ana_name = o->value();
109 }
110
111 // *** input window size
112
113 void
114 set_win_size_cb1(Fl_Input* o, void* v)
115 {
116   SubanaWindow* T=(SubanaWindow*)v;
117   T->real_set_win_size_cb(o);
118 }
119
120 void
121 SubanaWindow::real_set_win_size_cb(Fl_Input* o)
122 {
123   window = atoi(o->value());
124 }
125
126 // *** input threshold
127
128 void
129 set_threshold_cb1(Fl_Input* o, void* v)
130 {
131   SubanaWindow* T=(SubanaWindow*)v;
132   T->real_set_threshold_cb(o);
133 }
134
135 void
136 SubanaWindow::real_set_threshold_cb(Fl_Input* o)
137 {
138   threshold = atoi(o->value());
139 }
140
141
142 bool
143 SubanaWindow::done()
144 {
145   return all_done;
146 }
147
148
149 SubanaWindow::SubanaWindow(int w, int h, const char* title,Mussa *the_analysis,
150                            vector<Sequence> some_Seqs):Fl_Window(w,h,title)
151 {
152   string a_name;
153
154   color(FL_WHITE);
155
156   an_analysis = the_analysis;
157   the_Seqs = some_Seqs;
158   all_done = false;
159
160   // initialize parameters
161   ana_name = "";
162   window = -1;
163   threshold = -1; 
164
165   begin();
166
167   name_input = new Fl_Input(135, 10, w-140, 30, "SubAnalysis Name ");
168   name_input->value("");
169   //name_input->when(FL_WHEN_ENTER_KEY);
170   name_input->box(FL_BORDER_BOX);
171   name_input->callback((Fl_Callback*)set_ana_name_cb1, this);
172
173   // add in radio buttons for win_append and thres_append eventually
174   win_append = true;
175   thres_append = true;
176
177   win_input = new Fl_Input(135,45,100,30, "Window: ");
178   win_input->value("");
179   win_input->callback((Fl_Callback*)set_win_size_cb1, this);
180
181   thres_input = new Fl_Input(320,45,100,30, "Threshold: ");
182   thres_input->value("");
183   thres_input->callback((Fl_Callback*)set_threshold_cb1, this);
184
185   // button to launch the analysis
186   test = new Fl_Button(w-100,h-30,100,30,"Do Analysis");
187   test->callback((Fl_Callback*)do_subana_cb, this);
188
189   // test button to make sure setup data is being stored
190   test = new Fl_Button(w-200,h-30,100,30,"show setup");
191   test->callback((Fl_Callback*)print_cb, this);
192
193   // add all the inputs for the sub sequence starts & ends
194   int i;
195
196   seq_num = the_Seqs.size();
197
198   seq_scroll = new Fl_Scroll(5,80,w-10,h-115);
199   seq_scroll->color(FL_WHITE);
200
201   for (i = 0; i < seq_num; i++)
202   {
203     sub_seq_starts.push_back(0);
204     sub_seq_ends.push_back(0);
205     a_name = the_Seqs[i].sp_name();
206     cout << a_name << endl;
207     add_seq_input(i, a_name);
208   }
209   seq_scroll->box(FL_DOWN_FRAME);
210   //add(seq_scroll);
211   //redraw();
212
213   end();
214   //resizable(this);
215   show();
216 }
217
218
219 SubanaWindow::~SubanaWindow(){}
220
221
222 void
223 SubanaWindow::add_seq_input(int i, string a_name)
224 {
225   Fl_Input *start_input, *end_input;
226
227
228   // this remembers what seq index each input is associated with
229   sub_seq_data_instance * something;
230   something = new sub_seq_data_instance;
231   something->sw_ptr = this;
232   something->index = i;
233
234
235   // subsequence select, index of first bp wanted
236   start_input = new Fl_Input(150, 85+(i*35), 70, 30, "start index: ");
237   start_input->value("");
238   start_input->callback((Fl_Callback*)sub_start_in_cb1, (void*) something);
239
240   // subsequence select, index of last bp wanted
241   end_input = new Fl_Input(300, 85+(i*35), 70, 30, "end index: ");
242   end_input->value("");
243   end_input->callback((Fl_Callback*)sub_end_in_cb1, (void*) something);
244
245   seq_scroll->add(start_input);
246   seq_scroll->add(end_input);
247 }
248
249 /*
250   cout << "fee\n";
251   cout << "fie\n";
252   cout << "foe\n";
253   cout << "fum\n";
254 */
255
256 void SubanaWindow::print_cb(Fl_Button* o, void* v)
257 {
258   SubanaWindow* T=(SubanaWindow*)v;
259   T->print_cb_real(o,v);
260 }
261
262
263 void SubanaWindow::print_cb_real(Fl_Button* , void*)
264 {
265   cout << "ana_name: " << ana_name << endl;
266   cout << "win: " << window << endl;
267   cout << "thres: " << threshold << endl;
268   cout << "seq_num: " << seq_num << endl;
269   //cout << "win_add: " << win_append << end;
270   //cout << "thres_add: " << thres_append << endl;
271
272   int i;
273
274   
275
276   for (i = 0; i < seq_num; i++)
277   {
278     //cout << seq_files[i] << endl; 
279     //cout << annot_files[i] << endl;
280     //cout << "fasta: " << fasta_indices[i];
281     cout << " start: " << sub_seq_starts[i];
282     cout << " end: " << sub_seq_ends[i] << endl;
283     cout << "blargle!\n";
284   }
285   cout << "end of inputs\n" << endl;
286 }