libpappsomspp
Library for mass spectrometry
filterlocalmaximum.cpp
Go to the documentation of this file.
1 /**
2  * \file pappsomspp/filers/filterlocalmaximum.cpp
3  * \date 24/09/2019
4  * \author Olivier Langella
5  * \brief filter to select local maximum in a spectrum
6  * inspired from the proteowizard library "LocalMaximumPeakDetector"
7  */
8 
9 /*******************************************************************************
10  * Copyright (c) 2019 Olivier Langella <Olivier.Langella@u-psud.fr>.
11  *
12  * This file is part of the PAPPSOms++ library.
13  *
14  * PAPPSOms++ is free software: you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation, either version 3 of the License, or
17  * (at your option) any later version.
18  *
19  * PAPPSOms++ is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with PAPPSOms++. If not, see <http://www.gnu.org/licenses/>.
26  *
27  ******************************************************************************/
28 
29 
30 #include "filterlocalmaximum.h"
31 #include "../../trace/trace.h"
32 using namespace pappso;
33 
34 FilterLocalMaximum::FilterLocalMaximum(std::size_t half_window_size)
35  : m_halfWindowSize(half_window_size)
36 {
37 }
38 
40  : m_halfWindowSize(other.m_halfWindowSize)
41 {
42 }
43 
45 {
46 }
47 
48 Trace &
49 FilterLocalMaximum::filter(Trace &data_points) const
50 {
51 
52  if(m_halfWindowSize == 0)
53  return data_points;
54  Trace new_trace;
55  auto it = data_points.begin();
56 
57  auto itend =
58  data_points.end() - m_halfWindowSize - 1; // no filter at the end of signal
59  // new_trace.reserve(data_points.size());
60 
61  while((it != data_points.end()) &&
62  (std::distance(data_points.begin(), it) < (int)m_halfWindowSize))
63  {
64  // no filter at the begining of the signal
65  it++;
66  }
67  while(it != itend)
68  {
69  auto itwend = it + m_halfWindowSize + 1;
70  auto itw = maxYDataPoint(it - m_halfWindowSize, it + 1);
71  if(itw == it)
72  {
73  itw = maxYDataPoint(it, itwend);
74  if(itw == it)
75  {
76  new_trace.push_back({it->x, it->y});
77  }
78  }
79 
80  it++;
81  }
82 
83  data_points = std::move(new_trace);
84  return data_points;
85 }
86 
87 std::size_t
89 {
90  return m_halfWindowSize;
91 }
finds all local maxima, i.e. any point that has a greater y value than both of its neighboring points...
std::size_t getHalfWindowSize() const
Trace & filter(Trace &data_points) const override
FilterLocalMaximum(std::size_t half_window_size)
A simple container of DataPoint instances.
Definition: trace.h:148
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition: aa.cpp:39
std::vector< DataPoint >::const_iterator maxYDataPoint(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end)
Definition: trace.cpp:180