Go to the documentation of this file.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 #include <OpenMS/TRANSFORMATIONS/FEATUREFINDER/FeatureFinder.h>
00036
00037 #ifndef OPENMS_TRANSFORMATIONS_FEATUREFINDER_SIMPLESEEDER_H
00038 #define OPENMS_TRANSFORMATIONS_FEATUREFINDER_SIMPLESEEDER_H
00039
00040 #include <OpenMS/CONCEPT/Exception.h>
00041 #include <OpenMS/TRANSFORMATIONS/FEATUREFINDER/FeaFiModule.h>
00042 #include <OpenMS/FILTERING/NOISEESTIMATION/SignalToNoiseEstimatorMedian.h>
00043
00044 #include <algorithm>
00045 #include <vector>
00046 #include <iostream>
00047
00048 namespace OpenMS
00049 {
00060 template <class PeakType, class FeatureType>
00061 class SimpleSeeder :
00062 public FeaFiModule<PeakType, FeatureType>,
00063 public FeatureFinderDefs
00064 {
00065 public:
00066 typedef FeaFiModule<PeakType, FeatureType> Base;
00067 typedef MSExperiment<PeakType> MapType;
00068
00070 SimpleSeeder(const MSExperiment<PeakType> * map, FeatureMap<FeatureType> * features, FeatureFinder * ff) :
00071 Base(map, features, ff),
00072 initialized_(false)
00073 {
00074 this->setName("SimpleSeeder");
00075
00076 this->defaults_.setValue("min_intensity", 0.0, "Absolute value for the minimum intensity required for a seed.");
00077 this->defaults_.setMinFloat("min_intensity", 0.0);
00078 this->defaults_.setValue("signal_to_noise", 10.0, "Minimal required SignalToNoise (S/N) ratio for a seed.");
00079 this->defaults_.setMinFloat("signal_to_noise", 0.0);
00080
00081
00082 SignalToNoiseEstimatorMedian<typename MapType::SpectrumType> sne;
00083 this->defaults_.insert("SignalToNoiseEstimationParameter:", sne.getDefaults());
00084
00085 this->defaultsToParam_();
00086 }
00087
00089 virtual ~SimpleSeeder()
00090 {
00091 }
00092
00094 IndexPair nextSeed()
00095 {
00096 if (!initialized_)
00097 {
00098 initialize_();
00099 }
00100
00101
00102 while (current_peak_ != indices_.end() && this->ff_->getPeakFlag(*current_peak_) == USED)
00103 {
00104 ++current_peak_;
00105 }
00106
00107 if (current_peak_ == indices_.end())
00108 {
00109
00110 if (indices_.empty()) throw NoSuccessor(__FILE__, __LINE__, __PRETTY_FUNCTION__, IndexPair());
00111 else throw NoSuccessor(__FILE__, __LINE__, __PRETTY_FUNCTION__, *(current_peak_ - 1));
00112 }
00113
00114 this->ff_->setProgress(current_peak_ - indices_.begin());
00115
00116
00117 this->ff_->getPeakFlag(*current_peak_) = USED;
00118
00119 return *(current_peak_++);
00120 }
00121
00122 protected:
00123
00124 void initialize_()
00125 {
00126
00127 typename FeatureType::IntensityType noise_threshold = this->param_.getValue("min_intensity");
00128 typename FeatureType::IntensityType sn = this->param_.getValue("signal_to_noise");
00129
00130 #ifdef DEBUG_FEATUREFINDER
00131 std::cout << "Intensity threshold: " << noise_threshold << std::endl;
00132 std::cout << "S/N: " << sn << std::endl;
00133 #endif
00134
00135
00136 IndexPair tmp = std::make_pair(0, 0);
00137 if (sn == 0)
00138 {
00139 while (tmp.first < (*this->map_).size())
00140 {
00141 tmp.second = 0;
00142 while (tmp.second < (*this->map_)[tmp.first].size())
00143 {
00144 if (this->getPeakIntensity(tmp) > noise_threshold)
00145 {
00146 indices_.push_back(tmp);
00147 }
00148 ++tmp.second;
00149 }
00150 ++tmp.first;
00151 }
00152 }
00153 else
00154 {
00155 SignalToNoiseEstimatorMedian<typename MapType::SpectrumType> estimator;
00156 Param param(this->param_.copy("SignalToNoiseEstimationParameter:", true));
00157 estimator.setParameters(param);
00158
00159 for (typename MapType::ConstIterator it = (*this->map_).begin(); it != (*this->map_).end(); ++it)
00160 {
00161 estimator.init(it->begin(), it->end());
00162 tmp.second = 0;
00163 for (typename MapType::SpectrumType::ConstIterator spec = it->begin(); spec != it->end(); ++spec)
00164 {
00165 if (estimator.getSignalToNoise(spec) > sn && this->getPeakIntensity(tmp) > noise_threshold)
00166 {
00167 indices_.push_back(tmp);
00168 }
00169 ++tmp.second;
00170 }
00171 ++tmp.first;
00172 }
00173 }
00174
00175 #ifdef DEBUG_FEATUREFINDER
00176 std::cout << "Number of peaks above threshold (" << noise_threshold << ") and S/N (" << sn << "): " << indices_.size() << std::endl;
00177 #endif
00178
00179
00180 sort(indices_.begin(), indices_.end(),
00181 reverseComparator(Internal::IntensityLess<Base>(*this))
00182 );
00183
00184
00185 this->ff_->startProgress(0, indices_.size(), "FeatureFinder");
00186
00187 current_peak_ = indices_.begin();
00188
00189 initialized_ = true;
00190 }
00191
00193 std::vector<IndexPair> indices_;
00194
00196 std::vector<IndexPair>::const_iterator current_peak_;
00197
00199 bool initialized_;
00200
00201 private:
00203 SimpleSeeder();
00205 SimpleSeeder & operator=(const SimpleSeeder &);
00207 SimpleSeeder(const SimpleSeeder &);
00208
00209 };
00210
00211 }
00212
00213 #endif // OPENMS_TRANSFORMATIONS_FEATUREFINDER_SIMPLESEEDER_H