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
41
43
44
45namespace pappso
46{
47
48
53
54
60
61
65
68{
69 if(&other == this)
70 return *this;
71
73
74 return *this;
75}
76
77
82
83
84void
86{
87 // Typical string: "CeilingAmplitudePercentage|15"
88 if(parameters.startsWith(QString("%1|").arg(name())))
89 {
90 QStringList params = parameters.split("|").back().split(";");
91
92 m_percentage = params.at(0).toDouble();
93 }
94 else
95 {
97 QString("Building of FilterCeilingAmplitudePercentage from string %1 failed")
98 .arg(parameters));
99 }
100}
101
102
103Trace &
105{
106
107 auto it_min = minYDataPoint(data_points.begin(), data_points.end());
108 auto it_max = maxYDataPoint(data_points.begin(), data_points.end());
109
110 if(it_min == data_points.end() || it_max == data_points.end())
111 return data_points;
112
113 double min = it_min->y;
114 double max = it_max->y;
115
116 double amplitude = max - min;
117
118 double amplitude_ratio = amplitude * m_percentage / 100;
119
120 double threshold = min + amplitude_ratio;
121
122 // Since we never remove points, we only change their y value, we can do the
123 // filtering inplace.
124
125 for(auto &&data_point : data_points)
126 {
127 // Change the value to be threshold (re-ceiling in action).
128 if(data_point.y > threshold)
129 {
130 data_point.y = threshold;
131 }
132 }
133
134 return data_points;
135}
136
137
138double
143
144
145//! Return a string with the textual representation of the configuration data.
146QString
148{
149 return QString("%1|%2").arg(name()).arg(QString::number(m_percentage, 'f', 2));
150}
151
152
153QString
155{
156 return "CeilingAmplitudePercentage";
157}
158
159} // 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:152
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:169
std::vector< DataPoint >::const_iterator minYDataPoint(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end)
Definition trace.cpp:152