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

Constructor & Destructor Documentation

◆ Trace() [1/7]

pappso::Trace::Trace ( )

Definition at line 354 of file trace.cpp.

355 {
356 }

◆ Trace() [2/7]

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

Definition at line 359 of file trace.cpp.

361 {
362  reserve(dataPoints.size());
363 
364  for(auto &dataPoint : dataPoints)
365  {
366  push_back(DataPoint(dataPoint));
367  }
368 
369  std::sort(begin(), end(), [](const DataPoint &a, const DataPoint &b) {
370  return (a.y < b.y);
371  });
372 }

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

◆ Trace() [3/7]

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

Definition at line 375 of file trace.cpp.

376  : std::vector<DataPoint>(dataPoints)
377 {
378 }

◆ Trace() [4/7]

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

Definition at line 381 of file trace.cpp.

382  : std::vector<DataPoint>(std::move(dataPoints))
383 {
384  // This constructor used by the MassSpectrum && constructor.
385 }

◆ Trace() [5/7]

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

Definition at line 388 of file trace.cpp.

389 {
390  for(auto &&item : map_trace)
391  push_back(DataPoint(item.first, item.second));
392 }

◆ Trace() [6/7]

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

Definition at line 394 of file trace.cpp.

394  : std::vector<DataPoint>(other)
395 {
396 }

◆ Trace() [7/7]

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

Definition at line 399 of file trace.cpp.

399  : std::vector<DataPoint>(std::move(other))
400 {
401  // This constructor used by the MassSpectrum && constructor.
402 }

◆ ~Trace()

pappso::Trace::~Trace ( )
virtual

Definition at line 405 of file trace.cpp.

406 {
407  // Calls the destructor for each DataPoint object in the vector.
408  clear();
409 }

Member Function Documentation

◆ containsX()

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

Definition at line 607 of file trace.cpp.

608 {
609  auto iterator = std::find_if(
610  begin(), end(), [value, precision_p](const DataPoint &data_point) {
611  if(precision_p)
612  {
613  pappso_double delta = precision_p->delta(value);
614 
615  if(data_point.x >= (value - delta) && data_point.x <= (value + delta))
616  return true;
617  else
618  return false;
619  }
620  else
621  {
622  return (data_point.x == value);
623  }
624  });
625 
626  if(iterator != end())
627  {
628  // The returned data point is valid.
629  return *iterator;
630  }
631  else
632  {
633  // The returned data point is invalid because it is not initialized.
634  return DataPoint();
635  }
636 }

References pappso::DataPoint::x.

◆ dataPointCstIteratorxWithX()

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

Definition at line 582 of file trace.cpp.

583 {
584  auto iterator =
585  std::find_if(begin(), end(), [value](const DataPoint &dataPoint) {
586  return (dataPoint.x == value);
587  });
588 
589  return iterator;
590 }

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

595 {
596  std::vector<DataPoint>::const_iterator iterator =
598 
599  if(iterator != end())
600  return std::distance(begin(), iterator);
601 
602  return std::numeric_limits<std::size_t>::max();
603 }

References dataPointCstIteratorxWithX().

◆ dataPointIteratorxWithX()

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

Definition at line 570 of file trace.cpp.

571 {
572  auto iterator =
573  std::find_if(begin(), end(), [value](const DataPoint &dataPoint) {
574  return (dataPoint.x == value);
575  });
576 
577  return iterator;
578 }

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

808 {
809  return filter.filter(*this);
810 }

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

442 {
443 
444  // Do not force the release of the all the vector space, because we prefer
445  // resizing. clear(false);
446 
447  resize(map.size());
448 
449  for(auto &&item : map)
450  {
451  push_back(DataPoint(item.first, item.second));
452  }
453 
454  return size();
455 }

◆ initialize() [2/3]

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

Definition at line 413 of file trace.cpp.

415 {
416  // Sanity check
417  if(xVector.size() != yVector.size())
418  qFatal(
419  "Fatal error at %s@%d -- %s(). "
420  "xVector and yVector must have the same size."
421  "Program aborted.",
422  __FILE__,
423  __LINE__,
424  __FUNCTION__);
425 
426  // Do not force the release of the all the vector space, because we prefer
427  // resizing. clear();
428 
429  resize(xVector.size());
430 
431  for(std::size_t iter = 0; iter < xVector.size(); ++iter)
432  {
433  push_back(DataPoint(xVector.at(iter), yVector.at(iter)));
434  }
435 
436  return size();
437 }

◆ initialize() [3/3]

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

Definition at line 459 of file trace.cpp.

460 {
461  *this = other;
462 
463  return size();
464 }

◆ makeTraceCstSPtr()

TraceCstSPtr pappso::Trace::makeTraceCstSPtr ( ) const

Definition at line 492 of file trace.cpp.

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

◆ makeTraceSPtr()

TraceSPtr pappso::Trace::makeTraceSPtr ( ) const

Definition at line 485 of file trace.cpp.

486 {
487  return std::make_shared<Trace>(*this);
488 }

◆ maxY() [1/2]

pappso_double pappso::Trace::maxY ( ) const

Definition at line 685 of file trace.cpp.

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

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

◆ maxY() [2/2]

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

Definition at line 723 of file trace.cpp.

724 {
725  std::vector<DataPoint>::const_iterator begin_it =
726  findFirstEqualOrGreaterX(this->begin(), this->end(), mzStart);
727 
728  double max_y = 0;
729 
730  while(begin_it != this->end())
731  {
732  if(begin_it->y > max_y)
733  max_y = begin_it->y;
734  begin_it++;
735  }
736  return max_y;
737 }

References pappso::findFirstEqualOrGreaterX().

◆ maxYDataPoint()

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

Definition at line 659 of file trace.cpp.

660 {
661  auto dataPoint = std::max_element(
662  begin(), end(), [](const DataPoint &a, const DataPoint &b) {
663  return (a.y < b.y);
664  });
665 
666  if(dataPoint == end())
667  {
668  throw ExceptionOutOfRange(
669  QObject::tr("unable to get max peak intensity on spectrum size %1")
670  .arg(size()));
671  }
672 
673  return (*dataPoint);
674 }

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

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

◆ minY()

pappso_double pappso::Trace::minY ( ) const

Definition at line 678 of file trace.cpp.

679 {
680  return minYDataPoint().y;
681 }

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

◆ minYDataPoint()

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

Definition at line 640 of file trace.cpp.

641 {
642  auto dataPoint = std::min_element(
643  begin(), end(), [](const DataPoint &a, const DataPoint &b) {
644  return (b.y < a.y);
645  });
646 
647  if(dataPoint == end())
648  {
649  throw ExceptionOutOfRange(
650  QObject::tr("unable to get min peak intensity on spectrum size %1")
651  .arg(size()));
652  }
653 
654  return (*dataPoint);
655 }

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

469 {
470  assign(other.begin(), other.end());
471 
472  return *this;
473 }

◆ operator=() [2/2]

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

Definition at line 477 of file trace.cpp.

478 {
479  vector<DataPoint>::operator=(std::move(other));
480  return *this;
481 }

◆ sortX()

void pappso::Trace::sortX ( )

Definition at line 741 of file trace.cpp.

742 {
743  std::sort(begin(), end(), [](const DataPoint &a, const DataPoint &b) {
744  return (a.x < b.x);
745  });
746 }

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

Referenced by pappso::MsRunRetentionTime< T >::align(), pappso::FilterTriangle::filter(), pappso::MsRunRetentionTime< T >::getCommonDeltaRt(), pappso::IonIsotopeRatioScore::IonIsotopeRatioScore(), pappso::MassSpectrum::maxIntensityDataPoint(), and pappso::Xic::sortByRetentionTime().

◆ sumY() [1/2]

pappso_double pappso::Trace::sumY ( ) const

Definition at line 692 of file trace.cpp.

693 {
694  // double sum = 0;
695 
696  // for(auto &&dp : m_dataPoints)
697  // sum += dp.y;
698 
699  // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << " ()"
700  //<< "Returning sum/tic:" << sum;
701 
702  // return sum;
703 
704  return std::accumulate(begin(),
705  end(),
706  (double)0,
707  [](pappso_double sum, const DataPoint &dataPoint) {
708  return (sum + dataPoint.y);
709  });
710 }

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

715 {
716  auto begin_it = findFirstEqualOrGreaterX(this->begin(), this->end(), mzStart);
717  return sumYTrace(
718  begin_it, findFirstGreaterX(begin_it, this->end(), mzEnd), 0);
719 }

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

◆ toMap()

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

Definition at line 523 of file trace.cpp.

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

◆ toString()

QString pappso::Trace::toString ( ) const

Definition at line 790 of file trace.cpp.

791 {
792  // Even if the spectrum is empty, we should return an empty string.
793  QString text;
794 
795  for(auto &&dataPoint : *this)
796  {
797  text.append(QString("%1 %2\n")
798  .arg(dataPoint.x, 0, 'f', 10)
799  .arg(dataPoint.y, 0, 'f', 10));
800  }
801 
802  return text;
803 }

◆ unique()

void pappso::Trace::unique ( )

Definition at line 750 of file trace.cpp.

751 {
752  auto last =
753  std::unique(begin(), end(), [](const DataPoint &a, const DataPoint &b) {
754  return (a.x == b.x);
755  });
756 
757  erase(last, end());
758 }

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

500 {
501  std::vector<pappso_double> vector;
502 
503  for(auto &&dataPoint : *this)
504  vector.push_back(dataPoint.x);
505 
506  return vector;
507 }

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

◆ xValues()

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

Definition at line 762 of file trace.cpp.

763 {
764  std::vector<pappso_double> values;
765 
766  for(auto &&dataPoint : *this)
767  {
768  values.push_back(dataPoint.x);
769  }
770 
771  return values;
772 }

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

◆ yToVector()

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

Definition at line 511 of file trace.cpp.

512 {
513  std::vector<pappso_double> vector;
514 
515  for(auto &&dataPoint : *this)
516  vector.push_back(dataPoint.y);
517 
518  return vector;
519 }

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

◆ yValues()

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

Definition at line 776 of file trace.cpp.

777 {
778  std::vector<pappso_double> values;
779 
780  for(auto &&dataPoint : *this)
781  {
782  values.push_back(dataPoint.y);
783  }
784 
785  return values;
786 }

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

Friends And Related Function Documentation

◆ MassSpectrumCombinerInterface

friend class MassSpectrumCombinerInterface
friend

Definition at line 132 of file trace.h.

◆ TraceCombiner

friend class TraceCombiner
friend

Definition at line 128 of file trace.h.

◆ TraceMinusCombiner

friend class TraceMinusCombiner
friend

Definition at line 129 of file trace.h.

◆ TracePlusCombiner

friend class TracePlusCombiner
friend

Definition at line 130 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:659
pappso::pappso_double
double pappso_double
A type definition for doubles.
Definition: types.h:67
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:582
pappso::PeptideIonNter::a
pappso::Trace::filter
virtual Trace & filter(const FilterInterface &filter) final
apply a filter on this trace
Definition: trace.cpp:807
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:181
pappso::QualifiedMassSpectrumParameter::last
pappso::XicExtractMethod::sum
sum of intensities
pappso::Trace::minYDataPoint
const DataPoint & minYDataPoint() const
Definition: trace.cpp:640
pappso::PeptideIonNter::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:29
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:57