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< 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_doublexToVector () const
 
std::vector< pappso_doubleyToVector () 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 unique ()
 
std::vector< pappso_doublexValues ()
 
std::vector< pappso_doubleyValues ()
 
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 dataPointIteratorxWithX (pappso_double value)
 
std::vector< DataPoint >::const_iterator dataPointCstIteratorxWithX (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/7]

pappso::Trace::Trace ( )

Definition at line 366 of file trace.cpp.

367 {
368 }

◆ Trace() [2/7]

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

Definition at line 371 of file trace.cpp.

373 {
374  reserve(dataPoints.size());
375 
376  for(auto &dataPoint : dataPoints)
377  {
378  push_back(DataPoint(dataPoint));
379  }
380 
381  std::sort(begin(), end(), [](const DataPoint &a, const DataPoint &b) {
382  return (a.y < b.y);
383  });
384 }

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

◆ Trace() [3/7]

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

Definition at line 387 of file trace.cpp.

388  : std::vector<DataPoint>(dataPoints)
389 {
390 }

◆ Trace() [4/7]

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

Definition at line 393 of file trace.cpp.

394  : std::vector<DataPoint>(std::move(dataPoints))
395 {
396  // This constructor used by the MassSpectrum && constructor.
397 }

◆ Trace() [5/7]

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

Definition at line 400 of file trace.cpp.

401 {
402  for(auto &&item : map_trace)
403  push_back(DataPoint(item.first, item.second));
404 }

◆ Trace() [6/7]

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

Definition at line 406 of file trace.cpp.

406  : std::vector<DataPoint>(other)
407 {
408 }

◆ Trace() [7/7]

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

Definition at line 411 of file trace.cpp.

411  : std::vector<DataPoint>(std::move(other))
412 {
413  // This constructor used by the MassSpectrum && constructor.
414 }

◆ ~Trace()

pappso::Trace::~Trace ( )
virtual

Definition at line 417 of file trace.cpp.

418 {
419  // Calls the destructor for each DataPoint object in the vector.
420  clear();
421 }

Member Function Documentation

◆ containsX()

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

Definition at line 614 of file trace.cpp.

615 {
616  auto iterator = std::find_if(
617  begin(), end(), [value, precision_p](const DataPoint &data_point) {
618  if(precision_p)
619  {
620  pappso_double delta = precision_p->delta(value);
621 
622  if(data_point.x >= (value - delta) && data_point.x <= (value + delta))
623  return true;
624  else
625  return false;
626  }
627  else
628  {
629  return (data_point.x == value);
630  }
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 }

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

◆ dataPointCstIteratorxWithX()

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

Definition at line 589 of file trace.cpp.

590 {
591  auto iterator =
592  std::find_if(begin(), end(), [value](const DataPoint &dataPoint) {
593  return (dataPoint.x == value);
594  });
595 
596  return iterator;
597 }

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

602 {
603  std::vector<DataPoint>::const_iterator iterator =
605 
606  if(iterator != end())
607  return std::distance(begin(), iterator);
608 
609  return std::numeric_limits<std::size_t>::max();
610 }

References dataPointCstIteratorxWithX().

◆ dataPointIteratorxWithX()

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

Definition at line 577 of file trace.cpp.

578 {
579  auto iterator =
580  std::find_if(begin(), end(), [value](const DataPoint &dataPoint) {
581  return (dataPoint.x == value);
582  });
583 
584  return iterator;
585 }

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

815 {
816  return filter.filter(*this);
817 }

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

449 {
450 
451  // Do not force the release of the all the vector space, because we prefer
452  // resizing. clear(false);
453 
454  resize(map.size());
455 
456  for(auto &&item : map)
457  {
458  push_back(DataPoint(item.first, item.second));
459  }
460 
461  return size();
462 }

◆ initialize() [2/3]

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

Definition at line 425 of file trace.cpp.

427 {
428  // Sanity check
429  if(xVector.size() != yVector.size())
430  throw ExceptionNotPossible(
431  "trace.cpp -- ERROR xVector and yVector must have the same size.");
432 
433  // Do not force the release of the all the vector space, because we prefer
434  // resizing. clear();
435 
436  resize(xVector.size());
437 
438  for(std::size_t iter = 0; iter < xVector.size(); ++iter)
439  {
440  push_back(DataPoint(xVector.at(iter), yVector.at(iter)));
441  }
442 
443  return size();
444 }

◆ initialize() [3/3]

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

Definition at line 466 of file trace.cpp.

467 {
468  *this = other;
469 
470  return size();
471 }

◆ makeTraceCstSPtr()

TraceCstSPtr pappso::Trace::makeTraceCstSPtr ( ) const

Definition at line 499 of file trace.cpp.

500 {
501  return std::make_shared<const Trace>(*this);
502 }

◆ makeTraceSPtr()

TraceSPtr pappso::Trace::makeTraceSPtr ( ) const

Definition at line 492 of file trace.cpp.

493 {
494  return std::make_shared<Trace>(*this);
495 }

◆ maxY() [1/2]

pappso_double pappso::Trace::maxY ( ) const

Definition at line 692 of file trace.cpp.

693 {
694  return maxYDataPoint().y;
695 }

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

◆ maxY() [2/2]

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

Definition at line 730 of file trace.cpp.

731 {
732  std::vector<DataPoint>::const_iterator begin_it =
733  findFirstEqualOrGreaterX(this->begin(), this->end(), mzStart);
734 
735  double max_y = 0;
736 
737  while(begin_it != findFirstGreaterX(begin_it, this->end(), mzEnd))
738  {
739  if(begin_it->y > max_y)
740  max_y = begin_it->y;
741  begin_it++;
742  }
743  return max_y;
744 }

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

◆ maxYDataPoint()

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

Definition at line 666 of file trace.cpp.

667 {
668  auto dataPoint = std::max_element(
669  begin(), end(), [](const DataPoint &a, const DataPoint &b) {
670  return (a.y < b.y);
671  });
672 
673  if(dataPoint == end())
674  {
675  throw ExceptionOutOfRange(
676  QObject::tr("unable to get max peak intensity on spectrum size %1")
677  .arg(size()));
678  }
679 
680  return (*dataPoint);
681 }

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

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

◆ minY()

pappso_double pappso::Trace::minY ( ) const

Definition at line 685 of file trace.cpp.

686 {
687  return minYDataPoint().y;
688 }

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

◆ minYDataPoint()

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

Definition at line 647 of file trace.cpp.

648 {
649  auto dataPoint = std::min_element(
650  begin(), end(), [](const DataPoint &a, const DataPoint &b) {
651  return (b.y < a.y);
652  });
653 
654  if(dataPoint == end())
655  {
656  throw ExceptionOutOfRange(
657  QObject::tr("unable to get min peak intensity on spectrum size %1")
658  .arg(size()));
659  }
660 
661  return (*dataPoint);
662 }

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

476 {
477  assign(other.begin(), other.end());
478 
479  return *this;
480 }

◆ operator=() [2/2]

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

Definition at line 484 of file trace.cpp.

485 {
486  vector<DataPoint>::operator=(std::move(other));
487  return *this;
488 }

◆ sortX()

◆ sumY() [1/2]

pappso_double pappso::Trace::sumY ( ) const

Definition at line 699 of file trace.cpp.

700 {
701  // double sum = 0;
702 
703  // for(auto &&dp : m_dataPoints)
704  // sum += dp.y;
705 
706  // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << " ()"
707  //<< "Returning sum/tic:" << sum;
708 
709  // return sum;
710 
711  return std::accumulate(begin(),
712  end(),
713  (double)0,
714  [](pappso_double sum, const DataPoint &dataPoint) {
715  return (sum + dataPoint.y);
716  });
717 }

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

722 {
723  auto begin_it = findFirstEqualOrGreaterX(this->begin(), this->end(), mzStart);
724  return sumYTrace(
725  begin_it, findFirstGreaterX(begin_it, this->end(), mzEnd), 0);
726 }

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

◆ toMap()

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

Definition at line 530 of file trace.cpp.

531 {
532  std::map<pappso_double, pappso_double> map;
533 
534  std::pair<std::map<pappso_double, pappso_double>::iterator, bool> ret;
535 
536  for(auto &&dataPoint : *this)
537  {
538  ret = map.insert(
539  std::pair<pappso_double, pappso_double>(dataPoint.x, dataPoint.y));
540 
541  if(ret.second == false)
542  {
543  qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()"
544  << "It is odd that the Trace contains multiple same keys.";
545 
546  // No insertion, then increment the y value.
547  ret.first->second += dataPoint.y;
548  }
549  }
550 
551  return map;
552 }

◆ toString()

QString pappso::Trace::toString ( ) const

Definition at line 797 of file trace.cpp.

798 {
799  // Even if the spectrum is empty, we should return an empty string.
800  QString text;
801 
802  for(auto &&dataPoint : *this)
803  {
804  text.append(QString("%1 %2\n")
805  .arg(dataPoint.x, 0, 'f', 10)
806  .arg(dataPoint.y, 0, 'f', 10));
807  }
808 
809  return text;
810 }

◆ unique()

void pappso::Trace::unique ( )

Definition at line 757 of file trace.cpp.

758 {
759  auto last =
760  std::unique(begin(), end(), [](const DataPoint &a, const DataPoint &b) {
761  return (a.x == b.x);
762  });
763 
764  erase(last, end());
765 }

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

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

◆ xToVector()

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

Definition at line 506 of file trace.cpp.

507 {
508  std::vector<pappso_double> vector;
509 
510  for(auto &&dataPoint : *this)
511  vector.push_back(dataPoint.x);
512 
513  return vector;
514 }

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

◆ xValues()

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

Definition at line 769 of file trace.cpp.

770 {
771  std::vector<pappso_double> values;
772 
773  for(auto &&dataPoint : *this)
774  {
775  values.push_back(dataPoint.x);
776  }
777 
778  return values;
779 }

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

◆ yToVector()

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

Definition at line 518 of file trace.cpp.

519 {
520  std::vector<pappso_double> vector;
521 
522  for(auto &&dataPoint : *this)
523  vector.push_back(dataPoint.y);
524 
525  return vector;
526 }

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

◆ yValues()

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

Definition at line 783 of file trace.cpp.

784 {
785  std::vector<pappso_double> values;
786 
787  for(auto &&dataPoint : *this)
788  {
789  values.push_back(dataPoint.y);
790  }
791 
792  return values;
793 }

Referenced by 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:666
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::Trace::dataPointCstIteratorxWithX
std::vector< DataPoint >::const_iterator dataPointCstIteratorxWithX(pappso_double value) const
Definition: trace.cpp:589
pappso::PeptideIonNter::a
@ a
pappso::Trace::filter
virtual Trace & filter(const FilterInterface &filter) final
apply a filter on this trace
Definition: trace.cpp:814
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:193
pappso::QualifiedMassSpectrumParameter::last
@ last
pappso::Trace::minYDataPoint
const DataPoint & minYDataPoint() const
Definition: trace.cpp:647
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:30
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:58