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 QString &text)
 
 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 QString space_sep_text)
 
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 ()
 
std::size_t removeZeroYDataPoints ()
 
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/9]

pappso::Trace::Trace ( )

Definition at line 444 of file trace.cpp.

445{
446}

◆ Trace() [2/9]

pappso::Trace::Trace ( const QString &  text)

Definition at line 449 of file trace.cpp.

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

References initialize().

◆ Trace() [3/9]

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

Definition at line 455 of file trace.cpp.

457{
458 initialize(xVector, yVector);
459}

References initialize().

◆ Trace() [4/9]

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

Definition at line 488 of file trace.cpp.

490{
491 reserve(dataPoints.size());
492
493 for(auto &dataPoint : dataPoints)
494 {
495 push_back(DataPoint(dataPoint));
496 }
497
498 sortX();
499 // std::sort(begin(), end(), [](const DataPoint &a, const DataPoint &b) {
500 // return (a.x < b.x);
501 //});
502}
void sortX()
Definition: trace.cpp:987

References sortX().

◆ Trace() [5/9]

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

Definition at line 505 of file trace.cpp.

506 : std::vector<DataPoint>(dataPoints)
507{
508 sortX();
509 // std::sort(begin(), end(), [](const DataPoint &a, const DataPoint &b) {
510 // return (a.x < b.x);
511 //});
512}

References sortX().

◆ Trace() [6/9]

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

Definition at line 515 of file trace.cpp.

516 : std::vector<DataPoint>(std::move(dataPoints))
517{
518 // This constructor used by the MassSpectrum && constructor.
519
520 sortX();
521 // std::sort(begin(), end(), [](const DataPoint &a, const DataPoint &b) {
522 // return (a.x < b.x);
523 //});
524}

References sortX().

◆ Trace() [7/9]

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

Definition at line 527 of file trace.cpp.

528{
529 for(auto &&item : map_trace)
530 push_back(DataPoint(item.first, item.second));
531
532 // No need to sort, maps are sorted by key (that is, x).
533}

◆ Trace() [8/9]

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

Definition at line 535 of file trace.cpp.

535 : std::vector<DataPoint>(other)
536{
537}

◆ Trace() [9/9]

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

Definition at line 540 of file trace.cpp.

540 : std::vector<DataPoint>(std::move(other))
541{
542 // This constructor used by the MassSpectrum && constructor.
543}

◆ ~Trace()

pappso::Trace::~Trace ( )
virtual

Definition at line 546 of file trace.cpp.

547{
548 // Calls the destructor for each DataPoint object in the vector.
549 clear();
550}

Member Function Documentation

◆ append()

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

appends a datapoint and return new size

Definition at line 614 of file trace.cpp.

615{
616 push_back(data_point);
617
618 return size();
619}

Referenced by pappso::TimsFramesMsRunReader::computeTicChromatogram(), and initialize().

◆ containsX()

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

Definition at line 766 of file trace.cpp.

767{
768 // std::cout << std::setprecision(10) << "getting value: " << value
769 //<< " and precision: " << precision_p->getNominal() << std::endl;
770
771 pappso_double delta = precision_p->delta(value);
772
773 double left_most = value - delta;
774 double right_most = value + delta;
775
776 // std::cout << std::setprecision(10) << "delta: " << delta
777 //<< " left_most: " << left_most << " right_most: " << right_most
778 //<< std::endl;
779
780 auto iterator =
781 std::find_if(begin(),
782 end(),
783 [value, precision_p, delta, left_most, right_most](
784 const DataPoint &data_point) {
785 if(precision_p)
786 {
787
788 // FIXME: unbelievable behaviour: when building in
789 // release mode this code, under i386 (but not x86_64),
790 // this code fails if the following cout statement is
791 // missing.
792
793 // std::cout << std::setprecision(10)
794 //<< "Testing data_point.x: " << data_point.x
795 //<< std::endl;
796
797 // For this reason I had to deactivate the related tests
798 // for i386 in tests/test_trace.cpp
799
800 double diff_to_left_most = data_point.x - left_most;
801 double diff_to_right_most = data_point.x - right_most;
802
803 // std::cout << std::setprecision(10)
804 //<< "diff_to_left_most: " << diff_to_left_most
805 //<< " diff_to_right_most: " << diff_to_right_most <<
806 // std::endl;
807
808 // if(diff_to_left_most > 0)
809 //{
810 // std::cout << std::setprecision(10)
811 //<< " point is right of left_most: " <<
812 // diff_to_left_most
813 //<< std::endl;
814 //}
815 // if(diff_to_left_most < 0)
816 //{
817 // std::cout << std::setprecision(10)
818 //<< "point is left of left_most: " << diff_to_left_most
819 //<< std::endl;
820 //}
821 // if(!diff_to_left_most)
822 //{
823 // std::cout << std::setprecision(10)
824 //<< "point is spot on left_most: " << diff_to_left_most
825 //<< std::endl;
826 //}
827
828 // if(diff_to_right_most > 0)
829 //{
830 // std::cout << std::setprecision(10)
831 //<< "point is right of right_most: " <<
832 // diff_to_right_most
833 //<< std::endl;
834 //}
835 // if(diff_to_right_most < 0)
836 //{
837 // std::cout << std::setprecision(10)
838 //<< "point is left or of right_most: "
839 //<< diff_to_right_most << std::endl;
840 //}
841 // if(!diff_to_right_most)
842 //{
843 // std::cout << std::setprecision(10)
844 //<< "point is spot on right_most: " <<
845 // diff_to_right_most
846 //<< std::endl;
847 //}
848
849 if(diff_to_left_most >= 0 && diff_to_right_most <= 0)
850 {
851 // std::cout << "The point is inside the range,
852 // should return true."
853 //<< std::endl;
854 return true;
855 }
856 else
857 {
858 // std::cout
859 //<< "The point is outside the range, should return
860 // false."
861 //<< std::endl;
862 return false;
863 }
864 }
865 else
866 {
867 return (data_point.x == value);
868 }
869 });
870
871 if(iterator != end())
872 {
873 // The returned data point is valid.
874 return *iterator;
875 }
876 else
877 {
878 // The returned data point is invalid because it is not initialized.
879 return DataPoint();
880 }
881}
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 741 of file trace.cpp.

742{
743 auto iterator =
744 std::find_if(begin(), end(), [value](const DataPoint &dataPoint) {
745 return (dataPoint.x == value);
746 });
747
748 return iterator;
749}

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

754{
755 std::vector<DataPoint>::const_iterator iterator =
757
758 if(iterator != end())
759 return std::distance(begin(), iterator);
760
761 return std::numeric_limits<std::size_t>::max();
762}
std::vector< DataPoint >::const_iterator dataPointCstIteratorWithX(pappso_double value) const
find datapoint with exactly x value
Definition: trace.cpp:741

References dataPointCstIteratorWithX().

◆ dataPointIteratorWithX()

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

Definition at line 729 of file trace.cpp.

730{
731 auto iterator =
732 std::find_if(begin(), end(), [value](const DataPoint &dataPoint) {
733 return (dataPoint.x == value);
734 });
735
736 return iterator;
737}

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

1060{
1061 return filter.filter(*this);
1062}
virtual Trace & filter(const FilterInterface &filter) final
apply a filter on this trace
Definition: trace.cpp:1059

References filter().

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

◆ initialize() [1/4]

size_t pappso::Trace::initialize ( const QString  space_sep_text)

Definition at line 463 of file trace.cpp.

464{
465 QStringList string_list = space_sep_text.split("\n", Qt::SkipEmptyParts);
466
467 //qDebug() << "Split text into" << string_list.size()
468 //<< "substrings:" << string_list;
469 ;
470
471 for(int iter = 0; iter < string_list.size(); ++iter)
472 {
473 QString line = string_list.at(iter);
474 //qDebug() << "Now processing line:" << line;
475
476 // Returns a string that has whitespace removed from the start and the
477 // end, and that has each sequence of internal whitespace replaced with a
478 // single space.
479 line = line.simplified();
480
481 append(DataPoint(line));
482 }
483
484 return size();
485}
size_t append(const DataPoint &data_point)
appends a datapoint and return new size
Definition: trace.cpp:614

References append(), and line.

◆ initialize() [2/4]

size_t pappso::Trace::initialize ( const std::map< pappso_double, pappso_double > &  map)

Definition at line 587 of file trace.cpp.

588{
589
590 // We are initializing, not appending.
591 erase(begin(), end());
592
593 for(auto &&item : map)
594 {
595 push_back(DataPoint(item.first, item.second));
596 }
597
598 // No need to sort, maps are sorted by key (that is, x).
599
600 return size();
601}

◆ initialize() [3/4]

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

Definition at line 554 of file trace.cpp.

556{
557 // Sanity check
558 if(xVector.size() != yVector.size())
559 throw ExceptionNotPossible(
560 "trace.cpp -- ERROR xVector and yVector must have the same size.");
561
562 // We are initializing, not appending.
563 erase(begin(), end());
564
565 for(std::size_t iter = 0; iter < xVector.size(); ++iter)
566 {
567 push_back(DataPoint(xVector.at(iter), yVector.at(iter)));
568 }
569
570 sortX();
571 // std::sort(begin(), end(), [](const DataPoint &a, const DataPoint &b) {
572 // return (a.x < b.x);
573 //});
574
575#if 0
576 for(auto &item : *this)
577 {
578 std::cout << item.x << "-" << item.y;
579 }
580#endif
581
582 return size();
583}

References sortX().

Referenced by Trace().

◆ initialize() [4/4]

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

Definition at line 605 of file trace.cpp.

606{
607 *this = other;
608
609 return size();
610}

◆ makeTraceCstSPtr()

TraceCstSPtr pappso::Trace::makeTraceCstSPtr ( ) const

Definition at line 647 of file trace.cpp.

648{
649 return std::make_shared<const Trace>(*this);
650}

◆ makeTraceSPtr()

TraceSPtr pappso::Trace::makeTraceSPtr ( ) const

Definition at line 640 of file trace.cpp.

641{
642 return std::make_shared<Trace>(*this);
643}

◆ maxY() [1/2]

pappso_double pappso::Trace::maxY ( ) const

Definition at line 930 of file trace.cpp.

931{
932 return maxYDataPoint().y;
933}
const DataPoint & maxYDataPoint() const
Definition: trace.cpp:904
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 969 of file trace.cpp.

970{
971 std::vector<DataPoint>::const_iterator begin_it =
972 findFirstEqualOrGreaterX(this->begin(), this->end(), mzStart);
973
974 double max_y = 0;
975
976 while(begin_it != findFirstGreaterX(begin_it, this->end(), mzEnd))
977 {
978 if(begin_it->y > max_y)
979 max_y = begin_it->y;
980 begin_it++;
981 }
982 return max_y;
983}
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:71
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:99

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

◆ maxYDataPoint()

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

Definition at line 904 of file trace.cpp.

905{
906 auto dataPoint = std::max_element(
907 begin(), end(), [](const DataPoint &a, const DataPoint &b) {
908 return (a.y < b.y);
909 });
910
911 if(dataPoint == end())
912 {
913 throw ExceptionOutOfRange(
914 QObject::tr("unable to get max peak intensity on spectrum size %1")
915 .arg(size()));
916 }
917
918 return (*dataPoint);
919}

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

924{
925 return minYDataPoint().y;
926}
const DataPoint & minYDataPoint() const
Definition: trace.cpp:885

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

◆ minYDataPoint()

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

Definition at line 885 of file trace.cpp.

886{
887 auto dataPoint = std::min_element(
888 begin(), end(), [](const DataPoint &a, const DataPoint &b) {
889 return (a.y < b.y);
890 });
891
892 if(dataPoint == end())
893 {
894 throw ExceptionOutOfRange(
895 QObject::tr("unable to get min peak intensity on spectrum size %1")
896 .arg(size()));
897 }
898
899 return (*dataPoint);
900}

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

624{
625 assign(other.begin(), other.end());
626
627 return *this;
628}

◆ operator=() [2/2]

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

Definition at line 632 of file trace.cpp.

633{
634 vector<DataPoint>::operator=(std::move(other));
635 return *this;
636}

◆ removeZeroYDataPoints()

std::size_t pappso::Trace::removeZeroYDataPoints ( )

Definition at line 1015 of file trace.cpp.

1016{
1017 qDebug();
1018
1019 auto it = begin();
1020 auto end_it = end();
1021
1022 std::size_t count = 0;
1023
1024 while(it != end_it)
1025 {
1026 if(Utils::almostEqual(it->y, 0))
1027 {
1028 // erase returns an iterator to the next item in the vector.
1029 it = erase(it);
1030 ++count;
1031 }
1032 else
1033 // We need to increment (no call to erase here).
1034 ++it;
1035 }
1036
1037 return count;
1038}
static bool almostEqual(double value1, double value2, int decimalPlaces=10)
Definition: utils.cpp:261

References pappso::Utils::almostEqual().

◆ sortX()

◆ sortY()

void pappso::Trace::sortY ( )

Definition at line 995 of file trace.cpp.

996{
997 std::sort(begin(), end(), [](const DataPoint &a, const DataPoint &b) {
998 return (a.y > b.y);
999 });
1000}

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

938{
939 // double sum = 0;
940
941 // for(auto &&dp : m_dataPoints)
942 // sum += dp.y;
943
944 // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << " ()"
945 //<< "Returning sum/tic:" << sum;
946
947 // return sum;
948
949 return std::accumulate(begin(),
950 end(),
951 (double)0,
952 [](pappso_double sum, const DataPoint &dataPoint) {
953 return (sum + dataPoint.y);
954 });
955}

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

960{
961 auto begin_it = findFirstEqualOrGreaterX(this->begin(), this->end(), mzStart);
962 auto end_it = findFirstGreaterX(begin_it, this->end(), mzEnd);
963
964 return sumYTrace(begin_it, end_it, 0);
965}
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 682 of file trace.cpp.

683{
684 std::map<pappso_double, pappso_double> map;
685
686 std::pair<std::map<pappso_double, pappso_double>::iterator, bool> ret;
687
688 for(auto &&dataPoint : *this)
689 {
690 ret = map.insert(
691 std::pair<pappso_double, pappso_double>(dataPoint.x, dataPoint.y));
692
693 if(ret.second == false)
694 {
695 qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()"
696 << "It is odd that the Trace contains multiple same keys.";
697
698 // No insertion, then increment the y value.
699 ret.first->second += dataPoint.y;
700 }
701 }
702
703 return map;
704}

◆ toString()

QString pappso::Trace::toString ( ) const

Definition at line 1042 of file trace.cpp.

1043{
1044 // Even if the spectrum is empty, we should return an empty string.
1045 QString text;
1046
1047 for(auto &&dataPoint : *this)
1048 {
1049 text.append(QString("%1 %2\n")
1050 .arg(dataPoint.x, 0, 'f', 10)
1051 .arg(dataPoint.y, 0, 'f', 10));
1052 }
1053
1054 return text;
1055}

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

◆ unique()

void pappso::Trace::unique ( )

Definition at line 1003 of file trace.cpp.

1004{
1005 auto last =
1006 std::unique(begin(), end(), [](const DataPoint &a, const DataPoint &b) {
1007 return (a.x == b.x);
1008 });
1009
1010 erase(last, end());
1011}

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

655{
656 std::vector<pappso_double> values;
657
658 for(auto &&dataPoint : *this)
659 {
660 values.push_back(dataPoint.x);
661 }
662
663 return values;
664}

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

◆ yValues()

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

Definition at line 668 of file trace.cpp.

669{
670 std::vector<pappso_double> values;
671
672 for(auto &&dataPoint : *this)
673 {
674 values.push_back(dataPoint.y);
675 }
676
677 return values;
678}

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: