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