libpappsomspp
Library for mass spectrometry
Toggle main menu visibility
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 "
pappsomspp/core/exception/exceptionnotrecognized.h
"
41
42
#include "
filterceilingamplitudepercentage.h
"
43
44
45
namespace
pappso
46
{
47
48
49
FilterCeilingAmplitudePercentage::FilterCeilingAmplitudePercentage
(
double
percentage)
50
{
51
m_percentage
= percentage;
52
}
53
54
55
FilterCeilingAmplitudePercentage::FilterCeilingAmplitudePercentage
(
56
const
FilterCeilingAmplitudePercentage
&other)
57
{
58
m_percentage
= other.
m_percentage
;
59
}
60
61
62
FilterCeilingAmplitudePercentage::~FilterCeilingAmplitudePercentage
()
63
{
64
}
65
66
FilterCeilingAmplitudePercentage
&
67
FilterCeilingAmplitudePercentage::operator=
(
const
FilterCeilingAmplitudePercentage
&other)
68
{
69
if
(&other ==
this
)
70
return
*
this
;
71
72
m_percentage
= other.
m_percentage
;
73
74
return
*
this
;
75
}
76
77
78
FilterCeilingAmplitudePercentage::FilterCeilingAmplitudePercentage
(
const
QString ¶meters)
79
{
80
buildFilterFromString
(parameters);
81
}
82
83
84
void
85
FilterCeilingAmplitudePercentage::buildFilterFromString
(
const
QString ¶meters)
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
{
96
throw
pappso::ExceptionNotRecognized
(
97
QString(
"Building of FilterCeilingAmplitudePercentage from string %1 failed"
)
98
.arg(parameters));
99
}
100
}
101
102
103
Trace
&
104
FilterCeilingAmplitudePercentage::filter
(
Trace
&data_points)
const
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
138
double
139
FilterCeilingAmplitudePercentage::getPercentage
()
const
140
{
141
return
m_percentage
;
142
}
143
144
145
//! Return a string with the textual representation of the configuration data.
146
QString
147
FilterCeilingAmplitudePercentage::toString
()
const
148
{
149
return
QString(
"%1|%2"
).arg(
name
()).arg(QString::number(
m_percentage
,
'f'
, 2));
150
}
151
152
153
QString
154
FilterCeilingAmplitudePercentage::name
()
const
155
{
156
return
"CeilingAmplitudePercentage"
;
157
}
158
159
}
// namespace pappso
pappso::ExceptionNotRecognized
excetion to use when an item type is not recognized
Definition
exceptionnotrecognized.h:42
pappso::FilterCeilingAmplitudePercentage
Redefines the ceiling intensity of the Trace.
Definition
filterceilingamplitudepercentage.h:73
pappso::FilterCeilingAmplitudePercentage::filter
Trace & filter(Trace &data_points) const override
Definition
filterceilingamplitudepercentage.cpp:104
pappso::FilterCeilingAmplitudePercentage::~FilterCeilingAmplitudePercentage
virtual ~FilterCeilingAmplitudePercentage()
Definition
filterceilingamplitudepercentage.cpp:62
pappso::FilterCeilingAmplitudePercentage::FilterCeilingAmplitudePercentage
FilterCeilingAmplitudePercentage(double percentage)
Definition
filterceilingamplitudepercentage.cpp:49
pappso::FilterCeilingAmplitudePercentage::operator=
FilterCeilingAmplitudePercentage & operator=(const FilterCeilingAmplitudePercentage &other)
Definition
filterceilingamplitudepercentage.cpp:67
pappso::FilterCeilingAmplitudePercentage::getPercentage
double getPercentage() const
Definition
filterceilingamplitudepercentage.cpp:139
pappso::FilterCeilingAmplitudePercentage::buildFilterFromString
void buildFilterFromString(const QString &strBuildParams) override
build this filter using a string
Definition
filterceilingamplitudepercentage.cpp:85
pappso::FilterCeilingAmplitudePercentage::toString
QString toString() const override
Return a string with the textual representation of the configuration data.
Definition
filterceilingamplitudepercentage.cpp:147
pappso::FilterCeilingAmplitudePercentage::m_percentage
double m_percentage
Definition
filterceilingamplitudepercentage.h:96
pappso::FilterCeilingAmplitudePercentage::name
QString name() const override
Definition
filterceilingamplitudepercentage.cpp:154
pappso::Trace
A simple container of DataPoint instances.
Definition
trace.h:152
exceptionnotrecognized.h
filterceilingamplitudepercentage.h
pappso
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition
aa.cpp:39
pappso::maxYDataPoint
std::vector< DataPoint >::const_iterator maxYDataPoint(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end)
Definition
trace.cpp:169
pappso::minYDataPoint
std::vector< DataPoint >::const_iterator minYDataPoint(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end)
Definition
trace.cpp:152
pappsomspp
core
processing
filters
filterceilingamplitudepercentage.cpp
Generated on
for libpappsomspp by
1.17.0