libpappsomspp
Library for mass spectrometry
filtertriangle.cpp
Go to the documentation of this file.
1 /**
2  * \file pappsomspp/filers/filtertriangle.h
3  * \date 27/10/2019
4  * \author Olivier Langella
5  * \brief sum peaks under a triangle base
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 "filtertriangle.h"
29 #include <QDebug>
30 
31 using namespace pappso;
32 
34 {
35 }
36 
38 {
40 }
41 
43 {
44 }
45 
46 double
47 FilterTriangle::setTriangleSlope(double intensity, double mz)
48 {
49  m_maxMzRange = mz;
50  m_triangleSlope = mz / intensity;
51  return m_triangleSlope;
52 }
53 
55 FilterTriangle::sumAndRemove(Trace &trace, const DataPoint &max_intensity) const
56 {
57 
58  // qDebug();
59  // double sum = max_intensity.y;
60  // double wmean = max_intensity.y * max_intensity.x;
61  double mz_range = max_intensity.y * m_triangleSlope;
62  if(mz_range > m_maxMzRange)
63  {
64  mz_range = m_maxMzRange;
65  }
66  double min_range = max_intensity.x - mz_range;
67  double max_range = max_intensity.x + mz_range;
68 
69  DataPoint new_point;
70  new_point.y = 0;
71  new_point.x = 0;
72  // Trace new_trace;
73 
74  for(DataPoint &old_point : trace)
75  {
76  if((old_point.x < min_range) || (old_point.x > max_range))
77  {
78  // new_trace.push_back(old_point);
79  }
80  else
81  {
82  new_point.y += old_point.y;
83  new_point.x += old_point.y * old_point.x;
84  old_point.y = 0;
85  }
86  }
87 
88  // trace = std::move(new_trace);
89  new_point.x = new_point.x / new_point.y; // weighted mean on mz
90  return new_point;
91 }
92 
93 Trace &
94 FilterTriangle::filter(Trace &data_points) const
95 {
96  // qDebug() << data_points.size();
97  Trace new_trace;
98 
99  std::vector<DataPoint>::iterator it_max =
100  maxYDataPoint(data_points.begin(), data_points.end());
101  // qDebug();
102  while((it_max != data_points.end()) && (it_max->y > 0))
103  {
104  // qDebug();
105  new_trace.push_back(sumAndRemove(data_points, *it_max));
106  // qDebug();
107  it_max = maxYDataPoint(data_points.begin(), data_points.end());
108  }
109 
110  new_trace.sortX();
111  // qDebug() << new_trace.size();
112  data_points = std::move(new_trace);
113  // qDebug() << data_points.size();
114  return data_points;
115 }
Trace & filter(Trace &data_points) const override
DataPoint sumAndRemove(Trace &trace, const DataPoint &max_intensity) const
double setTriangleSlope(double intensity, double mz)
A simple container of DataPoint instances.
Definition: trace.h:148
void sortX()
Definition: trace.cpp:956
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
pappso_double x
Definition: datapoint.h:23
pappso_double y
Definition: datapoint.h:24