1 #include "mussa_gui_seq.hh"
5 SeqView::setup(string name, int sq_num,
6 vector<Sequence> *some_seqs,
7 list<vector<int> > some_paths, vector<int> some_lens,
8 vector<motif> *some_motifs)
11 list<vector<int> >::iterator pathz_i;
19 the_motifs = some_motifs;
21 y_seq_incre = (y_max-10-10) / (seq_num - 1);
23 fl_font(FL_COURIER, 14);
24 cout << "font width: " << fl_width('A') << endl;
26 index_pad = 6 * (int) fl_width('A') + 5;
31 for(seq_i = 0; seq_i < seq_num; ++seq_i)
32 raw_sequence.push_back( (*S)[seq_i].seq() );
34 for(pathz_i = P.begin(); pathz_i != P.end(); ++pathz_i)
36 show_aligns.push_back(true);
45 cout << x() << " " << y() << " " << w() << " " << h() << endl;
49 SeqView::resize(int new_x, int new_y, int new_w, int new_h)
56 // hmmm, why do I use these values on the the widgets inherent ones?
57 // I think there was a reason...once?
63 // things that need to be recalculated
64 y_seq_incre = (y_max-10-10) / (seq_num - 1);
76 // clear drawing area and set background to white
78 fl_rectf(x(), y(), w(), h());
81 fl_font(FL_COURIER, 14);
82 //blatantly stolen from FR2
83 ch_width = fl_width('A'); // monospaced: all characters are same width
88 int grey_box_num, grey_box_len;
90 // draw in some light grey boxes every 10bp to delineate for user
91 //fl_color(200,235,235);
92 fl_color(180,180,180);
93 grey_box_num = (((x_max - index_pad) / (int) ch_width) / 10) + 1;
94 grey_box_len = 10 * (int) ch_width;
95 for(i = 0; i < grey_box_num; i++)
97 fl_rectf(x()+index_pad-1 + (i * grey_box_len), y(), grey_box_len, h());
101 draw_motifs(ch_width);
103 draw_sequence(ch_width);
105 draw_match_lines(ch_width);
107 draw_indices(ch_width);
110 // draw some bounding boxes to visually separate things
111 fl_color(150,200,255);
112 fl_line_style(FL_SOLID, 2, NULL);
113 fl_rect(x(), y(), w(), h());
114 fl_rect(x()+index_pad-1, y(), w()-2*(index_pad-1), h());
118 SeqView::draw_motifs(double ch_width)
120 vector<motif>::iterator motif_i;
121 vector<int> some_motif_locs;
122 vector<int>::iterator i_locs;
123 int scale_len, motif_len, i2;
126 //fl_color(255,0,255);
127 fl_line_style(FL_SOLID, 10, NULL);
128 motif_i = the_motifs->begin();
129 while (motif_i != the_motifs->end())
131 fl_color(motif_i->color);
132 motif_len = motif_i->seq.length();
133 scale_len = (int) (motif_len * ch_width);
135 if (!motif_i->locations.empty())
136 for(i2 = 0; i2 < seq_num; i2++)
138 some_motif_locs = (*motif_i).locations[i2];
140 i_locs = some_motif_locs.begin();
141 while (i_locs != some_motif_locs.end())
143 x_start = (int) ((*i_locs +scroll_offset - seq_align_offsets[i2])
144 * ch_width) + index_pad + x();
146 //cout << *i_locs << ":" << x_start << " ";
147 // don't draw highlights outside of box range, they can wraparound past some boundry
148 if ((x_start > 0) && (x_start < w()))
149 fl_line(x_start,y_loc,x_start+scale_len,y_loc);
153 y_loc += y_seq_incre;
160 SeqView::draw_sequence(double ch_width)
165 int seq_len, sub_seq_start, sub_seq_len;
170 y_loc = y_min + 10 + 5;
172 for(seq_i = 0; seq_i < seq_num; seq_i++)
174 seq_len = raw_sequence[seq_i].length();
175 sub_seq_start = seq_align_offsets[seq_i] - scroll_offset;
176 sub_seq_len = (x_max - index_pad) / (int) ch_width;
177 //cout << x_max << " index_pad: " << index_pad << " y - ip: " << (x_max - index_pad) << endl;
179 // gotta check thru boundary conditions to make sure we're producing the
180 // right string for the current position (otherwise gonna crash due to
181 // illegal indexing into substr
182 if (sub_seq_start < 0)
184 sub_seq_len = sub_seq_len - sub_seq_start;
189 else if (sub_seq_start >= seq_len)
191 sub_seq_start = seq_len;
194 else if ((sub_seq_start + sub_seq_len) >= seq_len)
195 sub_seq_len = seq_len - sub_seq_start;
197 sub_seq = raw_sequence[seq_i].substr(sub_seq_start, sub_seq_len);
198 fl_draw(sub_seq.c_str(), index_pad, y_loc);
199 y_loc += y_seq_incre;
205 SeqView::draw_match_lines(double ch_width)
209 list<vector<int> >::iterator pathz_i;
211 int x_start, y_start, x_end, y_end;
212 int window_length, win_i;
215 int offset1, offset2;
216 float center1, center2;
218 vector<bool> rc_list;
220 vector<bool> matched;
225 for(pathz_i = P.begin(); pathz_i != P.end(); ++pathz_i)
227 if (show_aligns[align_counter])
230 window_length = a_path[0];
232 // determine which parts of the path are RC relative to first species
234 for(i2 = 1; i2 <= seq_num; i2++)
237 rc_list.push_back(true);
239 rc_list.push_back(false);
242 // loop over each bp in the conserved region for all sequences
243 for(win_i = 0; win_i < window_length; win_i++)
245 // determine which exact base pairs match between the sequences
247 for(i2 = 1; i2 < seq_num; i2++)
249 // assume not rc as most likely, adjust below
252 // no matter the case, any RC node needs adjustments
254 rc_1 = window_length-1;
255 if (a_path[i2+1] < 0)
256 rc_2 = window_length-1;
258 x_start = (abs(a_path[i2]-rc_1+win_i));
259 x_end = (abs(a_path[i2+1]-rc_2+win_i));
262 // ugh, and xor...only want rc coloring if just one of the nodes is rc
263 // if both nodes are rc, then they are 'normal' relative to each other
264 if ( ( rc_list[i2] || rc_list[i2-1] ) &&
265 !(rc_list[i2] && rc_list[i2-1] ) )
266 { //the hideous rc matching logic - not complex, but annoying
267 if ( !( ( (raw_sequence[i2-1][x_start] == 'A') &&
268 (raw_sequence[i2][x_end] == 'T') ) ||
269 ( (raw_sequence[i2-1][x_start] == 'T') &&
270 (raw_sequence[i2][x_end] == 'A') ) ||
271 ( (raw_sequence[i2-1][x_start] == 'G') &&
272 (raw_sequence[i2][x_end] == 'C') ) ||
273 ( (raw_sequence[i2-1][x_start] == 'C') &&
274 (raw_sequence[i2][x_end] == 'G') ) ) )
279 if (!( (raw_sequence[i2-1][x_start] == raw_sequence[i2][x_end]) &&
280 (raw_sequence[i2-1][x_start] != 'N') &&
281 (raw_sequence[i2][x_end] != 'N') ) )
286 // draw for matches stretching across all sequences
289 fl_line_style(FL_SOLID, 1, NULL);
291 // now can draw the line for each bp in this window that matches
292 // grrr, need to ask if anyone cares if I switch the seq top-bot order...
295 for(i2 = 1; i2 < seq_num; i2++)
297 // assume not rc as most likely, adjust below
300 // this makes the lines start in the middle of the drawn char/bp
303 // no matter the case, any RC node needs adjustments
306 rc_1 = window_length;
309 if (a_path[i2+1] < 0)
311 rc_2 = window_length;
315 // set offset based on current alignment for which bp to show
316 offset1 = seq_align_offsets[i2-1];
317 offset2 = seq_align_offsets[i2];
319 if ( ( rc_list[i2] || rc_list[i2-1] ) &&
320 !(rc_list[i2] && rc_list[i2-1] ) )
325 // maybe shouldn't recalc these, but store values from first loop
326 x_start = (abs((int) (a_path[i2]-rc_1+win_i)));
327 x_end = (abs((int) (a_path[i2+1]-rc_2+win_i)));
329 fl_line( (int)((x_start+center1-offset1+scroll_offset)*ch_width)
330 + index_pad, y_loc + 10,
331 (int)((x_end+center2-offset2+scroll_offset)*ch_width)
332 + index_pad, y_loc+y_seq_incre );
333 y_loc += y_seq_incre;
343 SeqView::draw_indices(double ch_width)
348 ostringstream an_index;
352 // clear out space on sides to draw in index values
353 // I block out the sides rather than adding offsets to the drawing of seq
354 // and conservation lines since the lines need to draw off the 'edge'
356 fl_rectf(0, y_min, index_pad, h()+y_min);
357 fl_rectf(w()-index_pad, y_min, index_pad, h()+y_min);
359 // now can draw in the indices of the start and end of the shown sequence
361 y_loc = y_min + 10 + 5;
362 for(seq_i = 0; seq_i < seq_num; seq_i++)
365 an_index << (seq_align_offsets[seq_i]-scroll_offset);
366 fl_draw((an_index.str()).c_str(), 2, y_loc);
368 shown_seq_len = (w() - 2 * index_pad) / (int) ch_width;
370 an_index << (seq_align_offsets[seq_i]-scroll_offset+shown_seq_len);
371 fl_draw((an_index.str()).c_str(), w()-index_pad+2, y_loc);
372 y_loc += y_seq_incre;
378 SeqView::toggle_align(int align_num)
380 //cout << align_num << endl;
381 //cout << show_aligns[align_num] << endl;
382 show_aligns[align_num] = !show_aligns[align_num];
383 //cout << show_aligns[align_num] << endl;
388 SeqView::align_offsets(int align_num)
390 list<vector<int> >::iterator pathz_i;
395 cout << "alignment: " << align_num << endl;
397 if (P.begin() == P.end())
398 cout << "crud....\n";
403 while(pathz_i != P.end())
406 // find the path specified
409 while( (i < align_num) && (pathz_i != P.end()) )
415 // now set the alignment offsets - basically where the path starts
416 seq_align_offsets.clear();
417 for(i = 0; i < seq_num ; i++)
419 //cout << (*pathz_i)[i+1] << endl;
420 seq_align_offsets.push_back( abs((*pathz_i)[i+1]) );
421 // for testing purposes: to see everything in the short test sequences
422 //seq_align_offsets.push_back(0);
424 // reset any dragging done, otherwise might be hard to find selected align
432 SeqView::handle(int e)
436 // this empty string needs to be put on cout, otherwise the -O optimize
437 // compile option seems to throw this function away with the following:
438 // gcc version 3.2.2 20030222 (Red Hat Linux 3.2.2-5)
444 if (Fl::event_button3())
446 cout << "menu menu menu!\n";
453 drag_change = Fl::event_x();
457 drag_change = Fl::event_x() - drag_change;
458 scroll_offset += drag_change;
459 drag_change = Fl::event_x();
465 //scroll_offset += Fl::event_x() - drag_start;
466 //scroll_dist = Fl::event_x() - drag_start;
467 //scroll_offset += scroll_dist;
468 //scroll_offset += scroll_pos;
475 return_value = Fl_Widget::handle(e);
482 SeqView::toggle_bars()
484 show_bars = !show_bars;
490 SeqView::toggle_motifs()
492 show_motifs = !show_motifs;
498 SeqView::reporter(string id, int value)
500 cout << id << " : " << value << endl;