35 #ifndef OPENMS_FILTERING_TRANSFORMERS_WINDOWMOWER_H
36 #define OPENMS_FILTERING_TRANSFORMERS_WINDOWMOWER_H
72 template <
typename SpectrumType>
75 typedef typename SpectrumType::ConstIterator ConstIterator;
77 windowsize_ = (
double)param_.getValue(
"windowsize");
78 peakcount_ = (
UInt)param_.getValue(
"peakcount");
81 SpectrumType old_spectrum = spectrum;
82 old_spectrum.sortByPosition();
86 std::set<double> positions;
87 for (ConstIterator it = old_spectrum.begin(); it != old_spectrum.end(); ++it)
91 for (ConstIterator it2 = it; (it2->getPosition() - it->getPosition() < windowsize_); )
93 window.push_back(*it2);
94 if (++it2 == old_spectrum.end())
102 window.sortByIntensity(
true);
103 for (
Size i = 0; i < peakcount_; ++i)
105 if (i < window.size())
107 positions.insert(window[i].getMZ());
115 spectrum.clear(
false);
116 for (ConstIterator it = old_spectrum.begin(); it != old_spectrum.end(); ++it)
118 if (positions.find(it->getMZ()) != positions.end())
120 spectrum.push_back(*it);
127 void filterPeakMap(
PeakMap& exp);
130 template <
typename SpectrumType>
133 if (spectrum.empty())
138 spectrum.sortByPosition();
140 windowsize_ =
static_cast<double>(param_.getValue(
"windowsize"));
141 peakcount_ =
static_cast<UInt>(param_.getValue(
"peakcount"));
144 SpectrumType out = spectrum;
147 SpectrumType peaks_in_window;
148 double window_start = spectrum[0].getMZ();
149 for (
Size i = 0; i != spectrum.size(); ++i)
151 if (spectrum[i].getMZ() - window_start < windowsize_)
153 peaks_in_window.push_back(spectrum[i]);
157 window_start = spectrum[i].getMZ();
160 if (peaks_in_window.size() > peakcount_)
162 std::partial_sort(peaks_in_window.begin(), peaks_in_window.begin() + peakcount_, peaks_in_window.end(),
reverseComparator(
typename SpectrumType::PeakType::IntensityLess()));
163 copy(peaks_in_window.begin(), peaks_in_window.begin() + peakcount_, back_inserter(out));
167 std::sort(peaks_in_window.begin(), peaks_in_window.end(),
reverseComparator(
typename SpectrumType::PeakType::IntensityLess()));
168 copy(peaks_in_window.begin(), peaks_in_window.end(), back_inserter(out));
171 peaks_in_window.clear(
false);
172 peaks_in_window.push_back(spectrum[i]);
176 if (peaks_in_window.empty())
178 out.sortByPosition();
187 double last_window_size = peaks_in_window.back().getMZ() - window_start;
188 double last_window_size_fraction = last_window_size / windowsize_;
189 Size last_window_peakcount = last_window_size_fraction * peakcount_;
191 if (last_window_peakcount)
193 last_window_peakcount = 1;
197 std::partial_sort(peaks_in_window.begin(), peaks_in_window.begin() + last_window_peakcount, peaks_in_window.end(),
reverseComparator(
typename SpectrumType::PeakType::IntensityLess()));
199 if (peaks_in_window.size() > last_window_peakcount)
201 std::copy(peaks_in_window.begin(), peaks_in_window.begin() + last_window_peakcount, back_inserter(out));
205 std::copy(peaks_in_window.begin(), peaks_in_window.end(), std::back_inserter(out));
208 out.sortByPosition();
222 #endif //OPENMS_FILTERING_TRANSFORMERS_WINDOWMOWER_H
WindowMower augments the highest peaks in a sliding or jumping window.
Definition: WindowMower.h:53
unsigned int UInt
Unsigned integer type.
Definition: Types.h:88
ReverseComparator< Cmp > reverseComparator(Cmp const &cmp)
Make-function to create a ReverseComparator from another comparator without the need to specify the t...
Definition: ComparatorUtils.h:261
void filterPeakSpectrumForTopNInSlidingWindow(SpectrumType &spectrum)
sliding window version (slower)
Definition: WindowMower.h:73
void filterPeakSpectrumForTopNInJumpingWindow(SpectrumType &spectrum)
Definition: WindowMower.h:131
UInt peakcount_
Definition: WindowMower.h:217
double windowsize_
Definition: WindowMower.h:216
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:92