root/trunk/FRII/gui/BlastFeaturesContainer.hh

Revision 10, 3.8 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 // A FeaturesContainer for features with BLAST-style scores.
17
18 #ifndef BLAST_FEATURES_CONTAINER_HH
19 #define BLAST_FEATURES_CONTAINER_HH
20
21 #include "FeaturesContainer.hh"
22
23 #include <vector>
24
25 namespace gui {
26   class BlastFeaturesContainer;
27
28   class BlastFeature : public Feature {
29   public:
30     const float score;
31
32     BlastFeature(int s, int e, int o, float sc) : Feature(s, e, o),
33                                                   score(sc) { _other = NULL; }
34
35     BlastFeature * copy_me() const {
36       BlastFeature * new_f = new BlastFeature(start, end, orientation, score);
37       if (_other) {
38         new_f->_other = _other->copy_me();
39       }
40       new_f->set_alignment(top_aln, bot_aln);
41       new_f->_info = _info;
42
43       return new_f;
44     }
45   };
46
47   class BlastFeatureList : public FeatureList {
48     friend class BlastFeaturesContainer;
49   protected:
50     BlastFeatureList() { }
51
52     BlastFeatureList* filter_at(float th) const {
53       BlastFeatureList* n = new BlastFeatureList();
54       BlastFeature* f;
55      
56       for (unsigned int i = 0; i < _list.size(); i++) {
57         f = (BlastFeature*) _list[i];
58         if (f->score <= th) {
59           n->add_feature(f->copy_me());
60         }
61       }
62       return n;
63     }
64
65     BlastFeatureList* copy_me() const {
66       BlastFeatureList* n = new BlastFeatureList();
67       BlastFeature* f;
68      
69       for (unsigned int i = 0; i < _list.size(); i++) {
70         f = (BlastFeature*) _list[i];
71         n->add_feature(f->copy_me());
72       }
73       return n;
74     }
75   };
76
77   //
78   // A FeaturesContainer for feature lists with BLAST-type scores.
79   //
80
81   class BlastFeaturesContainer : public FeaturesContainer {
82   private:
83     BlastFeatureList* _orig;
84     BlastFeatureList* _list;
85
86     float _threshold, _min_val;
87
88     void _filter(float th) {
89       BlastFeatureList * old = _list;
90       if (th < _threshold) {    // more stringent
91         _list = old->filter_at(th);
92       } else {                  // less stringent
93         _list = _orig->filter_at(th);
94       }
95       delete old;
96      
97       notify_changed();
98     }
99
100     BlastFeaturesContainer(BlastFeatureList * l, float th, float min_val) {
101       _orig = l;                // consumes l...x
102       _list = _orig->filter_at(th);
103       _min_val = min_val;
104       _threshold = th;
105     }
106   public:
107     // Constructor.
108     BlastFeaturesContainer(std::vector<BlastFeature*> l, float th) {
109       // create the basic list.
110       _orig = new BlastFeatureList();
111
112       if (l.size()) { _min_val = l[0]->score; } // initialize _min_val
113       else { _min_val = 1.0; }
114
115       for (unsigned int i = 0; i < l.size(); i++) {
116         _orig->add_feature(l[i]);
117         if (l[i]->score < _min_val) { _min_val = l[i]->score; }
118       }
119
120       // initialize list to the passed-in threshold.
121       _list = _orig->filter_at(th);
122
123       _threshold = th;
124     }
125
126     // set the threshold
127     void threshold(float th) {
128       if (th != _threshold) { _filter(th); }
129       _threshold = th;
130     }
131
132     // get the threshold
133     float threshold() { return _threshold; }
134    
135     virtual const FeatureList* getFeatureList() const { return _list; }
136     FeaturesContainer* copy_me() const {
137       return new BlastFeaturesContainer(_list->copy_me(), _threshold, _min_val);
138     }
139    
140     // delete stuff.
141     ~BlastFeaturesContainer() {
142       for (unsigned int i = 0; i < _orig->n_features(); i++) {
143         delete _orig->get(i);
144       }
145       delete _list;
146     }
147    
148     float min() { return _min_val; }
149   };
150 }
151
152 #endif // BLAST_FEATURES_CONTAINER_HH
153
Note: See TracBrowser for help on using the browser.