libpappsomspp
Library for mass spectrometry
Toggle main menu visibility
Loading...
Searching...
No Matches
filternormalizeintensities.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
#include <limits>
37
#include <iterator>
38
39
#include <QVector>
40
#include <QDebug>
41
42
#include "
filternormalizeintensities.h
"
43
#include "
pappsomspp/core/exception/exceptionnotrecognized.h
"
44
#include "
pappsomspp/core/exception/exceptionnotpossible.h
"
45
46
namespace
pappso
47
{
48
49
50
FilterNormalizeIntensities::FilterNormalizeIntensities
(
double
new_max_y_value)
51
:
m_newYMax
(new_max_y_value)
52
{
53
}
54
55
56
FilterNormalizeIntensities::FilterNormalizeIntensities
(
const
QString ¶meters)
57
{
58
buildFilterFromString
(parameters);
59
}
60
61
62
FilterNormalizeIntensities::FilterNormalizeIntensities
(
const
FilterNormalizeIntensities
&other)
63
{
64
m_newYMax
= other.
m_newYMax
;
65
}
66
67
68
FilterNormalizeIntensities::~FilterNormalizeIntensities
()
69
{
70
}
71
72
73
FilterNormalizeIntensities
&
74
FilterNormalizeIntensities::operator=
(
const
FilterNormalizeIntensities
&other)
75
{
76
if
(&other ==
this
)
77
return
*
this
;
78
79
m_newYMax
= other.
m_newYMax
;
80
81
return
*
this
;
82
}
83
84
85
void
86
FilterNormalizeIntensities::buildFilterFromString
(
const
QString ¶meters)
87
{
88
// Typical string: "FloorAmplitudePercentage|15"
89
if
(parameters.startsWith(QString(
"%1|"
).arg(
name
())))
90
{
91
QStringList params = parameters.split(
"|"
).back().split(
";"
);
92
93
m_newYMax
= params.at(0).toDouble();
94
}
95
else
96
{
97
throw
pappso::ExceptionNotRecognized
(
98
QString(
"Building of FilterNormalizeIntensities from string %1 failed"
).arg(parameters));
99
}
100
}
101
102
103
Trace
&
104
FilterNormalizeIntensities::filter
(
Trace
&trace)
const
105
{
106
// Start by looking at the most intense data point (greatest y value of the
107
// whole trace)
108
109
auto
max_dp_iter =
maxYDataPoint
(trace.cbegin(), trace.cend());
110
111
if
(max_dp_iter == trace.cend())
112
throw
pappso::ExceptionNotPossible
(
113
QString(
"Failed to find the max intensity data point in the trace."
));
114
115
if
(!max_dp_iter->y)
116
throw
pappso::ExceptionNotPossible
(
117
QString(
"The max intensity data point in the trace has intensity 0."
));
118
119
double
ratio =
m_newYMax
/ max_dp_iter->y;
120
121
for
(
DataPoint
&dp : trace)
122
{
123
dp.y *= ratio;
124
}
125
126
// #if 0
127
max_dp_iter =
maxYDataPoint
(trace.cbegin(), trace.cend());
128
qDebug() <<
"Now max int:"
<< max_dp_iter->y;
129
130
// #endif
131
132
return
trace;
133
}
134
135
136
//! Return a string with the textual representation of the configuration data.
137
QString
138
FilterNormalizeIntensities::toString
()
const
139
{
140
return
QString(
"%1"
).arg(
name
()).arg(QString::number(
m_newYMax
,
'f'
, 2));
141
}
142
143
144
QString
145
FilterNormalizeIntensities::name
()
const
146
{
147
return
"FilterNormalizeIntensities"
;
148
}
149
150
}
// namespace pappso
pappso::ExceptionNotPossible
Definition
exceptionnotpossible.h:29
pappso::ExceptionNotRecognized
excetion to use when an item type is not recognized
Definition
exceptionnotrecognized.h:42
pappso::FilterNormalizeIntensities
Sets the maximum intensity of the trace to the provided value.
Definition
filternormalizeintensities.h:68
pappso::FilterNormalizeIntensities::toString
QString toString() const override
Return a string with the textual representation of the configuration data.
Definition
filternormalizeintensities.cpp:138
pappso::FilterNormalizeIntensities::buildFilterFromString
void buildFilterFromString(const QString &strBuildParams) override
build this filter using a string
Definition
filternormalizeintensities.cpp:86
pappso::FilterNormalizeIntensities::filter
Trace & filter(Trace &data_points) const override
Definition
filternormalizeintensities.cpp:104
pappso::FilterNormalizeIntensities::operator=
FilterNormalizeIntensities & operator=(const FilterNormalizeIntensities &other)
Definition
filternormalizeintensities.cpp:74
pappso::FilterNormalizeIntensities::~FilterNormalizeIntensities
virtual ~FilterNormalizeIntensities()
Definition
filternormalizeintensities.cpp:68
pappso::FilterNormalizeIntensities::FilterNormalizeIntensities
FilterNormalizeIntensities(double new_max_y_value)
Definition
filternormalizeintensities.cpp:50
pappso::FilterNormalizeIntensities::m_newYMax
double m_newYMax
Definition
filternormalizeintensities.h:89
pappso::FilterNormalizeIntensities::name
QString name() const override
Definition
filternormalizeintensities.cpp:145
pappso::Trace
A simple container of DataPoint instances.
Definition
trace.h:152
exceptionnotpossible.h
exceptionnotrecognized.h
filternormalizeintensities.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::DataPoint
Definition
datapoint.h:22
pappsomspp
core
processing
filters
filternormalizeintensities.cpp
Generated on
for libpappsomspp by
1.17.0