massive code move
[mussa.git] / gui / SeqWindow.cxx
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 "SeqWindow.hh"
12
13 #include <sstream>
14
15 #include <FL/Fl.H>
16
17 using namespace std;
18
19 void
20 set_align_cb(Fl_Widget* widg, void* the_data)
21 {
22   menu_align_data_bundle * blah = (menu_align_data_bundle *) the_data;
23   SeqWindow* T= blah->swm_ptr;
24   T->real_set_align_cb(blah->which_align);
25 }
26
27
28 void
29 SeqWindow::real_set_align_cb(int which_align)
30 {
31   vector<int> a_path;
32   int window_length;
33
34
35   a_path = *P.begin();
36   window_length = a_path[0];
37   cout << window_length << endl;
38
39   cout << "fum1\n";    
40   seq_box->align_offsets(which_align);
41   seq_box->redraw();
42 }
43
44
45 void
46 show_align_cb(Fl_Widget* widg, void* the_data)
47 {
48   menu_align_data_bundle * blah = (menu_align_data_bundle *) the_data;
49   SeqWindow* T= blah->swm_ptr;
50   T->real_show_align_cb(blah->which_align);
51 }
52
53
54 void
55 SeqWindow::real_show_align_cb(int which_align)
56 {
57   vector<int> a_path;
58   int window_length;
59
60
61   cout << "fumish\n";    
62   seq_box->toggle_align(which_align);
63   seq_box->redraw();
64 }
65
66
67 void
68 toggle_bars_cb(Fl_Button* o, void* v)
69 {
70   SeqWindow* T=(SeqWindow*)v;
71   T->real_toggle_bars_cb();
72 }
73
74
75 void
76 SeqWindow::real_toggle_bars_cb()
77 {
78   seq_box->toggle_bars();
79 }
80
81
82 void
83 toggle_motifs_cb(Fl_Button* o, void* v)
84 {
85   SeqWindow* T=(SeqWindow*)v;
86   T->real_toggle_motifs_cb();
87 }
88
89
90 void
91 SeqWindow::real_toggle_motifs_cb()
92 {
93   seq_box->toggle_motifs();
94 }
95
96
97 // main code, window creation
98
99 SeqWindow::SeqWindow(int w, int h, const char* title, int sq_num,
100                      vector<Sequence> *some_seqs, 
101                      list<vector<int> > some_paths, 
102                      vector<int> some_lens,
103                      vector<motif> *some_motifs):
104   Fl_Double_Window(w,h,title)
105 {
106   menu_align_data_bundle * some_menu_data;
107   vector<int> a_path;
108   int window_length, align_number;
109   int i;
110   ostringstream align_id_ostr;
111   string align_id_string;
112   list<vector<int> >::iterator align_iter;
113
114
115
116   // most of this stuff is here just to pass to SeqView object
117   // some is needed to setup the window menus
118   seq_num = sq_num;
119   S = some_seqs;
120   P = some_paths;
121   seq_lens = some_lens;
122   the_motifs = some_motifs;
123
124
125   begin();
126   color(FL_WHITE);
127   resizable(this);
128
129   // make the menu that allows alignment selection
130   choose_align_menu = new Fl_Menu_Button(5, 2, 180, 30, "Choose Alignment");
131   choose_align_menu->color(FL_WHITE,FL_BLUE);
132   choose_align_menu->box(FL_BORDER_BOX);
133   choose_align_menu->clear();
134   
135   // make the menu that allows alignment selection
136   show_align_menu = new Fl_Menu_Button(190, 2, 180, 30, "Show Alignment");
137   show_align_menu->color(FL_WHITE,FL_BLUE);
138   show_align_menu->box(FL_BORDER_BOX);
139   show_align_menu->clear();
140
141
142   // adds menu items for each path
143   align_iter = P.begin();
144   align_number = 0;
145   while(align_iter != P.end())
146   {
147     some_menu_data = new menu_align_data_bundle;
148     some_menu_data->swm_ptr = this;
149     some_menu_data->which_align = align_number;
150     align_id_ostr << (*align_iter)[0] << ": ";
151     for(i = 1; i <= seq_num; i++)
152       align_id_ostr << (*align_iter)[i] << ", ";
153     align_id_string = align_id_ostr.str();
154     choose_align_menu->add((const char*)align_id_string.c_str(), 0, 
155                            (Fl_Callback *) set_align_cb, 
156                            (void*) some_menu_data);
157     show_align_menu->add((const char*)align_id_string.c_str(), 0, 
158                          (Fl_Callback *) show_align_cb, 
159                          (void*) some_menu_data, FL_MENU_TOGGLE|FL_MENU_VALUE);
160
161     align_id_ostr.str("");
162     ++align_number;
163     ++align_iter;
164   }
165
166   /*
167   show_align_menu->add("f&ee"); 
168   show_align_menu->add("f&ie"); 
169   show_align_menu->add("f&oe"); 
170   show_align_menu->add("f&um"); 
171   */
172
173   Fl_Button *test_but = new Fl_Button(375, 2, 150, 30, "Toggle Motifs");
174   test_but->color(FL_WHITE,FL_BLUE);
175   test_but->box(FL_BORDER_BOX);
176   test_but->callback((Fl_Callback*) toggle_motifs_cb, this);
177
178   toggle_bars = new Fl_Button(530, 2, 150, 30, "Toggle 10bp bars");
179   toggle_bars->color(FL_WHITE,FL_BLUE);
180   toggle_bars->box(FL_BORDER_BOX);
181   toggle_bars->callback((Fl_Callback*) toggle_bars_cb, this);
182  
183
184   // make the view of the sequence
185   seq_box = new SeqView(0, 34, w, h-34);
186   seq_box->setup(ana_name, seq_num, S, P, seq_lens, the_motifs);
187   //real_set_align_cb(2);
188
189   end();
190   Fl::visual(FL_DOUBLE|FL_INDEX);
191   show();
192 }
193
194
195
196 /*
197   some_menu_data = new menu_align_data_bundle;
198   some_menu_data->swm_ptr = this;
199   some_menu_data->which_align = 2;
200   choose_align_menu->add("f&ie", FL_ALT+'i', (Fl_Callback *) set_align_cb,
201                   (void*) some_menu_data);
202
203   some_menu_data = new menu_align_data_bundle;
204   some_menu_data->swm_ptr = this;
205   some_menu_data->which_align = 3;
206   choose_align_menu->add("f&oe", FL_ALT+'o', (Fl_Callback *) set_align_cb,
207                   (void*) some_menu_data);
208
209   some_menu_data = new menu_align_data_bundle;
210   some_menu_data->swm_ptr = this;
211   some_menu_data->which_align = 4;
212   choose_align_menu->add("f&um", FL_ALT+'u', (Fl_Callback *) set_align_cb,
213                   (void*) some_menu_data);
214 */
215
216
217
218