libpappsomspp
Library for mass spectrometry
trace.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 #include <QDebug>
11 
12 #include "trace.h"
13 #include "maptrace.h"
14 #include "../processing/combiners/tracepluscombiner.h"
15 #include "../processing/combiners/traceminuscombiner.h"
16 #include "../types.h"
17 #include "../pappsoexception.h"
18 #include "../exception/exceptionoutofrange.h"
19 #include "../exception/exceptionnotpossible.h"
20 #include "../processing/filters/filterresample.h"
21 #include "../processing/filters/filterpass.h"
22 
23 
24 int traceMetaTypeId = qRegisterMetaType<pappso::Trace>("pappso::Trace");
25 int tracePtrMetaTypeId = qRegisterMetaType<pappso::Trace *>("pappso::Trace *");
26 
27 
28 namespace pappso
29 {
30 
31 std::vector<DataPoint>::iterator
32 findFirstEqualOrGreaterX(std::vector<DataPoint>::iterator begin,
33  std::vector<DataPoint>::iterator end,
34  const double &value)
35 {
36  return std::find_if(begin, end, [value](const DataPoint &to_compare) {
37  if(to_compare.x < value)
38  {
39  return false;
40  }
41  return true;
42  });
43 }
44 
45 std::vector<DataPoint>::const_iterator
46 findFirstEqualOrGreaterX(std::vector<DataPoint>::const_iterator begin,
47  std::vector<DataPoint>::const_iterator end,
48  const double &value)
49 {
50  return std::find_if(begin, end, [value](const DataPoint &to_compare) {
51  if(to_compare.x < value)
52  {
53  return false;
54  }
55  return true;
56  });
57 }
58 
59 std::vector<DataPoint>::iterator
60 findFirstGreaterX(std::vector<DataPoint>::iterator begin,
61  std::vector<DataPoint>::iterator end,
62  const double &value)
63 {
64  return std::find_if(begin, end, [value](const DataPoint &to_compare) {
65  if(to_compare.x > value)
66  {
67  return true;
68  }
69  return false;
70  });
71 }
72 
73 std::vector<DataPoint>::const_iterator
74 findFirstGreaterX(std::vector<DataPoint>::const_iterator begin,
75  std::vector<DataPoint>::const_iterator end,
76  const double &value)
77 {
78  return std::find_if(begin, end, [value](const DataPoint &to_compare) {
79  if(to_compare.x > value)
80  {
81  return true;
82  }
83  return false;
84  });
85 }
86 
87 std::vector<DataPoint>::iterator
88 findDifferentYvalue(std::vector<DataPoint>::iterator begin,
89  std::vector<DataPoint>::iterator end,
90  const double &y_value)
91 {
92  return std::find_if(begin, end, [y_value](const DataPoint &to_compare) {
93  if(to_compare.y != y_value)
94  {
95  return true;
96  }
97  return false;
98  });
99 }
100 
101 std::vector<DataPoint>::const_iterator
102 findDifferentYvalue(std::vector<DataPoint>::const_iterator begin,
103  std::vector<DataPoint>::const_iterator end,
104  const double &y_value)
105 {
106  return std::find_if(begin, end, [y_value](const DataPoint &to_compare) {
107  if(to_compare.y != y_value)
108  {
109  return true;
110  }
111  return false;
112  });
113 }
114 
115 
116 std::vector<DataPoint>::const_iterator
117 minYDataPoint(std::vector<DataPoint>::const_iterator begin,
118  std::vector<DataPoint>::const_iterator end)
119 {
120  return std::min_element(
121  begin, end, [](const DataPoint &a, const DataPoint &b) {
122  return a.y < b.y;
123  });
124 }
125 
126 
127 std::vector<DataPoint>::iterator
128 minYDataPoint(std::vector<DataPoint>::iterator begin,
129  std::vector<DataPoint>::iterator end)
130 {
131  return std::min_element(
132  begin, end, [](const DataPoint &a, const DataPoint &b) {
133  return a.y < b.y;
134  });
135 }
136 
137 
138 std::vector<DataPoint>::const_iterator
139 maxYDataPoint(std::vector<DataPoint>::const_iterator begin,
140  std::vector<DataPoint>::const_iterator end)
141 {
142  return std::max_element(
143  begin, end, [](const DataPoint &a, const DataPoint &b) {
144  return a.y < b.y;
145  });
146 }
147 
148 
149 std::vector<DataPoint>::iterator
150 maxYDataPoint(std::vector<DataPoint>::iterator begin,
151  std::vector<DataPoint>::iterator end)
152 {
153  return std::max_element(
154  begin, end, [](const DataPoint &a, const DataPoint &b) {
155  return a.y < b.y;
156  });
157 }
158 
159 
160 // As long as next DataPoint has its y value less or equal to prev's,
161 // move along down the container. That is, continue moving is
162 // direction is downhill to the end of the container (its back).
163 std::vector<DataPoint>::const_iterator
165  std::vector<DataPoint>::const_iterator begin)
166 {
167  if(begin == trace.end())
168  return begin;
169  auto it = begin + 1;
170  auto result = begin;
171  // Move along as long as next point's y value is less
172  // or equal to prev point's y value (FR, check).
173  while((it != trace.end()) && (it->y <= result->y))
174  {
175  it++;
176  result++;
177  }
178  return result;
179 }
180 
181 std::vector<DataPoint>::const_iterator
183  std::vector<DataPoint>::const_iterator begin)
184 {
185  if(begin == trace.begin())
186  return begin;
187  auto it = begin - 1;
188  auto result = begin;
189 
190  // As long as prev datapoint has y value less or equal to next,
191  // move along up the container. That is, continue moving if
192  // direction is downhill to the beginning of the container (its front).
193  while((it != trace.begin()) && (it->y <= result->y))
194  {
195  it--;
196  result--;
197  }
198  return result;
199 }
200 
201 
202 double
203 sumYTrace(std::vector<DataPoint>::const_iterator begin,
204  std::vector<DataPoint>::const_iterator end,
205  double init)
206 {
207  return std::accumulate(
208  begin, end, init, [](double a, const DataPoint &b) { return a + b.y; });
209 }
210 
211 double
212 meanYTrace(std::vector<DataPoint>::const_iterator begin,
213  std::vector<DataPoint>::const_iterator end)
214 {
215  pappso_double nb_element = distance(begin, end);
216  if(nb_element == 0)
217  throw ExceptionOutOfRange(
218  QObject::tr("unable to compute mean on a trace of size 0"));
219  return (sumYTrace(begin, end, 0) / nb_element);
220 }
221 
222 
223 double
224 quantileYTrace(std::vector<DataPoint>::const_iterator begin,
225  std::vector<DataPoint>::const_iterator end,
226  double quantile)
227 {
228  std::size_t nb_element = distance(begin, end);
229  if(nb_element == 0)
230  throw ExceptionOutOfRange(
231  QObject::tr("unable to compute quantile on a trace of size 0"));
232 
233 
234  std::size_t ieth_element = std::round((double)nb_element * quantile);
235  if(ieth_element > nb_element)
236  throw ExceptionOutOfRange(
237  QObject::tr("quantile value must be lower than 1"));
238 
239 
240  std::vector<DataPoint> data(begin, end);
241  std::nth_element(
242  data.begin(),
243  data.begin() + ieth_element,
244  data.end(),
245  [](const DataPoint &a, const DataPoint &b) { return a.y < b.y; });
246  return data[ieth_element].y;
247 }
248 
249 double
250 medianYTrace(std::vector<DataPoint>::const_iterator begin,
251  std::vector<DataPoint>::const_iterator end)
252 {
253  std::size_t nb_element = distance(begin, end);
254  if(nb_element == 0)
255  throw ExceptionOutOfRange(
256  QObject::tr("unable to compute median on a trace of size 0"));
257 
258  std::vector<DataPoint> data(begin, end);
259  std::nth_element(
260  data.begin(),
261  data.begin() + data.size() / 2,
262  data.end(),
263  [](const DataPoint &a, const DataPoint &b) { return a.y < b.y; });
264  return data[data.size() / 2].y;
265 }
266 
267 double
268 areaTrace(std::vector<DataPoint>::const_iterator begin,
269  std::vector<DataPoint>::const_iterator end)
270 {
271 
272  if(begin == end)
273  return 0;
274  auto previous = begin;
275  auto next = begin + 1;
276  double area = 0;
277  while(next != end)
278  {
279  area += ((next->x - previous->x) * (previous->y + next->y)) / (double)2;
280  previous++;
281  next++;
282  }
283  return area;
284 }
285 
286 
287 Trace
288 flooredLocalMaxima(std::vector<DataPoint>::const_iterator begin,
289  std::vector<DataPoint>::const_iterator end,
290  double y_floor)
291 {
292  Trace local_maxima_trace;
293 
294  Trace single_peak_trace;
295 
296  DataPoint previous_data_point;
297 
298  for(auto iter = begin; iter != end; ++iter)
299  {
300  DataPoint iterated_data_point(iter->x, iter->y);
301 
302  // qDebug().noquote() << "Current data point:"
303  //<< iterated_data_point.toString();
304 
305  if(iterated_data_point.y < y_floor)
306  {
307  // qDebug() << "under the floor";
308 
309  if(single_peak_trace.size())
310  {
311  // qDebug() << "There was a single peak trace cooking";
312 
313  local_maxima_trace.push_back(single_peak_trace.maxYDataPoint());
314 
315  // qDebug().noquote() << "pushed back local maximum point:"
316  //<< local_maxima_trace.back().toString();
317 
318  // Clean and set the context.
319  single_peak_trace.clear();
320 
321  previous_data_point = iterated_data_point;
322 
323  continue;
324  }
325  else
326  {
327  // qDebug() << "no single peak trace cooking";
328 
329  previous_data_point = iterated_data_point;
330 
331  continue;
332  }
333  }
334  else
335  {
336  // qDebug() << "over the floor";
337 
338  // The iterated value is greater than the y_floor value, so we need to
339  // handle it.
340 
341  if(iterated_data_point.y == previous_data_point.y)
342  {
343  // We are in a flat region, no need to change anything to the
344  // context, just skip the point.
345  continue;
346  }
347  else if(iterated_data_point.y > previous_data_point.y)
348  {
349  // qDebug().noquote() << "ascending in a peak";
350 
351  // The previously iterated y value was smaller than the presently
352  // iterated one, so we are ascending in a peak.
353 
354  // All we need to do is set the context.
355 
356  single_peak_trace.push_back(iterated_data_point);
357 
358  // qDebug().noquote() << "pushed back normal point:"
359  //<< single_peak_trace.back().toString();
360 
361  previous_data_point = iterated_data_point;
362 
363  continue;
364  }
365  else
366  {
367  // qDebug().noquote() << "started descending in a peak";
368 
369  // No, the currently iterated y value is less than the previously
370  // iterated value.
371 
372  single_peak_trace.push_back(iterated_data_point);
373 
374  // qDebug().noquote() << "pushed back normal point:"
375  //<< single_peak_trace.back().toString();
376 
377  previous_data_point = iterated_data_point;
378 
379  continue;
380  }
381  }
382  }
383  // End of
384  // for(auto iter = begin; iter != end; ++iter)
385 
386  // Attention, we might arrive here with a peak being created, we need to get
387  // its maximum if that peak is non-empty;
388 
389  if(single_peak_trace.size())
390  {
391 
392  local_maxima_trace.push_back(single_peak_trace.maxYDataPoint());
393 
394  // qDebug().noquote()
395  //<< "was cooking a peak: pushed back local maximum point:"
396  //<< local_maxima_trace.back().toString();
397  }
398 
399  return local_maxima_trace;
400 }
401 
402 
404 {
405 }
406 
407 
408 Trace::Trace(const std::vector<pappso_double> &xVector,
409  const std::vector<pappso_double> &yVector)
410 {
411  initialize(xVector, yVector);
412 }
413 
414 
416  const std::vector<std::pair<pappso_double, pappso_double>> &dataPoints)
417 {
418  reserve(dataPoints.size());
419 
420  for(auto &dataPoint : dataPoints)
421  {
422  push_back(DataPoint(dataPoint));
423  }
424 
425  sortX();
426  // std::sort(begin(), end(), [](const DataPoint &a, const DataPoint &b) {
427  // return (a.x < b.x);
428  //});
429 }
430 
431 
432 Trace::Trace(const std::vector<DataPoint> &dataPoints)
433  : std::vector<DataPoint>(dataPoints)
434 {
435  sortX();
436  // std::sort(begin(), end(), [](const DataPoint &a, const DataPoint &b) {
437  // return (a.x < b.x);
438  //});
439 }
440 
441 
442 Trace::Trace(const std::vector<DataPoint> &&dataPoints)
443  : std::vector<DataPoint>(std::move(dataPoints))
444 {
445  // This constructor used by the MassSpectrum && constructor.
446 
447  sortX();
448  // std::sort(begin(), end(), [](const DataPoint &a, const DataPoint &b) {
449  // return (a.x < b.x);
450  //});
451 }
452 
453 
454 Trace::Trace(const MapTrace &map_trace)
455 {
456  for(auto &&item : map_trace)
457  push_back(DataPoint(item.first, item.second));
458 
459  // No need to sort, maps are sorted by key (that is, x).
460 }
461 
462 Trace::Trace(const Trace &other) : std::vector<DataPoint>(other)
463 {
464 }
465 
466 
467 Trace::Trace(const Trace &&other) : std::vector<DataPoint>(std::move(other))
468 {
469  // This constructor used by the MassSpectrum && constructor.
470 }
471 
472 
474 {
475  // Calls the destructor for each DataPoint object in the vector.
476  clear();
477 }
478 
479 
480 size_t
481 Trace::initialize(const std::vector<pappso_double> &xVector,
482  const std::vector<pappso_double> &yVector)
483 {
484  // Sanity check
485  if(xVector.size() != yVector.size())
486  throw ExceptionNotPossible(
487  "trace.cpp -- ERROR xVector and yVector must have the same size.");
488 
489  // We are initializing, not appending.
490  erase(begin(), end());
491 
492  for(std::size_t iter = 0; iter < xVector.size(); ++iter)
493  {
494  push_back(DataPoint(xVector.at(iter), yVector.at(iter)));
495  }
496 
497  sortX();
498  // std::sort(begin(), end(), [](const DataPoint &a, const DataPoint &b) {
499  // return (a.x < b.x);
500  //});
501 
502 #if 0
503  for(auto &item : *this)
504  {
505  std::cout << item.x << "-" << item.y;
506  }
507 #endif
508 
509  return size();
510 }
511 
512 
513 size_t
514 Trace::initialize(const std::map<pappso_double, pappso_double> &map)
515 {
516 
517  // We are initializing, not appending.
518  erase(begin(), end());
519 
520  for(auto &&item : map)
521  {
522  push_back(DataPoint(item.first, item.second));
523  }
524 
525  // No need to sort, maps are sorted by key (that is, x).
526 
527  return size();
528 }
529 
530 
531 size_t
533 {
534  *this = other;
535 
536  return size();
537 }
538 
539 
540 Trace &
541 Trace::operator=(const Trace &other)
542 {
543  assign(other.begin(), other.end());
544 
545  return *this;
546 }
547 
548 
549 Trace &
551 {
552  vector<DataPoint>::operator=(std::move(other));
553  return *this;
554 }
555 
556 
557 TraceSPtr
559 {
560  return std::make_shared<Trace>(*this);
561 }
562 
563 
566 {
567  return std::make_shared<const Trace>(*this);
568 }
569 
570 
571 std::vector<pappso_double>
573 {
574  std::vector<pappso_double> values;
575 
576  for(auto &&dataPoint : *this)
577  {
578  values.push_back(dataPoint.x);
579  }
580 
581  return values;
582 }
583 
584 
585 std::vector<pappso_double>
587 {
588  std::vector<pappso_double> values;
589 
590  for(auto &&dataPoint : *this)
591  {
592  values.push_back(dataPoint.y);
593  }
594 
595  return values;
596 }
597 
598 
599 std::map<pappso_double, pappso_double>
601 {
602  std::map<pappso_double, pappso_double> map;
603 
604  std::pair<std::map<pappso_double, pappso_double>::iterator, bool> ret;
605 
606  for(auto &&dataPoint : *this)
607  {
608  ret = map.insert(
609  std::pair<pappso_double, pappso_double>(dataPoint.x, dataPoint.y));
610 
611  if(ret.second == false)
612  {
613  qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()"
614  << "It is odd that the Trace contains multiple same keys.";
615 
616  // No insertion, then increment the y value.
617  ret.first->second += dataPoint.y;
618  }
619  }
620 
621  return map;
622 }
623 
624 
625 // const DataPoint &
626 // Trace::dataPointWithX(pappso_double value) const
627 //{
628 // auto iterator =
629 // std::find_if(begin(), end(), [value](const DataPoint &dataPoint) {
630 // return (dataPoint.x == value);
631 //});
632 
633 // if(iterator != end())
634 //{
635 //// The returned data point is valid.
636 // return *iterator;
637 //}
638 // else
639 //{
640 //// The returned data point is invalid because it is not initialized.
641 // return DataPoint();
642 //}
643 //}
644 
645 
646 std::vector<DataPoint>::iterator
648 {
649  auto iterator =
650  std::find_if(begin(), end(), [value](const DataPoint &dataPoint) {
651  return (dataPoint.x == value);
652  });
653 
654  return iterator;
655 }
656 
657 
658 std::vector<DataPoint>::const_iterator
660 {
661  auto iterator =
662  std::find_if(begin(), end(), [value](const DataPoint &dataPoint) {
663  return (dataPoint.x == value);
664  });
665 
666  return iterator;
667 }
668 
669 
670 std::size_t
672 {
673  std::vector<DataPoint>::const_iterator iterator =
675 
676  if(iterator != end())
677  return std::distance(begin(), iterator);
678 
679  return std::numeric_limits<std::size_t>::max();
680 }
681 
682 
683 DataPoint
684 Trace::containsX(pappso_double value, PrecisionPtr precision_p) const
685 {
686  // std::cout << std::setprecision(10) << "getting value: " << value
687  //<< " and precision: " << precision_p->getNominal() << std::endl;
688 
689  pappso_double delta = precision_p->delta(value);
690 
691  double left_most = value - delta;
692  double right_most = value + delta;
693 
694  // std::cout << std::setprecision(10) << "delta: " << delta
695  //<< " left_most: " << left_most << " right_most: " << right_most
696  //<< std::endl;
697 
698  auto iterator =
699  std::find_if(begin(),
700  end(),
701  [value, precision_p, delta, left_most, right_most](
702  const DataPoint &data_point) {
703  if(precision_p)
704  {
705 
706  // FIXME: unbelievable behaviour: when building in
707  // release mode this code, under i386 (but not x86_64),
708  // this code fails if the following cout statement is
709  // missing.
710 
711  // std::cout << std::setprecision(10)
712  //<< "Testing data_point.x: " << data_point.x
713  //<< std::endl;
714 
715  // For this reason I had to deactivate the related tests
716  // for i386 in tests/test_trace.cpp
717 
718  double diff_to_left_most = data_point.x - left_most;
719  double diff_to_right_most = data_point.x - right_most;
720 
721  // std::cout << std::setprecision(10)
722  //<< "diff_to_left_most: " << diff_to_left_most
723  //<< " diff_to_right_most: " << diff_to_right_most <<
724  // std::endl;
725 
726  // if(diff_to_left_most > 0)
727  //{
728  // std::cout << std::setprecision(10)
729  //<< " point is right of left_most: " <<
730  // diff_to_left_most
731  //<< std::endl;
732  //}
733  // if(diff_to_left_most < 0)
734  //{
735  // std::cout << std::setprecision(10)
736  //<< "point is left of left_most: " << diff_to_left_most
737  //<< std::endl;
738  //}
739  // if(!diff_to_left_most)
740  //{
741  // std::cout << std::setprecision(10)
742  //<< "point is spot on left_most: " << diff_to_left_most
743  //<< std::endl;
744  //}
745 
746  // if(diff_to_right_most > 0)
747  //{
748  // std::cout << std::setprecision(10)
749  //<< "point is right of right_most: " <<
750  // diff_to_right_most
751  //<< std::endl;
752  //}
753  // if(diff_to_right_most < 0)
754  //{
755  // std::cout << std::setprecision(10)
756  //<< "point is left or of right_most: "
757  //<< diff_to_right_most << std::endl;
758  //}
759  // if(!diff_to_right_most)
760  //{
761  // std::cout << std::setprecision(10)
762  //<< "point is spot on right_most: " <<
763  // diff_to_right_most
764  //<< std::endl;
765  //}
766 
767  if(diff_to_left_most >= 0 && diff_to_right_most <= 0)
768  {
769  // std::cout << "The point is inside the range,
770  // should return true."
771  //<< std::endl;
772  return true;
773  }
774  else
775  {
776  // std::cout
777  //<< "The point is outside the range, should return
778  // false."
779  //<< std::endl;
780  return false;
781  }
782  }
783  else
784  {
785  return (data_point.x == value);
786  }
787  });
788 
789  if(iterator != end())
790  {
791  // The returned data point is valid.
792  return *iterator;
793  }
794  else
795  {
796  // The returned data point is invalid because it is not initialized.
797  return DataPoint();
798  }
799 }
800 
801 
802 const DataPoint &
804 {
805  auto dataPoint = std::min_element(
806  begin(), end(), [](const DataPoint &a, const DataPoint &b) {
807  return (a.y < b.y);
808  });
809 
810  if(dataPoint == end())
811  {
812  throw ExceptionOutOfRange(
813  QObject::tr("unable to get min peak intensity on spectrum size %1")
814  .arg(size()));
815  }
816 
817  return (*dataPoint);
818 }
819 
820 
821 const DataPoint &
823 {
824  auto dataPoint = std::max_element(
825  begin(), end(), [](const DataPoint &a, const DataPoint &b) {
826  return (a.y < b.y);
827  });
828 
829  if(dataPoint == end())
830  {
831  throw ExceptionOutOfRange(
832  QObject::tr("unable to get max peak intensity on spectrum size %1")
833  .arg(size()));
834  }
835 
836  return (*dataPoint);
837 }
838 
839 
841 Trace::minY() const
842 {
843  return minYDataPoint().y;
844 }
845 
846 
848 Trace::maxY() const
849 {
850  return maxYDataPoint().y;
851 }
852 
853 
855 Trace::sumY() const
856 {
857  // double sum = 0;
858 
859  // for(auto &&dp : m_dataPoints)
860  // sum += dp.y;
861 
862  // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << " ()"
863  //<< "Returning sum/tic:" << sum;
864 
865  // return sum;
866 
867  return std::accumulate(begin(),
868  end(),
869  (double)0,
870  [](pappso_double sum, const DataPoint &dataPoint) {
871  return (sum + dataPoint.y);
872  });
873 }
874 
875 
877 Trace::sumY(double mzStart, double mzEnd) const
878 {
879  auto begin_it = findFirstEqualOrGreaterX(this->begin(), this->end(), mzStart);
880  auto end_it = findFirstGreaterX(begin_it, this->end(), mzEnd);
881 
882  return sumYTrace(begin_it, end_it, 0);
883 }
884 
885 
887 Trace::maxY(double mzStart, double mzEnd) const
888 {
889  std::vector<DataPoint>::const_iterator begin_it =
890  findFirstEqualOrGreaterX(this->begin(), this->end(), mzStart);
891 
892  double max_y = 0;
893 
894  while(begin_it != findFirstGreaterX(begin_it, this->end(), mzEnd))
895  {
896  if(begin_it->y > max_y)
897  max_y = begin_it->y;
898  begin_it++;
899  }
900  return max_y;
901 }
902 
903 
904 void
906 {
907  std::sort(begin(), end(), [](const DataPoint &a, const DataPoint &b) {
908  return (a.x < b.x);
909  });
910 }
911 
912 void
914 {
915  std::sort(begin(), end(), [](const DataPoint &a, const DataPoint &b) {
916  return (a.y > b.y);
917  });
918 }
919 
920 void
922 {
923  auto last =
924  std::unique(begin(), end(), [](const DataPoint &a, const DataPoint &b) {
925  return (a.x == b.x);
926  });
927 
928  erase(last, end());
929 }
930 
931 
932 QString
934 {
935  // Even if the spectrum is empty, we should return an empty string.
936  QString text;
937 
938  for(auto &&dataPoint : *this)
939  {
940  text.append(QString("%1 %2\n")
941  .arg(dataPoint.x, 0, 'f', 10)
942  .arg(dataPoint.y, 0, 'f', 10));
943  }
944 
945  return text;
946 }
947 
948 
949 Trace &
951 {
952  return filter.filter(*this);
953 }
954 
955 } // namespace pappso
generic interface to apply a filter on a trace
virtual pappso_double delta(pappso_double value) const =0
A simple container of DataPoint instances.
Definition: trace.h:148
virtual Trace & operator=(const Trace &x)
Definition: trace.cpp:541
void unique()
Definition: trace.cpp:921
pappso_double maxY() const
Definition: trace.cpp:848
pappso_double sumY() const
Definition: trace.cpp:855
void sortY()
Definition: trace.cpp:913
const DataPoint & maxYDataPoint() const
Definition: trace.cpp:822
std::map< pappso_double, pappso_double > toMap() const
Definition: trace.cpp:600
std::vector< pappso_double > xValues() const
Definition: trace.cpp:572
void sortX()
Definition: trace.cpp:905
TraceCstSPtr makeTraceCstSPtr() const
Definition: trace.cpp:565
virtual Trace & filter(const FilterInterface &filter) final
apply a filter on this trace
Definition: trace.cpp:950
DataPoint containsX(pappso_double value, PrecisionPtr precision_p=nullptr) const
Definition: trace.cpp:684
std::vector< pappso_double > yValues() const
Definition: trace.cpp:586
pappso_double minY() const
Definition: trace.cpp:841
virtual ~Trace()
Definition: trace.cpp:473
size_t initialize(const std::vector< pappso_double > &xVector, const std::vector< pappso_double > &yVector)
Definition: trace.cpp:481
std::size_t dataPointIndexWithX(pappso_double value) const
Definition: trace.cpp:671
std::vector< DataPoint >::const_iterator dataPointCstIteratorWithX(pappso_double value) const
Definition: trace.cpp:659
std::vector< DataPoint >::iterator dataPointIteratorWithX(pappso_double value)
Definition: trace.cpp:647
const DataPoint & minYDataPoint() const
Definition: trace.cpp:803
TraceSPtr makeTraceSPtr() const
Definition: trace.cpp:558
QString toString() const
Definition: trace.cpp:933
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition: aa.cpp:39
std::shared_ptr< const Trace > TraceCstSPtr
Definition: trace.h:136
std::vector< DataPoint >::iterator findDifferentYvalue(std::vector< DataPoint >::iterator begin, std::vector< DataPoint >::iterator end, const double &y_value)
find the first element in which Y is different of value
Definition: trace.cpp:88
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:32
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:60
std::vector< DataPoint >::const_iterator moveLowerYLeftDataPoint(const Trace &trace, std::vector< DataPoint >::const_iterator begin)
Move left to the lower value.
Definition: trace.cpp:182
std::vector< DataPoint >::const_iterator maxYDataPoint(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end)
Definition: trace.cpp:139
double medianYTrace(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end)
calculate the median of y value of a trace
Definition: trace.cpp:250
double areaTrace(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end)
calculate the area of a trace
Definition: trace.cpp:268
std::shared_ptr< Trace > TraceSPtr
Definition: trace.h:135
double pappso_double
A type definition for doubles.
Definition: types.h:48
double meanYTrace(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end)
calculate the mean of y value of a trace
Definition: trace.cpp:212
std::vector< DataPoint >::const_iterator moveLowerYRigthDataPoint(const Trace &trace, std::vector< DataPoint >::const_iterator begin)
Move right to the lower value.
Definition: trace.cpp:164
double sumYTrace(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end, double init)
calculate the sum of y value of a trace
Definition: trace.cpp:203
std::vector< DataPoint >::const_iterator minYDataPoint(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end)
Definition: trace.cpp:117
double quantileYTrace(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end, double quantile)
calculate the quantile of y value of a trace
Definition: trace.cpp:224
@ sum
sum of intensities
Trace flooredLocalMaxima(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end, double y_floor)
Definition: trace.cpp:288
pappso_double x
Definition: datapoint.h:22
pappso_double y
Definition: datapoint.h:23
int traceMetaTypeId
Definition: trace.cpp:24
int tracePtrMetaTypeId
Definition: trace.cpp:25