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_TRANSFORMATIONS_FEATUREFINDER_FEATUREFINDERALGORITHMSIMPLE_H
00028 #define OPENMS_TRANSFORMATIONS_FEATUREFINDER_FEATUREFINDERALGORITHMSIMPLE_H
00029
00030 #include <OpenMS/TRANSFORMATIONS/FEATUREFINDER/FeatureFinderAlgorithm.h>
00031
00032 #include <OpenMS/TRANSFORMATIONS/FEATUREFINDER/SimpleSeeder.h>
00033 #include <OpenMS/TRANSFORMATIONS/FEATUREFINDER/SimpleExtender.h>
00034 #include <OpenMS/TRANSFORMATIONS/FEATUREFINDER/ModelFitter.h>
00035
00036 namespace OpenMS
00037 {
00047 template<class PeakType, class FeatureType> class FeatureFinderAlgorithmSimple :
00048 public FeatureFinderAlgorithm<PeakType, FeatureType>,
00049 public FeatureFinderDefs
00050 {
00051
00052 public:
00054 FeatureFinderAlgorithmSimple() :
00055 FeatureFinderAlgorithm<PeakType,FeatureType>()
00056 {
00057 this->defaults_ = getDefaultParameters();
00058 this->check_defaults_ = false;
00059 }
00060
00061 virtual Param getDefaultParameters() const
00062 {
00063 Param tmp;
00064
00065 SimpleSeeder<PeakType,FeatureType> seeder(this->map_, this->features_, this->ff_);
00066 tmp.insert("seeder:", seeder.getParameters());
00067 tmp.setSectionDescription("seeder", "Settings for the seeder (Determines potential feature regions)");
00068
00069 SimpleExtender<PeakType,FeatureType> extender(this->map_, this->features_, this->ff_);
00070 tmp.insert("extender:", extender.getParameters());
00071 tmp.setSectionDescription("extender", "Settings for the extender (Collects all peaks belonging to a feature)");
00072
00073 ModelFitter<PeakType,FeatureType> fitter(this->map_, this->features_, this->ff_);
00074 tmp.insert("fitter:", fitter.getParameters());
00075 tmp.setSectionDescription("fitter", "Settings for the modefitter (Fits a model to the data determinging the probapility that they represent a feature.)");
00076
00077 return tmp;
00078 }
00079
00080 virtual void run()
00081 {
00082 UInt seed_nr=1;
00083
00084 SimpleSeeder<PeakType,FeatureType> seeder(this->map_, this->features_, this->ff_);
00085 seeder.setParameters(this->getParameters().copy("seeder:",true));
00086
00087 SimpleExtender<PeakType,FeatureType> extender(this->map_, this->features_, this->ff_);
00088 extender.setParameters(this->getParameters().copy("extender:",true));
00089
00090 ModelFitter<PeakType,FeatureType> fitter(this->map_, this->features_, this->ff_);
00091 Param params;
00092 params.setDefaults(this->getParameters().copy("fitter:",true));
00093 params.setValue("fit_algorithm", "simple");
00094 fitter.setParameters(params);
00095
00097 struct Summary
00098 {
00099 std::map<String,UInt> exception;
00100 UInt no_exceptions;
00101 std::map<String,UInt> mz_model;
00102 std::map<float,UInt> mz_stdev;
00103 std::vector<UInt> charge;
00104 DoubleReal corr_mean, corr_max, corr_min;
00105
00107 Summary() :
00108 no_exceptions(0),
00109 corr_mean(0),
00110 corr_max(0),
00111 corr_min(1)
00112 {}
00113
00114 } summary;
00115
00116 try
00117 {
00118 for(;;)
00119 {
00120
00121 std::cout << "===============================" << std::endl;
00122
00123 std::cout << "### Seeder (seed # " << ++seed_nr << ")..." << std::endl;
00124 IndexPair seed = seeder.nextSeed();
00125
00126 std::cout << "seed ... " << seed.first << " - " << seed.second << std::endl;
00127
00128
00129 std::cout << "### Extender..." << std::endl;
00130 ChargedIndexSet index_set;
00131 index_set.insert(seed);
00132 ChargedIndexSet region;
00133 extender.extend(index_set, region);
00134
00135 std::cout << "### ModelFitter..." << std::endl;
00136 try
00137 {
00138 this->features_->push_back(fitter.fit(region));
00139
00140
00141 {
00142 const Feature& f = this->features_->back();
00143
00144
00145 DoubleReal corr = f.getOverallQuality();
00146 summary.corr_mean += corr;
00147 if (corr<summary.corr_min) summary.corr_min = corr;
00148 if (corr>summary.corr_max) summary.corr_max = corr;
00149
00150
00151 UInt ch = f.getCharge();
00152 if (ch>= summary.charge.size())
00153 {
00154 summary.charge.resize(ch+1);
00155 }
00156 summary.charge[ch]++;
00157
00158
00159 const Param& p = f.getModelDescription().getParam();
00160 ++summary.mz_model[ p.getValue("MZ") ];
00161
00162
00163 if (p.exists("MZ:isotope:stdev") && p.getValue("MZ:isotope:stdev")!=DataValue::EMPTY)
00164 {
00165 ++summary.mz_stdev[p.getValue("MZ:isotope:stdev")];
00166 }
00167 }
00168 }
00169 catch( UnableToFit ex)
00170 {
00171 std::cout << "UnableToFit: " << ex.what() << std::endl;
00172
00173
00174 for (IndexSet::const_iterator it=region.begin(); it!=region.end(); ++it)
00175 {
00176 this->ff_->getPeakFlag(*it) = UNUSED;
00177 }
00178
00179
00180 {
00181 ++summary.no_exceptions;
00182 ++summary.exception[ex.getName()];
00183 }
00184 }
00185 }
00186 }
00187 catch(NoSuccessor ex)
00188 {
00189 }
00190
00191 {
00192 UInt size = this->features_->size();
00193 std::cout << size << " features were found. " << std::endl;
00194
00195
00196 summary.corr_mean /= size;
00197
00198 std::cout << "FeatureFinder summary:\n"
00199 << "Correlation:\n\tminimum: " << summary.corr_min << "\n\tmean: " << summary.corr_mean
00200 << "\n\tmaximum: " << summary.corr_max << std::endl;
00201
00202 std::cout << "Exceptions:\n";
00203 for (std::map<String,UInt>::const_iterator it=summary.exception.begin(); it!=summary.exception.end(); ++it)
00204 {
00205 std::cout << "\t" << it->first << ": " << it->second*100/summary.no_exceptions << "% (" << it->second << ")\n";
00206 }
00207
00208 std::cout << "Chosen mz models:\n";
00209 for (std::map<String,UInt>::const_iterator it=summary.mz_model.begin(); it!=summary.mz_model.end(); ++it)
00210 {
00211 std::cout << "\t" << it->first << ": " << it->second*100/size << "% (" << it->second << ")\n";
00212 }
00213
00214 std::cout << "Chosen mz stdevs:\n";
00215 for (std::map<float,UInt>::const_iterator it=summary.mz_stdev.begin(); it!=summary.mz_stdev.end(); ++it)
00216 {
00217 std::cout << "\t" << it->first << ": " << it->second*100/(size-summary.charge[0]) << "% (" << it->second << ")\n";
00218 }
00219
00220 std::cout << "Charges:\n";
00221 for (UInt i=1; i<summary.charge.size(); ++i)
00222 {
00223 if (summary.charge[i]!=0)
00224 {
00225 std::cout << "\t+" << i << ": " << summary.charge[i]*100/(size-summary.charge[0]) << "% (" << summary.charge[i] << ")\n";
00226 }
00227 }
00228 }
00229 return;
00230 }
00231
00232 static FeatureFinderAlgorithm<PeakType,FeatureType>* create()
00233 {
00234 return new FeatureFinderAlgorithmSimple();
00235 }
00236
00237 static const String getProductName()
00238 {
00239 return "simple";
00240 }
00241 private:
00243 FeatureFinderAlgorithmSimple& operator=(const FeatureFinderAlgorithmSimple&);
00245 FeatureFinderAlgorithmSimple(const FeatureFinderAlgorithmSimple&);
00246
00247 };
00248
00249 }
00250
00251 #endif // OPENMS_TRANSFORMATIONS_FEATUREFINDER_FEATUREFINDERALGORITHMSIMPLE_H