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