35 #ifndef OPENMS_FILTERING_TRANSFORMERS_WINDOWMOWER_H 36 #define OPENMS_FILTERING_TRANSFORMERS_WINDOWMOWER_H 74 template <
typename SpectrumType>
79 windowsize_ = (
double)param_.getValue(
"windowsize");
80 peakcount_ = (
UInt)param_.getValue(
"peakcount");
88 std::set<double> positions;
89 for (ConstIterator it = old_spectrum.begin(); it != old_spectrum.end(); ++it)
93 for (ConstIterator it2 = it; (it2->getPosition() - it->getPosition() < windowsize_); )
95 window.push_back(*it2);
96 if (++it2 == old_spectrum.end())
105 for (
Size i = 0; i < peakcount_; ++i)
107 if (i < window.size())
109 positions.insert(window[i].getMZ());
117 std::vector<Size> indices;
118 for (ConstIterator it = spectrum.begin(); it != spectrum.end(); ++it)
120 if (positions.find(it->getMZ()) != positions.end())
122 Size index(it - spectrum.begin());
123 indices.push_back(index);
131 void filterPeakMap(
PeakMap& exp);
134 template <
typename SpectrumType>
137 if (spectrum.empty())
144 windowsize_ =
static_cast<double>(param_.getValue(
"windowsize"));
145 peakcount_ =
static_cast<UInt>(param_.getValue(
"peakcount"));
152 double window_start = spectrum[0].getMZ();
153 for (
Size i = 0; i != spectrum.size(); ++i)
155 if (spectrum[i].getMZ() - window_start < windowsize_)
157 peaks_in_window.push_back(spectrum[i]);
161 window_start = spectrum[i].getMZ();
164 if (peaks_in_window.size() > peakcount_)
166 std::partial_sort(peaks_in_window.begin(), peaks_in_window.begin() + peakcount_, peaks_in_window.end(),
reverseComparator(
typename SpectrumType::PeakType::IntensityLess()));
167 copy(peaks_in_window.begin(), peaks_in_window.begin() + peakcount_, back_inserter(out));
171 std::sort(peaks_in_window.begin(), peaks_in_window.end(),
reverseComparator(
typename SpectrumType::PeakType::IntensityLess()));
172 copy(peaks_in_window.begin(), peaks_in_window.end(), back_inserter(out));
175 peaks_in_window.
clear(
false);
176 peaks_in_window.push_back(spectrum[i]);
180 if (peaks_in_window.empty())
183 std::vector<Size> indices;
186 if (std::find(out.begin(), out.end(), *it) != out.end())
188 Size index(it - spectrum.begin());
189 indices.push_back(index);
200 double last_window_size = peaks_in_window.back().getMZ() - window_start;
201 double last_window_size_fraction = last_window_size / windowsize_;
202 Size last_window_peakcount = last_window_size_fraction * peakcount_;
204 if (last_window_peakcount)
206 last_window_peakcount = 1;
210 std::partial_sort(peaks_in_window.begin(), peaks_in_window.begin() + last_window_peakcount, peaks_in_window.end(),
reverseComparator(
typename SpectrumType::PeakType::IntensityLess()));
212 if (peaks_in_window.size() > last_window_peakcount)
214 std::copy(peaks_in_window.begin(), peaks_in_window.begin() + last_window_peakcount, back_inserter(out));
218 std::copy(peaks_in_window.begin(), peaks_in_window.end(), std::back_inserter(out));
222 std::vector<Size> indices;
225 if (std::find(out.begin(), out.end(), *it) != out.end())
227 Size index(it - spectrum.begin());
228 indices.push_back(index);
245 #endif //OPENMS_FILTERING_TRANSFORMERS_WINDOWMOWER_H WindowMower augments the highest peaks in a sliding or jumping window.
Definition: WindowMower.h:55
void sortByPosition()
Lexicographically sorts the peaks by their position.
unsigned int UInt
Unsigned integer type.
Definition: Types.h:95
ContainerType::const_iterator ConstIterator
Non-mutable iterator.
Definition: MSSpectrum.h:104
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:75
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
The representation of a 1D spectrum.
Definition: MSSpectrum.h:67
void filterPeakSpectrumForTopNInJumpingWindow(SpectrumType &spectrum)
Definition: WindowMower.h:135
void sortByIntensity(bool reverse=false)
Lexicographically sorts the peaks by their intensity.
UInt peakcount_
Definition: WindowMower.h:240
void clear(bool clear_meta_data)
Clears all data and meta data.
In-Memory representation of a mass spectrometry experiment.
Definition: MSExperiment.h:82
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:128
double windowsize_
Definition: WindowMower.h:239
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:92
MSSpectrum & select(const std::vector< Size > &indices)