libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
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
45namespace pappso
46{
47
48
54
55
61
62
66
70{
71 if(&other == this)
72 return *this;
73
75
76 return *this;
77}
78
79
85
86
87void
89 const QString &parameters)
90{
91 // Typical string: "CeilingAmplitudePercentage|15"
92 if(parameters.startsWith(QString("%1|").arg(name())))
93 {
94 QStringList params = parameters.split("|").back().split(";");
95
96 m_percentage = params.at(0).toDouble();
97 }
98 else
99 {
101 QString(
102 "Building of FilterCeilingAmplitudePercentage from string %1 failed")
103 .arg(parameters));
104 }
105}
106
107
108Trace &
110{
111
112 auto it_min = minYDataPoint(data_points.begin(), data_points.end());
113 auto it_max = maxYDataPoint(data_points.begin(), data_points.end());
114
115 if(it_min == data_points.end() || it_max == data_points.end())
116 return data_points;
117
118 double min = it_min->y;
119 double max = it_max->y;
120
121 double amplitude = max - min;
122
123 double amplitude_ratio = amplitude * m_percentage / 100;
124
125 double threshold = min + amplitude_ratio;
126
127 // Since we never remove points, we only change their y value, we can do the
128 // filtering inplace.
129
130 for(auto &&data_point : data_points)
131 {
132 // Change the value to be threshold (re-ceiling in action).
133 if(data_point.y > threshold)
134 {
135 data_point.y = threshold;
136 }
137 }
138
139 return data_points;
140}
141
142
143double
148
149
150//! Return a string with the textual representation of the configuration data.
151QString
153{
154 return QString("%1|%2").arg(name()).arg(
155 QString::number(m_percentage, 'f', 2));
156}
157
158
159QString
161{
162 return "CeilingAmplitudePercentage";
163}
164
165} // 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