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 376 of file trace.cpp.

377 {
378 }

◆ Trace() [2/8]

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

Definition at line 381 of file trace.cpp.

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

References initialize().

◆ Trace() [3/8]

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

Definition at line 388 of file trace.cpp.

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

References sortX().

◆ Trace() [4/8]

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

Definition at line 405 of file trace.cpp.

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

References sortX().

◆ Trace() [5/8]

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

Definition at line 415 of file trace.cpp.

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

References sortX().

◆ Trace() [6/8]

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

Definition at line 427 of file trace.cpp.

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

◆ Trace() [7/8]

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

Definition at line 435 of file trace.cpp.

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

◆ Trace() [8/8]

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

Definition at line 440 of file trace.cpp.

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

◆ ~Trace()

pappso::Trace::~Trace ( )
virtual

Definition at line 446 of file trace.cpp.

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

Member Function Documentation

◆ containsX()

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

Definition at line 657 of file trace.cpp.

658 {
659  // std::cout << std::setprecision(10) << "getting value: " << value
660  //<< " and precision: " << precision_p->getNominal() << std::endl;
661 
662  pappso_double delta = precision_p->delta(value);
663 
664  double left_most = value - delta;
665  double right_most = value + delta;
666 
667  // std::cout << std::setprecision(10) << "delta: " << delta
668  //<< " left_most: " << left_most << " right_most: " << right_most
669  //<< std::endl;
670 
671  auto iterator =
672  std::find_if(begin(),
673  end(),
674  [value, precision_p, delta, left_most, right_most](
675  const DataPoint &data_point) {
676  if(precision_p)
677  {
678 
679  // FIXME: unbelievable behaviour: when building in
680  // release mode this code, under i386 (but not x86_64),
681  // this code fails if the following cout statement is
682  // missing.
683 
684  //std::cout << std::setprecision(10)
685  //<< "Testing data_point.x: " << data_point.x
686  //<< std::endl;
687 
688  // For this reason I had to deactivate the related tests
689  // for i386 in tests/test_trace.cpp
690 
691  double diff_to_left_most = data_point.x - left_most;
692  double diff_to_right_most = data_point.x - right_most;
693 
694  // std::cout << std::setprecision(10)
695  //<< "diff_to_left_most: " << diff_to_left_most
696  //<< " diff_to_right_most: " << diff_to_right_most <<
697  // std::endl;
698 
699  // if(diff_to_left_most > 0)
700  //{
701  // std::cout << std::setprecision(10)
702  //<< " point is right of left_most: " <<
703  // diff_to_left_most
704  //<< std::endl;
705  //}
706  // if(diff_to_left_most < 0)
707  //{
708  // std::cout << std::setprecision(10)
709  //<< "point is left of left_most: " << diff_to_left_most
710  //<< std::endl;
711  //}
712  // if(!diff_to_left_most)
713  //{
714  // std::cout << std::setprecision(10)
715  //<< "point is spot on left_most: " << diff_to_left_most
716  //<< std::endl;
717  //}
718 
719  // if(diff_to_right_most > 0)
720  //{
721  // std::cout << std::setprecision(10)
722  //<< "point is right of right_most: " <<
723  // diff_to_right_most
724  //<< std::endl;
725  //}
726  // if(diff_to_right_most < 0)
727  //{
728  // std::cout << std::setprecision(10)
729  //<< "point is left or of right_most: "
730  //<< diff_to_right_most << std::endl;
731  //}
732  // if(!diff_to_right_most)
733  //{
734  // std::cout << std::setprecision(10)
735  //<< "point is spot on right_most: " <<
736  // diff_to_right_most
737  //<< std::endl;
738  //}
739 
740  if(diff_to_left_most >= 0 && diff_to_right_most <= 0)
741  {
742  // std::cout << "The point is inside the range,
743  // should return true."
744  //<< std::endl;
745  return true;
746  }
747  else
748  {
749  // std::cout
750  //<< "The point is outside the range, should return
751  // false."
752  //<< std::endl;
753  return false;
754  }
755  }
756  else
757  {
758  return (data_point.x == value);
759  }
760  });
761 
762  if(iterator != end())
763  {
764  // The returned data point is valid.
765  return *iterator;
766  }
767  else
768  {
769  // The returned data point is invalid because it is not initialized.
770  return DataPoint();
771  }
772 }
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 632 of file trace.cpp.

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

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 644 of file trace.cpp.

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

References dataPointCstIteratorWithX().

◆ dataPointIteratorWithX()

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

Definition at line 620 of file trace.cpp.

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

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 923 of file trace.cpp.

924 {
925  return filter.filter(*this);
926 }
virtual Trace & filter(const FilterInterface &filter) final
apply a filter on this trace
Definition: trace.cpp:923

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 487 of file trace.cpp.

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

◆ initialize() [2/3]

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

Definition at line 454 of file trace.cpp.

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

References sortX().

Referenced by Trace().

◆ initialize() [3/3]

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

Definition at line 505 of file trace.cpp.

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

◆ makeTraceCstSPtr()

TraceCstSPtr pappso::Trace::makeTraceCstSPtr ( ) const

Definition at line 538 of file trace.cpp.

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

◆ makeTraceSPtr()

TraceSPtr pappso::Trace::makeTraceSPtr ( ) const

Definition at line 531 of file trace.cpp.

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

◆ maxY() [1/2]

pappso_double pappso::Trace::maxY ( ) const

Definition at line 821 of file trace.cpp.

822 {
823  return maxYDataPoint().y;
824 }
const DataPoint & maxYDataPoint() const
Definition: trace.cpp:795
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 860 of file trace.cpp.

861 {
862  std::vector<DataPoint>::const_iterator begin_it =
863  findFirstEqualOrGreaterX(this->begin(), this->end(), mzStart);
864 
865  double max_y = 0;
866 
867  while(begin_it != findFirstGreaterX(begin_it, this->end(), mzEnd))
868  {
869  if(begin_it->y > max_y)
870  max_y = begin_it->y;
871  begin_it++;
872  }
873  return max_y;
874 }
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

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

◆ maxYDataPoint()

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

Definition at line 795 of file trace.cpp.

796 {
797  auto dataPoint = std::max_element(
798  begin(), end(), [](const DataPoint &a, const DataPoint &b) {
799  return (a.y < b.y);
800  });
801 
802  if(dataPoint == end())
803  {
804  throw ExceptionOutOfRange(
805  QObject::tr("unable to get max peak intensity on spectrum size %1")
806  .arg(size()));
807  }
808 
809  return (*dataPoint);
810 }

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 814 of file trace.cpp.

815 {
816  return minYDataPoint().y;
817 }
const DataPoint & minYDataPoint() const
Definition: trace.cpp:776

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

◆ minYDataPoint()

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

Definition at line 776 of file trace.cpp.

777 {
778  auto dataPoint = std::min_element(
779  begin(), end(), [](const DataPoint &a, const DataPoint &b) {
780  return (a.y < b.y);
781  });
782 
783  if(dataPoint == end())
784  {
785  throw ExceptionOutOfRange(
786  QObject::tr("unable to get min peak intensity on spectrum size %1")
787  .arg(size()));
788  }
789 
790  return (*dataPoint);
791 }

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 514 of file trace.cpp.

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

◆ operator=() [2/2]

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

Definition at line 523 of file trace.cpp.

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

◆ sortX()

◆ sortY()

void pappso::Trace::sortY ( )

Definition at line 886 of file trace.cpp.

887 {
888  std::sort(begin(), end(), [](const DataPoint &a, const DataPoint &b) {
889  return (a.y > b.y);
890  });
891 }

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 828 of file trace.cpp.

829 {
830  // double sum = 0;
831 
832  // for(auto &&dp : m_dataPoints)
833  // sum += dp.y;
834 
835  // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << " ()"
836  //<< "Returning sum/tic:" << sum;
837 
838  // return sum;
839 
840  return std::accumulate(begin(),
841  end(),
842  (double)0,
843  [](pappso_double sum, const DataPoint &dataPoint) {
844  return (sum + dataPoint.y);
845  });
846 }

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 850 of file trace.cpp.

851 {
852  auto begin_it = findFirstEqualOrGreaterX(this->begin(), this->end(), mzStart);
853  auto end_it = findFirstGreaterX(begin_it, this->end(), mzEnd);
854 
855  return sumYTrace(begin_it, end_it, 0);
856 }
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

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

◆ toMap()

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

Definition at line 573 of file trace.cpp.

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

◆ toString()

QString pappso::Trace::toString ( ) const

Definition at line 906 of file trace.cpp.

907 {
908  // Even if the spectrum is empty, we should return an empty string.
909  QString text;
910 
911  for(auto &&dataPoint : *this)
912  {
913  text.append(QString("%1 %2\n")
914  .arg(dataPoint.x, 0, 'f', 10)
915  .arg(dataPoint.y, 0, 'f', 10));
916  }
917 
918  return text;
919 }

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

◆ unique()

void pappso::Trace::unique ( )

Definition at line 894 of file trace.cpp.

895 {
896  auto last =
897  std::unique(begin(), end(), [](const DataPoint &a, const DataPoint &b) {
898  return (a.x == b.x);
899  });
900 
901  erase(last, end());
902 }

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 545 of file trace.cpp.

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

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

◆ yValues()

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

Definition at line 559 of file trace.cpp.

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

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: