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

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