1 #include "mussa_gui_conn_view.hh"
6 ConnView::setup(string name, int sq_num, int win_len,
7 vector<Sequence> *some_seqs,
8 Nway_Paths *some_paths)
10 int i, i2, seq_length;
13 annot_color new_annot;
22 cout << "num of paths = " << some_paths->refined_pathz.size() << endl;
24 cout << "x()=" << x() << " y()=" << y() << " w()=" << w() << " h()=" << h();
28 for(i = 0; i < seq_num; ++i)
31 cout << a_seq.len() << endl;
32 seq_length = a_seq.len();
33 seq_lens.push_back(seq_length);
34 if (seq_length > max_seq_len)
35 max_seq_len = seq_length;
36 if (seq_length < 1000)
37 seq_scales.push_back(1);
38 else if (seq_length < 1000000)
39 seq_scales.push_back(2);
41 seq_scales.push_back(3);
47 x_scale_factor = (float) max_seq_len / (w() - name_pad);
48 cout << "scale factor is " << x_scale_factor << endl;
49 y_seq_incre = (h()-(y_pad*2)) / (seq_num - 1);
62 bar_interval = max_seq_len / 20;
63 line_interval = max_seq_len / 20;
68 for(i = 0; i < 5; ++i)
70 blank_motif = new_blank_motif();
71 some_motifs.push_back(blank_motif);
74 // find all unique annotation type ids
76 vector<annot_color>::iterator annot_type_i;
77 list<annot>::iterator annot_i;
79 // loop thru all sequences
80 for(i2 = 0; i2 < seq_num; i2++)
82 cout << "ConnView: annotation loop\n";
83 // loop thru all annotation entries in this sequence
84 for(annot_i = (*S)[i2].annots.begin(); annot_i != (*S)[i2].annots.end(); ++annot_i)
86 cout << annot_i->start << ", " << annot_i->end << " : ";
87 cout << annot_i->name << " " << annot_i->type << endl;
88 // loop thru annotation types
89 annot_type_i = some_annots.begin();
90 bool type_unfound = true;
91 while ((annot_type_i != some_annots.end()) && type_unfound)
93 if (annot_i->type == annot_type_i->type)
94 type_unfound = false; // stop search if found
97 //if unfound, then add to list
100 new_annot = new_blank_annot();
101 new_annot.type = annot_i->type;
102 some_annots.push_back(new_annot);
110 ConnView::scale_paths()
113 list<vector<int> >::iterator pathz_i;
117 scaled_pathz.clear();
119 for(pathz_i = P->refined_pathz.begin(); pathz_i != P->refined_pathz.end(); ++pathz_i)
122 for(i2 = 0; i2 <= seq_num; i2++)
123 a_path[i2] = (int) (a_path[i2] / x_scale_factor);
124 scaled_pathz.push_back(a_path);
129 ConnView::toggle_bars()
131 show_bars = !show_bars;
136 ConnView::set_bar_interval(int new_bar_len)
138 bar_interval = new_bar_len;
139 cout << "bar interval = " << bar_interval << endl;
144 ConnView::toggle_lines()
146 show_lines = !show_lines;
151 ConnView::set_line_interval(int new_line_len)
153 line_interval = new_line_len;
154 cout << "line interval = " << line_interval << endl;
162 // this is temporary - check if new motifs have been added
165 // clear drawing area and set background to white
167 fl_rectf(x(), y(), w(), h());
170 // draw the scale indicators if they are on
171 // put into own method soon...
172 int i, div_num, x_loc;
173 float div_len_scaled;
177 div_num = max_seq_len / bar_interval;
178 div_len_scaled = ((float) bar_interval) / x_scale_factor;
179 fl_color(230,230,230);
180 for(i = 0; i <= div_num; i+=2)
182 x_loc = (int)(i * div_len_scaled+x());
183 fl_rectf(x_loc, y(), (int) div_len_scaled, h());
189 div_num = max_seq_len / line_interval;
190 div_len_scaled = ((float) line_interval) / x_scale_factor;
192 fl_line_style(FL_SOLID, 1, NULL);
193 for(i = 0; i <= div_num; i++)
195 x_loc = (int)(i * div_len_scaled+x());
196 fl_line(x_loc, y(), x_loc, h()+y());
201 // divide up the space with some light blue lines
202 fl_color(150,200,255);
203 fl_line_style(FL_SOLID, 2, NULL);
204 fl_rect(x(), y(), w(), h());
205 fl_line(w()+x()-name_pad, y(), w()+x()-name_pad, h()+y());
209 // white out any overdraw from path area into name/info area
211 fl_rectf(w()+x()-name_pad, y(), w()+x(), h());
213 draw_sequence_stuff();
215 // draw selection box
220 fl_line_style(FL_SOLID, 1, NULL);
221 fl_rect(drag_start,(ref_seq_num*y_seq_incre)+y(),drag_end-drag_start,
229 ConnView::draw_paths()
231 list<vector<int> >::iterator i;
232 int i2, i3, y_loc, x_loc, x_start, x_end;
234 list<bool>::iterator highlight_i;
237 int path_start, path_end;
241 // determine which paths to highlight
243 for(i = scaled_pathz.begin(); i != scaled_pathz.end(); ++i)
246 // determine if path falls within the selected region and mark it for
248 path_start = abs(a_path[ref_seq_num+1]);
249 path_end = path_start + a_path[0];
250 if ( ( (path_start >= drag_start-x()) && (path_end <= drag_end-x()) ) ||
251 ( (path_start < drag_start-x()) && (path_end > drag_end-x()) ) ||
252 ( (path_start < drag_start-x()) && (path_end > drag_start-x()) ) ||
253 ( (path_start < drag_end-x()) && (path_end > drag_end-x()) ) )
254 highlight.push_back(true);
256 highlight.push_back(false);
259 fl_line_style(FL_SOLID, 1, NULL);
260 // draw non-highlight paths (ie not in the selection box)
261 highlight_i = highlight.begin();
262 for(i = scaled_pathz.begin(); i != scaled_pathz.end(); ++i)
267 // get window size to determine line width
268 window_size = a_path[0];
269 // make sure width is at least 1 - might be zero to my slack rounding
270 if (window_size == 0)
274 for(i2 = 1; i2 < seq_num; i2++)
277 // ugh, an xor...only want blue if one of the nodes is rc
278 if ( ((a_path[i2] < 0) || (a_path[i2+1] < 0)) &&
279 !((a_path[i2] < 0) && (a_path[i2+1] < 0)) )
280 fl_color(200,200,255);
282 fl_color(255,200,200);
284 fl_line_style(FL_SOLID, 1, NULL);
285 fl_polygon((int)abs(a_path[i2])+x(), y_loc + 3,
286 (int)abs(a_path[i2])+window_size+x(), y_loc + 3,
287 (int)abs(a_path[i2+1])+window_size+x(), y_loc + y_seq_incre - 3,
288 (int)abs(a_path[i2+1])+x(), y_loc + y_seq_incre - 3);
290 y_loc += y_seq_incre;
295 // draw highlighted paths (ie in or partially in selection)
296 // drawing these separately and after other paths so they are on top
297 highlight_i = highlight.begin();
298 for(i = scaled_pathz.begin(); i != scaled_pathz.end(); ++i)
303 // get window size to determine line width
304 window_size = a_path[0];
305 // make sure width is at least 1 - might be zero to my slack rounding
306 if (window_size == 0)
310 for(i2 = 1; i2 < seq_num; i2++)
313 // ugh, an xor...only want blue if one of the nodes is rc
314 if ( ((a_path[i2] < 0) || (a_path[i2+1] < 0)) &&
315 !((a_path[i2] < 0) && (a_path[i2+1] < 0)) )
320 fl_polygon((int)abs(a_path[i2])+x(), y_loc + 3,
321 (int)abs(a_path[i2])+window_size+x(), y_loc + 3,
322 (int)abs(a_path[i2+1])+window_size+x(), y_loc + y_seq_incre - 3,
323 (int)abs(a_path[i2+1])+x(), y_loc + y_seq_incre - 3);
325 y_loc += y_seq_incre;
332 list<vector<int> >::iterator i;
335 int path_start, path_end;
341 ConnView::draw_sequence_stuff()
343 int i2, i3, y_loc, y_offset, x_loc, x_start, x_end, mv_offset;
344 list<annot>::iterator annot_i;
345 string species_name, seq_length;
346 stringstream raw_length;
349 // draw sequence representation lines
350 fl_font(FL_COURIER, 14);
351 //fl_color(FL_BLACK);
353 fl_line_style(FL_SOLID, 7, NULL);
356 for(i2 = 0; i2 < seq_num; i2++)
358 if (i2 == seq_num - 1)
360 x_loc = (int)(seq_lens[i2] / x_scale_factor) + x();
361 //report_float("seq scaled len", x_loc);
362 fl_line(x(),y_loc,x_loc,y_loc);
364 species_name = (*S)[i2].species;
365 fl_draw(species_name.c_str(), x()+w()-name_pad+5, y_loc+y_offset);
367 // funkiness to figure out which genomic scale to report size in
368 if (seq_scales[i2] == 1)
369 raw_length << setprecision(3) << seq_lens[i2] << " bp";
370 else if (seq_scales[i2] == 2)
371 raw_length << setprecision(3) << seq_lens[i2] / 1000.0 << " Kb";
372 else if (seq_scales[i2] == 3)
373 raw_length << setprecision(3) << seq_lens[i2] /1000000.0<< " Mb";
374 seq_length = raw_length.str();
375 fl_draw(seq_length.c_str(), x()+w()-name_pad+5, y_loc+y_offset+15);
378 y_loc += y_seq_incre;
381 //fl_line(x(),y()+y_pad/2,w()-name_pad,y()+y_pad/2);
382 //fl_line(x(),y()+h()-y_pad/2,w()-name_pad,y()+h()-y_pad/2);
385 vector<annot_color>::iterator annot_type_i;
388 fl_line_style(FL_SOLID, 3, NULL);
390 for(i2 = 0; i2 < seq_num; i2++)
392 // loop thru all annotation entries
393 for(annot_i = (*S)[i2].annots.begin(); annot_i != (*S)[i2].annots.end(); ++annot_i)
395 fl_line_style(FL_SOLID, 3, NULL);
398 // loop thru annotation types to determine color
399 annot_type_i = some_annots.begin();
400 bool type_unfound = true;
401 while ((annot_type_i != some_annots.end()) && type_unfound)
403 if (annot_i->type == annot_type_i->type)
405 fl_color(annot_type_i->color);
406 type_unfound = false;
413 // calculate scaled start and end, and draw
414 x_start = (int)(annot_i->start / x_scale_factor) + x();
415 x_end = (int)(annot_i->end / x_scale_factor) + x();
416 fl_line(x_start,y_loc+mv_offset,x_end,y_loc+mv_offset);
418 y_loc += y_seq_incre;
423 vector<motif>::iterator motif_i;
424 vector<int> some_motif_locs;
425 vector<int>::iterator i_locs;
426 int scale_len, motif_len;
429 fl_line_style(FL_SOLID, 9, NULL);
430 motif_i = some_motifs.begin();
431 while (motif_i != some_motifs.end())
433 fl_color(motif_i->color);
434 motif_len = motif_i->seq.length();
435 scale_len = (int) (motif_len / x_scale_factor);
439 if (!motif_i->locations.empty())
440 for(i2 = 0; i2 < seq_num; i2++)
442 some_motif_locs = (*motif_i).locations[i2];
444 i_locs = some_motif_locs.begin();
445 while (i_locs != some_motif_locs.end())
447 x_start = (int)(*i_locs / x_scale_factor) + x();
448 fl_line(x_start,y_loc,x_start+scale_len,y_loc);
451 y_loc += y_seq_incre;
459 ConnView::resize(int new_x, int new_y, int new_w, int new_h)
467 x_scale_factor = (float) max_seq_len / (w() - name_pad);
468 cout << "scale factor is " << x_scale_factor << endl;
469 y_seq_incre = (h()-(2*y_pad)) / (seq_num - 1);
476 ConnView::reporter(string var, int value)
478 cout << var << " : " << value << endl;
483 ConnView::report_float(string var, float value)
485 cout << var << " : " << value << endl;
489 ConnView::handle(int e)
494 // this empty string needs to be put on cout, otherwise the -O optimize
495 // compile option seems to throw this function away with the following:
496 // gcc version 3.2.2 20030222 (Red Hat Linux 3.2.2-5)
499 // why do I need a -O for this module? Well, originally I just used the
500 // same compile flags for all modules. I changed that. However, on debian
501 // systems I need the -O otherwise the behavior I observe on redhat machines
502 // with above compiler happens if I don't have that empty cout. WTF
507 if (Fl::event_button3())
512 else if (Fl::event_button2())
521 drag_start = Fl::event_x();
522 y_drag_start = (float) Fl::event_y();
523 ref_seq_num = (int) (round ( (y_drag_start/y_seq_incre) ) );
528 fl_line_style(FL_SOLID, 1, NULL);
529 fl_overlay_rect(drag_start, (ref_seq_num*y_seq_incre)+y(),
530 Fl::event_x()-drag_start, 16);
536 drag_end = Fl::event_x();
544 return_value = Fl_Widget::handle(e);
553 ConnView::check_new_motifs()
555 vector<motif>::iterator i;
557 vector<int> some_motif_locs;
558 vector<int>::iterator i_locs;
560 i = some_motifs.begin();
561 while (i != some_motifs.end())
565 cout << i->seq << " is new\n";
566 i->locations.clear();
567 //i_locs = i->locations;
568 for(i2 = 0; i2 < seq_num; i2++)
570 some_motif_locs = (*S)[i2].find_motif(i->seq);
571 (*i).locations.push_back(some_motif_locs);
574 i_locs = some_motif_locs.begin();
575 while (i_locs != some_motif_locs.end())
577 cout << *i_locs << " ";
594 list<vector<int> > selected_paths;
595 list<vector<int> >::iterator pathz_i;
596 int i2, i3, y_loc, x_loc, x_start, x_end;
598 list<bool>::iterator highlight_i;
605 // make new list of connections that are highlighted
606 selected_paths.clear();
607 highlight_i = highlight.begin();
608 for(pathz_i = P->refined_pathz.begin(); pathz_i != P->refined_pathz.end(); ++pathz_i)
613 selected_paths.push_back(a_path);
618 // give 50 pixels of height per sequence
619 y_max = seq_num * 50;
620 window_name = "Mussa Sequence: " + ana_name;
622 a_seq_win = new SeqWindow(800, y_max, (const char*) window_name.c_str(),
624 S, selected_paths, seq_lens, &some_motifs);
630 ConnView::find_motifs()
632 motif_find_window = new MotifWindow(300, 300, "Motifs", &some_motifs);
636 ConnView::annot_win()
638 annot_color_window = new AnnotWindow(300, 300, "Annotations", &some_annots);
641 // @!@! special hacked in color coding for the myf5/6 region annots
644 if (annot_i->type == "mvista")
647 fl_line_style(FL_SOLID, 8, NULL);
650 else if (annot_i->type == "reg")
652 fl_line_style(FL_SOLID, 10, NULL);
655 if (annot_i->name == "CNS")
657 else if (annot_i->name == "ELA")
659 else if (annot_i->name == "ES")
661 else if (annot_i->name == "NA")
662 fl_color(120,120,120);
663 else if (annot_i->name == "EA")
665 fl_line_style(FL_SOLID, 7, NULL);
669 else if (annot_i->name == "VS")
671 fl_line_style(FL_SOLID, 7, NULL);
675 else if (annot_i->name == "SP")
677 fl_line_style(FL_SOLID, 7, NULL);
679 fl_color(255,230,150);
681 else if (annot_i->name == "L")
683 fl_line_style(FL_SOLID, 7, NULL);
687 else if (annot_i->name == "TCM")