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);
130 void filterPeakMap(
PeakMap& exp);
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(),
reverseComparator(
typename SpectrumType::PeakType::IntensityLess()));
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(),
reverseComparator(
typename SpectrumType::PeakType::IntensityLess()));
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())
182 std::vector<Size> indices;
185 if (
std::find(out.begin(), out.end(), *it) != out.end())
187 Size index(it - spectrum.begin());
188 indices.push_back(index);
199 double last_window_size = peaks_in_window.back().getMZ() - window_start;
200 double last_window_size_fraction = last_window_size / windowsize_;
201 Size last_window_peakcount = last_window_size_fraction * peakcount_;
203 if (last_window_peakcount)
205 last_window_peakcount = 1;
209 std::partial_sort(peaks_in_window.begin(), peaks_in_window.begin() + last_window_peakcount, peaks_in_window.end(),
reverseComparator(
typename SpectrumType::PeakType::IntensityLess()));
211 if (peaks_in_window.size() > last_window_peakcount)
213 std::copy(peaks_in_window.begin(), peaks_in_window.begin() + last_window_peakcount, back_inserter(out));
217 std::copy(peaks_in_window.begin(), peaks_in_window.end(), std::back_inserter(out));
221 std::vector<Size> indices;
224 if (
std::find(out.begin(), out.end(), *it) != out.end())
226 Size index(it - spectrum.begin());
227 indices.push_back(index);
WindowMower augments the highest peaks in a sliding or jumping window.
Definition: WindowMower.h:54
void sortByPosition()
Lexicographically sorts the peaks by their position.
unsigned int UInt
Unsigned integer type.
Definition: Types.h:94
ContainerType::const_iterator ConstIterator
Non-mutable iterator.
Definition: MSSpectrum.h:103
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:260
void filterPeakSpectrumForTopNInSlidingWindow(SpectrumType &spectrum)
sliding window version (slower)
Definition: WindowMower.h:74
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
bool find(TFinder &finder, const Pattern< TNeedle, FuzzyAC > &me, PatternAuxData< TNeedle > &dh)
Definition: AhoCorasickAmbiguous.h:884
The representation of a 1D spectrum.
Definition: MSSpectrum.h:66
void filterPeakSpectrumForTopNInJumpingWindow(SpectrumType &spectrum)
Definition: WindowMower.h:134
void sortByIntensity(bool reverse=false)
Lexicographically sorts the peaks by their intensity.
UInt peakcount_
Definition: WindowMower.h:239
void clear(bool clear_meta_data)
Clears all data and meta data.
In-Memory representation of a mass spectrometry experiment.
Definition: MSExperiment.h:77
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
double windowsize_
Definition: WindowMower.h:238
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:91
MSSpectrum & select(const std::vector< Size > &indices)