libpappsomspp
Library for mass spectrometry
Toggle main menu visibility
Loading...
Searching...
No Matches
filterresample.cpp
Go to the documentation of this file.
1
/**
2
* \file pappsomspp/filers/filterresample.cpp
3
* \date 28/04/2019
4
* \author Olivier Langella
5
* \brief collection of filters concerned by X selection
6
*/
7
8
/*******************************************************************************
9
* Copyright (c) 2019 Olivier Langella <Olivier.Langella@u-psud.fr>.
10
*
11
* This file is part of the PAPPSOms++ library.
12
*
13
* PAPPSOms++ is free software: you can redistribute it and/or modify
14
* it under the terms of the GNU General Public License as published by
15
* the Free Software Foundation, either version 3 of the License, or
16
* (at your option) any later version.
17
*
18
* PAPPSOms++ is distributed in the hope that it will be useful,
19
* but WITHOUT ANY WARRANTY; without even the implied warranty of
20
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
* GNU General Public License for more details.
22
*
23
* You should have received a copy of the GNU General Public License
24
* along with PAPPSOms++. If not, see <http://www.gnu.org/licenses/>.
25
*
26
******************************************************************************/
27
28
#include "
filterresample.h
"
29
#include "
pappsomspp/core/massspectrum/massspectrum.h
"
30
#include <QDebug>
31
32
namespace
pappso
33
{
34
35
36
FilterResampleKeepSmaller::FilterResampleKeepSmaller
(
double
x_value) :
m_value
(x_value)
37
{
38
}
39
40
FilterResampleKeepSmaller::FilterResampleKeepSmaller
(
const
FilterResampleKeepSmaller
&other)
41
:
FilterResampleKeepSmaller
(other.
m_value
)
42
{
43
}
44
45
46
Trace
&
47
FilterResampleKeepSmaller::filter
(
Trace
&spectrum)
const
48
{
49
auto
begin_it =
findFirstEqualOrGreaterX
(spectrum.begin(), spectrum.end(),
m_value
);
50
spectrum.erase(begin_it, spectrum.end());
51
return
spectrum;
52
}
53
54
FilterResampleKeepGreater::FilterResampleKeepGreater
(
double
x_value) :
m_value
(x_value)
55
{
56
}
57
58
FilterResampleKeepGreater::FilterResampleKeepGreater
(
const
FilterResampleKeepGreater
&other)
59
:
FilterResampleKeepGreater
(other.
m_value
)
60
{
61
}
62
63
64
double
65
FilterResampleKeepGreater::getThresholdX
()
const
66
{
67
return
m_value
;
68
}
69
70
FilterResampleKeepGreater
&
71
FilterResampleKeepGreater::operator=
(
const
FilterResampleKeepGreater
&other)
72
{
73
m_value
= other.
m_value
;
74
75
return
*
this
;
76
}
77
78
Trace
&
79
FilterResampleKeepGreater::filter
(
Trace
&spectrum)
const
80
{
81
// qDebug() << " spectrum.size()=" << spectrum.size();
82
83
auto
last_it =
findFirstGreaterX
(spectrum.begin(), spectrum.end(),
m_value
);
84
spectrum.erase(spectrum.begin(), last_it);
85
86
// qDebug() << " spectrum.size()=" << spectrum.size();
87
88
return
spectrum;
89
}
90
91
FilterResampleRemoveXRange::FilterResampleRemoveXRange
(
double
min_x,
double
max_x)
92
:
m_minX
(min_x),
m_maxX
(max_x)
93
{
94
}
95
96
FilterResampleRemoveXRange::FilterResampleRemoveXRange
(
const
FilterResampleRemoveXRange
&other)
97
:
FilterResampleRemoveXRange
(other.
m_minX
, other.
m_maxX
)
98
{
99
}
100
101
102
FilterResampleRemoveXRange
&
103
FilterResampleRemoveXRange::operator=
(
const
FilterResampleRemoveXRange
&other)
104
{
105
m_minX
= other.
m_minX
;
106
m_maxX
= other.
m_maxX
;
107
108
return
*
this
;
109
}
110
111
112
Trace
&
113
FilterResampleRemoveXRange::filter
(
Trace
&spectrum)
const
114
{
115
116
// qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
117
// << " m_min_x=" << m_min_x;
118
// qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
119
// << " m_max_x=" << m_max_x;
120
auto
begin_it =
findFirstEqualOrGreaterX
(spectrum.begin(), spectrum.end(),
m_minX
);
121
// qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
122
// << " begin_it->x=" << begin_it->x;
123
auto
end_it =
findFirstGreaterX
(begin_it, spectrum.end(),
m_maxX
);
124
// qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
125
// << " end_it->x=" << end_it->x;
126
spectrum.erase(begin_it, end_it);
127
128
// qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
129
// << " spectrum.size()=" << spectrum.size();
130
return
spectrum;
131
}
132
133
134
FilterResampleKeepXRange::FilterResampleKeepXRange
(
double
min_x,
double
max_x)
135
:
m_minX
(min_x),
m_maxX
(max_x)
136
{
137
}
138
139
FilterResampleKeepXRange::FilterResampleKeepXRange
(
const
FilterResampleKeepXRange
&other)
140
:
m_minX
(other.
m_minX
),
m_maxX
(other.
m_maxX
)
141
{
142
}
143
144
145
FilterResampleKeepXRange
&
146
FilterResampleKeepXRange::operator=
(
const
FilterResampleKeepXRange
&other)
147
{
148
if
(&other ==
this
)
149
return
*
this
;
150
151
m_minX
= other.
m_minX
;
152
m_maxX
= other.
m_maxX
;
153
154
return
*
this
;
155
}
156
157
158
Trace
&
159
FilterResampleKeepXRange::filter
(
Trace
&spectrum)
const
160
{
161
// qDebug() << "The range to keep:" << m_minX << "-" << m_maxX;
162
163
auto
begin_it =
findFirstEqualOrGreaterX
(spectrum.begin(), spectrum.end(),
m_minX
);
164
165
// qDebug() << "Found begin iterator (for m_minX) having:" << begin_it->x
166
//<< "x (m/z) value";
167
168
auto
end_it =
findFirstGreaterX
(begin_it, spectrum.end(),
m_maxX
);
169
170
if
(end_it == spectrum.end())
171
{
172
// qDebug() << "The end iterator (for m_maxX) is the end(). The prev "
173
//"iterator has"
174
//<< std::prev(end_it)->x << " x(m / z) value.";
175
}
176
else
177
{
178
// qDebug() << "Found end iterator (for m_maxX) having:" << end_it->x
179
//<< "x (m/z) value";
180
}
181
182
// qDebug() << "Only keeping range" << begin_it->x << "-"
183
//<< std::prev(end_it)->x;
184
185
spectrum.erase(end_it, spectrum.end());
186
spectrum.erase(spectrum.begin(), begin_it);
187
188
return
spectrum;
189
}
190
191
192
MassSpectrumFilterResampleRemoveMzRange::MassSpectrumFilterResampleRemoveMzRange
(
193
const
MzRange
&mz_range)
194
:
m_filterRange
(mz_range.lower(), mz_range.upper())
195
{
196
}
197
198
MassSpectrumFilterResampleRemoveMzRange::MassSpectrumFilterResampleRemoveMzRange
(
199
const
MassSpectrumFilterResampleRemoveMzRange
&other)
200
:
m_filterRange
(other.
m_filterRange
)
201
{
202
}
203
204
MassSpectrum
&
205
MassSpectrumFilterResampleRemoveMzRange::filter
(
MassSpectrum
&spectrum)
const
206
{
207
// qDebug() << m_filterRange.filter(spectrum);
208
m_filterRange
.filter(spectrum);
209
return
spectrum;
210
}
211
212
213
MassSpectrumFilterResampleKeepMzRange::MassSpectrumFilterResampleKeepMzRange
(
214
const
MzRange
&mz_range)
215
:
m_filterRange
(mz_range.lower(), mz_range.upper())
216
{
217
}
218
219
MassSpectrumFilterResampleKeepMzRange::MassSpectrumFilterResampleKeepMzRange
(
220
const
MassSpectrumFilterResampleKeepMzRange
&other)
221
:
m_filterRange
(other.
m_filterRange
)
222
{
223
}
224
225
MassSpectrum
&
226
MassSpectrumFilterResampleKeepMzRange::filter
(
MassSpectrum
&spectrum)
const
227
{
228
m_filterRange
.filter(spectrum);
229
return
spectrum;
230
}
231
232
233
FilterResampleKeepPointInPolygon::FilterResampleKeepPointInPolygon
()
234
{
235
}
236
237
238
FilterResampleKeepPointInPolygon::FilterResampleKeepPointInPolygon
(
239
IntegrationScopeBase
*integration_scope_p,
Enums::DataKind
data_kind)
240
{
241
m_integrationScopeSpecs
.push_back(
IntegrationScopeSpec
(integration_scope_p, data_kind));
242
243
QPointF point;
244
if
(!
m_integrationScopeSpecs
.front().mpa_integrationScope->getPoint(point))
245
qFatal(
"Failed to get point."
);
246
m_lowestMz
= point.y();
247
248
double
height;
249
if
(!
m_integrationScopeSpecs
.front().mpa_integrationScope->getHeight(height))
250
qFatal(
"Failed to get height."
);
251
m_greatestMz
=
m_lowestMz
+ height;
252
}
253
254
255
FilterResampleKeepPointInPolygon::FilterResampleKeepPointInPolygon
(
256
const
IntegrationScopeSpecVector
&integration_scope_specs)
257
{
258
// qDebug();
259
260
m_integrationScopeSpecs
.assign(integration_scope_specs.begin(), integration_scope_specs.end());
261
262
for
(
auto
&&item :
m_integrationScopeSpecs
)
263
{
264
if
(item.mpa_integrationScope->isRectangle())
265
{
266
// qDebug() << "item is Rectangle.";
267
268
QPointF point;
269
if
(!item.mpa_integrationScope->getPoint(point))
270
qFatal(
"Failed to get point."
);
271
m_lowestMz
= std::min(
m_lowestMz
, point.y());
272
273
double
height;
274
if
(!item.mpa_integrationScope->getHeight(height))
275
qFatal(
"Failed to get height."
);
276
m_greatestMz
= std::max(
m_greatestMz
,
m_lowestMz
+ height);
277
}
278
else
279
{
280
if
(!item.mpa_integrationScope->isRhomboid())
281
qFatal(
282
"If integration scope is not Rectangle, then it must be "
283
"Rhomboid."
);
284
285
// qDebug() << "item is Rhomboid.";
286
287
QPointF point;
288
289
// Because the mz scale is on the coordinate, we ask for
290
// bottom-most and top-most points of the rhomboid polygon.
291
292
if
(!item.mpa_integrationScope->getBottomMostPoint(point))
293
qFatal(
"Failed to get point."
);
294
m_lowestMz
= std::min(
m_lowestMz
, point.y());
295
296
if
(!item.mpa_integrationScope->getTopMostPoint(point))
297
qFatal(
"Failed to get point."
);
298
m_greatestMz
= std::max(
m_greatestMz
, point.y());
299
}
300
}
301
}
302
303
304
FilterResampleKeepPointInPolygon::FilterResampleKeepPointInPolygon
(
305
const
FilterResampleKeepPointInPolygon
&other)
306
{
307
// qDebug();
308
309
m_integrationScopeSpecs
.assign(other.
m_integrationScopeSpecs
.begin(),
310
other.
m_integrationScopeSpecs
.end());
311
312
for
(
auto
&&item :
m_integrationScopeSpecs
)
313
{
314
QPointF point;
315
if
(!item.mpa_integrationScope->getPoint(point))
316
qFatal(
"Failed to get point."
);
317
m_lowestMz
= std::min(
m_lowestMz
, point.y());
318
319
double
height;
320
if
(!item.mpa_integrationScope->getHeight(height))
321
qFatal(
"Failed to get height."
);
322
m_greatestMz
= std::max(
m_greatestMz
,
m_lowestMz
+ height);
323
}
324
}
325
326
327
void
328
FilterResampleKeepPointInPolygon::newSelectionPolygonSpec
(
329
const
IntegrationScopeSpec
&integration_scope_spec)
330
{
331
332
m_integrationScopeSpecs
.push_back(integration_scope_spec);
333
334
QPointF point;
335
if
(!
m_integrationScopeSpecs
.back().mpa_integrationScope->getPoint(point))
336
qFatal(
"Failed to get point."
);
337
m_lowestMz
= std::min(
m_lowestMz
, point.y());
338
339
double
height;
340
if
(!
m_integrationScopeSpecs
.back().mpa_integrationScope->getHeight(height))
341
qFatal(
"Failed to get height."
);
342
m_greatestMz
= std::max(
m_greatestMz
,
m_lowestMz
+ height);
343
}
344
345
346
FilterResampleKeepPointInPolygon
&
347
FilterResampleKeepPointInPolygon::operator=
(
const
FilterResampleKeepPointInPolygon
&other)
348
{
349
if
(
this
== &other)
350
return
*
this
;
351
352
m_integrationScopeSpecs
.assign(other.
m_integrationScopeSpecs
.begin(),
353
other.
m_integrationScopeSpecs
.end());
354
355
m_lowestMz
= other.
m_lowestMz
;
356
m_greatestMz
= other.
m_greatestMz
;
357
358
return
*
this
;
359
}
360
361
362
Trace
&
363
FilterResampleKeepPointInPolygon::filter
([[maybe_unused]]
Trace
&trace)
const
364
{
365
qFatal(
"Programming error."
);
366
return
trace;
367
}
368
369
370
Trace
&
371
FilterResampleKeepPointInPolygon::filter
(
Trace
&trace,
double
dt_value,
double
rt_value)
const
372
{
373
// Each time a new integration scope spec is added, the lowest and greatest
374
// m/z values are computed. We use these values to remove from the spectrum
375
// all the points that are outside of that lowest-gratest range.
376
377
// Find the iterator to the most front of the DataPoint vector (mass
378
// spectrum).
379
380
// Note that the m_lowestMz and m_greatestMz are set during construction of
381
// this FilterResampleKeepPointInPolygon filter using the
382
// integration scope specs.
383
384
// qDebug() << "The lowest and greatest m/z values:" << m_lowestMz << "and"
385
//<< m_greatestMz;
386
387
// Start by filtering away all the data points outside of the
388
// [m_lowestMz--m_greatestMz] range.
389
390
FilterResampleKeepXRange
the_filter(
m_lowestMz
,
m_greatestMz
);
391
392
trace = the_filter.
filter
(trace);
393
394
// Now iterate in all the data points remaining in the trace and for each
395
// point craft a "virtual" point using the dt|rt value and the m/z value of
396
// the data point (data_point.x).
397
398
auto
begin_it = trace.begin();
399
auto
end_it = trace.end();
400
401
// qDebug() << "Iterating in the m/z range:" << begin_it->x << "-"
402
//<< std::prev(end_it)->x;
403
404
// Start at the end of the range. The iter is outside of the requested range,
405
// in fact, as shown using iter-- below.
406
auto
iter = end_it;
407
408
while
(iter > begin_it)
409
{
410
// Immediately go to the last data point of the desired iteration range of
411
// the trace that we need to filter. Remember that end() is not pointing
412
// to any vector item, but past the last one.
413
iter--;
414
415
// qDebug() << "Iterating in trace data point with m/z value:" << iter->x;
416
417
// Now that we have the m/z value, we can check it, in combination with
418
// the value in the selection polygon spec (to make a point) against the
419
// various selection polygon specs in our member vector.
420
421
double
checked_value;
422
423
for
(
auto
&&spec :
m_integrationScopeSpecs
)
424
{
425
// qDebug() << "Iterating in selection polygon spec:" <<
426
// spec.toString();
427
428
if
(spec.dataKind ==
Enums::DataKind::dt
)
429
{
430
if
(dt_value == -1)
431
qFatal(
"Programming error."
);
432
433
checked_value = dt_value;
434
435
// qDebug() << "The data kind: dt.";
436
}
437
else
if
(spec.dataKind ==
Enums::DataKind::rt
)
438
{
439
checked_value = rt_value;
440
441
// qDebug() << "The data kind: rt.";
442
}
443
else
444
qFatal(
"Programming error."
);
445
446
// First version doing the whole computation on the basis of the
447
// selection polygon's all faces.
448
//
449
if
(!spec.mpa_integrationScope->contains(QPointF(checked_value, iter->x)))
450
iter = trace.erase(iter);
451
}
452
// End of
453
// for(auto &&spec : m_selectionPolygonSpecs)
454
}
455
// End of
456
// while(iter > begin_it)
457
458
return
trace;
459
}
460
461
}
// namespace pappso
pappso::FilterResampleKeepGreater
Definition
filterresample.h:55
pappso::FilterResampleKeepGreater::getThresholdX
double getThresholdX() const
Definition
filterresample.cpp:65
pappso::FilterResampleKeepGreater::operator=
FilterResampleKeepGreater & operator=(const FilterResampleKeepGreater &other)
Definition
filterresample.cpp:71
pappso::FilterResampleKeepGreater::m_value
double m_value
Definition
filterresample.h:57
pappso::FilterResampleKeepGreater::FilterResampleKeepGreater
FilterResampleKeepGreater(double x_value)
Definition
filterresample.cpp:54
pappso::FilterResampleKeepGreater::filter
Trace & filter(Trace &trace) const override
Definition
filterresample.cpp:79
pappso::FilterResampleKeepPointInPolygon
Definition
filterresample.h:108
pappso::FilterResampleKeepPointInPolygon::m_lowestMz
double m_lowestMz
Definition
filterresample.h:136
pappso::FilterResampleKeepPointInPolygon::m_greatestMz
double m_greatestMz
Definition
filterresample.h:137
pappso::FilterResampleKeepPointInPolygon::newSelectionPolygonSpec
void newSelectionPolygonSpec(const IntegrationScopeSpec &integration_scope_spec)
Definition
filterresample.cpp:328
pappso::FilterResampleKeepPointInPolygon::m_integrationScopeSpecs
IntegrationScopeSpecVector m_integrationScopeSpecs
Definition
filterresample.h:135
pappso::FilterResampleKeepPointInPolygon::operator=
FilterResampleKeepPointInPolygon & operator=(const FilterResampleKeepPointInPolygon &other)
Definition
filterresample.cpp:347
pappso::FilterResampleKeepPointInPolygon::filter
Trace & filter(Trace &trace) const override
Definition
filterresample.cpp:363
pappso::FilterResampleKeepPointInPolygon::FilterResampleKeepPointInPolygon
FilterResampleKeepPointInPolygon()
Definition
filterresample.cpp:233
pappso::FilterResampleKeepSmaller::filter
Trace & filter(Trace &trace) const override
Definition
filterresample.cpp:47
pappso::FilterResampleKeepSmaller::m_value
double m_value
Definition
filterresample.h:44
pappso::FilterResampleKeepSmaller::FilterResampleKeepSmaller
FilterResampleKeepSmaller(double x_value)
Definition
filterresample.cpp:36
pappso::FilterResampleKeepXRange
Definition
filterresample.h:89
pappso::FilterResampleKeepXRange::operator=
FilterResampleKeepXRange & operator=(const FilterResampleKeepXRange &other)
Definition
filterresample.cpp:146
pappso::FilterResampleKeepXRange::m_maxX
double m_maxX
Definition
filterresample.h:92
pappso::FilterResampleKeepXRange::FilterResampleKeepXRange
FilterResampleKeepXRange(double min_x=0, double max_x=0)
Definition
filterresample.cpp:134
pappso::FilterResampleKeepXRange::filter
Trace & filter(Trace &trace) const override
Definition
filterresample.cpp:159
pappso::FilterResampleKeepXRange::m_minX
double m_minX
Definition
filterresample.h:91
pappso::FilterResampleRemoveXRange
Definition
filterresample.h:72
pappso::FilterResampleRemoveXRange::FilterResampleRemoveXRange
FilterResampleRemoveXRange(double min_x, double max_x)
Definition
filterresample.cpp:91
pappso::FilterResampleRemoveXRange::operator=
FilterResampleRemoveXRange & operator=(const FilterResampleRemoveXRange &other)
Definition
filterresample.cpp:103
pappso::FilterResampleRemoveXRange::m_maxX
double m_maxX
Definition
filterresample.h:75
pappso::FilterResampleRemoveXRange::filter
Trace & filter(Trace &trace) const override
Definition
filterresample.cpp:113
pappso::FilterResampleRemoveXRange::m_minX
double m_minX
Definition
filterresample.h:74
pappso::IntegrationScopeBase
Definition
integrationscopebase.h:61
pappso::MassSpectrumFilterResampleKeepMzRange::MassSpectrumFilterResampleKeepMzRange
MassSpectrumFilterResampleKeepMzRange(const MzRange &mz_range)
Definition
filterresample.cpp:213
pappso::MassSpectrumFilterResampleKeepMzRange::filter
MassSpectrum & filter(MassSpectrum &spectrum) const override
Definition
filterresample.cpp:226
pappso::MassSpectrumFilterResampleKeepMzRange::m_filterRange
const FilterResampleKeepXRange m_filterRange
Definition
filterresample.h:160
pappso::MassSpectrumFilterResampleRemoveMzRange::m_filterRange
const FilterResampleRemoveXRange m_filterRange
Definition
filterresample.h:145
pappso::MassSpectrumFilterResampleRemoveMzRange::MassSpectrumFilterResampleRemoveMzRange
MassSpectrumFilterResampleRemoveMzRange(const MzRange &mz_range)
Definition
filterresample.cpp:192
pappso::MassSpectrumFilterResampleRemoveMzRange::filter
MassSpectrum & filter(MassSpectrum &spectrum) const override
Definition
filterresample.cpp:205
pappso::MassSpectrum
Class to represent a mass spectrum.
Definition
massspectrum.h:70
pappso::MzRange
Definition
mzrange.h:46
pappso::Trace
A simple container of DataPoint instances.
Definition
trace.h:152
filterresample.h
massspectrum.h
pappso::Enums::DataKind
DataKind
Definition
types.h:238
pappso::Enums::DataKind::dt
@ dt
Drift time.
Definition
types.h:241
pappso::Enums::DataKind::rt
@ rt
Retention time.
Definition
types.h:240
pappso
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition
aa.cpp:39
pappso::findFirstEqualOrGreaterX
std::vector< DataPoint >::iterator findFirstEqualOrGreaterX(std::vector< DataPoint >::iterator begin, std::vector< DataPoint >::iterator end, const double &value)
find the first element in which X is equal or greater than the value searched important : it implies ...
Definition
trace.cpp:65
pappso::findFirstGreaterX
std::vector< DataPoint >::iterator findFirstGreaterX(std::vector< DataPoint >::iterator begin, std::vector< DataPoint >::iterator end, const double &value)
find the first element in which X is greater than the value searched important : it implies that Trac...
Definition
trace.cpp:93
pappso::IntegrationScopeSpecVector
std::vector< IntegrationScopeSpec > IntegrationScopeSpecVector
Definition
filterresample.h:105
pappso::IntegrationScopeSpec
Definition
integrationscopebase.h:124
pappsomspp
core
processing
filters
filterresample.cpp
Generated on
for libpappsomspp by
1.17.0