47 template <
typename SpectrumType>
52 windowsize_ = (double)param_.getValue(
"windowsize");
53 peakcount_ = (
UInt)param_.getValue(
"peakcount");
61 std::set<double> positions;
62 for (ConstIterator it = old_spectrum.begin(); it != old_spectrum.end(); ++it)
66 for (ConstIterator it2 = it; (it2->getPosition() - it->getPosition() < windowsize_); )
68 window.push_back(*it2);
69 if (++it2 == old_spectrum.end())
78 for (
Size i = 0; i < peakcount_; ++i)
80 if (i < window.size())
82 positions.insert(window[i].getMZ());
90 std::vector<Size> indices;
91 for (ConstIterator it = spectrum.begin(); it != spectrum.end(); ++it)
93 if (positions.find(it->getMZ()) != positions.end())
95 Size index(it - spectrum.begin());
96 indices.push_back(index);
107 template <
typename SpectrumType>
110 if (spectrum.empty())
117 windowsize_ =
static_cast<double>(param_.getValue(
"windowsize"));
118 peakcount_ =
static_cast<UInt>(param_.getValue(
"peakcount"));
125 double window_start = spectrum[0].getMZ();
126 for (
Size i = 0; i != spectrum.size(); ++i)
128 if (spectrum[i].getMZ() - window_start < windowsize_)
130 peaks_in_window.push_back(spectrum[i]);
134 window_start = spectrum[i].getMZ();
137 if (peaks_in_window.size() > peakcount_)
139 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);});
140 copy(peaks_in_window.begin(), peaks_in_window.begin() + peakcount_, back_inserter(out));
144 std::sort(peaks_in_window.begin(), peaks_in_window.end(), [](
auto &left,
auto &right) {typename SpectrumType::PeakType::IntensityLess cmp; return cmp(right, left);});
145 copy(peaks_in_window.begin(), peaks_in_window.end(), back_inserter(out));
148 peaks_in_window.
clear(
false);
149 peaks_in_window.push_back(spectrum[i]);
153 if (!peaks_in_window.empty())
159 double last_window_size = peaks_in_window.back().getMZ() - window_start;
160 double last_window_size_fraction = last_window_size / windowsize_;
161 Size last_window_peakcount =
static_cast<Size>(
std::round(last_window_size_fraction * peakcount_));
163 if (peaks_in_window.size() > last_window_peakcount)
165 std::partial_sort(peaks_in_window.begin(), peaks_in_window.begin() + last_window_peakcount, peaks_in_window.end(),
166 [](
auto &left,
auto &right) {typename SpectrumType::PeakType::IntensityLess cmp; return cmp(right, left);});
167 std::copy(peaks_in_window.begin(), peaks_in_window.begin() + last_window_peakcount, back_inserter(out));
171 std::copy(peaks_in_window.begin(), peaks_in_window.end(), std::back_inserter(out));
176 std::vector<Size> indices;
179 if (std::find(out.begin(), out.end(), *it) != out.end())
181 Size index(it - spectrum.begin());
182 indices.push_back(index);
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:66
In-Memory representation of a mass spectrometry run.
Definition: MSExperiment.h:46
The representation of a 1D spectrum.
Definition: MSSpectrum.h:44
ContainerType::const_iterator ConstIterator
Non-mutable iterator.
Definition: MSSpectrum.h:110
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:30
void filterPeakSpectrumForTopNInJumpingWindow(SpectrumType &spectrum)
Definition: WindowMower.h:108
void filterPeakSpectrum(PeakSpectrum &spectrum)
WindowMower(const WindowMower &source)
copy constructor
void filterPeakMap(PeakMap &exp)
WindowMower()
default constructor
double windowsize_
Definition: WindowMower.h:193
void filterPeakSpectrumForTopNInSlidingWindow(SpectrumType &spectrum)
sliding window version (slower)
Definition: WindowMower.h:48
UInt peakcount_
Definition: WindowMower.h:194
~WindowMower() override
destructor
WindowMower & operator=(const WindowMower &source)
assignment operator
unsigned int UInt
Unsigned integer type.
Definition: Types.h:68
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:101
T round(T x)
Rounds the value.
Definition: MathFunctions.h:184
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:22