root/trunk/FRII/cartwheel-interface/AlignmentCloseupView.cc

Revision 10, 6.3 kB (checked in by t, 3 years ago)

Tailorization
Import of the upstream sources from

Repository: :pserver:anonymous@cvs.sf.net:/cvsroot/familyjewels

Kind: cvs

Module: FRII

Revision: 2005-12-09 09:00:54 by titus

Original author: tailor@vallista.idyll.org
Date: 2005-12-09 09:00:54

Line 
1 /*
2  * This file is part of the FamilyRelations II source distribution.
3  *
4  * FamilyRelations II is part of the FamilyJewels package for comparative
5  * sequence analysis: http://family.caltech.edu/.
6  *
7  * Contact author: C. Titus Brown, titus@caltech.edu.
8  *
9  * This program and all associated source code files are Copyright (C) 2003,
10  * 2004 the California Institute of Technology, Pasadena, CA, 91125 USA.  It
11  * is under the Lesser GNU Public License; please see the included
12  * LICENSE.txt file for more information, or contact Titus directly.
13  *
14  */
15
16 #include <iostream>
17 #include "AlignmentCloseupView.hh"
18 #include "SequenceZoomCoordinator.hh"
19 #include "FeatureInfoDisplayWindow.hh"
20
21 // An internal class to deal with highlighting features in the pairwise map
22 // display alignments between the two sequences.
23
24 class _HighlightedFeatureList : public gui::SimpleMappingContainer {
25 protected:
26   gui::FeaturesContainer * _orig_c;
27 public:
28   _HighlightedFeatureList(gui::FeaturesContainer* c) :_orig_c(c) {
29     select_feature(NULL);
30   }
31
32   void select_feature(const gui::Feature * f) {
33     delete _c;
34     gui::FeatureList * new_l = new gui::FeatureList();
35     if (f) { new_l->add_feature(f->copy_me()); }
36     _c = new gui::SimpleFeaturesContainer(new_l);
37
38     notify_changed();
39   }
40 };
41
42 static void feature_select_cb(const gui::Feature * f, void * passthru)
43 {
44   AlignmentCloseupView * aln_obj;
45   aln_obj = (AlignmentCloseupView *) passthru;
46
47   aln_obj->change_viewed_feature(f);
48 }
49
50 static void feature_info_cb(Fl_Widget * w, void * passthru)
51 {
52   gui::Feature * f = (gui::Feature*) passthru;
53   if (f && f->has_info()) {
54     FeatureInfoDisplayWindow * disp = new FeatureInfoDisplayWindow(300, 400,
55                                                                    f);
56     disp->show();
57   }
58 }
59
60 static void del_window_cb(Fl_Widget * w, void * p)
61 {
62   Fl_Window * window = (Fl_Window *) w;
63
64   w->hide();
65   delete window;
66 }
67
68 AlignmentCloseupView::AlignmentCloseupView(const gui::SimpleMappingContainer * map,
69                                            const gui::MappingView * view,
70                                            unsigned int w, unsigned int h) :
71   Fl_Double_Window(w, h)
72 {
73   callback(del_window_cb);
74
75   gui::SequenceView * old_top_view = view->get_top_seq_view();
76   gui::SequenceView * old_bot_view = view->get_bot_seq_view();
77
78   std::string top_name = old_top_view->sequence_name();
79   std::string top_seq = old_top_view->sequence_text();
80   std::string bot_name = old_top_view->sequence_name();
81   std::string bot_seq = old_bot_view->sequence_text();
82
83   // tile this window
84   tiling = new Fl_Pack(0, 0, w, h);
85   add(tiling);
86
87   // Also create two separate sequence lines showing the features.
88   line_view_a = new gui::HorizontalSequenceView(0, 100, w, top_seq.length());
89   line_view_a->sequence_text(top_seq);
90
91   line_view_b = new gui::ClickableFeaturesSequenceView(0, 0, w, top_seq.length(), map->get_features_container());
92   line_view_b->sequence_text(top_seq);
93   line_view_b->show_sequence_line(false);
94   line_view_b->select_feature_handler(feature_select_cb, this);
95
96   gui::SequenceZoomCoordinator* top_coord = new gui::SequenceZoomCoordinator();
97   gui::SequenceZoomCoordinator* bot_coord = new gui::SequenceZoomCoordinator();
98   line_view_a->zoom_coordinator(top_coord);
99   line_view_b->zoom_coordinator(top_coord);
100
101   // create a new alignment map
102   gui::SimpleMappingContainer * new_map = map->copy_me();
103
104   // create a new view with that map.
105   new_view = new gui::PairwiseMappingView(0, 200, w, 250,
106                                           top_name, top_seq,
107                                           bot_name, bot_seq);
108  
109   new_view->get_top_seq_view()->zoom_coordinator(top_coord);
110   new_view->get_bot_seq_view()->zoom_coordinator(bot_coord);
111
112   new_view->add_map(new_map);
113
114   hilite = new _HighlightedFeatureList(map->get_features_container());
115   hilite->color(FL_RED);
116   new_view->add_map(hilite);
117
118   //
119   // Devote the lower half of the window to display the alignment
120   // and associated information.
121   //
122
123   aln_label = new gui::TextLabel(0, 0, w - 120, 40, "Alignment:");
124   aln_label->align(FL_ALIGN_LEFT);
125   aln_label->color(FL_WHITE);
126   aln_label->bold(true);
127   aln_label->box(FL_THIN_DOWN_FRAME);
128
129   aln_info_pack = new Fl_Pack(0, 0, w, 40);
130   aln_info_pack->type(Fl_Pack::HORIZONTAL);
131   aln_info_pack->add(aln_label);
132
133   view_info = new Fl_Button(w - 120, 0, 120, 40);
134   view_info->label("View feature info");
135   view_info->callback(feature_info_cb);
136   aln_info_pack->add(view_info);
137  
138   aln_view = new gui::AlignedSequencePairWidget(0, 0, w, h);
139
140   tiling->add(line_view_a);
141   tiling->add(line_view_b);
142   tiling->add(new_view);
143   tiling->add(aln_info_pack);
144   tiling->add(aln_view);
145
146   //
147   // Set the basic viewing boundaries of the maps.
148   //
149
150   unsigned int top_sel_start = old_top_view->start_sel_base();
151   unsigned int top_sel_end = old_top_view->end_sel_base();
152  
153   unsigned int bot_sel_start = old_bot_view->start_sel_base();
154   unsigned int bot_sel_end = old_bot_view->end_sel_base();
155
156   line_view_a->set_visible_bases(top_sel_start, top_sel_end);
157   line_view_b->set_visible_bases(top_sel_start, top_sel_end);
158   new_view->get_top_seq_view()->set_visible_bases(top_sel_start,
159                                                   top_sel_end);
160
161   new_view->get_bot_seq_view()->set_visible_bases(bot_sel_start, bot_sel_end);
162
163   //
164   // Select a feature.
165   //
166
167   const gui::FeatureList * l = map->get_features_container()->getFeatureList();
168   const gui::Feature * f = NULL;
169   for (unsigned int i = 0; i < l->n_features(); i++) {
170     f = l->get(i);
171     if (f->has_alignment() &&
172         f->end > top_sel_start && // overlaps
173         f->start < top_sel_end) {
174       break;
175     }
176   }
177
178   // this calls the select_feature callback, which in turn sets the aln_view
179   // current feature.
180   if (f) {
181     line_view_b->select_feature(f);
182   }
183
184   //
185   // Finalize.
186   //
187
188   resizable(this);
189   end();
190 }
191
192 AlignmentCloseupView::~AlignmentCloseupView()
193 {
194   // delete hilite;
195   // delete new_view;
196   // delete aln_view;
197   // delete line_view_a;
198   // delete line_view_b;
199   // delete aln_label;
200   // delete aln_pair;
201 }
202
203 void AlignmentCloseupView::change_viewed_feature(const gui::Feature * f)
204 {
205   aln_view->change_feature(f);
206   ((_HighlightedFeatureList *) hilite)->select_feature(f);
207
208   gui::Feature * new_f = f->copy_me();
209   gui::Feature * old_f = (gui::Feature *) view_info->user_data();
210   if (old_f) { delete old_f; }
211
212   if (f->has_info()) {
213     view_info->label("View info...");
214     view_info->user_data(new_f);        // so the "view info" button has access to it.
215   } else {
216     view_info->label("no info");
217     view_info->user_data(NULL);
218   }
219   redraw();
220 }
Note: See TracBrowser for help on using the browser.