libpappsomspp
Library for mass spectrometry
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 "../../massspectrum/massspectrum.h"
30#include <QDebug>
31
32namespace pappso
33{
34
35
37 : m_value(x_value)
38{
39}
40
46
47
48Trace &
50{
51 auto begin_it =
52 findFirstEqualOrGreaterX(spectrum.begin(), spectrum.end(), m_value);
53 spectrum.erase(begin_it, spectrum.end());
54 return spectrum;
55}
56
58 : m_value(x_value)
59{
60}
61
67
68
69double
74
77{
78 m_value = other.m_value;
79
80 return *this;
81}
82
83Trace &
85{
86 // qDebug() << " spectrum.size()=" << spectrum.size();
87
88 auto last_it = findFirstGreaterX(spectrum.begin(), spectrum.end(), m_value);
89 spectrum.erase(spectrum.begin(), last_it);
90
91 // qDebug() << " spectrum.size()=" << spectrum.size();
92
93 return spectrum;
94}
95
97 double max_x)
98 : m_minX(min_x), m_maxX(max_x)
99{
100}
101
107
108
111{
112 m_minX = other.m_minX;
113 m_maxX = other.m_maxX;
114
115 return *this;
116}
117
118
119Trace &
121{
122
123 // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
124 // << " m_min_x=" << m_min_x;
125 // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
126 // << " m_max_x=" << m_max_x;
127 auto begin_it =
128 findFirstEqualOrGreaterX(spectrum.begin(), spectrum.end(), m_minX);
129 // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
130 // << " begin_it->x=" << begin_it->x;
131 auto end_it = findFirstGreaterX(begin_it, spectrum.end(), m_maxX);
132 // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
133 // << " end_it->x=" << end_it->x;
134 spectrum.erase(begin_it, end_it);
135
136 // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
137 // << " spectrum.size()=" << spectrum.size();
138 return spectrum;
139}
140
141
143 : m_minX(min_x), m_maxX(max_x)
144{
145}
146
148 const FilterResampleKeepXRange &other)
149 : m_minX(other.m_minX), m_maxX(other.m_maxX)
150{
151}
152
153
156{
157 if(&other == this)
158 return *this;
159
160 m_minX = other.m_minX;
161 m_maxX = other.m_maxX;
162
163 return *this;
164}
165
166
167Trace &
169{
170 // qDebug() << "The range to keep:" << m_minX << "-" << m_maxX;
171
172 auto begin_it =
173 findFirstEqualOrGreaterX(spectrum.begin(), spectrum.end(), m_minX);
174
175 // qDebug() << "Found begin iterator (for m_minX) having:" << begin_it->x
176 //<< "x (m/z) value";
177
178 auto end_it = findFirstGreaterX(begin_it, spectrum.end(), m_maxX);
179
180 if(end_it == spectrum.end())
181 {
182 // qDebug() << "The end iterator (for m_maxX) is the end(). The prev "
183 //"iterator has"
184 //<< std::prev(end_it)->x << " x(m / z) value.";
185 }
186 else
187 {
188 // qDebug() << "Found end iterator (for m_maxX) having:" << end_it->x
189 //<< "x (m/z) value";
190 }
191
192 // qDebug() << "Only keeping range" << begin_it->x << "-"
193 //<< std::prev(end_it)->x;
194
195 spectrum.erase(end_it, spectrum.end());
196 spectrum.erase(spectrum.begin(), begin_it);
197
198 return spectrum;
199}
200
201
204 : m_filterRange(mz_range.lower(), mz_range.upper())
205{
206}
207
214
217{
218 // qDebug() << m_filterRange.filter(spectrum);
219 m_filterRange.filter(spectrum);
220 return spectrum;
221}
222
223
225 const MzRange &mz_range)
226 : m_filterRange(mz_range.lower(), mz_range.upper())
227{
228}
229
235
238{
239 m_filterRange.filter(spectrum);
240 return spectrum;
241}
242
243
247
248
250 IntegrationScopeBaseSPtr integration_scope_sp, DataKind data_kind)
251{
252 m_integrationScopeSpecs.push_back(
253 IntegrationScopeSpec(integration_scope_sp, data_kind));
254
255 QPointF point;
256 if(!m_integrationScopeSpecs.front().integrationScopeSPtr->getPoint(point))
257 qFatal("Failed to get point.");
258 m_lowestMz = point.y();
259
260 double height;
261 if(!m_integrationScopeSpecs.front().integrationScopeSPtr->getHeight(height))
262 qFatal("Failed to get height.");
263 m_greatestMz = m_lowestMz + height;
264}
265
266
268 const IntegrationScopeSpecVector &integration_scope_specs)
269{
270 // qDebug();
271
272 m_integrationScopeSpecs.assign(integration_scope_specs.begin(),
273 integration_scope_specs.end());
274
275 for(auto &&item : m_integrationScopeSpecs)
276 {
277 if(item.integrationScopeSPtr->isRectangle())
278 {
279 // qDebug() << "item is Rectangle.";
280
281 QPointF point;
282 if(!item.integrationScopeSPtr->getPoint(point))
283 qFatal("Failed to get point.");
284 m_lowestMz = std::min(m_lowestMz, point.y());
285
286 double height;
287 if(!item.integrationScopeSPtr->getHeight(height))
288 qFatal("Failed to get height.");
289 m_greatestMz = std::max(m_greatestMz, m_lowestMz + height);
290 }
291 else
292 {
293 if(!item.integrationScopeSPtr->isRhomboid())
294 qFatal(
295 "If integration scope is not Rectangle, then it must be "
296 "Rhomboid.");
297
298 // qDebug() << "item is Rhomboid.";
299
300 QPointF point;
301
302 // Because the mz scale is on the coordinate, we ask for
303 // bottom-most and top-most points of the rhomboid polygon.
304
305 if(!item.integrationScopeSPtr->getBottomMostPoint(point))
306 qFatal("Failed to get point.");
307 m_lowestMz = std::min(m_lowestMz, point.y());
308
309 if(!item.integrationScopeSPtr->getTopMostPoint(point))
310 qFatal("Failed to get point.");
311 m_greatestMz = std::max(m_greatestMz, point.y());
312 }
313 }
314}
315
316
319{
320 // qDebug();
321
323 other.m_integrationScopeSpecs.end());
324
325 for(auto &&item : m_integrationScopeSpecs)
326 {
327 QPointF point;
328 if(!item.integrationScopeSPtr->getPoint(point))
329 qFatal("Failed to get point.");
330 m_lowestMz = std::min(m_lowestMz, point.y());
331
332 double height;
333 if(!item.integrationScopeSPtr->getHeight(height))
334 qFatal("Failed to get height.");
335 m_greatestMz = std::max(m_greatestMz, m_lowestMz + height);
336 }
337}
338
339
340void
342 const IntegrationScopeSpec &integration_scope_spec)
343{
344
345 m_integrationScopeSpecs.push_back(integration_scope_spec);
346
347 QPointF point;
348 if(!m_integrationScopeSpecs.back().integrationScopeSPtr->getPoint(point))
349 qFatal("Failed to get point.");
350 m_lowestMz = std::min(m_lowestMz, point.y());
351
352 double height;
353 if(!m_integrationScopeSpecs.back().integrationScopeSPtr->getHeight(height))
354 qFatal("Failed to get height.");
355 m_greatestMz = std::max(m_greatestMz, m_lowestMz + height);
356}
357
358
362{
363 if(this == &other)
364 return *this;
365
367 other.m_integrationScopeSpecs.end());
368
369 m_lowestMz = other.m_lowestMz;
371
372 return *this;
373}
374
375
376Trace &
378{
379 qFatal("Programming error.");
380 return trace;
381}
382
383
384Trace &
386 double dt_value,
387 double rt_value) const
388{
389 // Each time a new integration scope spec is added, the lowest and greatest
390 // m/z values are computed. We use these values to remove from the spectrum
391 // all the points that are outside of that lowest-gratest range.
392
393 // Find the iterator to the most front of the DataPoint vector (mass
394 // spectrum).
395
396 // Note that the m_lowestMz and m_greatestMz are set during construction of
397 // this FilterResampleKeepPointInPolygon filter using the
398 // integration scope specs.
399
400 // qDebug() << "The lowest and greatest m/z values:" << m_lowestMz << "and"
401 //<< m_greatestMz;
402
403 // Start by filtering away all the data points outside of the
404 // [m_lowestMz--m_greatestMz] range.
405
407
408 trace = the_filter.filter(trace);
409
410 // Now iterate in all the data points remaining in the trace and for each
411 // point craft a "virtual" point using the dt|rt value and the m/z value of
412 // the data point (data_point.x).
413
414 auto begin_it = trace.begin();
415 auto end_it = trace.end();
416
417 // qDebug() << "Iterating in the m/z range:" << begin_it->x << "-"
418 //<< std::prev(end_it)->x;
419
420 // Start at the end of the range. The iter is outside of the requested range,
421 // in fact, as shown using iter-- below.
422 auto iter = end_it;
423
424 while(iter > begin_it)
425 {
426 // Immediately go to the last data point of the desired iteration range of
427 // the trace that we need to filter. Remember that end() is not pointing
428 // to any vector item, but past the last one.
429 iter--;
430
431 // qDebug() << "Iterating in trace data point with m/z value:" << iter->x;
432
433 // Now that we have the m/z value, we can check it, in combination with
434 // the value in the selection polygon spec (to make a point) against the
435 // various selection polygon specs in our member vector.
436
437 double checked_value;
438
439 for(auto &&spec : m_integrationScopeSpecs)
440 {
441 // qDebug() << "Iterating in selection polygon spec:" <<
442 // spec.toString();
443
444 if(spec.dataKind == DataKind::dt)
445 {
446 if(dt_value == -1)
447 qFatal("Programming error.");
448
449 checked_value = dt_value;
450
451 // qDebug() << "The data kind: dt.";
452 }
453 else if(spec.dataKind == DataKind::rt)
454 {
455 checked_value = rt_value;
456
457 // qDebug() << "The data kind: rt.";
458 }
459 else
460 qFatal("Programming error.");
461
462 // First version doing the whole computation on the basis of the
463 // selection polygon's all faces.
464 //
465 if(!spec.integrationScopeSPtr->contains(
466 QPointF(checked_value, iter->x)))
467 iter = trace.erase(iter);
468 }
469 // End of
470 // for(auto &&spec : m_selectionPolygonSpecs)
471 }
472 // End of
473 // while(iter > begin_it)
474
475 return trace;
476}
477
478} // namespace pappso
FilterResampleKeepGreater & operator=(const FilterResampleKeepGreater &other)
Trace & filter(Trace &trace) const override
void newSelectionPolygonSpec(const IntegrationScopeSpec &integration_scope_spec)
IntegrationScopeSpecVector m_integrationScopeSpecs
FilterResampleKeepPointInPolygon & operator=(const FilterResampleKeepPointInPolygon &other)
Trace & filter(Trace &trace) const override
Trace & filter(Trace &trace) const override
FilterResampleKeepXRange & operator=(const FilterResampleKeepXRange &other)
FilterResampleKeepXRange(double min_x=0, double max_x=0)
Trace & filter(Trace &trace) const override
FilterResampleRemoveXRange(double min_x, double max_x)
FilterResampleRemoveXRange & operator=(const FilterResampleRemoveXRange &other)
Trace & filter(Trace &trace) const override
MassSpectrumFilterResampleKeepMzRange(const MzRange &mz_range)
MassSpectrum & filter(MassSpectrum &spectrum) const override
const FilterResampleKeepXRange m_filterRange
const FilterResampleRemoveXRange m_filterRange
MassSpectrumFilterResampleRemoveMzRange(const MzRange &mz_range)
MassSpectrum & filter(MassSpectrum &spectrum) const override
Class to represent a mass spectrum.
A simple container of DataPoint instances.
Definition trace.h:148
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39
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:71
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:99
std::shared_ptr< IntegrationScopeBase > IntegrationScopeBaseSPtr
DataKind
Definition types.h:211
@ dt
Drift time.
@ rt
Retention time.
std::vector< IntegrationScopeSpec > IntegrationScopeSpecVector