1 // This file is part of the Mussa source distribution.
2 // http://mussa.caltech.edu/
3 // Contact author: Tristan De Buysscher, tristan@caltech.edu
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.
11 #include "mussa_gui_conn_view.hh"
18 ConnView::setup(string name, int sq_num, int win_len,
19 vector<Sequence> *some_seqs,
20 Nway_Paths *some_paths)
22 int i, i2, seq_length;
25 annot_color new_annot;
34 cout << "num of paths = " << some_paths->refined_pathz.size() << endl;
36 cout << "x()=" << x() << " y()=" << y() << " w()=" << w() << " h()=" << h();
40 for(i = 0; i < seq_num; ++i)
43 cout << a_seq.len() << endl;
44 seq_length = a_seq.len();
45 seq_lens.push_back(seq_length);
46 if (seq_length > max_seq_len)
47 max_seq_len = seq_length;
48 if (seq_length < 1000)
49 seq_scales.push_back(1);
50 else if (seq_length < 1000000)
51 seq_scales.push_back(2);
53 seq_scales.push_back(3);
59 x_scale_factor = (float) max_seq_len / (w() - name_pad);
60 cout << "scale factor is " << x_scale_factor << endl;
61 y_seq_incre = (h()-(y_pad*2)) / (seq_num - 1);
74 bar_interval = max_seq_len / 20;
75 line_interval = max_seq_len / 20;
80 for(i = 0; i < 5; ++i)
82 blank_motif = new_blank_motif();
83 some_motifs.push_back(blank_motif);
86 // find all unique annotation type ids
88 vector<annot_color>::iterator annot_type_i;
89 list<annot>::iterator annot_i;
91 // loop thru all sequences
92 for(i2 = 0; i2 < seq_num; i2++)
94 cout << "ConnView: annotation loop\n";
95 // loop thru all annotation entries in this sequence
96 for(annot_i = (*S)[i2].annots.begin(); annot_i != (*S)[i2].annots.end(); ++annot_i)
98 cout << annot_i->start << ", " << annot_i->end << " : ";
99 cout << annot_i->name << " " << annot_i->type << endl;
100 // loop thru annotation types
101 annot_type_i = some_annots.begin();
102 bool type_unfound = true;
103 while ((annot_type_i != some_annots.end()) && type_unfound)
105 if (annot_i->type == annot_type_i->type)
106 type_unfound = false; // stop search if found
109 //if unfound, then add to list
112 new_annot = new_blank_annot();
113 new_annot.type = annot_i->type;
114 some_annots.push_back(new_annot);
122 ConnView::scale_paths()
125 list<vector<int> >::iterator pathz_i;
129 scaled_pathz.clear();
131 for(pathz_i = P->refined_pathz.begin(); pathz_i != P->refined_pathz.end(); ++pathz_i)
134 for(i2 = 0; i2 <= seq_num; i2++)
135 a_path[i2] = (int) (a_path[i2] / x_scale_factor);
136 scaled_pathz.push_back(a_path);
141 ConnView::toggle_bars()
143 show_bars = !show_bars;
148 ConnView::set_bar_interval(int new_bar_len)
150 bar_interval = new_bar_len;
151 cout << "bar interval = " << bar_interval << endl;
156 ConnView::toggle_lines()
158 show_lines = !show_lines;
163 ConnView::set_line_interval(int new_line_len)
165 line_interval = new_line_len;
166 cout << "line interval = " << line_interval << endl;
174 // this is temporary - check if new motifs have been added
177 // clear drawing area and set background to white
179 fl_rectf(x(), y(), w(), h());
182 // draw the scale indicators if they are on
183 // put into own method soon...
184 int i, div_num, x_loc;
185 float div_len_scaled;
189 div_num = max_seq_len / bar_interval;
190 div_len_scaled = ((float) bar_interval) / x_scale_factor;
191 fl_color(230,230,230);
192 for(i = 0; i <= div_num; i+=2)
194 x_loc = (int)(i * div_len_scaled+x());
195 fl_rectf(x_loc, y(), (int) div_len_scaled, h());
201 div_num = max_seq_len / line_interval;
202 div_len_scaled = ((float) line_interval) / x_scale_factor;
204 fl_line_style(FL_SOLID, 1, NULL);
205 for(i = 0; i <= div_num; i++)
207 x_loc = (int)(i * div_len_scaled+x());
208 fl_line(x_loc, y(), x_loc, h()+y());
213 // divide up the space with some light blue lines
214 fl_color(150,200,255);
215 fl_line_style(FL_SOLID, 2, NULL);
216 fl_rect(x(), y(), w(), h());
217 fl_line(w()+x()-name_pad, y(), w()+x()-name_pad, h()+y());
221 // white out any overdraw from path area into name/info area
223 fl_rectf(w()+x()-name_pad, y(), w()+x(), h());
225 draw_sequence_stuff();
227 // draw selection box
232 fl_line_style(FL_SOLID, 1, NULL);
233 fl_rect(drag_start,(ref_seq_num*y_seq_incre)+y(),drag_end-drag_start,
241 ConnView::draw_paths()
243 list<vector<int> >::iterator i;
244 int i2, i3, y_loc, x_loc, x_start, x_end;
246 list<bool>::iterator highlight_i;
249 int path_start, path_end;
253 // determine which paths to highlight
255 for(i = scaled_pathz.begin(); i != scaled_pathz.end(); ++i)
258 // determine if path falls within the selected region and mark it for
260 path_start = abs(a_path[ref_seq_num+1]);
261 path_end = path_start + a_path[0];
262 if ( ( (path_start >= drag_start-x()) && (path_end <= drag_end-x()) ) ||
263 ( (path_start < drag_start-x()) && (path_end > drag_end-x()) ) ||
264 ( (path_start < drag_start-x()) && (path_end > drag_start-x()) ) ||
265 ( (path_start < drag_end-x()) && (path_end > drag_end-x()) ) )
266 highlight.push_back(true);
268 highlight.push_back(false);
271 fl_line_style(FL_SOLID, 1, NULL);
272 // draw non-highlight paths (ie not in the selection box)
273 highlight_i = highlight.begin();
274 for(i = scaled_pathz.begin(); i != scaled_pathz.end(); ++i)
279 // get window size to determine line width
280 window_size = a_path[0];
281 // make sure width is at least 1 - might be zero to my slack rounding
282 if (window_size == 0)
286 for(i2 = 1; i2 < seq_num; i2++)
289 // ugh, an xor...only want blue if one of the nodes is rc
290 if ( ((a_path[i2] < 0) || (a_path[i2+1] < 0)) &&
291 !((a_path[i2] < 0) && (a_path[i2+1] < 0)) )
292 fl_color(200,200,255);
294 fl_color(255,200,200);
296 fl_line_style(FL_SOLID, 1, NULL);
297 fl_polygon((int)abs(a_path[i2])+x(), y_loc + 3,
298 (int)abs(a_path[i2])+window_size+x(), y_loc + 3,
299 (int)abs(a_path[i2+1])+window_size+x(), y_loc + y_seq_incre - 3,
300 (int)abs(a_path[i2+1])+x(), y_loc + y_seq_incre - 3);
302 y_loc += y_seq_incre;
307 // draw highlighted paths (ie in or partially in selection)
308 // drawing these separately and after other paths so they are on top
309 highlight_i = highlight.begin();
310 for(i = scaled_pathz.begin(); i != scaled_pathz.end(); ++i)
315 // get window size to determine line width
316 window_size = a_path[0];
317 // make sure width is at least 1 - might be zero to my slack rounding
318 if (window_size == 0)
322 for(i2 = 1; i2 < seq_num; i2++)
325 // ugh, an xor...only want blue if one of the nodes is rc
326 if ( ((a_path[i2] < 0) || (a_path[i2+1] < 0)) &&
327 !((a_path[i2] < 0) && (a_path[i2+1] < 0)) )
332 fl_polygon((int)abs(a_path[i2])+x(), y_loc + 3,
333 (int)abs(a_path[i2])+window_size+x(), y_loc + 3,
334 (int)abs(a_path[i2+1])+window_size+x(), y_loc + y_seq_incre - 3,
335 (int)abs(a_path[i2+1])+x(), y_loc + y_seq_incre - 3);
337 y_loc += y_seq_incre;
344 list<vector<int> >::iterator i;
347 int path_start, path_end;
353 ConnView::draw_sequence_stuff()
355 int i2, i3, y_loc, y_offset, x_loc, x_start, x_end, mv_offset;
356 list<annot>::iterator annot_i;
357 string species_name, seq_length;
358 stringstream raw_length;
361 // draw sequence representation lines
362 fl_font(FL_COURIER, 14);
363 //fl_color(FL_BLACK);
364 fl_color(100,100,100);
365 // normally size 7, adjust for various screenshotage
366 fl_line_style(FL_SOLID, 11, NULL);
369 for(i2 = 0; i2 < seq_num; i2++)
371 if (i2 == seq_num - 1)
373 x_loc = (int)(seq_lens[i2] / x_scale_factor) + x();
374 //report_float("seq scaled len", x_loc);
375 fl_line(x(),y_loc,x_loc,y_loc);
377 species_name = (*S)[i2].species;
378 fl_draw(species_name.c_str(), x()+w()-name_pad+5, y_loc+y_offset);
380 // funkiness to figure out which genomic scale to report size in
381 if (seq_scales[i2] == 1)
382 raw_length << setprecision(3) << seq_lens[i2] << " bp";
383 else if (seq_scales[i2] == 2)
384 raw_length << setprecision(3) << seq_lens[i2] / 1000.0 << " Kb";
385 else if (seq_scales[i2] == 3)
386 raw_length << setprecision(3) << seq_lens[i2] /1000000.0<< " Mb";
387 seq_length = raw_length.str();
388 fl_draw(seq_length.c_str(), x()+w()-name_pad+5, y_loc+y_offset+15);
391 y_loc += y_seq_incre;
394 //fl_line(x(),y()+y_pad/2,w()-name_pad,y()+y_pad/2);
395 //fl_line(x(),y()+h()-y_pad/2,w()-name_pad,y()+h()-y_pad/2);
398 vector<annot_color>::iterator annot_type_i;
401 fl_line_style(FL_SOLID, 3, NULL);
403 for(i2 = 0; i2 < seq_num; i2++)
405 // loop thru all annotation entries
406 for(annot_i = (*S)[i2].annots.begin(); annot_i != (*S)[i2].annots.end(); ++annot_i)
408 fl_line_style(FL_SOLID, 7, NULL);
411 // loop thru annotation types to determine color
412 annot_type_i = some_annots.begin();
413 bool type_unfound = true;
414 while ((annot_type_i != some_annots.end()) && type_unfound)
416 if (annot_i->type == annot_type_i->type)
418 fl_color(annot_type_i->color);
419 type_unfound = false;
426 // calculate scaled start and end, and draw
427 x_start = (int)(annot_i->start / x_scale_factor) + x();
428 x_end = (int)(annot_i->end / x_scale_factor) + x();
429 fl_line(x_start,y_loc+mv_offset,x_end,y_loc+mv_offset);
431 y_loc += y_seq_incre;
436 vector<motif>::iterator motif_i;
437 vector<int> some_motif_locs;
438 vector<int>::iterator i_locs;
439 int scale_len, motif_len;
442 fl_line_style(FL_SOLID, 9, NULL);
443 motif_i = some_motifs.begin();
444 while (motif_i != some_motifs.end())
446 fl_color(motif_i->color);
447 motif_len = motif_i->seq.length();
448 scale_len = (int) (motif_len / x_scale_factor);
452 if (!motif_i->locations.empty())
453 for(i2 = 0; i2 < seq_num; i2++)
455 some_motif_locs = (*motif_i).locations[i2];
457 i_locs = some_motif_locs.begin();
458 while (i_locs != some_motif_locs.end())
460 x_start = (int)(*i_locs / x_scale_factor) + x();
461 fl_line(x_start,y_loc,x_start+scale_len,y_loc);
464 y_loc += y_seq_incre;
472 ConnView::resize(int new_x, int new_y, int new_w, int new_h)
480 x_scale_factor = (float) max_seq_len / (w() - name_pad);
481 cout << "scale factor is " << x_scale_factor << endl;
482 y_seq_incre = (h()-(2*y_pad)) / (seq_num - 1);
489 ConnView::reporter(string var, int value)
491 cout << var << " : " << value << endl;
496 ConnView::report_float(string var, float value)
498 cout << var << " : " << value << endl;
502 ConnView::handle(int e)
507 // this empty string needs to be put on cout, otherwise the -O optimize
508 // compile option seems to throw this function away with the following:
509 // gcc version 3.2.2 20030222 (Red Hat Linux 3.2.2-5)
512 // why do I need a -O for this module? Well, originally I just used the
513 // same compile flags for all modules. I changed that. However, on debian
514 // systems I need the -O otherwise the behavior I observe on redhat machines
515 // with above compiler happens if I don't have that empty cout. WTF
520 if (Fl::event_button3())
525 else if (Fl::event_button2())
534 drag_start = Fl::event_x();
535 y_drag_start = (float) Fl::event_y();
536 ref_seq_num = (int) (round ( (y_drag_start/y_seq_incre) ) );
541 fl_line_style(FL_SOLID, 1, NULL);
542 fl_overlay_rect(drag_start, (ref_seq_num*y_seq_incre)+y(),
543 Fl::event_x()-drag_start, 16);
549 drag_end = Fl::event_x();
557 return_value = Fl_Widget::handle(e);
566 ConnView::check_new_motifs()
568 vector<motif>::iterator i;
570 vector<int> some_motif_locs;
571 vector<int>::iterator i_locs;
573 i = some_motifs.begin();
574 while (i != some_motifs.end())
578 cout << i->seq << " is new\n";
579 i->locations.clear();
580 //i_locs = i->locations;
581 for(i2 = 0; i2 < seq_num; i2++)
583 some_motif_locs = (*S)[i2].find_motif(i->seq);
584 (*i).locations.push_back(some_motif_locs);
587 i_locs = some_motif_locs.begin();
588 while (i_locs != some_motif_locs.end())
590 cout << *i_locs << " ";
607 list<vector<int> > selected_paths;
608 list<vector<int> >::iterator pathz_i;
609 int i2, i3, y_loc, x_loc, x_start, x_end;
611 list<bool>::iterator highlight_i;
618 // make new list of connections that are highlighted
619 selected_paths.clear();
620 highlight_i = highlight.begin();
621 for(pathz_i = P->refined_pathz.begin(); pathz_i != P->refined_pathz.end(); ++pathz_i)
626 selected_paths.push_back(a_path);
631 // give 50 pixels of height per sequence
632 y_max = seq_num * 50;
633 window_name = "Mussa Sequence: " + ana_name;
635 a_seq_win = new SeqWindow(800, y_max, (const char*) window_name.c_str(),
637 S, selected_paths, seq_lens, &some_motifs);
643 ConnView::find_motifs()
645 motif_find_window = new MotifWindow(300, 300, "Motifs", &some_motifs);
649 ConnView::annot_win()
651 annot_color_window = new AnnotWindow(300, 300, "Annotations", &some_annots);
654 // @!@! special hacked in color coding for the myf5/6 region annots
657 if (annot_i->type == "mvista")
660 fl_line_style(FL_SOLID, 8, NULL);
663 else if (annot_i->type == "reg")
665 fl_line_style(FL_SOLID, 10, NULL);
668 if (annot_i->name == "CNS")
670 else if (annot_i->name == "ELA")
672 else if (annot_i->name == "ES")
674 else if (annot_i->name == "NA")
675 fl_color(120,120,120);
676 else if (annot_i->name == "EA")
678 fl_line_style(FL_SOLID, 7, NULL);
682 else if (annot_i->name == "VS")
684 fl_line_style(FL_SOLID, 7, NULL);
688 else if (annot_i->name == "SP")
690 fl_line_style(FL_SOLID, 7, NULL);
692 fl_color(255,230,150);
694 else if (annot_i->name == "L")
696 fl_line_style(FL_SOLID, 7, NULL);
700 else if (annot_i->name == "TCM")