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_FILTERING_TRANSFORMERS_BERNNORM_H
00028 #define OPENMS_FILTERING_TRANSFORMERS_BERNNORM_H
00029
00030 #include <OpenMS/FILTERING/TRANSFORMERS/PreprocessingFunctor.h>
00031 #include <map>
00032
00033 namespace OpenMS
00034 {
00046 class BernNorm
00047 : public PreprocessingFunctor
00048 {
00049 public:
00050
00051
00053
00054 BernNorm();
00055
00057 BernNorm(const BernNorm& source);
00058
00060 virtual ~BernNorm();
00062
00063
00064
00066 BernNorm& operator=(const BernNorm& source);
00067
00068
00069
00070
00072 static PreprocessingFunctor* create() { return new BernNorm(); }
00073
00075 template <typename SpectrumType> void filterSpectrum(SpectrumType& spectrum)
00076 {
00077 typedef typename SpectrumType::Iterator Iterator;
00078 typedef typename SpectrumType::ConstIterator ConstIterator;
00079
00080 double c1 = (double)param_.getValue("C1");
00081 double c2 = (double)param_.getValue("C2");
00082 double threshold = (double)param_.getValue("threshold");
00083
00084 spectrum.getContainer().sortByPosition();
00085
00086
00087 double maxint = 0;
00088 std::map<double, uint> peakranks;
00089 for (ConstIterator it = spectrum.begin(); it != spectrum.end(); ++it)
00090 {
00091 peakranks[it->getIntensity()] = 0;
00092 if (it->getIntensity() > maxint)
00093 {
00094 maxint = it->getIntensity();
00095 }
00096 }
00097 uint rank = 0;
00098 for (std::map<double, uint>::reverse_iterator mit = peakranks.rbegin(); mit != peakranks.rend(); ++mit)
00099 {
00100 mit->second = ++rank;
00101 }
00102
00103
00104 double maxmz = 0;
00105 for (int i = spectrum.size() -1 ; i >= 0 ; --i)
00106 {
00107 if (spectrum.getContainer()[i].getIntensity() > maxint * threshold)
00108 {
00109 maxmz = spectrum.getContainer()[i].getMZ();
00110 break;
00111 }
00112 }
00113
00114
00115 for (Iterator it = spectrum.begin() ; it != spectrum.end(); )
00116 {
00117 double newint = c1 - (c2 / maxmz) * peakranks[it->getIntensity()];
00118 if (newint < 0)
00119 {
00120 it = spectrum.getContainer().erase(it);
00121 }
00122 else
00123 {
00124 it->setIntensity(newint);
00125 ++it;
00126 }
00127 }
00128 return;
00129 }
00130
00131 void filterPeakSpectrum(PeakSpectrum& spectrum);
00132
00133 void filterPeakMap(PeakMap& exp);
00134
00136 static const String getProductName()
00137 {
00138 return "BernNorm";
00139 }
00140
00141
00142 };
00143
00144 }
00145
00146 #endif //OPENMS_FILTERING_TRANSFORMERS_BERNNORM_H