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

Revision 69, 5.5 kB (checked in by t, 2 years ago)

put initial_threshold into the parsed analyses stuff.

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 <assert.h>
17 #include "ParsedBlastPairwiseAnalysis.hh"
18 #include "BlastThresholdSlider.hh"
19 #include "AlignmentCloseupView.hh"
20
21 #define DEFAULT_BLAST_THRESHOLD 1e-6
22
23 #include <FL/Fl_Pack.H>
24 #include <FL/Fl_Button.H>
25 #include <FL/Fl_Check_Button.H>
26
27 #include "TextLabel.hh"
28 #include "ColorPatch.hh"
29
30 #include "PercentFeaturesContainer.hh"
31
32 // sole constructor.
33
34 ParsedBlastPairwiseAnalysis::ParsedBlastPairwiseAnalysis(iff::FeatureList * fl,
35                                                          gui::MappingView * v)
36 {
37   _view = v;
38
39   name = fl->name();
40
41   //
42   // transfer all of the features into a BlastFeaturesContainer.
43   //
44
45   std::vector<gui::BlastFeature*> new_features;
46
47   for (unsigned int j = 0; j < fl->n_features(); j++) {
48     iff::Feature * iff_f = fl->get(j);
49     gui::BlastFeature * f = new gui::BlastFeature(iff_f->start(),
50                                                   iff_f->end(),
51                                                   iff_f->orientation(),
52                                                   iff_f->score());
53
54     // add info
55     f->add_information(iff_f->information());
56
57     // put in the pair-match stuff.
58     iff::Feature * other_iff_f = iff_f->pair_match();
59     assert(other_iff_f);
60
61     f->other(other_iff_f->start(), other_iff_f->end());
62
63     std::string a, b;
64     a = iff_f->get_aln();
65     b = other_iff_f->get_aln();
66     if (a.length() && b.length()) {
67       assert(a.length() == b.length());
68
69       f->set_alignment(a, b);
70     }
71
72     new_features.push_back(f);
73   }
74
75   float initial_threshold = DEFAULT_BLAST_THRESHOLD;
76   std::string iff_threshold = fl->initial_threshold();
77   if (iff_threshold.length()) {
78     initial_threshold = atof(iff_threshold.c_str());
79   }
80
81   _blast_features = new gui::BlastFeaturesContainer(new_features,
82                                                     initial_threshold);
83
84   _map_cont = new gui::BlastMappingContainer(_blast_features);
85 }
86
87 static void map_show_toggle_cb(Fl_Widget * w, void * p)
88 {
89   gui::MappingContainer * map = (gui::MappingContainer *) p;
90   Fl_Button * b = (Fl_Button *) w;
91
92   map->visible(b->value());
93 }
94
95 // class to contain passthrough data for the view alignments callback.
96 class alignment_closeup_passthru {
97 public:
98   const gui::BlastMappingContainer * map;
99   const gui::MappingView * view;
100   const std::string name;
101   alignment_closeup_passthru(gui::BlastMappingContainer * m,
102                              gui::MappingView * v,
103                              std::string n)
104     : map(m), view(v), name(n) { };
105 };
106
107 // callback function for "view alignment" button on simple pairwise views:
108
109 static void alignment_closeup_cb(Fl_Widget * w, void * p)
110 {
111   alignment_closeup_passthru * container = (alignment_closeup_passthru *)p;
112
113   // extract stuff from the passthru data
114   const gui::MappingView * view = container->view;
115   const gui::BlastMappingContainer * map = container->map;
116   const std::string name = container->name;
117
118   gui::SimpleMappingContainer * simple;
119   simple = new gui::SimpleMappingContainer(map->get_features_container()->copy_me());
120
121   AlignmentCloseupView * new_view = new \
122     AlignmentCloseupView(simple, view, 600, 600);
123
124   std::string label = "Close-up of BLAST matches from '" + name + "'";
125   new_view->label(label.c_str());
126
127   new_view->show();
128 }
129
130 void ParsedBlastPairwiseAnalysis::add_control_panel(Fl_Group * container,
131                                                     int &x, int &y,
132                                                     const int width)
133 {
134   const unsigned int height = 30;
135   const int start_y = y;
136
137   gui::TextLabel * label = new gui::TextLabel(x + 5, y + 5, width - 10, height, name.c_str());
138   label->bold(true);
139   label->box(FL_DOWN_BOX);
140   y += height + 10;
141  
142   gui::BlastThresholdSlider * slider;
143   slider = new gui::BlastThresholdSlider(x + 5, y + 5, width - 10, height, 1,
144                                          _blast_features);
145
146   y += height + 10;
147
148   //
149   // add a 'view alignments' button.
150   //
151
152   Fl_Button * b = NULL;
153   if (_blast_features->contains_alignments()) {
154     b = new Fl_Button(x + 15, y + 5, 120, 25, "View alignments...");
155  
156     b->color(FL_WHITE);
157     b->labelsize(12);
158     b->callback(alignment_closeup_cb,
159                 new alignment_closeup_passthru(_map_cont, _view, name));
160     y += height + 10;
161   }
162
163   //
164   // add a display toggle.
165   //
166
167   Fl_Pack * p = new Fl_Pack(x + 5, y + 5, width, height);
168
169   Fl_Check_Button * check_b = new Fl_Check_Button(x + 5, y + 5, width - 10,
170                                                   height);
171   check_b->callback(map_show_toggle_cb, _map_cont);
172   check_b->label("show comparison");
173   check_b->value(1);
174   p->add(check_b);
175
176   y += height + 10;
177
178   // finally, add a color patch.
179   gui::TextLabel * cl = new gui::TextLabel(x + 5,
180                                            y + 5, (width - 10) / 2,
181                                            30, "Set color:");
182   gui::ColorPatch * c = new gui::ColorPatch(x + 5 + (width - 10) / 2,
183                                             y + 5, (width - 10) / 2,
184                                             height,
185                                             _map_cont->color());
186
187   gui::ColorChangeListener_MappingContainer * listener = new
188     gui::ColorChangeListener_MappingContainer(_map_cont);
189      
190   c->add_change_listener(listener);
191
192   y += height + 10;
193
194   Fl_Box * surround = new Fl_Box(x, start_y, width, y - start_y);
195   surround->box(FL_DOWN_BOX);
196   surround->color(FL_WHITE);
197   container->add(surround);
198
199   container->add(label);
200   container->add(slider);
201   if (b) {
202     container->add(b);
203   }
204   container->add(p);
205   container->add(cl);
206   container->add(c);
207 }
Note: See TracBrowser for help on using the browser.