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 }

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 }

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  auto iterator = std::find_if(
659  begin(), end(), [value, precision_p](const DataPoint &data_point) {
660  if(precision_p)
661  {
662  pappso_double delta = precision_p->delta(value);
663 
664  if(data_point.x >= (value - delta) && data_point.x <= (value + delta))
665  return true;
666  else
667  return false;
668  }
669  else
670  {
671  return (data_point.x == value);
672  }
673  });
674 
675  if(iterator != end())
676  {
677  // The returned data point is valid.
678  return *iterator;
679  }
680  else
681  {
682  // The returned data point is invalid because it is not initialized.
683  return DataPoint();
684  }
685 }

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 }

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

836 {
837  return filter.filter(*this);
838 }

References filter().

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

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

735 {
736  return maxYDataPoint().y;
737 }

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

◆ maxY() [2/2]

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

Definition at line 772 of file trace.cpp.

773 {
774  std::vector<DataPoint>::const_iterator begin_it =
775  findFirstEqualOrGreaterX(this->begin(), this->end(), mzStart);
776 
777  double max_y = 0;
778 
779  while(begin_it != findFirstGreaterX(begin_it, this->end(), mzEnd))
780  {
781  if(begin_it->y > max_y)
782  max_y = begin_it->y;
783  begin_it++;
784  }
785  return max_y;
786 }

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

◆ maxYDataPoint()

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

Definition at line 708 of file trace.cpp.

709 {
710  auto dataPoint = std::max_element(
711  begin(), end(), [](const DataPoint &a, const DataPoint &b) {
712  return (a.y < b.y);
713  });
714 
715  if(dataPoint == end())
716  {
717  throw ExceptionOutOfRange(
718  QObject::tr("unable to get max peak intensity on spectrum size %1")
719  .arg(size()));
720  }
721 
722  return (*dataPoint);
723 }

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

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

◆ minY()

pappso_double pappso::Trace::minY ( ) const

Definition at line 727 of file trace.cpp.

728 {
729  return minYDataPoint().y;
730 }

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

◆ minYDataPoint()

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

Definition at line 689 of file trace.cpp.

690 {
691  auto dataPoint = std::min_element(
692  begin(), end(), [](const DataPoint &a, const DataPoint &b) {
693  return (a.y < b.y);
694  });
695 
696  if(dataPoint == end())
697  {
698  throw ExceptionOutOfRange(
699  QObject::tr("unable to get min peak intensity on spectrum size %1")
700  .arg(size()));
701  }
702 
703  return (*dataPoint);
704 }

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

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

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

799 {
800  std::sort(begin(), end(), [](const DataPoint &a, const DataPoint &b) {
801  return (a.y > b.y);
802  });
803 }

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

Referenced by pappso::FilterChargeDeconvolution::filter().

◆ sumY() [1/2]

pappso_double pappso::Trace::sumY ( ) const

Definition at line 741 of file trace.cpp.

742 {
743  // double sum = 0;
744 
745  // for(auto &&dp : m_dataPoints)
746  // sum += dp.y;
747 
748  // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << " ()"
749  //<< "Returning sum/tic:" << sum;
750 
751  // return sum;
752 
753  return std::accumulate(begin(),
754  end(),
755  (double)0,
756  [](pappso_double sum, const DataPoint &dataPoint) {
757  return (sum + dataPoint.y);
758  });
759 }

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

Referenced by pappso::MassSpectrum::makeMassSpectrumSPtr().

◆ sumY() [2/2]

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

Definition at line 763 of file trace.cpp.

764 {
765  auto begin_it = findFirstEqualOrGreaterX(this->begin(), this->end(), mzStart);
766  return sumYTrace(
767  begin_it, findFirstGreaterX(begin_it, this->end(), mzEnd), 0);
768 }

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

819 {
820  // Even if the spectrum is empty, we should return an empty string.
821  QString text;
822 
823  for(auto &&dataPoint : *this)
824  {
825  text.append(QString("%1 %2\n")
826  .arg(dataPoint.x, 0, 'f', 10)
827  .arg(dataPoint.y, 0, 'f', 10));
828  }
829 
830  return text;
831 }

◆ unique()

void pappso::Trace::unique ( )

Definition at line 806 of file trace.cpp.

807 {
808  auto last =
809  std::unique(begin(), end(), [](const DataPoint &a, const DataPoint &b) {
810  return (a.x == b.x);
811  });
812 
813  erase(last, end());
814 }

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(), 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:
pappso::Trace::maxYDataPoint
const DataPoint & maxYDataPoint() const
Definition: trace.cpp:708
pappso::pappso_double
double pappso_double
A type definition for doubles.
Definition: types.h:69
pappso::DataPoint::y
pappso_double y
Definition: datapoint.h:23
pappso::PeptideIonNter::a
@ a
pappso::Trace::initialize
size_t initialize(const std::vector< pappso_double > &xVector, const std::vector< pappso_double > &yVector)
Definition: trace.cpp:453
pappso::Trace::filter
virtual Trace & filter(const FilterInterface &filter) final
apply a filter on this trace
Definition: trace.cpp:835
pappso::sumYTrace
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
pappso::QualifiedMassSpectrumParameter::last
@ last
pappso::Trace::sortX
void sortX()
Definition: trace.cpp:790
pappso::Trace::minYDataPoint
const DataPoint & minYDataPoint() const
Definition: trace.cpp:689
pappso::PeptideIonNter::b
@ b
pappso::findFirstEqualOrGreaterX
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
pappso::Trace::dataPointCstIteratorWithX
std::vector< DataPoint >::const_iterator dataPointCstIteratorWithX(pappso_double value) const
Definition: trace.cpp:631
pappso::findFirstGreaterX
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