libpappsomspp
Library for mass spectrometry
Toggle main menu visibility
Loading...
Searching...
No Matches
maptrace.cpp
Go to the documentation of this file.
1
#include <numeric>
2
#include <limits>
3
#include <vector>
4
#include <map>
5
#include <cmath>
6
#include <algorithm>
7
#include <iostream>
8
#include <iomanip>
9
10
/////////////////////// Qt includes
11
#include <QDebug>
12
#include <QObject>
13
14
15
#include "
pappsomspp/core/exception/exceptionnotpossible.h
"
16
#include "
maptrace.h
"
17
#include "
pappsomspp/core/processing/combiners/tracepluscombiner.h
"
18
#include "
pappsomspp/core/processing/combiners/traceminuscombiner.h
"
19
#include "
pappsomspp/core/types.h
"
20
21
22
int
mapTraceMetaTypeId
= qRegisterMetaType<pappso::MapTrace>(
"pappso::MapTrace"
);
23
int
mapTracePtrMetaTypeId
= qRegisterMetaType<pappso::MapTrace *>(
"pappso::MapTrace *"
);
24
25
26
namespace
pappso
27
{
28
29
MapTrace::MapTrace
()
30
{
31
}
32
33
34
MapTrace::MapTrace
(
const
std::vector<std::pair<pappso_double, pappso_double>> &dataPoints)
35
{
36
for
(
auto
&dataPoint : dataPoints)
37
{
38
insert(dataPoint);
39
}
40
}
41
42
43
MapTrace::MapTrace
(
const
std::vector<DataPoint> &dataPoints)
44
{
45
for
(
auto
&dataPoint : dataPoints)
46
{
47
insert(std::pair<pappso_double, pappso_double>(dataPoint.x, dataPoint.y));
48
}
49
}
50
51
52
MapTrace::MapTrace
(
const
MapTrace
&other) : std::map<
pappso_double
,
pappso_double
>(other)
53
{
54
}
55
56
57
MapTrace::MapTrace
(
const
Trace
&trace)
58
{
59
// qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << " ()";
60
61
for
(
auto
&dataPoint : trace)
62
{
63
// std::cout << __FILE__ << " @ " << __LINE__ << " " << __FUNCTION__ << "
64
// () "
65
//<< std::setprecision(15)
66
//<< "Current data point: " << dataPoint.toString().toStdString() <<
67
// std::endl;
68
69
insert(std::pair<pappso_double, pappso_double>(dataPoint.x, dataPoint.y));
70
}
71
72
// qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << " ()"
73
//<< "After construction, map size: " << size();
74
}
75
76
77
MapTrace::~MapTrace
()
78
{
79
// Calls the destructor for each DataPoint object in the vector.
80
clear();
81
}
82
83
84
size_t
85
MapTrace::initialize
(
const
std::vector<pappso_double> &xVector,
86
const
std::vector<pappso_double> &yVector)
87
{
88
// Clear *this, because initialize supposes that *this will contain only the
89
// data in the vectors.
90
91
clear();
92
93
// Sanity check
94
if
(xVector.size() != yVector.size())
95
throw
ExceptionNotPossible
(
96
QObject::tr(
"Fatal error at msrundatasettreenode.cpp "
97
"-- ERROR xVector and yVector must have the same size."
98
"Program aborted."
));
99
100
for
(std::size_t iter = 0; iter < xVector.size(); ++iter)
101
{
102
insert(std::pair<pappso_double, pappso_double>(xVector.at(iter), yVector.at(iter)));
103
}
104
105
return
size();
106
}
107
108
109
size_t
110
MapTrace::initialize
(
const
std::map<pappso_double, pappso_double> &map)
111
{
112
113
// Clear *this, because initialize supposes that *this will be identical to
114
// map.
115
116
clear();
117
118
for
(
auto
&&pair : map)
119
{
120
insert(pair);
121
}
122
123
return
size();
124
}
125
126
127
MapTrace
&
128
MapTrace::operator=
(
const
MapTrace
&other)
129
{
130
131
if
(&other ==
this
)
132
return
*
this
;
133
134
// Clear *this, because initialize supposes that *this will be identical to
135
// other.
136
137
clear();
138
139
for
(
auto
&pair : other)
140
{
141
insert(pair);
142
}
143
144
return
*
this
;
145
}
146
147
148
MapTraceSPtr
149
MapTrace::makeMapTraceSPtr
()
const
150
{
151
return
std::make_shared<MapTrace>(*
this
);
152
}
153
154
155
MapTraceCstSPtr
156
MapTrace::makeMapTraceCstSPtr
()
const
157
{
158
return
std::make_shared<const MapTrace>(*
this
);
159
}
160
161
162
std::vector<pappso_double>
163
MapTrace::xValues
()
164
{
165
std::vector<pappso_double> vector;
166
167
for
(
auto
&&pair : *
this
)
168
vector.push_back(pair.first);
169
170
return
vector;
171
}
172
173
174
std::vector<pappso_double>
175
MapTrace::yValues
()
176
{
177
std::vector<pappso_double> vector;
178
179
for
(
auto
&&pair : *
this
)
180
vector.push_back(pair.second);
181
182
return
vector;
183
}
184
185
186
void
187
MapTrace::insertOrUpdate
(
const
DataPoint
&data_point)
188
{
189
190
// Try to insert the data point into the map. Check if that was done or
191
// not.
192
std::pair<std::map<double, double>::iterator,
bool
> res =
193
insert(std::pair<double, double>(data_point.
x
, data_point.
y
));
194
195
if
(!res.second)
196
{
197
// One other same (x,y) value pair was seen already. Only increment the y
198
// value.
199
200
res.first->second += data_point.
y
;
201
}
202
}
203
204
205
void
206
MapTrace::insertOrUpdate
(
const
Trace
&trace)
207
{
208
for
(
const
DataPoint
&data_point : trace)
209
insertOrUpdate
(data_point);
210
}
211
212
213
Trace
214
MapTrace::toTrace
()
const
215
{
216
Trace
trace;
217
218
for
(
auto
&&pair : *
this
)
219
trace.push_back(
DataPoint
(pair.first, pair.second));
220
221
return
trace;
222
}
223
224
225
QString
226
MapTrace::toString
()
const
227
{
228
// Even if the spectrum is empty, we should return an empty string.
229
QString text;
230
231
for
(
auto
&&pair : *
this
)
232
{
233
// For debugging
234
#if 0
235
236
QString new_data_point_text = QString(
"%1 %2\n"
)
237
.arg(pair.first, 0,
'f'
, 10)
238
.arg(pair.second, 0,
'f'
, 10);
239
240
qDebug() <<
"new data point text:"
<< new_data_point_text;
241
text.append(new_data_point_text);
242
#endif
243
244
text.append(QString(
"%1 %2\n"
).arg(pair.first, 0,
'f'
, 10).arg(pair.second, 0,
'f'
, 10));
245
}
246
247
return
text;
248
}
249
250
251
}
// namespace pappso
pappso::ExceptionNotPossible
Definition
exceptionnotpossible.h:29
pappso::MapTrace
Definition
maptrace.h:36
pappso::MapTrace::toString
QString toString() const
Definition
maptrace.cpp:226
pappso::MapTrace::makeMapTraceSPtr
MapTraceSPtr makeMapTraceSPtr() const
Definition
maptrace.cpp:149
pappso::MapTrace::~MapTrace
virtual ~MapTrace()
Definition
maptrace.cpp:77
pappso::MapTrace::MapTrace
MapTrace()
Definition
maptrace.cpp:29
pappso::MapTrace::operator=
virtual MapTrace & operator=(const MapTrace &other)
Definition
maptrace.cpp:128
pappso::MapTrace::toTrace
Trace toTrace() const
Definition
maptrace.cpp:214
pappso::MapTrace::xValues
std::vector< pappso_double > xValues()
Definition
maptrace.cpp:163
pappso::MapTrace::makeMapTraceCstSPtr
MapTraceCstSPtr makeMapTraceCstSPtr() const
Definition
maptrace.cpp:156
pappso::MapTrace::initialize
size_t initialize(const std::vector< pappso_double > &xVector, const std::vector< pappso_double > &yVector)
Definition
maptrace.cpp:85
pappso::MapTrace::insertOrUpdate
void insertOrUpdate(const DataPoint &data_point)
Definition
maptrace.cpp:187
pappso::MapTrace::yValues
std::vector< pappso_double > yValues()
Definition
maptrace.cpp:175
pappso::Trace
A simple container of DataPoint instances.
Definition
trace.h:152
exceptionnotpossible.h
mapTracePtrMetaTypeId
int mapTracePtrMetaTypeId
Definition
maptrace.cpp:23
mapTraceMetaTypeId
int mapTraceMetaTypeId
Definition
maptrace.cpp:22
maptrace.h
pappso
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition
aa.cpp:39
pappso::MapTraceSPtr
std::shared_ptr< MapTrace > MapTraceSPtr
Definition
maptrace.h:28
pappso::pappso_double
double pappso_double
A type definition for doubles.
Definition
types.h:60
pappso::MapTraceCstSPtr
std::shared_ptr< const MapTrace > MapTraceCstSPtr
Definition
maptrace.h:29
pappso::DataPoint
Definition
datapoint.h:22
pappso::DataPoint::x
pappso_double x
Definition
datapoint.h:24
pappso::DataPoint::y
pappso_double y
Definition
datapoint.h:25
traceminuscombiner.h
tracepluscombiner.h
types.h
pappsomspp
core
trace
maptrace.cpp
Generated on
for libpappsomspp by
1.17.0