libpappsomspp
Library for mass spectrometry
filterceilingamplitudepercentage.cpp
Go to the documentation of this file.
1 /* BEGIN software license
2  *
3  * msXpertSuite - mass spectrometry software suite
4  * -----------------------------------------------
5  * Copyright(C) 2009,...,2021 Filippo Rusconi
6  *
7  * http://www.msxpertsuite.org
8  *
9  * This file is part of the msXpertSuite project.
10  *
11  * The msXpertSuite project is the successor of the massXpert project. This
12  * project now includes various independent modules:
13  *
14  * - massXpert, model polymer chemistries and simulate mass spectrometric data;
15  * - mineXpert, a powerful TIC chromatogram/mass spectrum viewer/miner;
16  *
17  * This program is free software: you can redistribute it and/or modify
18  * it under the terms of the GNU General Public License as published by
19  * the Free Software Foundation, either version 3 of the License, or
20  * (at your option) any later version.
21  *
22  * This program is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25  * GNU General Public License for more details.
26  *
27  * You should have received a copy of the GNU General Public License
28  * along with this program. If not, see <http://www.gnu.org/licenses/>.
29  *
30  * END software license
31  */
32 
33 
34 #include <qmath.h>
35 
36 
37 #include <QVector>
38 #include <QDebug>
39 
40 #include "../../exception/exceptionnotrecognized.h"
41 
43 
44 
45 namespace pappso
46 {
47 
48 
50  double percentage)
51 {
52  m_percentage = percentage;
53 }
54 
55 
58 {
59  m_percentage = other.m_percentage;
60 }
61 
62 
64 {
65 }
66 
70 {
71  if(&other == this)
72  return *this;
73 
74  m_percentage = other.m_percentage;
75 
76  return *this;
77 }
78 
79 
81  const QString &parameters)
82 {
83  buildFilterFromString(parameters);
84 }
85 
86 
87 void
89 {
90  // Typical string: "CeilingAmplitudePercentage|15"
91  if(parameters.startsWith(QString("%1|").arg(name())))
92  {
93  QStringList params = parameters.split("|").back().split(";");
94 
95  m_percentage = params.at(0).toDouble();
96  }
97  else
98  {
100  QString(
101  "Building of FilterCeilingAmplitudePercentage from string %1 failed")
102  .arg(parameters));
103  }
104 }
105 
106 
107 Trace &
109 {
110 
111  auto it_min = minYDataPoint(data_points.begin(), data_points.end());
112  auto it_max = maxYDataPoint(data_points.begin(), data_points.end());
113 
114  if(it_min == data_points.end() || it_max == data_points.end())
115  return data_points;
116 
117  double min = it_min->y;
118  double max = it_max->y;
119 
120  double amplitude = max - min;
121 
122  double amplitude_ratio = amplitude * m_percentage / 100;
123 
124  double threshold = min + amplitude_ratio;
125 
126  // Since we never remove points, we only change their y value, we can do the
127  // filtering inplace.
128 
129  for(auto &&data_point : data_points)
130  {
131  // Change the value to be threshold (re-ceiling in action).
132  if(data_point.y > threshold)
133  {
134  data_point.y = threshold;
135  }
136  }
137 
138  return data_points;
139 }
140 
141 
142 double
144 {
145  return m_percentage;
146 }
147 
148 
149 //! Return a string with the textual representation of the configuration data.
150 QString
152 {
153  return QString("%1|%2").arg(name()).arg(
154  QString::number(m_percentage, 'f', 2));
155 }
156 
157 
158 QString
160 {
161  return "CeilingAmplitudePercentage";
162 }
163 
164 } // namespace pappso
excetion to use when an item type is not recognized
Redefines the ceiling intensity of the Trace.
Trace & filter(Trace &data_points) const override
FilterCeilingAmplitudePercentage & operator=(const FilterCeilingAmplitudePercentage &other)
void buildFilterFromString(const QString &strBuildParams) override
build this filter using a string
QString toString() const override
Return a string with the textual representation of the configuration data.
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
std::vector< DataPoint >::const_iterator minYDataPoint(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end)
Definition: trace.cpp:158
@ max
maximum of intensities