libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
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"
32using namespace pappso;
33
34FilterLocalMaximum::FilterLocalMaximum(std::size_t half_window_size)
35 : m_halfWindowSize(half_window_size)
36{
37}
38
43
47
48Trace &
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 = data_points.end() - m_halfWindowSize - 1; // no filter at the end of signal
58 // new_trace.reserve(data_points.size());
59
60 while((it != data_points.end()) &&
61 (std::distance(data_points.begin(), it) < (int)m_halfWindowSize))
62 {
63 // no filter at the begining of the signal
64 it++;
65 }
66 while(it != itend)
67 {
68 auto itwend = it + m_halfWindowSize + 1;
69 auto itw = maxYDataPoint(it - m_halfWindowSize, it + 1);
70 if(itw == it)
71 {
72 itw = maxYDataPoint(it, itwend);
73 if(itw == it)
74 {
75 new_trace.push_back({it->x, it->y});
76 }
77 }
78
79 it++;
80 }
81
82 data_points = std::move(new_trace);
83 return data_points;
84}
85
86std::size_t
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:152
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:169