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

Constructor & Destructor Documentation

◆ Trace() [1/7]

pappso::Trace::Trace ( )

Definition at line 355 of file trace.cpp.

356 {
357 }

◆ Trace() [2/7]

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

Definition at line 360 of file trace.cpp.

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

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

◆ Trace() [3/7]

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

Definition at line 376 of file trace.cpp.

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

◆ Trace() [4/7]

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

Definition at line 382 of file trace.cpp.

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

◆ Trace() [5/7]

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

Definition at line 389 of file trace.cpp.

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

◆ Trace() [6/7]

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

Definition at line 395 of file trace.cpp.

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

◆ Trace() [7/7]

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

Definition at line 400 of file trace.cpp.

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

◆ ~Trace()

pappso::Trace::~Trace ( )
virtual

Definition at line 406 of file trace.cpp.

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

Member Function Documentation

◆ containsX()

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

Definition at line 603 of file trace.cpp.

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

References pappso::DataPoint::x.

◆ dataPointCstIteratorxWithX()

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

Definition at line 578 of file trace.cpp.

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

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

591 {
592  std::vector<DataPoint>::const_iterator iterator =
594 
595  if(iterator != end())
596  return std::distance(begin(), iterator);
597 
598  return std::numeric_limits<std::size_t>::max();
599 }

References dataPointCstIteratorxWithX().

◆ dataPointIteratorxWithX()

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

Definition at line 566 of file trace.cpp.

567 {
568  auto iterator =
569  std::find_if(begin(), end(), [value](const DataPoint &dataPoint) {
570  return (dataPoint.x == value);
571  });
572 
573  return iterator;
574 }

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

804 {
805  return filter.filter(*this);
806 }

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

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

◆ initialize() [2/3]

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

Definition at line 414 of file trace.cpp.

416 {
417  // Sanity check
418  if(xVector.size() != yVector.size())
419  throw ExceptionNotPossible(
420  "trace.cpp -- ERROR xVector and yVector must have the same size.");
421 
422  // Do not force the release of the all the vector space, because we prefer
423  // resizing. clear();
424 
425  resize(xVector.size());
426 
427  for(std::size_t iter = 0; iter < xVector.size(); ++iter)
428  {
429  push_back(DataPoint(xVector.at(iter), yVector.at(iter)));
430  }
431 
432  return size();
433 }

◆ initialize() [3/3]

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

Definition at line 455 of file trace.cpp.

456 {
457  *this = other;
458 
459  return size();
460 }

◆ makeTraceCstSPtr()

TraceCstSPtr pappso::Trace::makeTraceCstSPtr ( ) const

Definition at line 488 of file trace.cpp.

489 {
490  return std::make_shared<const Trace>(*this);
491 }

◆ makeTraceSPtr()

TraceSPtr pappso::Trace::makeTraceSPtr ( ) const

Definition at line 481 of file trace.cpp.

482 {
483  return std::make_shared<Trace>(*this);
484 }

◆ maxY() [1/2]

pappso_double pappso::Trace::maxY ( ) const

Definition at line 681 of file trace.cpp.

682 {
683  return maxYDataPoint().y;
684 }

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

◆ maxY() [2/2]

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

Definition at line 719 of file trace.cpp.

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

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

◆ maxYDataPoint()

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

Definition at line 655 of file trace.cpp.

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

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

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

◆ minY()

pappso_double pappso::Trace::minY ( ) const

Definition at line 674 of file trace.cpp.

675 {
676  return minYDataPoint().y;
677 }

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

◆ minYDataPoint()

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

Definition at line 636 of file trace.cpp.

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

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

465 {
466  assign(other.begin(), other.end());
467 
468  return *this;
469 }

◆ operator=() [2/2]

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

Definition at line 473 of file trace.cpp.

474 {
475  vector<DataPoint>::operator=(std::move(other));
476  return *this;
477 }

◆ sortX()

void pappso::Trace::sortX ( )

Definition at line 737 of file trace.cpp.

738 {
739  std::sort(begin(), end(), [](const DataPoint &a, const DataPoint &b) {
740  return (a.x < b.x);
741  });
742 }

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

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

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

711 {
712  auto begin_it = findFirstEqualOrGreaterX(this->begin(), this->end(), mzStart);
713  return sumYTrace(
714  begin_it, findFirstGreaterX(begin_it, this->end(), mzEnd), 0);
715 }

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

◆ toMap()

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

Definition at line 519 of file trace.cpp.

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

◆ toString()

QString pappso::Trace::toString ( ) const

Definition at line 786 of file trace.cpp.

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

◆ unique()

void pappso::Trace::unique ( )

Definition at line 746 of file trace.cpp.

747 {
748  auto last =
749  std::unique(begin(), end(), [](const DataPoint &a, const DataPoint &b) {
750  return (a.x == b.x);
751  });
752 
753  erase(last, end());
754 }

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

496 {
497  std::vector<pappso_double> vector;
498 
499  for(auto &&dataPoint : *this)
500  vector.push_back(dataPoint.x);
501 
502  return vector;
503 }

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

◆ xValues()

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

Definition at line 758 of file trace.cpp.

759 {
760  std::vector<pappso_double> values;
761 
762  for(auto &&dataPoint : *this)
763  {
764  values.push_back(dataPoint.x);
765  }
766 
767  return values;
768 }

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

◆ yToVector()

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

Definition at line 507 of file trace.cpp.

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

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

◆ yValues()

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

Definition at line 772 of file trace.cpp.

773 {
774  std::vector<pappso_double> values;
775 
776  for(auto &&dataPoint : *this)
777  {
778  values.push_back(dataPoint.y);
779  }
780 
781  return values;
782 }

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

Friends And Related Function Documentation

◆ MassSpectrumCombinerInterface

friend class MassSpectrumCombinerInterface
friend

Definition at line 133 of file trace.h.

◆ TraceCombiner

friend class TraceCombiner
friend

Definition at line 129 of file trace.h.

◆ TraceMinusCombiner

friend class TraceMinusCombiner
friend

Definition at line 130 of file trace.h.

◆ TracePlusCombiner

friend class TracePlusCombiner
friend

Definition at line 131 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:655
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:578
pappso::PeptideIonNter::a
@ a
pappso::Trace::filter
virtual Trace & filter(const FilterInterface &filter) final
apply a filter on this trace
Definition: trace.cpp:803
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:182
pappso::QualifiedMassSpectrumParameter::last
@ last
pappso::Trace::minYDataPoint
const DataPoint & minYDataPoint() const
Definition: trace.cpp:636
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