| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 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 |
|
|---|
| 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) { |
|---|
| 91 |
_list = old->filter_at(th); |
|---|
| 92 |
} else { |
|---|
| 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; |
|---|
| 102 |
_list = _orig->filter_at(th); |
|---|
| 103 |
_min_val = min_val; |
|---|
| 104 |
_threshold = th; |
|---|
| 105 |
} |
|---|
| 106 |
public: |
|---|
| 107 |
|
|---|
| 108 |
BlastFeaturesContainer(std::vector<BlastFeature*> l, float th) { |
|---|
| 109 |
|
|---|
| 110 |
_orig = new BlastFeatureList(); |
|---|
| 111 |
|
|---|
| 112 |
if (l.size()) { _min_val = l[0]->score; } |
|---|
| 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 |
|
|---|
| 121 |
_list = _orig->filter_at(th); |
|---|
| 122 |
|
|---|
| 123 |
_threshold = th; |
|---|
| 124 |
} |
|---|
| 125 |
|
|---|
| 126 |
|
|---|
| 127 |
void threshold(float th) { |
|---|
| 128 |
if (th != _threshold) { _filter(th); } |
|---|
| 129 |
_threshold = th; |
|---|
| 130 |
} |
|---|
| 131 |
|
|---|
| 132 |
|
|---|
| 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 |
|
|---|
| 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 |
|---|
| 153 |
|
|---|