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 147 of file trace.h.

Constructor & Destructor Documentation

◆ Trace() [1/8]

pappso::Trace::Trace ( )

Definition at line 403 of file trace.cpp.

404 {
405 }

◆ Trace() [2/8]

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

Definition at line 408 of file trace.cpp.

410 {
411  initialize(xVector, yVector);
412 }
size_t initialize(const std::vector< pappso_double > &xVector, const std::vector< pappso_double > &yVector)
Definition: trace.cpp:481

References initialize().

◆ Trace() [3/8]

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

Definition at line 415 of file trace.cpp.

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 }
void sortX()
Definition: trace.cpp:905

References sortX().

◆ Trace() [4/8]

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

Definition at line 432 of file trace.cpp.

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 }

References sortX().

◆ Trace() [5/8]

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

Definition at line 442 of file trace.cpp.

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 }

References sortX().

◆ Trace() [6/8]

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

Definition at line 454 of file trace.cpp.

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 }

◆ Trace() [7/8]

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

Definition at line 462 of file trace.cpp.

462  : std::vector<DataPoint>(other)
463 {
464 }

◆ Trace() [8/8]

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

Definition at line 467 of file trace.cpp.

467  : std::vector<DataPoint>(std::move(other))
468 {
469  // This constructor used by the MassSpectrum && constructor.
470 }

◆ ~Trace()

pappso::Trace::~Trace ( )
virtual

Definition at line 473 of file trace.cpp.

474 {
475  // Calls the destructor for each DataPoint object in the vector.
476  clear();
477 }

Member Function Documentation

◆ containsX()

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

Definition at line 684 of file trace.cpp.

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

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 }

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

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 }
std::vector< DataPoint >::const_iterator dataPointCstIteratorWithX(pappso_double value) const
Definition: trace.cpp:659

References dataPointCstIteratorWithX().

◆ dataPointIteratorWithX()

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

Definition at line 647 of file trace.cpp.

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 }

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

951 {
952  return filter.filter(*this);
953 }
virtual Trace & filter(const FilterInterface &filter) final
apply a filter on this trace
Definition: trace.cpp:950

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

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 }

◆ initialize() [2/3]

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

Definition at line 481 of file trace.cpp.

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 }

References sortX().

Referenced by Trace().

◆ initialize() [3/3]

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

Definition at line 532 of file trace.cpp.

533 {
534  *this = other;
535 
536  return size();
537 }

◆ makeTraceCstSPtr()

TraceCstSPtr pappso::Trace::makeTraceCstSPtr ( ) const

Definition at line 565 of file trace.cpp.

566 {
567  return std::make_shared<const Trace>(*this);
568 }

◆ makeTraceSPtr()

TraceSPtr pappso::Trace::makeTraceSPtr ( ) const

Definition at line 558 of file trace.cpp.

559 {
560  return std::make_shared<Trace>(*this);
561 }

◆ maxY() [1/2]

pappso_double pappso::Trace::maxY ( ) const

Definition at line 848 of file trace.cpp.

849 {
850  return maxYDataPoint().y;
851 }
const DataPoint & maxYDataPoint() const
Definition: trace.cpp:822
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 887 of file trace.cpp.

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

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 }

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

842 {
843  return minYDataPoint().y;
844 }
const DataPoint & minYDataPoint() const
Definition: trace.cpp:803

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

◆ minYDataPoint()

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

Definition at line 803 of file trace.cpp.

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 }

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

542 {
543  assign(other.begin(), other.end());
544 
545  return *this;
546 }

◆ operator=() [2/2]

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

Definition at line 550 of file trace.cpp.

551 {
552  vector<DataPoint>::operator=(std::move(other));
553  return *this;
554 }

◆ sortX()

◆ sortY()

void pappso::Trace::sortY ( )

Definition at line 913 of file trace.cpp.

914 {
915  std::sort(begin(), end(), [](const DataPoint &a, const DataPoint &b) {
916  return (a.y > b.y);
917  });
918 }

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

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 }

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

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

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 }

◆ toString()

QString pappso::Trace::toString ( ) const

Definition at line 933 of file trace.cpp.

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 }

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

◆ unique()

void pappso::Trace::unique ( )

Definition at line 921 of file trace.cpp.

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 }

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

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 }

Referenced by pappso::BaseTracePlotWidget::addTrace().

◆ yValues()

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

Definition at line 586 of file trace.cpp.

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 }

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

Friends And Related Function Documentation

◆ MassSpectrumCombinerInterface

friend class MassSpectrumCombinerInterface
friend

Definition at line 154 of file trace.h.

◆ TraceCombiner

friend class TraceCombiner
friend

Definition at line 150 of file trace.h.

◆ TraceMinusCombiner

friend class TraceMinusCombiner
friend

Definition at line 151 of file trace.h.

◆ TracePlusCombiner

friend class TracePlusCombiner
friend

Definition at line 152 of file trace.h.


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