OpenMS
NLargest.h
Go to the documentation of this file.
1 // Copyright (c) 2002-present, The OpenMS Team -- EKU Tuebingen, ETH Zurich, and FU Berlin
2 // SPDX-License-Identifier: BSD-3-Clause
3 //
4 // --------------------------------------------------------------------------
5 // $Maintainer: Mathias Walzer $
6 // $Authors: $
7 // --------------------------------------------------------------------------
8 //
9 #pragma once
10 
14 
17 
18 namespace OpenMS
19 {
20 
28  class OPENMS_DLLAPI NLargest :
29  public DefaultParamHandler
30  {
31 public:
32 
33  // @name Constructors and Destructors
34  // @{
35 
41  ~NLargest() override;
42 
44  NLargest(const NLargest & source);
46  NLargest & operator=(const NLargest & source);
47 
48  // @}
49 
51  template <typename SpectrumType>
52  void filterSpectrum(SpectrumType & spectrum)
53  {
54  if (spectrum.size() <= peakcount_) return;
55 
56  // sort by reverse intensity
57  spectrum.sortByIntensity(true);
58 
59  // keep the n largest peaks if more than n are present
60  std::vector<Size> indices;
61  for (Size i = 0; i != peakcount_; ++i)
62  {
63  indices.push_back(i);
64  }
65  spectrum.select(indices);
66  }
67 
68  void filterPeakSpectrum(PeakSpectrum & spectrum);
69 
70  void filterPeakMap(PeakMap & exp);
71 
72  //TODO reimplement DefaultParamHandler::updateMembers_()
73 
74  // @}
75 
76 protected:
77  void updateMembers_() override;
79 
81  void init_();
82 
83  };
84 
85 }
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
MSSpectrum & select(const std::vector< Size > &indices)
void sortByIntensity(bool reverse=false)
Lexicographically sorts the peaks by their intensity.
NLargest removes all but the n largest peaks.
Definition: NLargest.h:30
void init_()
handles the initialization of the default parameters for the 2 constructors
NLargest & operator=(const NLargest &source)
assignment operator
NLargest(UInt n)
detailed constructor
NLargest()
default constructor
void filterPeakSpectrum(PeakSpectrum &spectrum)
~NLargest() override
destructor
void filterPeakMap(PeakMap &exp)
UInt peakcount_
Definition: NLargest.h:78
void updateMembers_() override
This method is used to update extra member variables at the end of the setParameters() method.
void filterSpectrum(SpectrumType &spectrum)
Definition: NLargest.h:52
NLargest(const NLargest &source)
copy constructor
unsigned int UInt
Unsigned integer type.
Definition: Types.h:64
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:97
Main OpenMS namespace.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19