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
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef OPENMS_TRANSFORMATIONS_FEATUREFINDER_FEAFIMODULE_H
00036 #define OPENMS_TRANSFORMATIONS_FEATUREFINDER_FEAFIMODULE_H
00037
00038 #include <OpenMS/DATASTRUCTURES/DefaultParamHandler.h>
00039 #include <OpenMS/TRANSFORMATIONS/FEATUREFINDER/FeatureFinderDefs.h>
00040 #include <OpenMS/KERNEL/FeatureMap.h>
00041 #include <OpenMS/KERNEL/MSExperiment.h>
00042
00043 namespace OpenMS
00044 {
00045
00046 class FeatureFinder;
00047
00048 namespace Internal
00049 {
00050
00051
00055 template <typename FeaFiModuleType>
00056 struct IntensityLess :
00057 std::binary_function<typename FeatureFinderDefs::IndexPair, typename FeatureFinderDefs::IndexPair, bool>
00058 {
00060 IntensityLess(const FeaFiModuleType & module) :
00061 module_(module)
00062 {
00063 }
00064
00066 IntensityLess(const IntensityLess & rhs) :
00067 module_(rhs.module_)
00068 {
00069 }
00070
00072 inline bool operator()(const typename FeatureFinderDefs::IndexPair & left, const typename FeatureFinderDefs::IndexPair & right) const
00073 {
00074 return module_.getPeakIntensity(left) < module_.getPeakIntensity(right);
00075 }
00076
00077 private:
00079 const FeaFiModuleType & module_;
00081 IntensityLess();
00082 };
00083
00084
00085
00087 template <typename FeaFiModuleType>
00088 struct IntensityIterator :
00089 FeatureFinderDefs::IndexSet::const_iterator
00090 {
00091 IntensityIterator(const FeatureFinderDefs::IndexSet::const_iterator & iter, const FeaFiModuleType * module) :
00092 FeatureFinderDefs::IndexSet::const_iterator(iter),
00093 module_(module)
00094 {
00095 }
00096
00097 typename FeaFiModuleType::IntensityType operator*() const
00098 {
00099 return module_->getPeakIntensity(FeatureFinderDefs::IndexSet::const_iterator::operator*());
00100 }
00101
00102 protected:
00103 const FeaFiModuleType * module_;
00104 };
00105
00106
00107
00109 template <typename FeaFiModuleType>
00110 struct MzIterator :
00111 FeatureFinderDefs::IndexSet::const_iterator
00112 {
00113 MzIterator(const FeatureFinderDefs::IndexSet::const_iterator & iter, const FeaFiModuleType * module) :
00114 FeatureFinderDefs::IndexSet::const_iterator(iter),
00115 module_(module)
00116 {
00117 }
00118
00119 typename FeaFiModuleType::IntensityType operator*() const
00120 {
00121 return module_->getPeakMz(FeatureFinderDefs::IndexSet::const_iterator::operator*());
00122 }
00123
00124 protected:
00125 const FeaFiModuleType * module_;
00126 };
00127
00128
00129
00131 template <typename FeaFiModuleType>
00132 struct RtIterator :
00133 FeatureFinderDefs::IndexSet::const_iterator
00134 {
00135 RtIterator(const FeatureFinderDefs::IndexSet::const_iterator & iter, const FeaFiModuleType * module) :
00136 FeatureFinderDefs::IndexSet::const_iterator(iter),
00137 module_(module)
00138 {
00139 }
00140
00141 typename FeaFiModuleType::IntensityType operator*() const
00142 {
00143 return module_->getPeakRt(FeatureFinderDefs::IndexSet::const_iterator::operator*());
00144 }
00145
00146 protected:
00147 const FeaFiModuleType * module_;
00148 };
00149
00150
00151 }
00152
00156 template <class PeakType, class FeatureType>
00157 class FeaFiModule :
00158 public DefaultParamHandler
00159 {
00160 public:
00162 typedef FeatureMap<FeatureType> FeatureMapType;
00164 typedef MSExperiment<PeakType> MapType;
00166 typedef typename MapType::SpectrumType SpectrumType;
00168 typedef typename PeakType::IntensityType IntensityType;
00170 typedef typename PeakType::CoordinateType CoordinateType;
00171
00173 FeaFiModule(const MSExperiment<PeakType> * map, FeatureMap<FeatureType> * features, FeatureFinder * ff) :
00174 DefaultParamHandler("FeaFiModule"),
00175 map_(0),
00176 features_(0),
00177 ff_(0)
00178 {
00179 map_ = map;
00180 features_ = features;
00181 ff_ = ff;
00182 }
00183
00185 virtual ~FeaFiModule()
00186 {
00187 }
00188
00190 inline IntensityType getPeakIntensity(const FeatureFinderDefs::IndexPair & index) const
00191 {
00192
00193 OPENMS_PRECONDITION(index.first < map_->size(), "Scan index outside of map!");
00194 OPENMS_PRECONDITION(index.second < (*map_)[index.first].size(), "Peak index outside of scan!");
00195
00196 return (*map_)[index.first][index.second].getIntensity();
00197 }
00198
00200 inline CoordinateType getPeakMz(const FeatureFinderDefs::IndexPair & index) const
00201 {
00202
00203 OPENMS_PRECONDITION(index.first < map_->size(), "Scan index outside of map!");
00204 OPENMS_PRECONDITION(index.second < (*map_)[index.first].size(), "Peak index outside of scan!");
00205
00206 return (*map_)[index.first][index.second].getMZ();
00207 }
00208
00210 inline CoordinateType getPeakRt(const FeatureFinderDefs::IndexPair & index) const
00211 {
00212
00213 OPENMS_PRECONDITION(index.first < map_->size(), "Scan index outside of map!");
00214 OPENMS_PRECONDITION(index.second < (*map_)[index.first].size(), "Peak index outside of scan!");
00215
00216 return (*map_)[index.first].getRT();
00217 }
00218
00225 inline void getNextMz(FeatureFinderDefs::IndexPair & index) const
00226 {
00227
00228 OPENMS_PRECONDITION(index.first < map_->size(), "Scan index outside of map!");
00229 OPENMS_PRECONDITION(index.second < (*map_)[index.first].size(), "Peak index outside of scan!");
00230
00231
00232 if (index.second + 1 >= (*map_)[index.first].size())
00233 {
00234 throw FeatureFinderDefs::NoSuccessor(__FILE__, __LINE__, "FeatureFinder::getNextMz", index);
00235 }
00236
00237 ++index.second;
00238 }
00239
00246 inline void getPrevMz(FeatureFinderDefs::IndexPair & index) const
00247 {
00248
00249 OPENMS_PRECONDITION(index.first < map_->size(), "Scan index outside of map!");
00250 OPENMS_PRECONDITION(index.second < (*map_)[index.first].size(), "Peak index outside of scan!");
00251
00252
00253 if (index.second == 0)
00254 {
00255 throw FeatureFinderDefs::NoSuccessor(__FILE__, __LINE__, "FeatureFinder::getPrevMz", index);
00256 }
00257
00258 --index.second;
00259 }
00260
00267 void getNextRt(FeatureFinderDefs::IndexPair & index)
00268 {
00269
00270 OPENMS_PRECONDITION(index.first < map_->size(), "Scan index outside of map!");
00271 OPENMS_PRECONDITION(index.second < (*map_)[index.first].size(), "Peak index outside of scan!");
00272
00273 CoordinateType mz_pos = (*map_)[index.first][index.second].getMZ();
00274 Size index_first_tmp = index.first;
00275
00276 ++index.first;
00277 while (index.first < map_->size() &&
00278 (*map_)[index.first].empty())
00279 {
00280 ++index.first;
00281 }
00282
00283 if (index.first >= map_->size())
00284 {
00285 throw FeatureFinderDefs::NoSuccessor(__FILE__, __LINE__, "FeatureFinder::getNextRt", index);
00286 }
00287
00288
00289
00290 typename SpectrumType::ConstIterator it = lower_bound((*map_)[index.first].begin(), (*map_)[index.first].end(), (*map_)[index_first_tmp][index.second], typename PeakType::PositionLess());
00291
00292
00293 if (it == (*map_)[index.first].end())
00294 {
00295 index.second = (*map_)[index.first].size() - 1;
00296 }
00297
00298 else if (it == (*map_)[index.first].begin())
00299 {
00300 index.second = 0;
00301 }
00302
00303 else
00304 {
00305
00306 if (it->getMZ() - mz_pos < mz_pos - (it - 1)->getMZ())
00307 {
00308 index.second = it - (*map_)[index.first].begin();
00309 }
00310 else
00311 {
00312 index.second = --it - (*map_)[index.first].begin();
00313 }
00314 }
00315 }
00316
00323 void getPrevRt(FeatureFinderDefs::IndexPair & index)
00324 {
00325
00326 OPENMS_PRECONDITION(index.first < map_->size(), "Scan index outside of map!");
00327 OPENMS_PRECONDITION(index.second < (*map_)[index.first].size(), "Peak index outside of scan!");
00328
00329
00330 if (index.first >= map_->size())
00331 {
00332 std::cout << "Scan index outside of map!" << std::endl;
00333 std::cout << index.first << " " << index.second << std::endl;
00334 return;
00335 }
00336 if (index.second >= (*map_)[index.first].size())
00337 {
00338 std::cout << "Peak index outside of scan!" << std::endl;
00339 std::cout << index.first << " " << index.second << std::endl;
00340 return;
00341 }
00342
00343 CoordinateType mz_pos = (*map_)[index.first][index.second].getMZ();
00344 Size index_first_tmp = index.first;
00345
00346
00347 if (index.first == 0)
00348 {
00349 throw FeatureFinderDefs::NoSuccessor(__FILE__, __LINE__, "FeatureFinder::getPrevRt", index);
00350 }
00351
00352 --index.first;
00353 while ((index.first > 0) && ((*map_)[index.first].empty()))
00354 {
00355 --index.first;
00356 }
00357
00358 if ((*map_)[index.first].empty()) throw FeatureFinderDefs::NoSuccessor(__FILE__, __LINE__, "FeatureFinder::getPrevRt", index);
00359
00360
00361
00362 typename MapType::SpectrumType::ConstIterator it = lower_bound((*map_)[index.first].begin(),
00363 (*map_)[index.first].end(),
00364 (*map_)[index_first_tmp][index.second],
00365 typename PeakType::PositionLess());
00366
00367
00368 if (it == (*map_)[index.first].end())
00369 {
00370 index.second = (*map_)[index.first].size() - 1;
00371 }
00372
00373 else if (it == (*map_)[index.first].begin())
00374 {
00375 index.second = 0;
00376 }
00377
00378 else
00379 {
00380
00381 if (it->getMZ() - mz_pos < mz_pos - (it - 1)->getMZ())
00382 {
00383 index.second = it - (*map_)[index.first].begin();
00384 }
00385 else
00386 {
00387 index.second = --it - (*map_)[index.first].begin();
00388 }
00389 }
00390 }
00391
00393 void addConvexHull(const FeatureFinderDefs::IndexSet & set, Feature & feature) const
00394 {
00395 std::vector<DPosition<2> > points;
00396 points.reserve(set.size());
00397 DPosition<2> tmp;
00398 for (FeatureFinderDefs::IndexSet::const_iterator it = set.begin(); it != set.end(); ++it)
00399 {
00400 tmp[Peak2D::MZ] = (*map_)[it->first][it->second].getMZ();
00401 tmp[Peak2D::RT] = (*map_)[it->first].getRT();
00402 points.push_back(tmp);
00403 }
00404 feature.getConvexHulls().resize(feature.getConvexHulls().size() + 1);
00405
00406 feature.getConvexHulls().back().addPoints(points);
00407 }
00408
00409 protected:
00411 const MapType * map_;
00413 FeatureMapType * features_;
00415 FeatureFinder * ff_;
00416
00417 private:
00419 FeaFiModule();
00421 FeaFiModule & operator=(const FeaFiModule &);
00423 FeaFiModule(const FeaFiModule &);
00424
00425 };
00426
00427 }
00428
00429 #endif // OPENMS_TRANSFORMATIONS_FEATUREFINDER_FEAFIMODULE_H