libpappsomspp
Library for mass spectrometry
pappso::Trace Class Reference

A simple container of DataPoint instances. More...

#include <trace.h>

Inheritance diagram for pappso::Trace:
pappso::MassSpectrum pappso::Xic

Public Member Functions

 Trace ()
 
 Trace (const std::vector< pappso_double > &xVector, const std::vector< pappso_double > &yVector)
 
 Trace (const std::vector< std::pair< pappso_double, pappso_double >> &dataPoints)
 
 Trace (const std::vector< DataPoint > &dataPoints)
 
 Trace (const std::vector< DataPoint > &&dataPoints)
 
 Trace (const MapTrace &map_trace)
 
 Trace (const Trace &other)
 
 Trace (const Trace &&other)
 
virtual ~Trace ()
 
size_t initialize (const std::vector< pappso_double > &xVector, const std::vector< pappso_double > &yVector)
 
size_t initialize (const Trace &other)
 
size_t initialize (const std::map< pappso_double, pappso_double > &map)
 
virtual Traceoperator= (const Trace &x)
 
virtual Traceoperator= (Trace &&x)
 
TraceSPtr makeTraceSPtr () const
 
TraceCstSPtr makeTraceCstSPtr () const
 
std::vector< pappso_doublexValues () const
 
std::vector< pappso_doubleyValues () const
 
std::map< pappso_double, pappso_doubletoMap () const
 
DataPoint containsX (pappso_double value, PrecisionPtr precision_p=nullptr) const
 
const DataPointminYDataPoint () const
 
const DataPointmaxYDataPoint () const
 
pappso_double minY () const
 
pappso_double maxY () const
 
pappso_double maxY (double mzStart, double mzEnd) const
 
pappso_double sumY () const
 
pappso_double sumY (double mzStart, double mzEnd) const
 
void sortX ()
 
void sortY ()
 
void unique ()
 
virtual Tracefilter (const FilterInterface &filter) final
 apply a filter on this trace More...
 
QString toString () const
 

Protected Member Functions

std::size_t dataPointIndexWithX (pappso_double value) const
 
std::vector< DataPoint >::iterator dataPointIteratorWithX (pappso_double value)
 
std::vector< DataPoint >::const_iterator dataPointCstIteratorWithX (pappso_double value) const
 

Friends

class TraceCombiner
 
class TraceMinusCombiner
 
class TracePlusCombiner
 
class MassSpectrumCombinerInterface
 

Detailed Description

A simple container of DataPoint instances.

Definition at line 131 of file trace.h.

Constructor & Destructor Documentation

◆ Trace() [1/8]

pappso::Trace::Trace ( )

Definition at line 375 of file trace.cpp.

376 {
377 }

◆ Trace() [2/8]

pappso::Trace::Trace ( const std::vector< pappso_double > &  xVector,
const std::vector< pappso_double > &  yVector 
)

Definition at line 380 of file trace.cpp.

382 {
383  initialize(xVector, yVector);
384 }
size_t initialize(const std::vector< pappso_double > &xVector, const std::vector< pappso_double > &yVector)
Definition: trace.cpp:453

References initialize().

◆ Trace() [3/8]

pappso::Trace::Trace ( const std::vector< std::pair< pappso_double, pappso_double >> &  dataPoints)

Definition at line 387 of file trace.cpp.

389 {
390  reserve(dataPoints.size());
391 
392  for(auto &dataPoint : dataPoints)
393  {
394  push_back(DataPoint(dataPoint));
395  }
396 
397  sortX();
398  // std::sort(begin(), end(), [](const DataPoint &a, const DataPoint &b) {
399  // return (a.x < b.x);
400  //});
401 }
void sortX()
Definition: trace.cpp:854

References sortX().

◆ Trace() [4/8]

pappso::Trace::Trace ( const std::vector< DataPoint > &  dataPoints)

Definition at line 404 of file trace.cpp.

405  : std::vector<DataPoint>(dataPoints)
406 {
407  sortX();
408  // std::sort(begin(), end(), [](const DataPoint &a, const DataPoint &b) {
409  // return (a.x < b.x);
410  //});
411 }

References sortX().

◆ Trace() [5/8]

pappso::Trace::Trace ( const std::vector< DataPoint > &&  dataPoints)

Definition at line 414 of file trace.cpp.

415  : std::vector<DataPoint>(std::move(dataPoints))
416 {
417  // This constructor used by the MassSpectrum && constructor.
418 
419  sortX();
420  // std::sort(begin(), end(), [](const DataPoint &a, const DataPoint &b) {
421  // return (a.x < b.x);
422  //});
423 }

References sortX().

◆ Trace() [6/8]

pappso::Trace::Trace ( const MapTrace map_trace)
explicit

Definition at line 426 of file trace.cpp.

427 {
428  for(auto &&item : map_trace)
429  push_back(DataPoint(item.first, item.second));
430 
431  // No need to sort, maps are sorted by key (that is, x).
432 }

◆ Trace() [7/8]

pappso::Trace::Trace ( const Trace other)

Definition at line 434 of file trace.cpp.

434  : std::vector<DataPoint>(other)
435 {
436 }

◆ Trace() [8/8]

pappso::Trace::Trace ( const Trace &&  other)

Definition at line 439 of file trace.cpp.

439  : std::vector<DataPoint>(std::move(other))
440 {
441  // This constructor used by the MassSpectrum && constructor.
442 }

◆ ~Trace()

pappso::Trace::~Trace ( )
virtual

Definition at line 445 of file trace.cpp.

446 {
447  // Calls the destructor for each DataPoint object in the vector.
448  clear();
449 }

Member Function Documentation

◆ containsX()

DataPoint pappso::Trace::containsX ( pappso_double  value,
PrecisionPtr  precision_p = nullptr 
) const

Definition at line 656 of file trace.cpp.

657 {
658  //qDebug() << qSetRealNumberPrecision(10) << "getting value:" << value
659  //<< "and precision:" << precision_p->getNominal();
660 
661  pappso_double delta = precision_p->delta(value);
662 
663  double left_most = value - delta;
664  double right_most = value + delta;
665 
666  //qDebug() << qSetRealNumberPrecision(10) << "delta:" << delta
667  //<< "left_most:" << left_most << "right_most:" << right_most;
668 
669  auto iterator = std::find_if(
670  begin(),
671  end(),
672  [value, precision_p, delta, left_most, right_most](
673  const DataPoint &data_point) {
674  if(precision_p)
675  {
676  //qDebug() << qSetRealNumberPrecision(10)
677  //<< "Testing data_point.x:" << data_point.x;
678 
679  double diff_to_left_most = data_point.x - left_most;
680 
681  double diff_to_right_most = data_point.x - right_most;
682 
683  //qDebug() << qSetRealNumberPrecision(10)
684  //<< "diff_to_left_most:" << diff_to_left_most
685  //<< "diff_to_right_most:" << diff_to_right_most;
686 
687  //if(diff_to_left_most > 0)
688  //{
689  //qDebug() << qSetRealNumberPrecision(10)
690  //<< "point is right of left_most:" << diff_to_left_most;
691  //}
692  //if(diff_to_left_most < 0)
693  //{
694  //qDebug() << qSetRealNumberPrecision(10)
695  //<< "point is left of left_most:" << diff_to_left_most;
696  //}
697  //if(!diff_to_left_most)
698  //{
699  //qDebug() << qSetRealNumberPrecision(10)
700  //<< "point is spot on left_most:" << diff_to_left_most;
701  //}
702 
703  //if(diff_to_right_most > 0)
704  //{
705  //qDebug() << qSetRealNumberPrecision(10)
706  //<< "point is right of right_most:" << diff_to_right_most;
707  //}
708  //if(diff_to_right_most < 0)
709  //{
710  //qDebug() << qSetRealNumberPrecision(10)
711  //<< "point is left or of right_most:"
712  //<< diff_to_right_most;
713  //}
714  //if(!diff_to_right_most)
715  //{
716  //qDebug() << qSetRealNumberPrecision(10)
717  //<< "point is spot on right_most:" << diff_to_right_most;
718  //}
719 
720  if(diff_to_left_most >= 0 && diff_to_right_most <= 0)
721  {
722  //qDebug() << "The point is inside the range, should return true.";
723  return true;
724  }
725  else
726  {
727  //qDebug()
728  //<< "The point is outside the range, should return false.";
729  return false;
730  }
731  }
732  else
733  {
734  return (data_point.x == value);
735  }
736  });
737 
738  if(iterator != end())
739  {
740  // The returned data point is valid.
741  return *iterator;
742  }
743  else
744  {
745  // The returned data point is invalid because it is not initialized.
746  return DataPoint();
747  }
748 }
double pappso_double
A type definition for doubles.
Definition: types.h:48

References pappso::PrecisionBase::delta(), and pappso::DataPoint::x.

◆ dataPointCstIteratorWithX()

std::vector< DataPoint >::const_iterator pappso::Trace::dataPointCstIteratorWithX ( pappso_double  value) const
protected

Definition at line 631 of file trace.cpp.

632 {
633  auto iterator =
634  std::find_if(begin(), end(), [value](const DataPoint &dataPoint) {
635  return (dataPoint.x == value);
636  });
637 
638  return iterator;
639 }

References pappso::DataPoint::x.

Referenced by dataPointIndexWithX().

◆ dataPointIndexWithX()

std::size_t pappso::Trace::dataPointIndexWithX ( pappso_double  value) const
protected

Return a reference to the DataPoint instance that has its y member equal to value.

Definition at line 643 of file trace.cpp.

644 {
645  std::vector<DataPoint>::const_iterator iterator =
647 
648  if(iterator != end())
649  return std::distance(begin(), iterator);
650 
651  return std::numeric_limits<std::size_t>::max();
652 }
std::vector< DataPoint >::const_iterator dataPointCstIteratorWithX(pappso_double value) const
Definition: trace.cpp:631

References dataPointCstIteratorWithX().

◆ dataPointIteratorWithX()

std::vector< DataPoint >::iterator pappso::Trace::dataPointIteratorWithX ( pappso_double  value)
protected

Definition at line 619 of file trace.cpp.

620 {
621  auto iterator =
622  std::find_if(begin(), end(), [value](const DataPoint &dataPoint) {
623  return (dataPoint.x == value);
624  });
625 
626  return iterator;
627 }

References pappso::DataPoint::x.

◆ filter()

Trace & pappso::Trace::filter ( const FilterInterface filter)
finalvirtual

apply a filter on this trace

Parameters
filterto process the signal
Returns
reference on the modified Trace

Definition at line 899 of file trace.cpp.

900 {
901  return filter.filter(*this);
902 }
virtual Trace & filter(const FilterInterface &filter) final
apply a filter on this trace
Definition: trace.cpp:899

References filter().

Referenced by pappso::MsRunRetentionTime< T >::align(), filter(), pappso::FilterSuiteString::filter(), pappso::FilterSuite::filter(), and pappso::MassSpectrum::massSpectrumFilter().

◆ initialize() [1/3]

size_t pappso::Trace::initialize ( const std::map< pappso_double, pappso_double > &  map)

Definition at line 486 of file trace.cpp.

487 {
488 
489  // We are initializing, not appending.
490  erase(begin(), end());
491 
492  for(auto &&item : map)
493  {
494  push_back(DataPoint(item.first, item.second));
495  }
496 
497  // No need to sort, maps are sorted by key (that is, x).
498 
499  return size();
500 }

◆ initialize() [2/3]

size_t pappso::Trace::initialize ( const std::vector< pappso_double > &  xVector,
const std::vector< pappso_double > &  yVector 
)

Definition at line 453 of file trace.cpp.

455 {
456  // Sanity check
457  if(xVector.size() != yVector.size())
458  throw ExceptionNotPossible(
459  "trace.cpp -- ERROR xVector and yVector must have the same size.");
460 
461  // We are initializing, not appending.
462  erase(begin(), end());
463 
464  for(std::size_t iter = 0; iter < xVector.size(); ++iter)
465  {
466  push_back(DataPoint(xVector.at(iter), yVector.at(iter)));
467  }
468 
469  sortX();
470  // std::sort(begin(), end(), [](const DataPoint &a, const DataPoint &b) {
471  // return (a.x < b.x);
472  //});
473 
474 #if 0
475  for(auto &item : *this)
476  {
477  std::cout << item.x << "-" << item.y;
478  }
479 #endif
480 
481  return size();
482 }

References sortX().

Referenced by Trace().

◆ initialize() [3/3]

size_t pappso::Trace::initialize ( const Trace other)

Definition at line 504 of file trace.cpp.

505 {
506  *this = other;
507 
508  return size();
509 }

◆ makeTraceCstSPtr()

TraceCstSPtr pappso::Trace::makeTraceCstSPtr ( ) const

Definition at line 537 of file trace.cpp.

538 {
539  return std::make_shared<const Trace>(*this);
540 }

◆ makeTraceSPtr()

TraceSPtr pappso::Trace::makeTraceSPtr ( ) const

Definition at line 530 of file trace.cpp.

531 {
532  return std::make_shared<Trace>(*this);
533 }

◆ maxY() [1/2]

pappso_double pappso::Trace::maxY ( ) const

Definition at line 797 of file trace.cpp.

798 {
799  return maxYDataPoint().y;
800 }
const DataPoint & maxYDataPoint() const
Definition: trace.cpp:771
pappso_double y
Definition: datapoint.h:23

References maxYDataPoint(), and pappso::DataPoint::y.

◆ maxY() [2/2]

pappso_double pappso::Trace::maxY ( double  mzStart,
double  mzEnd 
) const

Definition at line 836 of file trace.cpp.

837 {
838  std::vector<DataPoint>::const_iterator begin_it =
839  findFirstEqualOrGreaterX(this->begin(), this->end(), mzStart);
840 
841  double max_y = 0;
842 
843  while(begin_it != findFirstGreaterX(begin_it, this->end(), mzEnd))
844  {
845  if(begin_it->y > max_y)
846  max_y = begin_it->y;
847  begin_it++;
848  }
849  return max_y;
850 }
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:31
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:59

References pappso::findFirstEqualOrGreaterX(), and pappso::findFirstGreaterX().

◆ maxYDataPoint()

const DataPoint & pappso::Trace::maxYDataPoint ( ) const

Definition at line 771 of file trace.cpp.

772 {
773  auto dataPoint = std::max_element(
774  begin(), end(), [](const DataPoint &a, const DataPoint &b) {
775  return (a.y < b.y);
776  });
777 
778  if(dataPoint == end())
779  {
780  throw ExceptionOutOfRange(
781  QObject::tr("unable to get max peak intensity on spectrum size %1")
782  .arg(size()));
783  }
784 
785  return (*dataPoint);
786 }

References pappso::a, and pappso::b.

Referenced by pappso::flooredLocalMaxima(), pappso::MassSpectrum::maxIntensityDataPoint(), and maxY().

◆ minY()

pappso_double pappso::Trace::minY ( ) const

Definition at line 790 of file trace.cpp.

791 {
792  return minYDataPoint().y;
793 }
const DataPoint & minYDataPoint() const
Definition: trace.cpp:752

References minYDataPoint(), and pappso::DataPoint::y.

◆ minYDataPoint()

const DataPoint & pappso::Trace::minYDataPoint ( ) const

Definition at line 752 of file trace.cpp.

753 {
754  auto dataPoint = std::min_element(
755  begin(), end(), [](const DataPoint &a, const DataPoint &b) {
756  return (a.y < b.y);
757  });
758 
759  if(dataPoint == end())
760  {
761  throw ExceptionOutOfRange(
762  QObject::tr("unable to get min peak intensity on spectrum size %1")
763  .arg(size()));
764  }
765 
766  return (*dataPoint);
767 }

References pappso::a, and pappso::b.

Referenced by pappso::MassSpectrum::minIntensityDataPoint(), and minY().

◆ operator=() [1/2]

Trace & pappso::Trace::operator= ( const Trace x)
virtual

Definition at line 513 of file trace.cpp.

514 {
515  assign(other.begin(), other.end());
516 
517  return *this;
518 }

◆ operator=() [2/2]

Trace & pappso::Trace::operator= ( Trace &&  x)
virtual

Definition at line 522 of file trace.cpp.

523 {
524  vector<DataPoint>::operator=(std::move(other));
525  return *this;
526 }

◆ sortX()

◆ sortY()

void pappso::Trace::sortY ( )

Definition at line 862 of file trace.cpp.

863 {
864  std::sort(begin(), end(), [](const DataPoint &a, const DataPoint &b) {
865  return (a.y > b.y);
866  });
867 }

References pappso::a, and pappso::b.

Referenced by pappso::FilterChargeDeconvolution::filter(), and pappso::FilterMzExclusion::filter().

◆ sumY() [1/2]

pappso_double pappso::Trace::sumY ( ) const

Definition at line 804 of file trace.cpp.

805 {
806  // double sum = 0;
807 
808  // for(auto &&dp : m_dataPoints)
809  // sum += dp.y;
810 
811  // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << " ()"
812  //<< "Returning sum/tic:" << sum;
813 
814  // return sum;
815 
816  return std::accumulate(begin(),
817  end(),
818  (double)0,
819  [](pappso_double sum, const DataPoint &dataPoint) {
820  return (sum + dataPoint.y);
821  });
822 }

References pappso::sum, and pappso::DataPoint::y.

Referenced by pappso::MassSpectrum::tic(), and pappso::MassSpectrum::totalIonCurrent().

◆ sumY() [2/2]

pappso_double pappso::Trace::sumY ( double  mzStart,
double  mzEnd 
) const

Definition at line 826 of file trace.cpp.

827 {
828  auto begin_it = findFirstEqualOrGreaterX(this->begin(), this->end(), mzStart);
829  auto end_it = findFirstGreaterX(begin_it, this->end(), mzEnd);
830 
831  return sumYTrace(begin_it, end_it, 0);
832 }
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:202

References pappso::findFirstEqualOrGreaterX(), pappso::findFirstGreaterX(), and pappso::sumYTrace().

◆ toMap()

std::map< pappso_double, pappso_double > pappso::Trace::toMap ( ) const

Definition at line 572 of file trace.cpp.

573 {
574  std::map<pappso_double, pappso_double> map;
575 
576  std::pair<std::map<pappso_double, pappso_double>::iterator, bool> ret;
577 
578  for(auto &&dataPoint : *this)
579  {
580  ret = map.insert(
581  std::pair<pappso_double, pappso_double>(dataPoint.x, dataPoint.y));
582 
583  if(ret.second == false)
584  {
585  qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()"
586  << "It is odd that the Trace contains multiple same keys.";
587 
588  // No insertion, then increment the y value.
589  ret.first->second += dataPoint.y;
590  }
591  }
592 
593  return map;
594 }

◆ toString()

QString pappso::Trace::toString ( ) const

Definition at line 882 of file trace.cpp.

883 {
884  // Even if the spectrum is empty, we should return an empty string.
885  QString text;
886 
887  for(auto &&dataPoint : *this)
888  {
889  text.append(QString("%1 %2\n")
890  .arg(dataPoint.x, 0, 'f', 10)
891  .arg(dataPoint.y, 0, 'f', 10));
892  }
893 
894  return text;
895 }

Referenced by pappso::FilterSuiteString::filter(), and pappso::FilterSuiteString::toString().

◆ unique()

void pappso::Trace::unique ( )

Definition at line 870 of file trace.cpp.

871 {
872  auto last =
873  std::unique(begin(), end(), [](const DataPoint &a, const DataPoint &b) {
874  return (a.x == b.x);
875  });
876 
877  erase(last, end());
878 }

References pappso::a, pappso::b, and pappso::last.

Referenced by pappso::MsRunRetentionTime< T >::getCommonDeltaRt().

◆ xValues()

std::vector< pappso_double > pappso::Trace::xValues ( ) const

Definition at line 544 of file trace.cpp.

545 {
546  std::vector<pappso_double> values;
547 
548  for(auto &&dataPoint : *this)
549  {
550  values.push_back(dataPoint.x);
551  }
552 
553  return values;
554 }

Referenced by pappso::BaseTracePlotWidget::addTrace(), and pappso::FilterPseudoCentroid::filter().

◆ yValues()

std::vector< pappso_double > pappso::Trace::yValues ( ) const

Definition at line 558 of file trace.cpp.

559 {
560  std::vector<pappso_double> values;
561 
562  for(auto &&dataPoint : *this)
563  {
564  values.push_back(dataPoint.y);
565  }
566 
567  return values;
568 }

Referenced by pappso::BaseTracePlotWidget::addTrace(), pappso::MsRunRetentionTime< T >::align(), and pappso::FilterPseudoCentroid::filter().

Friends And Related Function Documentation

◆ MassSpectrumCombinerInterface

friend class MassSpectrumCombinerInterface
friend

Definition at line 138 of file trace.h.

◆ TraceCombiner

friend class TraceCombiner
friend

Definition at line 134 of file trace.h.

◆ TraceMinusCombiner

friend class TraceMinusCombiner
friend

Definition at line 135 of file trace.h.

◆ TracePlusCombiner

friend class TracePlusCombiner
friend

Definition at line 136 of file trace.h.


The documentation for this class was generated from the following files: