libpappsomspp
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 pass_y) : m_passY(pass_y)
38 {
39 }
41  : m_passY(other.m_passY)
42 {
43 }
44 
47 {
48  m_passY = other.m_passY;
49 
50  return *this;
51 }
52 
53 
54 Trace &
55 FilterLowPass::filter(Trace &data_points) const
56 {
57  Trace new_data_points;
58  for(auto &&data_point : data_points)
59  {
60  if(data_point.y < m_passY)
61  {
62  new_data_points.push_back(data_point);
63  }
64  }
65  data_points = std::move(new_data_points);
66  return data_points;
67 }
68 
69 FilterHighPass::FilterHighPass(double pass_y) : m_passY(pass_y)
70 {
71 }
73  : m_passY(other.m_passY)
74 {
75 }
76 
79 {
80  m_passY = other.m_passY;
81 
82  return *this;
83 }
84 
85 
86 Trace &
87 FilterHighPass::filter(Trace &data_points) const
88 {
89  Trace new_data_points;
90  for(auto &&data_point : data_points)
91  {
92  if(data_point.y > m_passY)
93  {
94  new_data_points.push_back(data_point);
95  }
96  }
97  data_points = std::move(new_data_points);
98  return data_points;
99 }
100 
101 
103  : m_ratioPassY(ratio_pass_y)
104 {
105 }
106 
108  const FilterHighPassPercentage &other)
109  : m_ratioPassY(other.m_ratioPassY)
110 {
111 }
112 
115 {
116  m_ratioPassY = other.m_ratioPassY;
117 
118  return *this;
119 }
120 
121 
122 Trace &
124 {
125  auto it_max = maxYDataPoint(data_points.begin(), data_points.end());
126  if(it_max == data_points.end())
127  return data_points;
128  double pass = (it_max->y * m_ratioPassY);
129  Trace new_data_points;
130  for(auto &&data_point : data_points)
131  {
132  if(data_point.y > pass)
133  {
134  new_data_points.push_back(data_point);
135  }
136  }
137  data_points = std::move(new_data_points);
138  return data_points;
139 }
140 
141 
142 FilterGreatestY::FilterGreatestY(std::size_t number_of_points)
143  : m_numberOfPoints(number_of_points)
144 {
145 }
146 
147 
149  : m_numberOfPoints(other.m_numberOfPoints)
150 {
151 }
152 
153 
156 {
158 
159  return *this;
160 }
161 
162 
163 Trace &
164 FilterGreatestY::filter(Trace &data_points) const
165 {
166 
167  // Reverse-sort the data points (in y decreasing order) so that we get the
168  // greatest to the front of the vector and we'll then copy the first n data
169  // points to the returned vector. See that return (b < a) ?
170  if(m_numberOfPoints >= data_points.size())
171  return data_points;
172 
173  std::sort(data_points.begin(),
174  data_points.end(),
175  [](const DataPoint &a, const DataPoint &b) { return (b.y < a.y); });
176 
177  data_points.erase(data_points.begin() + m_numberOfPoints, data_points.end());
178 
179  // And now sort the Trace conventionally, that is in x increasing order.
180  std::sort(data_points.begin(),
181  data_points.end(),
182  [](const DataPoint &a, const DataPoint &b) { return (a.x < b.x); });
183 
184 
185  return data_points;
186 }
187 
188 std::size_t
190 {
191  return m_numberOfPoints;
192 }
193 
194 
196 {
197 }
198 FilterFloorY::FilterFloorY([[maybe_unused]] const FilterFloorY &other)
199 {
200 }
201 
202 FilterFloorY &
203 FilterFloorY::operator=([[maybe_unused]] const FilterFloorY &other)
204 {
205  return *this;
206 }
207 
208 
209 Trace &
210 FilterFloorY::filter(Trace &data_points) const
211 {
212  for(auto &&dataPoint : data_points)
213  {
214  dataPoint.y = std::floor(dataPoint.y);
215  }
216  return data_points;
217 }
218 
219 
221 {
222 }
223 FilterRoundY::FilterRoundY([[maybe_unused]] const FilterRoundY &other)
224 {
225 }
226 
227 FilterRoundY &
228 FilterRoundY::operator=([[maybe_unused]] const FilterRoundY &other)
229 {
230  return *this;
231 }
232 
233 Trace &
234 FilterRoundY::filter(Trace &data_points) const
235 {
236  for(auto &&dataPoint : data_points)
237  {
238  dataPoint.y = std::round(dataPoint.y);
239  }
240  return data_points;
241 }
242 
243 
244 FilterRescaleY::FilterRescaleY(double dynamic) : m_dynamic(dynamic)
245 {
246 }
248  : m_dynamic(other.m_dynamic)
249 {
250 }
251 Trace &
252 FilterRescaleY::filter(Trace &data_points) const
253 {
254  if(m_dynamic == 0)
255  return data_points;
256  auto it_max = maxYDataPoint(data_points.begin(), data_points.end());
257  if(it_max == data_points.end())
258  return data_points;
259  double maximum = it_max->y;
260  for(auto &&dataPoint : data_points)
261  {
262  dataPoint.y = (dataPoint.y / maximum) * m_dynamic;
263  }
264  return data_points;
265 }
266 
269 {
270  m_dynamic = other.m_dynamic;
271 
272  return *this;
273 }
274 
275 
276 double
278 {
279  return m_dynamic;
280 }
281 
282 
284  std::size_t number_of_points)
285  : m_filterGreatestY(number_of_points)
286 {
287 }
288 
291  : m_filterGreatestY(other.m_filterGreatestY)
292 {
293 }
294 
298 {
300 
301  return *this;
302 }
303 
304 
305 MassSpectrum &
307 {
308  m_filterGreatestY.filter(spectrum);
309  return spectrum;
310 }
311 
312 
313 FilterScaleFactorY::FilterScaleFactorY(double dynamic) : m_factor(dynamic)
314 {
315 }
317  : m_factor(other.m_factor)
318 {
319 }
320 
323 {
324  m_factor = other.m_factor;
325 
326  return *this;
327 }
328 
329 
330 Trace &
332 {
333  if(m_factor == 1)
334  return data_points;
335  for(auto &&dataPoint : data_points)
336  {
337  dataPoint.y = dataPoint.y * m_factor;
338  }
339  return data_points;
340 }
341 double
343 {
344  return m_factor;
345 }
pappso::FilterHighPassPercentage::operator=
FilterHighPassPercentage & operator=(const FilterHighPassPercentage &other)
Definition: filterpass.cpp:114
pappso::FilterScaleFactorY::filter
Trace & filter(Trace &data_points) const override
Definition: filterpass.cpp:331
pappso::MassSpectrumFilterGreatestItensities::m_filterGreatestY
FilterGreatestY m_filterGreatestY
Definition: filterpass.h:136
pappso::FilterRescaleY::filter
Trace & filter(Trace &data_points) const override
Definition: filterpass.cpp:252
pappso::FilterHighPass::FilterHighPass
FilterHighPass(double pass_y)
Definition: filterpass.cpp:69
pappso::FilterGreatestY
keep N datapoints form the greatest intensities to the lowest
Definition: filterpass.h:113
pappso::FilterRescaleY::m_dynamic
double m_dynamic
Definition: filterpass.h:184
pappso
Definition: aa.cpp:38
pappso::MassSpectrumFilterGreatestItensities::filter
MassSpectrum & filter(MassSpectrum &spectrum) const override
Definition: filterpass.cpp:306
pappso::MassSpectrum
Class to represent a mass spectrum.
Definition: massspectrum.h:91
pappso::FilterLowPass::operator=
FilterLowPass & operator=(const FilterLowPass &other)
Definition: filterpass.cpp:46
pappso::FilterHighPassPercentage
remove datapoints below a given intensity percentage (ratio) of the maximum intensity
Definition: filterpass.h:93
pappso::MassSpectrumFilterGreatestItensities
Definition: filterpass.h:132
pappso::PeptideIonNter::a
@ a
pappso::FilterRescaleY::FilterRescaleY
FilterRescaleY(double dynamic)
Definition: filterpass.cpp:244
pappso::MassSpectrumFilterGreatestItensities::operator=
MassSpectrumFilterGreatestItensities & operator=(const MassSpectrumFilterGreatestItensities &other)
Definition: filterpass.cpp:297
pappso::FilterHighPass
remove datapoints below a given Y value (intensity)
Definition: filterpass.h:75
pappso::DataPoint
Definition: datapoint.h:20
pappso::FilterRoundY
apply std::round (round to nearest integer) to all Y values
Definition: filterpass.h:166
filterpass.h
pappso::FilterFloorY::filter
Trace & filter(Trace &data_points) const override
Definition: filterpass.cpp:210
pappso::FilterGreatestY::getNumberOfPoints
std::size_t getNumberOfPoints() const
Definition: filterpass.cpp:189
pappso::FilterGreatestY::filter
Trace & filter(Trace &data_points) const override
Definition: filterpass.cpp:164
pappso::FilterGreatestY::operator=
FilterGreatestY & operator=(const FilterGreatestY &other)
Definition: filterpass.cpp:155
pappso::FilterRoundY::operator=
FilterRoundY & operator=(const FilterRoundY &other)
Definition: filterpass.cpp:228
pappso::Trace
A simple container of DataPoint instances.
Definition: trace.h:126
pappso::FilterLowPass
remove datapoints higher than a given Y value (intensity)
Definition: filterpass.h:58
pappso::FilterFloorY::operator=
FilterFloorY & operator=(const FilterFloorY &other)
Definition: filterpass.cpp:203
pappso::FilterScaleFactorY::m_factor
double m_factor
Definition: filterpass.h:203
pappso::maxYDataPoint
std::vector< DataPoint >::const_iterator maxYDataPoint(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end)
Definition: trace.cpp:127
pappso::FilterHighPass::m_passY
double m_passY
Definition: filterpass.h:78
pappso::MassSpectrumFilterGreatestItensities::MassSpectrumFilterGreatestItensities
MassSpectrumFilterGreatestItensities(std::size_t number_of_points=0)
Definition: filterpass.cpp:283
pappso::FilterRoundY::FilterRoundY
FilterRoundY()
Definition: filterpass.cpp:220
pappso::FilterRescaleY
rescales Y values into a dynamic range if the dynamic range is set to 0, this filter is ignored
Definition: filterpass.h:181
pappso::FilterHighPass::operator=
FilterHighPass & operator=(const FilterHighPass &other)
Definition: filterpass.cpp:78
pappso::FilterScaleFactorY::FilterScaleFactorY
FilterScaleFactorY(double m_factor)
Definition: filterpass.cpp:313
pappso::FilterScaleFactorY
rescales Y values given a tranformation factor
Definition: filterpass.h:200
pappso::FilterLowPass::filter
Trace & filter(Trace &data_points) const override
Definition: filterpass.cpp:55
pappso::FilterHighPassPercentage::m_ratioPassY
double m_ratioPassY
Definition: filterpass.h:107
pappso::PeptideIonNter::b
@ b
pappso::FilterScaleFactorY::operator=
FilterScaleFactorY & operator=(const FilterScaleFactorY &other)
Definition: filterpass.cpp:322
pappso::FilterHighPassPercentage::FilterHighPassPercentage
FilterHighPassPercentage(double y_ratio)
Definition: filterpass.cpp:102
pappso::FilterRoundY::filter
Trace & filter(Trace &data_points) const override
Definition: filterpass.cpp:234
pappso::FilterGreatestY::m_numberOfPoints
std::size_t m_numberOfPoints
Definition: filterpass.h:129
pappso::FilterScaleFactorY::getScaleFactorY
double getScaleFactorY() const
Definition: filterpass.cpp:342
pappso::FilterFloorY::FilterFloorY
FilterFloorY()
Definition: filterpass.cpp:195
pappso::FilterRescaleY::getDynamicRange
double getDynamicRange() const
Definition: filterpass.cpp:277
pappso::FilterLowPass::FilterLowPass
FilterLowPass(double pass_y)
Definition: filterpass.cpp:37
pappso::FilterHighPass::filter
Trace & filter(Trace &data_points) const override
Definition: filterpass.cpp:87
pappso::FilterRescaleY::operator=
FilterRescaleY & operator=(const FilterRescaleY &other)
Definition: filterpass.cpp:268
pappso::FilterGreatestY::FilterGreatestY
FilterGreatestY(std::size_t number_of_points=0)
constructor with the number of datapoints to keep
Definition: filterpass.cpp:142
pappso::FilterHighPassPercentage::filter
Trace & filter(Trace &data_points) const override
Definition: filterpass.cpp:123
pappso::FilterLowPass::m_passY
double m_passY
Definition: filterpass.h:79
pappso::FilterFloorY
apply std::floor (round to lowest integer) to all Y values
Definition: filterpass.h:151