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_ = (
DoubleReal)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_ = (
DoubleReal)param_.getValue(
"windowsize");
 
  141         peakcount_ = (
UInt)param_.getValue(
"peakcount");
 
  144         SpectrumType out = spectrum;
 
  147         SpectrumType peaks_in_window;
 
  148         DoubleReal 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]);
 
  156                 window_start = spectrum[i].getMZ(); 
 
  158                 std::partial_sort(peaks_in_window.begin(), peaks_in_window.begin() + peakcount_, peaks_in_window.end(), 
reverseComparator(
typename SpectrumType::PeakType::IntensityLess()));
 
  160                 if (peaks_in_window.size() > peakcount_)
 
  162                     copy(peaks_in_window.begin(), peaks_in_window.begin() + peakcount_, back_inserter(out));
 
  165                     copy(peaks_in_window.begin(), peaks_in_window.end(), back_inserter(out));
 
  167                 peaks_in_window.clear(
false);
 
  168                 peaks_in_window.push_back(spectrum[i]);
 
  172         if (peaks_in_window.empty())  
 
  174           out.sortByPosition();
 
  183         DoubleReal last_window_size = peaks_in_window.back().getMZ() - window_start;
 
  184         DoubleReal last_window_size_fraction = last_window_size / windowsize_;
 
  185         Size last_window_peakcount = last_window_size_fraction * peakcount_;
 
  187         if (last_window_peakcount)  
 
  189           last_window_peakcount = 1;
 
  193         std::partial_sort(peaks_in_window.begin(), peaks_in_window.begin() + last_window_peakcount, peaks_in_window.end(), 
reverseComparator(
typename SpectrumType::PeakType::IntensityLess()));
 
  195         if (peaks_in_window.size() > last_window_peakcount)
 
  197           std::copy(peaks_in_window.begin(), peaks_in_window.begin() + last_window_peakcount, back_inserter(out));
 
  200           std::copy(peaks_in_window.begin(), peaks_in_window.end(), std::back_inserter(out));
 
  203         out.sortByPosition();
 
  217 #endif //OPENMS_FILTERING_TRANSFORMERS_WINDOWMOWER_H 
WindowMower augments the highest peaks in a sliding or jumping window. 
Definition: WindowMower.h:53
DoubleReal windowsize_
Definition: WindowMower.h:211
unsigned int UInt
Unsigned integer type. 
Definition: Types.h:92
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:212
size_t Size
Size type e.g. used as variable which can hold result of size() 
Definition: Types.h:144
A base class for all classes handling default parameters. 
Definition: DefaultParamHandler.h:90
double DoubleReal
Double-precision real type. 
Definition: Types.h:118