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
 
size_t append (const DataPoint &data_point)
 appends a datapoint and return new size More...
 
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
 
std::vector< DataPoint >::const_iterator dataPointCstIteratorWithX (pappso_double value) const
 find datapoint with exactly x value More...
 

Protected Member Functions

std::size_t dataPointIndexWithX (pappso_double value) const
 
std::vector< DataPoint >::iterator dataPointIteratorWithX (pappso_double value)
 

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

445{
446}

◆ Trace() [2/8]

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

Definition at line 449 of file trace.cpp.

451{
452 initialize(xVector, yVector);
453}
size_t initialize(const std::vector< pappso_double > &xVector, const std::vector< pappso_double > &yVector)
Definition: trace.cpp:523

References initialize().

◆ Trace() [3/8]

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

Definition at line 456 of file trace.cpp.

458{
459 reserve(dataPoints.size());
460
461 for(auto &dataPoint : dataPoints)
462 {
463 push_back(DataPoint(dataPoint));
464 }
465
466 sortX();
467 // std::sort(begin(), end(), [](const DataPoint &a, const DataPoint &b) {
468 // return (a.x < b.x);
469 //});
470}
void sortX()
Definition: trace.cpp:956

References sortX().

◆ Trace() [4/8]

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

Definition at line 473 of file trace.cpp.

474 : std::vector<DataPoint>(dataPoints)
475{
476 sortX();
477 // std::sort(begin(), end(), [](const DataPoint &a, const DataPoint &b) {
478 // return (a.x < b.x);
479 //});
480}

References sortX().

◆ Trace() [5/8]

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

Definition at line 483 of file trace.cpp.

484 : std::vector<DataPoint>(std::move(dataPoints))
485{
486 // This constructor used by the MassSpectrum && constructor.
487
488 sortX();
489 // std::sort(begin(), end(), [](const DataPoint &a, const DataPoint &b) {
490 // return (a.x < b.x);
491 //});
492}

References sortX().

◆ Trace() [6/8]

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

Definition at line 495 of file trace.cpp.

496{
497 for(auto &&item : map_trace)
498 push_back(DataPoint(item.first, item.second));
499
500 // No need to sort, maps are sorted by key (that is, x).
501}

◆ Trace() [7/8]

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

Definition at line 503 of file trace.cpp.

503 : std::vector<DataPoint>(other)
504{
505}

◆ Trace() [8/8]

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

Definition at line 508 of file trace.cpp.

509 : std::vector<DataPoint>(std::move(other))
510{
511 // This constructor used by the MassSpectrum && constructor.
512}

◆ ~Trace()

pappso::Trace::~Trace ( )
virtual

Definition at line 515 of file trace.cpp.

516{
517 // Calls the destructor for each DataPoint object in the vector.
518 clear();
519}

Member Function Documentation

◆ append()

size_t pappso::Trace::append ( const DataPoint data_point)

appends a datapoint and return new size

Definition at line 583 of file trace.cpp.

584{
585 push_back(data_point);
586
587 return size();
588}

Referenced by pappso::TimsFramesMsRunReader::computeTicChromatogram().

◆ containsX()

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

Definition at line 735 of file trace.cpp.

736{
737 // std::cout << std::setprecision(10) << "getting value: " << value
738 //<< " and precision: " << precision_p->getNominal() << std::endl;
739
740 pappso_double delta = precision_p->delta(value);
741
742 double left_most = value - delta;
743 double right_most = value + delta;
744
745 // std::cout << std::setprecision(10) << "delta: " << delta
746 //<< " left_most: " << left_most << " right_most: " << right_most
747 //<< std::endl;
748
749 auto iterator =
750 std::find_if(begin(),
751 end(),
752 [value, precision_p, delta, left_most, right_most](
753 const DataPoint &data_point) {
754 if(precision_p)
755 {
756
757 // FIXME: unbelievable behaviour: when building in
758 // release mode this code, under i386 (but not x86_64),
759 // this code fails if the following cout statement is
760 // missing.
761
762 // std::cout << std::setprecision(10)
763 //<< "Testing data_point.x: " << data_point.x
764 //<< std::endl;
765
766 // For this reason I had to deactivate the related tests
767 // for i386 in tests/test_trace.cpp
768
769 double diff_to_left_most = data_point.x - left_most;
770 double diff_to_right_most = data_point.x - right_most;
771
772 // std::cout << std::setprecision(10)
773 //<< "diff_to_left_most: " << diff_to_left_most
774 //<< " diff_to_right_most: " << diff_to_right_most <<
775 // std::endl;
776
777 // if(diff_to_left_most > 0)
778 //{
779 // std::cout << std::setprecision(10)
780 //<< " point is right of left_most: " <<
781 // diff_to_left_most
782 //<< std::endl;
783 //}
784 // if(diff_to_left_most < 0)
785 //{
786 // std::cout << std::setprecision(10)
787 //<< "point is left of left_most: " << diff_to_left_most
788 //<< std::endl;
789 //}
790 // if(!diff_to_left_most)
791 //{
792 // std::cout << std::setprecision(10)
793 //<< "point is spot on left_most: " << diff_to_left_most
794 //<< std::endl;
795 //}
796
797 // if(diff_to_right_most > 0)
798 //{
799 // std::cout << std::setprecision(10)
800 //<< "point is right of right_most: " <<
801 // diff_to_right_most
802 //<< std::endl;
803 //}
804 // if(diff_to_right_most < 0)
805 //{
806 // std::cout << std::setprecision(10)
807 //<< "point is left or of right_most: "
808 //<< diff_to_right_most << std::endl;
809 //}
810 // if(!diff_to_right_most)
811 //{
812 // std::cout << std::setprecision(10)
813 //<< "point is spot on right_most: " <<
814 // diff_to_right_most
815 //<< std::endl;
816 //}
817
818 if(diff_to_left_most >= 0 && diff_to_right_most <= 0)
819 {
820 // std::cout << "The point is inside the range,
821 // should return true."
822 //<< std::endl;
823 return true;
824 }
825 else
826 {
827 // std::cout
828 //<< "The point is outside the range, should return
829 // false."
830 //<< std::endl;
831 return false;
832 }
833 }
834 else
835 {
836 return (data_point.x == value);
837 }
838 });
839
840 if(iterator != end())
841 {
842 // The returned data point is valid.
843 return *iterator;
844 }
845 else
846 {
847 // The returned data point is invalid because it is not initialized.
848 return DataPoint();
849 }
850}
double pappso_double
A type definition for doubles.
Definition: types.h:49

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

◆ dataPointCstIteratorWithX()

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

find datapoint with exactly x value

Definition at line 710 of file trace.cpp.

711{
712 auto iterator =
713 std::find_if(begin(), end(), [value](const DataPoint &dataPoint) {
714 return (dataPoint.x == value);
715 });
716
717 return iterator;
718}

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

723{
724 std::vector<DataPoint>::const_iterator iterator =
726
727 if(iterator != end())
728 return std::distance(begin(), iterator);
729
730 return std::numeric_limits<std::size_t>::max();
731}
std::vector< DataPoint >::const_iterator dataPointCstIteratorWithX(pappso_double value) const
find datapoint with exactly x value
Definition: trace.cpp:710

References dataPointCstIteratorWithX().

◆ dataPointIteratorWithX()

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

Definition at line 698 of file trace.cpp.

699{
700 auto iterator =
701 std::find_if(begin(), end(), [value](const DataPoint &dataPoint) {
702 return (dataPoint.x == value);
703 });
704
705 return iterator;
706}

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

1002{
1003 return filter.filter(*this);
1004}
virtual Trace & filter(const FilterInterface &filter) final
apply a filter on this trace
Definition: trace.cpp:1001

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

557{
558
559 // We are initializing, not appending.
560 erase(begin(), end());
561
562 for(auto &&item : map)
563 {
564 push_back(DataPoint(item.first, item.second));
565 }
566
567 // No need to sort, maps are sorted by key (that is, x).
568
569 return size();
570}

◆ initialize() [2/3]

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

Definition at line 523 of file trace.cpp.

525{
526 // Sanity check
527 if(xVector.size() != yVector.size())
528 throw ExceptionNotPossible(
529 "trace.cpp -- ERROR xVector and yVector must have the same size.");
530
531 // We are initializing, not appending.
532 erase(begin(), end());
533
534 for(std::size_t iter = 0; iter < xVector.size(); ++iter)
535 {
536 push_back(DataPoint(xVector.at(iter), yVector.at(iter)));
537 }
538
539 sortX();
540 // std::sort(begin(), end(), [](const DataPoint &a, const DataPoint &b) {
541 // return (a.x < b.x);
542 //});
543
544#if 0
545 for(auto &item : *this)
546 {
547 std::cout << item.x << "-" << item.y;
548 }
549#endif
550
551 return size();
552}

References sortX().

Referenced by Trace().

◆ initialize() [3/3]

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

Definition at line 574 of file trace.cpp.

575{
576 *this = other;
577
578 return size();
579}

◆ makeTraceCstSPtr()

TraceCstSPtr pappso::Trace::makeTraceCstSPtr ( ) const

Definition at line 616 of file trace.cpp.

617{
618 return std::make_shared<const Trace>(*this);
619}

◆ makeTraceSPtr()

TraceSPtr pappso::Trace::makeTraceSPtr ( ) const

Definition at line 609 of file trace.cpp.

610{
611 return std::make_shared<Trace>(*this);
612}

◆ maxY() [1/2]

pappso_double pappso::Trace::maxY ( ) const

Definition at line 899 of file trace.cpp.

900{
901 return maxYDataPoint().y;
902}
const DataPoint & maxYDataPoint() const
Definition: trace.cpp:873
pappso_double y
Definition: datapoint.h:24

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

◆ maxY() [2/2]

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

Definition at line 938 of file trace.cpp.

939{
940 std::vector<DataPoint>::const_iterator begin_it =
941 findFirstEqualOrGreaterX(this->begin(), this->end(), mzStart);
942
943 double max_y = 0;
944
945 while(begin_it != findFirstGreaterX(begin_it, this->end(), mzEnd))
946 {
947 if(begin_it->y > max_y)
948 max_y = begin_it->y;
949 begin_it++;
950 }
951 return max_y;
952}
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:69
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:97

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

◆ maxYDataPoint()

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

Definition at line 873 of file trace.cpp.

874{
875 auto dataPoint = std::max_element(
876 begin(), end(), [](const DataPoint &a, const DataPoint &b) {
877 return (a.y < b.y);
878 });
879
880 if(dataPoint == end())
881 {
882 throw ExceptionOutOfRange(
883 QObject::tr("unable to get max peak intensity on spectrum size %1")
884 .arg(size()));
885 }
886
887 return (*dataPoint);
888}

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

893{
894 return minYDataPoint().y;
895}
const DataPoint & minYDataPoint() const
Definition: trace.cpp:854

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

◆ minYDataPoint()

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

Definition at line 854 of file trace.cpp.

855{
856 auto dataPoint = std::min_element(
857 begin(), end(), [](const DataPoint &a, const DataPoint &b) {
858 return (a.y < b.y);
859 });
860
861 if(dataPoint == end())
862 {
863 throw ExceptionOutOfRange(
864 QObject::tr("unable to get min peak intensity on spectrum size %1")
865 .arg(size()));
866 }
867
868 return (*dataPoint);
869}

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

593{
594 assign(other.begin(), other.end());
595
596 return *this;
597}

◆ operator=() [2/2]

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

Definition at line 601 of file trace.cpp.

602{
603 vector<DataPoint>::operator=(std::move(other));
604 return *this;
605}

◆ sortX()

◆ sortY()

void pappso::Trace::sortY ( )

Definition at line 964 of file trace.cpp.

965{
966 std::sort(begin(), end(), [](const DataPoint &a, const DataPoint &b) {
967 return (a.y > b.y);
968 });
969}

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

907{
908 // double sum = 0;
909
910 // for(auto &&dp : m_dataPoints)
911 // sum += dp.y;
912
913 // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << " ()"
914 //<< "Returning sum/tic:" << sum;
915
916 // return sum;
917
918 return std::accumulate(begin(),
919 end(),
920 (double)0,
921 [](pappso_double sum, const DataPoint &dataPoint) {
922 return (sum + dataPoint.y);
923 });
924}

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

Referenced by pappso::PsmFeatures::setPeptideSpectrumCharge(), pappso::MassSpectrum::tic(), and pappso::MassSpectrum::totalIonCurrent().

◆ sumY() [2/2]

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

Definition at line 928 of file trace.cpp.

929{
930 auto begin_it = findFirstEqualOrGreaterX(this->begin(), this->end(), mzStart);
931 auto end_it = findFirstGreaterX(begin_it, this->end(), mzEnd);
932
933 return sumYTrace(begin_it, end_it, 0);
934}
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:244

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

◆ toMap()

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

Definition at line 651 of file trace.cpp.

652{
653 std::map<pappso_double, pappso_double> map;
654
655 std::pair<std::map<pappso_double, pappso_double>::iterator, bool> ret;
656
657 for(auto &&dataPoint : *this)
658 {
659 ret = map.insert(
660 std::pair<pappso_double, pappso_double>(dataPoint.x, dataPoint.y));
661
662 if(ret.second == false)
663 {
664 qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()"
665 << "It is odd that the Trace contains multiple same keys.";
666
667 // No insertion, then increment the y value.
668 ret.first->second += dataPoint.y;
669 }
670 }
671
672 return map;
673}

◆ toString()

QString pappso::Trace::toString ( ) const

Definition at line 984 of file trace.cpp.

985{
986 // Even if the spectrum is empty, we should return an empty string.
987 QString text;
988
989 for(auto &&dataPoint : *this)
990 {
991 text.append(QString("%1 %2\n")
992 .arg(dataPoint.x, 0, 'f', 10)
993 .arg(dataPoint.y, 0, 'f', 10));
994 }
995
996 return text;
997}

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

◆ unique()

void pappso::Trace::unique ( )

Definition at line 972 of file trace.cpp.

973{
974 auto last =
975 std::unique(begin(), end(), [](const DataPoint &a, const DataPoint &b) {
976 return (a.x == b.x);
977 });
978
979 erase(last, end());
980}

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

624{
625 std::vector<pappso_double> values;
626
627 for(auto &&dataPoint : *this)
628 {
629 values.push_back(dataPoint.x);
630 }
631
632 return values;
633}

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

◆ yValues()

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

Definition at line 637 of file trace.cpp.

638{
639 std::vector<pappso_double> values;
640
641 for(auto &&dataPoint : *this)
642 {
643 values.push_back(dataPoint.y);
644 }
645
646 return values;
647}

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: