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