00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef OPENMS_KERNEL_CONSENSUSFEATURE_H
00028 #define OPENMS_KERNEL_CONSENSUSFEATURE_H
00029
00030 #include <OpenMS/KERNEL/FeatureMap.h>
00031 #include <OpenMS/DATASTRUCTURES/DRange.h>
00032 #include <OpenMS/ANALYSIS/MAPMATCHING/Group.h>
00033
00034 namespace OpenMS
00035 {
00036
00044 template < typename ContainerT = FeatureMap< > >
00045 class ConsensusFeature :
00046 public Feature,
00047 public Group< ContainerT >
00048 {
00049 public:
00054 typedef Feature BaseElementType;
00055 typedef ContainerT ElementContainerType;
00056 typedef typename ElementContainerType::value_type ElementType;
00057 typedef Group< ElementContainerType > Group;
00058
00059 typedef DPosition < 2> PositionType;
00060 typedef DoubleReal IntensityType;
00061 typedef IndexTuple< ElementContainerType > IndexTuple;
00062 typedef DRange<2> PositionBoundingBoxType;
00063 typedef DRange<1> IntensityBoundingBoxType;
00065
00066
00070
00071 ConsensusFeature()
00072 : BaseElementType(),
00073 Group(),
00074 position_range_(),
00075 intensity_range_()
00076 {}
00077
00079 ConsensusFeature(const PositionType& pos, IntensityType i)
00080 : BaseElementType(),
00081 Group(),
00082 position_range_(),
00083 intensity_range_()
00084 {
00085 this->getPosition() = pos;
00086 this->setIntensity(i);
00087 }
00088
00090 ConsensusFeature(UInt map_index, UInt feature_index, const ElementType& feature)
00091 {
00092 try
00093 {
00094 IndexTuple i(map_index,feature_index,feature);
00095 i.setTransformedPosition(feature.getPosition());
00096 this->insert(i);
00097 }
00098 catch(Exception::InvalidValue)
00099 {}
00100
00101 this->getPosition() = feature.getPosition();
00102 this->setIntensity(feature.getIntensity());
00103
00104 position_range_.setMinMax(feature.getPosition(),feature.getPosition());
00105 intensity_range_.setMinMax(feature.getIntensity(),feature.getIntensity());
00106 }
00107
00109 ConsensusFeature(UInt map_1_index, UInt feature_index_1, const ElementType& feature_1,
00110 UInt map_2_index, UInt feature_index_2, const ElementType& feature_2)
00111 {
00112 try
00113 {
00114 IndexTuple i1(map_1_index,feature_index_1, feature_1);
00115 i1.setTransformedPosition(feature_1.getPosition());
00116 this->insert(i1);
00117 IndexTuple i2(map_2_index,feature_index_2, feature_2);
00118 i2.setTransformedPosition(feature_2.getPosition());
00119 this->insert(i2);
00120 }
00121 catch(Exception::InvalidValue)
00122 {}
00123
00124 computeConsensus_();
00125 }
00126
00128 ConsensusFeature(UInt map_index, UInt feature_index, const ElementType& feature, const ConsensusFeature& c_feature)
00129 {
00130 Group::operator=(c_feature);
00131 IndexTuple i(map_index,feature_index,feature);
00132 i.setTransformedPosition(feature.getPosition());
00133 this->insert(i);
00134
00135 computeConsensus_();
00136 }
00137
00139 ConsensusFeature(const ConsensusFeature& c_feature_1, const ConsensusFeature& c_feature_2)
00140 {
00141 Group::operator=(c_feature_1);
00142
00143 for (typename Group::iterator it = c_feature_2.begin(); it != c_feature_2.end(); ++it)
00144 {
00145 try
00146 {
00147 this->insert(*it);
00148 }
00149 catch(Exception::InvalidValue)
00150 {}
00151 }
00152
00153 computeConsensus_();
00154 }
00155
00156
00158 inline ConsensusFeature(const ConsensusFeature& source)
00159 : BaseElementType(source),
00160 Group(source),
00161 position_range_(source.position_range_),
00162 intensity_range_(source.intensity_range_)
00163 {}
00164
00166 ConsensusFeature& operator=(const ConsensusFeature& source)
00167 {
00168 if (&source==this)
00169 return *this;
00170
00171 Group::operator=(source);
00172 BaseElementType::operator=(source);
00173 position_range_=source.position_range_;
00174 intensity_range_=source.intensity_range_;
00175
00176 return *this;
00177 }
00178
00180 virtual ~ConsensusFeature()
00181 {}
00183
00184
00185 void insert(const IndexTuple& tuple)
00186 {
00187 Group::insert(tuple);
00188
00189 computeConsensus_();
00190 }
00191
00193 inline const PositionBoundingBoxType& getPositionRange() const
00194 {
00195 return position_range_;
00196 }
00198 inline PositionBoundingBoxType& getPositionRange()
00199 {
00200 return position_range_;
00201 }
00203 inline void setPositionRange(const PositionBoundingBoxType& p)
00204 {
00205 position_range_= p;
00206 }
00207
00209 inline const IntensityBoundingBoxType& getIntensityRange() const
00210 {
00211 return intensity_range_;
00212 }
00214 inline IntensityBoundingBoxType& getIntensityRange()
00215 {
00216 return intensity_range_;
00217 }
00219 inline void setIntensityRange(const IntensityBoundingBoxType& i)
00220 {
00221 intensity_range_ = i;
00222 }
00223
00225 inline const Group& getFeatures() const
00226 {
00227 return *this;
00228 }
00230 inline Group& getFeatures()
00231 {
00232 return *this;
00233 }
00235 inline void setFeatures(const Group& g)
00236 {
00237 Group::operator=(g);
00238 }
00239
00240
00241 protected:
00242 PositionBoundingBoxType position_range_;
00243 IntensityBoundingBoxType intensity_range_;
00244
00245
00246 void computeConsensus_()
00247 {
00248 unsigned int n = Group::size();
00249 DPosition<2> sum_position;
00250 DPosition<2> pos_min(std::numeric_limits<DoubleReal>::max());
00251 DPosition<2> pos_max(std::numeric_limits<DoubleReal>::min());
00252 DPosition<1> sum_intensities = 0;
00253 DPosition<1> int_min(std::numeric_limits<DoubleReal>::max());
00254 DPosition<1> int_max(std::numeric_limits<DoubleReal>::min());
00255 for (typename Group::const_iterator it = Group::begin(); it != Group::end(); ++it)
00256 {
00257 DPosition<1> act_int = (it->getElement()).getIntensity();
00258 DPosition<2> act_pos = it->getTransformedPosition();
00259
00260 if (int_min > act_int)
00261 {
00262 int_min = act_int;
00263 }
00264 if (int_max < act_int)
00265 {
00266 int_max = act_int;
00267 }
00268
00269 for (UInt dim=0; dim < 2; ++dim)
00270 {
00271 if (act_pos[dim] > pos_max[dim])
00272 pos_max[dim] = act_pos[dim];
00273 if (act_pos[dim] < pos_min[dim])
00274 pos_min[dim] = act_pos[dim];
00275 }
00276
00277 sum_intensities += act_int;
00278 sum_position += act_pos;
00279 }
00280
00281 for (UInt dim = 0; dim< 2 ; ++dim)
00282 {
00283 this->position_[dim] = sum_position[dim] / n;
00284 }
00285 this->intensity_ = sum_intensities[0] / n;
00286
00287 intensity_range_.setMinMax(int_min,int_max);
00288 position_range_.setMinMax(pos_min,pos_max);
00289 }
00290 };
00291
00293 template < typename ContainerT >
00294 std::ostream& operator << (std::ostream& os, const ConsensusFeature<ContainerT>& cons)
00295 {
00296 os << "---------- CONSENSUS ELEMENT BEGIN -----------------\n";
00297 os << "Position: " << cons.getPosition()<< std::endl;
00298 os << "Intensity " << cons.getIntensity() << std::endl;
00299 os << "Position range " << cons.getPositionRange() << std::endl;
00300 os << "Intensity range " << cons.getIntensityRange() << std::endl;
00301 os << "Grouped elements: " << std::endl;
00302
00303 unsigned int i = 1;
00304 os << "Size " << cons.count() << std::endl;
00305 for (typename ConsensusFeature<ContainerT>::Group::const_iterator it = cons.begin(); it != cons.end(); ++it, ++i)
00306 {
00307 os << "Element: " << i << std::endl;
00308 os << "Map index: " << it->getMapIndex() << " feature index " << it->getElementIndex() << std::endl;
00309 os << "Transformed Position: " << it->getTransformedPosition() << std::endl;
00310 os << "Original Position: " << it->getElement() << std::endl;
00311 }
00312 os << "---------- CONSENSUS ELEMENT END ----------------- " << std::endl;
00313
00314 return os;
00315 }
00316
00317 }
00318
00319 #endif // OPENMS_KERNEL_DFEATURE_H