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_WINDOWMOWER_H
00028 #define OPENMS_FILTERING_TRANSFORMERS_WINDOWMOWER_H
00029
00030 #include <OpenMS/FILTERING/TRANSFORMERS/PreprocessingFunctor.h>
00031 #include <set>
00032
00033 namespace OpenMS
00034 {
00035
00043 class WindowMower
00044 : public PreprocessingFunctor
00045 {
00046 public:
00047
00048
00049
00051 WindowMower();
00052
00054 WindowMower(const WindowMower& source);
00055
00057 virtual ~WindowMower();
00058
00059
00060
00061
00063 WindowMower& operator = (const WindowMower& source);
00064
00065
00066
00067
00069 static PreprocessingFunctor* create() { return new WindowMower(); }
00070
00072 template <typename SpectrumType> void filterSpectrum(SpectrumType& spectrum)
00073 {
00074 typedef typename SpectrumType::Iterator Iterator;
00075 typedef typename SpectrumType::ConstIterator ConstIterator;
00076 typedef typename SpectrumType::ContainerType ContainerType;
00077
00078 double windowsize = (double)param_.getValue("windowsize");
00079 UInt peakcount = (int)param_.getValue("peakcount");
00080
00081 std::set<double> positions;
00082
00083 spectrum.getContainer().sortByPosition();
00084
00085
00086 bool end(false);
00087 for (ConstIterator it = spectrum.begin(); it != spectrum.end(); ++it)
00088 {
00089 ContainerType container;
00090 for (ConstIterator it2 = it; (it2->getPosition() - it->getPosition() < windowsize); )
00091 {
00092 container.push_back(*it2);
00093 if (++it2 == spectrum.end())
00094 {
00095 end = true;
00096 break;
00097 }
00098 }
00099
00100 container.sortByIntensity(true);
00101
00102 for (UInt i = 0; i < peakcount; ++i)
00103 {
00104 if (container.size() > i)
00105 {
00106 positions.insert(container[i].getMZ());
00107 }
00108 }
00109
00110 if (end)
00111 {
00112 break;
00113 }
00114 }
00115
00116
00117 ContainerType container;
00118 for (ConstIterator it = spectrum.begin(); it != spectrum.end(); ++it)
00119 {
00120 if (positions.find(it->getMZ()) != positions.end())
00121 {
00122 container.push_back(*it);
00123 }
00124 }
00125
00126
00127 spectrum.setContainer(container);
00128 }
00129
00130 void filterPeakSpectrum(PeakSpectrum& spectrum);
00131
00132 void filterPeakMap(PeakMap& exp);
00133
00135 static const String getProductName()
00136 {
00137 return "WindowMower";
00138 }
00139
00140
00141 };
00142
00143 }
00144
00145 #endif //OPENMS_FILTERING_TRANSFORMERS_WINDOWMOWER_H