73 template <
typename SpectrumType>
78 windowsize_ = (double)param_.getValue(
"windowsize");
79 peakcount_ = (
UInt)param_.getValue(
"peakcount");
87 std::set<double> positions;
88 for (ConstIterator it = old_spectrum.begin(); it != old_spectrum.end(); ++it)
92 for (ConstIterator it2 = it; (it2->getPosition() - it->getPosition() < windowsize_); )
94 window.push_back(*it2);
95 if (++it2 == old_spectrum.end())
104 for (
Size i = 0; i < peakcount_; ++i)
106 if (i < window.size())
108 positions.insert(window[i].getMZ());
116 std::vector<Size> indices;
117 for (ConstIterator it = spectrum.begin(); it != spectrum.end(); ++it)
119 if (positions.find(it->getMZ()) != positions.end())
121 Size index(it - spectrum.begin());
122 indices.push_back(index);
133 template <
typename SpectrumType>
136 if (spectrum.empty())
143 windowsize_ =
static_cast<double>(param_.getValue(
"windowsize"));
144 peakcount_ =
static_cast<UInt>(param_.getValue(
"peakcount"));
151 double window_start = spectrum[0].getMZ();
152 for (
Size i = 0; i != spectrum.size(); ++i)
154 if (spectrum[i].getMZ() - window_start < windowsize_)
156 peaks_in_window.push_back(spectrum[i]);
160 window_start = spectrum[i].getMZ();
163 if (peaks_in_window.size() > peakcount_)
165 std::partial_sort(peaks_in_window.begin(), peaks_in_window.begin() + peakcount_, peaks_in_window.end(), [](
auto &left,
auto &right) {typename SpectrumType::PeakType::IntensityLess cmp; return cmp(right, left);});
166 copy(peaks_in_window.begin(), peaks_in_window.begin() + peakcount_, back_inserter(out));
170 std::sort(peaks_in_window.begin(), peaks_in_window.end(), [](
auto &left,
auto &right) {typename SpectrumType::PeakType::IntensityLess cmp; return cmp(right, left);});
171 copy(peaks_in_window.begin(), peaks_in_window.end(), back_inserter(out));
174 peaks_in_window.
clear(
false);
175 peaks_in_window.push_back(spectrum[i]);
179 if (!peaks_in_window.empty())
185 double last_window_size = peaks_in_window.back().getMZ() - window_start;
186 double last_window_size_fraction = last_window_size / windowsize_;
187 Size last_window_peakcount =
static_cast<Size>(
std::round(last_window_size_fraction * peakcount_));
189 if (peaks_in_window.size() > last_window_peakcount)
191 std::partial_sort(peaks_in_window.begin(), peaks_in_window.begin() + last_window_peakcount, peaks_in_window.end(),
192 [](
auto &left,
auto &right) {typename SpectrumType::PeakType::IntensityLess cmp; return cmp(right, left);});
193 std::copy(peaks_in_window.begin(), peaks_in_window.begin() + last_window_peakcount, back_inserter(out));
197 std::copy(peaks_in_window.begin(), peaks_in_window.end(), std::back_inserter(out));
202 std::vector<Size> indices;
205 if (std::find(out.begin(), out.end(), *it) != out.end())
207 Size index(it - spectrum.begin());
208 indices.push_back(index);
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:92
In-Memory representation of a mass spectrometry run.
Definition: MSExperiment.h:72
The representation of a 1D spectrum.
Definition: MSSpectrum.h:70
ContainerType::const_iterator ConstIterator
Non-mutable iterator.
Definition: MSSpectrum.h:136
MSSpectrum & select(const std::vector< Size > &indices)
void sortByPosition()
Lexicographically sorts the peaks by their position.
void sortByIntensity(bool reverse=false)
Lexicographically sorts the peaks by their intensity.
void clear(bool clear_meta_data)
Clears all data and meta data.
WindowMower augments the highest peaks in a sliding or jumping window.
Definition: WindowMower.h:56
void filterPeakSpectrumForTopNInJumpingWindow(SpectrumType &spectrum)
Definition: WindowMower.h:134
void filterPeakSpectrum(PeakSpectrum &spectrum)
WindowMower(const WindowMower &source)
copy constructor
void filterPeakMap(PeakMap &exp)
WindowMower()
default constructor
double windowsize_
Definition: WindowMower.h:219
void filterPeakSpectrumForTopNInSlidingWindow(SpectrumType &spectrum)
sliding window version (slower)
Definition: WindowMower.h:74
UInt peakcount_
Definition: WindowMower.h:220
~WindowMower() override
destructor
WindowMower & operator=(const WindowMower &source)
assignment operator
unsigned int UInt
Unsigned integer type.
Definition: Types.h:94
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
T round(T x)
Rounds the value.
Definition: MathFunctions.h:210
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:48