pappsomspp
Library for mass spectrometry
filterpass.cpp
Go to the documentation of this file.
1 /**
2  * \file pappsomspp/filers/filterpass.cpp
3  * \date 26/04/2019
4  * \author Olivier Langella
5  * \brief collection of filters concerned by Y selection
6  */
7 
8 /*******************************************************************************
9  * Copyright (c) 2019 Olivier Langella <Olivier.Langella@u-psud.fr>.
10  *
11  * This file is part of the PAPPSOms++ library.
12  *
13  * PAPPSOms++ is free software: you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation, either version 3 of the License, or
16  * (at your option) any later version.
17  *
18  * PAPPSOms++ is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with PAPPSOms++. If not, see <http://www.gnu.org/licenses/>.
25  *
26  ******************************************************************************/
27 
28 #include "filterpass.h"
29 #include "../../trace/trace.h"
30 #include <algorithm>
31 #include <cmath>
32 #include "../../massspectrum/massspectrum.h"
33 
34 using namespace pappso;
35 
36 
37 FilterLowPass::FilterLowPass(double y_pass) : m_y_pass(y_pass)
38 {
39 }
41  : m_y_pass(other.m_y_pass)
42 {
43 }
44 Trace &
45 FilterLowPass::filter(Trace &data_points) const
46 {
47  Trace new_data_points;
48  for(auto &&data_point : data_points)
49  {
50  if(data_point.y < m_y_pass)
51  {
52  new_data_points.push_back(data_point);
53  }
54  }
55  data_points = std::move(new_data_points);
56  return data_points;
57 }
58 
59 FilterHighPass::FilterHighPass(double y_pass) : m_y_pass(y_pass)
60 {
61 }
63  : m_y_pass(other.m_y_pass)
64 {
65 }
66 Trace &
67 FilterHighPass::filter(Trace &data_points) const
68 {
69  Trace new_data_points;
70  for(auto &&data_point : data_points)
71  {
72  if(data_point.y > m_y_pass)
73  {
74  new_data_points.push_back(data_point);
75  }
76  }
77  data_points = std::move(new_data_points);
78  return data_points;
79 }
80 
81 
83  : m_y_pass_ratio(y_pass)
84 {
85 }
87  const FilterHighPassPercentage &other)
88  : m_y_pass_ratio(other.m_y_pass_ratio)
89 {
90 }
91 Trace &
93 {
94  auto it_max = maxYDataPoint(data_points.begin(), data_points.end());
95  if(it_max == data_points.end())
96  return data_points;
97  double pass = (it_max->y * m_y_pass_ratio);
98  Trace new_data_points;
99  for(auto &&data_point : data_points)
100  {
101  if(data_point.y > pass)
102  {
103  new_data_points.push_back(data_point);
104  }
105  }
106  data_points = std::move(new_data_points);
107  return data_points;
108 }
109 
110 
111 FilterGreatestY::FilterGreatestY(std::size_t number_of_points)
112  : m_number_of_points(number_of_points)
113 {
114 }
115 
116 
118  : m_number_of_points(other.m_number_of_points)
119 {
120 }
121 
122 Trace &
123 FilterGreatestY::filter(Trace &data_points) const
124 {
125 
126  // Reverse-sort the data points (in y decreasing order) so that we get the
127  // greatest to the front of the vector and we'll then copy the first n data
128  // points to the returned vector. See that return (b < a) ?
129  if(m_number_of_points >= data_points.size())
130  return data_points;
131 
132  std::sort(data_points.begin(),
133  data_points.end(),
134  [](const DataPoint &a, const DataPoint &b) { return (b.y < a.y); });
135 
136  data_points.erase(data_points.begin() + m_number_of_points,
137  data_points.end());
138 
139  // And now sort the Trace conventionally, that is in x increasing order.
140  std::sort(data_points.begin(),
141  data_points.end(),
142  [](const DataPoint &a, const DataPoint &b) { return (a.x < b.x); });
143 
144 
145  return data_points;
146 }
147 
148 std::size_t
150 {
151  return m_number_of_points;
152 }
153 
154 
156 {
157 }
159 {
160 }
161 Trace &
162 FilterFloorY::filter(Trace &data_points) const
163 {
164  for(auto &&dataPoint : data_points)
165  {
166  dataPoint.y = std::floor(dataPoint.y);
167  }
168  return data_points;
169 }
170 
171 
173 {
174 }
176 {
177 }
178 Trace &
179 FilterRoundY::filter(Trace &data_points) const
180 {
181  for(auto &&dataPoint : data_points)
182  {
183  dataPoint.y = std::round(dataPoint.y);
184  }
185  return data_points;
186 }
187 
188 
189 FilterRescaleY::FilterRescaleY(double dynamic) : m_dynamic(dynamic)
190 {
191 }
193  : m_dynamic(other.m_dynamic)
194 {
195 }
196 Trace &
197 FilterRescaleY::filter(Trace &data_points) const
198 {
199  if(m_dynamic == 0)
200  return data_points;
201  auto it_max = maxYDataPoint(data_points.begin(), data_points.end());
202  if(it_max == data_points.end())
203  return data_points;
204  double maximum = it_max->y;
205  for(auto &&dataPoint : data_points)
206  {
207  dataPoint.y = (dataPoint.y / maximum) * m_dynamic;
208  }
209  return data_points;
210 }
211 double
213 {
214  return m_dynamic;
215 }
216 
217 
219  std::size_t number_of_points)
220  : m_filterGreatestY(number_of_points)
221 {
222 }
223 
226  : m_filterGreatestY(other.m_filterGreatestY)
227 {
228 }
229 
230 MassSpectrum &
232 {
233  m_filterGreatestY.filter(spectrum);
234  return spectrum;
235 }
236 
237 
238 FilterScaleFactorY::FilterScaleFactorY(double dynamic) : m_factor(dynamic)
239 {
240 }
242  : m_factor(other.m_factor)
243 {
244 }
245 Trace &
247 {
248  if(m_factor == 1)
249  return data_points;
250  for(auto &&dataPoint : data_points)
251  {
252  dataPoint.y = dataPoint.y * m_factor;
253  }
254  return data_points;
255 }
256 double
258 {
259  return m_factor;
260 }
pappso::FilterScaleFactorY::filter
Trace & filter(Trace &data_points) const override
Definition: filterpass.cpp:246
pappso::FilterRescaleY::filter
Trace & filter(Trace &data_points) const override
Definition: filterpass.cpp:197
pappso::FilterGreatestY
Definition: filterpass.h:92
pappso::FilterRescaleY::m_dynamic
double m_dynamic
Definition: filterpass.h:146
pappso
Definition: aa.cpp:38
pappso::MassSpectrumFilterGreatestItensities::filter
MassSpectrum & filter(MassSpectrum &spectrum) const override
Definition: filterpass.cpp:231
pappso::MassSpectrum
Class to represent a mass spectrum.
Definition: massspectrum.h:89
pappso::FilterHighPassPercentage
Definition: filterpass.h:79
pappso::MassSpectrumFilterGreatestItensities
Definition: filterpass.h:106
pappso::PeptideIonNter::a
pappso::FilterRescaleY::FilterRescaleY
FilterRescaleY(double dynamic)
Definition: filterpass.cpp:189
pappso::FilterHighPass
Definition: filterpass.h:66
pappso::DataPoint
Definition: datapoint.h:20
pappso::FilterRoundY
Definition: filterpass.h:130
filterpass.h
pappso::FilterFloorY::filter
Trace & filter(Trace &data_points) const override
Definition: filterpass.cpp:162
pappso::FilterHighPass::m_y_pass
double m_y_pass
Definition: filterpass.h:69
pappso::MassSpectrumFilterGreatestItensities::m_filterGreatestY
const FilterGreatestY m_filterGreatestY
Definition: filterpass.h:109
pappso::FilterGreatestY::getNumberOfPoints
std::size_t getNumberOfPoints() const
Definition: filterpass.cpp:149
pappso::FilterGreatestY::filter
Trace & filter(Trace &data_points) const override
Definition: filterpass.cpp:123
pappso::Trace
A simple container of DataPoint instances.
Definition: trace.h:125
pappso::FilterLowPass
Definition: filterpass.h:54
pappso::FilterScaleFactorY::m_factor
double m_factor
Definition: filterpass.h:163
pappso::maxYDataPoint
std::vector< DataPoint >::const_iterator maxYDataPoint(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end)
Definition: trace.cpp:126
pappso::MassSpectrumFilterGreatestItensities::MassSpectrumFilterGreatestItensities
MassSpectrumFilterGreatestItensities(std::size_t number_of_points=0)
Definition: filterpass.cpp:218
pappso::FilterLowPass::FilterLowPass
FilterLowPass(double y_pass)
Definition: filterpass.cpp:37
pappso::FilterRoundY::FilterRoundY
FilterRoundY()
Definition: filterpass.cpp:172
pappso::FilterRescaleY
rescales Y values into a dynamic range if the dynamic range is set to 0, this filter is ignored
Definition: filterpass.h:143
pappso::FilterScaleFactorY::FilterScaleFactorY
FilterScaleFactorY(double m_factor)
Definition: filterpass.cpp:238
pappso::FilterScaleFactorY
rescales Y values given a tranformation factor
Definition: filterpass.h:160
pappso::FilterLowPass::filter
Trace & filter(Trace &data_points) const override
Definition: filterpass.cpp:45
pappso::FilterGreatestY::m_number_of_points
std::size_t m_number_of_points
Definition: filterpass.h:95
pappso::PeptideIonNter::b
pappso::FilterHighPassPercentage::m_y_pass_ratio
double m_y_pass_ratio
Definition: filterpass.h:82
pappso::FilterLowPass::m_y_pass
double m_y_pass
Definition: filterpass.h:74
pappso::FilterHighPassPercentage::FilterHighPassPercentage
FilterHighPassPercentage(double y_ratio)
Definition: filterpass.cpp:82
pappso::FilterHighPass::FilterHighPass
FilterHighPass(double y_pass)
Definition: filterpass.cpp:59
pappso::FilterRoundY::filter
Trace & filter(Trace &data_points) const override
Definition: filterpass.cpp:179
pappso::FilterScaleFactorY::getScaleFactorY
double getScaleFactorY() const
Definition: filterpass.cpp:257
pappso::FilterFloorY::FilterFloorY
FilterFloorY()
Definition: filterpass.cpp:155
pappso::FilterRescaleY::getDynamicRange
double getDynamicRange() const
Definition: filterpass.cpp:212
pappso::FilterHighPass::filter
Trace & filter(Trace &data_points) const override
Definition: filterpass.cpp:67
pappso::FilterGreatestY::FilterGreatestY
FilterGreatestY(std::size_t number_of_points=0)
Definition: filterpass.cpp:111
pappso::FilterHighPassPercentage::filter
Trace & filter(Trace &data_points) const override
Definition: filterpass.cpp:92
pappso::FilterFloorY
Definition: filterpass.h:119