libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
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 &x_text, const QString &y_text)
 
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
 
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 DataPointminXDataPoint () const
 
const DataPointmaxXDataPoint () const
 
const DataPointminYDataPoint () const
 
const DataPointmaxYDataPoint () const
 
pappso_double minX () const
 
pappso_double maxX () 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 sort (Enums::SortType sort_type, Enums::SortOrder sort_order=Enums::SortOrder::ascending)
 
void sortX (Enums::SortOrder sort_order=Enums::SortOrder::ascending)
 
void sortY (Enums::SortOrder sort_order=Enums::SortOrder::ascending)
 
void unique ()
 
std::size_t removeZeroYDataPoints ()
 
virtual Tracefilter (const FilterInterface &filter) final
 apply a filter on this trace
 
QString toString () const
 
QByteArray xAsBase64Encoded () const
 
QByteArray yAsBase64Encoded () const
 
std::vector< DataPoint >::const_iterator dataPointCstIteratorWithX (pappso_double value) const
 find datapoint with exactly x value
 

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]

◆ Trace() [2/9]

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

Definition at line 427 of file trace.cpp.

428{
429 initialize(text);
430}
size_t initialize(const std::vector< pappso_double > &xVector, const std::vector< pappso_double > &yVector)
Definition trace.cpp:564

References initialize().

◆ Trace() [3/9]

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

Definition at line 433 of file trace.cpp.

434{
435 initialize(xVector, yVector);
436}

References initialize().

◆ Trace() [4/9]

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

Definition at line 500 of file trace.cpp.

501{
502 reserve(dataPoints.size());
503
504 for(auto &dataPoint : dataPoints)
505 {
506 push_back(DataPoint(dataPoint));
507 }
508
509 sortX();
510 // std::sort(begin(), end(), [](const DataPoint &a, const DataPoint &b) {
511 // return (a.x < b.x);
512 //});
513}
void sortX(Enums::SortOrder sort_order=Enums::SortOrder::ascending)
Definition trace.cpp:1039

References sortX().

◆ Trace() [5/9]

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

Definition at line 516 of file trace.cpp.

516 : std::vector<DataPoint>(dataPoints)
517{
518 sortX();
519 // std::sort(begin(), end(), [](const DataPoint &a, const DataPoint &b) {
520 // return (a.x < b.x);
521 //});
522}

References sortX().

◆ Trace() [6/9]

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

Definition at line 525 of file trace.cpp.

526 : std::vector<DataPoint>(std::move(dataPoints))
527{
528 // This constructor used by the MassSpectrum && constructor.
529
530 sortX();
531 // std::sort(begin(), end(), [](const DataPoint &a, const DataPoint &b) {
532 // return (a.x < b.x);
533 //});
534}

References sortX().

◆ Trace() [7/9]

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

Definition at line 537 of file trace.cpp.

538{
539 for(auto &&item : map_trace)
540 push_back(DataPoint(item.first, item.second));
541
542 // No need to sort, maps are sorted by key (that is, x).
543}

◆ Trace() [8/9]

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

Definition at line 545 of file trace.cpp.

545 : std::vector<DataPoint>(other)
546{
547}

References Trace().

◆ Trace() [9/9]

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

Definition at line 550 of file trace.cpp.

550 : std::vector<DataPoint>(std::move(other))
551{
552 // This constructor used by the MassSpectrum && constructor.
553}

References Trace().

◆ ~Trace()

pappso::Trace::~Trace ( )
virtual

Definition at line 556 of file trace.cpp.

557{
558 // Calls the destructor for each DataPoint object in the vector.
559 clear();
560}

Member Function Documentation

◆ append()

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

appends a datapoint and return new size

Definition at line 623 of file trace.cpp.

624{
625 push_back(data_point);
626
627 return size();
628}

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

◆ containsX()

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

Definition at line 768 of file trace.cpp.

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

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

Referenced by MassSpectrumCombinerInterface.

◆ dataPointCstIteratorWithX()

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

find datapoint with exactly x value

Definition at line 746 of file trace.cpp.

747{
748 auto iterator = std::find_if(
749 begin(), end(), [value](const DataPoint &dataPoint) { return (dataPoint.x == value); });
750
751 return iterator;
752}

References pappso::DataPoint::x.

Referenced by dataPointIndexWithX(), and MassSpectrumCombinerInterface.

◆ dataPointIndexWithX()

std::size_t pappso::Trace::dataPointIndexWithX ( pappso_double value) const
protected

Return a reference to the DataPoint instance that has its x member equal to value.

Definition at line 756 of file trace.cpp.

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

References dataPointCstIteratorWithX().

Referenced by MassSpectrumCombinerInterface.

◆ dataPointIteratorWithX()

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

Definition at line 736 of file trace.cpp.

737{
738 auto iterator = std::find_if(
739 begin(), end(), [value](const DataPoint &dataPoint) { return (dataPoint.x == value); });
740
741 return iterator;
742}

References pappso::DataPoint::x.

Referenced by MassSpectrumCombinerInterface.

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

1154{
1155 return filter.filter(*this);
1156}
virtual Trace & filter(const FilterInterface &filter) final
apply a filter on this trace
Definition trace.cpp:1153

References filter().

Referenced by filter(), MassSpectrumCombinerInterface, and pappso::MassSpectrum::massSpectrumFilter().

◆ initialize() [1/5]

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

Definition at line 440 of file trace.cpp.

441{
442 QStringList string_list = space_sep_text.split("\n", Qt::SkipEmptyParts);
443
444 // qDebug() << "Split text into" << string_list.size()
445 //<< "substrings:" << string_list;
446
447 for(int iter = 0; iter < string_list.size(); ++iter)
448 {
449 QString line = string_list.at(iter);
450 // qDebug() << "Now processing line:" << line;
451
452 // Returns a string that has whitespace removed from the start and the
453 // end, and that has each sequence of internal whitespace replaced with a
454 // single space.
455 line = line.simplified();
456
457 // Remove any parentheses and replace comma and semicolumn with space.
458 // line.remove(QChar('('));
459 // line.remove(QChar(')'));
460
461 // line.replace(QChar(','), QChar(' '));
462 // line.replace(QChar(';'), QChar(' '));
463
464 qDebug() << "Now appending DataPoint as this line:" << line;
465 append(DataPoint(line));
466 }
467
468 return size();
469}
size_t append(const DataPoint &data_point)
appends a datapoint and return new size
Definition trace.cpp:623

References append(), and line.

◆ initialize() [2/5]

size_t pappso::Trace::initialize ( const QString & x_text,
const QString & y_text )

Definition at line 473 of file trace.cpp.

474{
475 QStringList x_string_list = x_text.split("\n", Qt::SkipEmptyParts);
476 QStringList y_string_list = y_text.split("\n", Qt::SkipEmptyParts);
477
478 if(x_string_list.size() != y_string_list.size())
479 throw ExceptionNotPossible(
480 "trace.cpp -- ERROR x_text and y_text must have the same number of "
481 "lines.");
482
483 for(int iter = 0; iter < x_string_list.size(); ++iter)
484 {
485 QString x_line = x_string_list.at(iter);
486 QString y_line = y_string_list.at(iter);
487
488 // Returns a string that has whitespace removed from the start and the
489 // end, and that has each sequence of internal whitespace replaced with a
490 // single space.
491 x_line = x_line.simplified();
492 y_line = y_line.simplified();
493
494 append(DataPoint(x_line + " " + y_line));
495 }
496 return size();
497}

References append().

◆ initialize() [3/5]

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

Definition at line 596 of file trace.cpp.

597{
598
599 // We are initializing, not appending.
600 erase(begin(), end());
601
602 for(auto &&item : map)
603 {
604 push_back(DataPoint(item.first, item.second));
605 }
606
607 // No need to sort, maps are sorted by key (that is, x).
608
609 return size();
610}

◆ initialize() [4/5]

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

Definition at line 564 of file trace.cpp.

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

References sortX().

Referenced by Trace(), Trace(), and MassSpectrumCombinerInterface.

◆ initialize() [5/5]

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

Definition at line 614 of file trace.cpp.

615{
616 *this = other;
617
618 return size();
619}

References Trace().

◆ makeTraceCstSPtr()

TraceCstSPtr pappso::Trace::makeTraceCstSPtr ( ) const

Definition at line 656 of file trace.cpp.

657{
658 return std::make_shared<const Trace>(*this);
659}

Referenced by MassSpectrumCombinerInterface.

◆ makeTraceSPtr()

TraceSPtr pappso::Trace::makeTraceSPtr ( ) const

Definition at line 649 of file trace.cpp.

650{
651 return std::make_shared<Trace>(*this);
652}

Referenced by pappso::TimsFrameMobilityTraces::extractMobilityTraces(), and MassSpectrumCombinerInterface.

◆ maxX()

pappso_double pappso::Trace::maxX ( ) const

Definition at line 957 of file trace.cpp.

958{
959 return maxXDataPoint().x;
960}
const DataPoint & maxXDataPoint() const
Definition trace.cpp:902
pappso_double x
Definition datapoint.h:24

References maxXDataPoint(), and pappso::DataPoint::x.

Referenced by MassSpectrumCombinerInterface.

◆ maxXDataPoint()

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

Definition at line 902 of file trace.cpp.

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

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

Referenced by MassSpectrumCombinerInterface, and maxX().

◆ maxY() [1/2]

pappso_double pappso::Trace::maxY ( ) const

Definition at line 971 of file trace.cpp.

972{
973 return maxYDataPoint().y;
974}
const DataPoint & maxYDataPoint() const
Definition trace.cpp:934
pappso_double y
Definition datapoint.h:25

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

Referenced by MassSpectrumCombinerInterface.

◆ maxY() [2/2]

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

Definition at line 1008 of file trace.cpp.

1009{
1010 std::vector<DataPoint>::const_iterator begin_it =
1011 findFirstEqualOrGreaterX(this->begin(), this->end(), mzStart);
1012
1013 double max_y = 0;
1014
1015 while(begin_it != findFirstGreaterX(begin_it, this->end(), mzEnd))
1016 {
1017 if(begin_it->y > max_y)
1018 max_y = begin_it->y;
1019 begin_it++;
1020 }
1021 return max_y;
1022}
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:70
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:98

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

◆ maxYDataPoint()

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

Definition at line 934 of file trace.cpp.

935{
936 auto dataPoint = std::max_element(
937 begin(), end(), [](const DataPoint &a, const DataPoint &b) { return (a.y < b.y); });
938
939 if(dataPoint == end())
940 {
941 throw ExceptionOutOfRange(
942 QObject::tr("unable to get max peak intensity on spectrum size %1").arg(size()));
943 }
944
945 return (*dataPoint);
946}

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

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

◆ minX()

pappso_double pappso::Trace::minX ( ) const

Definition at line 950 of file trace.cpp.

951{
952 return minXDataPoint().x;
953}
const DataPoint & minXDataPoint() const
Definition trace.cpp:886

References minXDataPoint(), and pappso::DataPoint::x.

Referenced by MassSpectrumCombinerInterface.

◆ minXDataPoint()

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

Definition at line 886 of file trace.cpp.

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

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

Referenced by MassSpectrumCombinerInterface, and minX().

◆ minY()

pappso_double pappso::Trace::minY ( ) const

Definition at line 964 of file trace.cpp.

965{
966 return minYDataPoint().y;
967}
const DataPoint & minYDataPoint() const
Definition trace.cpp:918

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

Referenced by MassSpectrumCombinerInterface.

◆ minYDataPoint()

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

Definition at line 918 of file trace.cpp.

919{
920 auto dataPoint = std::min_element(
921 begin(), end(), [](const DataPoint &a, const DataPoint &b) { return (a.y < b.y); });
922
923 if(dataPoint == end())
924 {
925 throw ExceptionOutOfRange(
926 QObject::tr("unable to get min peak intensity on spectrum size %1").arg(size()));
927 }
928
929 return (*dataPoint);
930}

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

Referenced by MassSpectrumCombinerInterface, pappso::MassSpectrum::minIntensityDataPoint(), and minY().

◆ operator=() [1/2]

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

Reimplemented in pappso::MassSpectrum, and pappso::Xic.

Definition at line 632 of file trace.cpp.

633{
634 assign(other.begin(), other.end());
635
636 return *this;
637}

References Trace().

Referenced by MassSpectrumCombinerInterface.

◆ operator=() [2/2]

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

Reimplemented in pappso::MassSpectrum, and pappso::Xic.

Definition at line 641 of file trace.cpp.

642{
643 vector<DataPoint>::operator=(std::move(other));
644 return *this;
645}

References Trace().

◆ removeZeroYDataPoints()

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

Definition at line 1069 of file trace.cpp.

1070{
1071 qDebug();
1072
1073 auto it = begin();
1074 auto end_it = end();
1075
1076 std::size_t count = 0;
1077
1078 while(it != end_it)
1079 {
1080 if(Utils::almostEqual(it->y, 0))
1081 {
1082 // erase returns an iterator to the next item in the vector.
1083 it = erase(it);
1084 ++count;
1085 }
1086 else
1087 // We need to increment (no call to erase here).
1088 ++it;
1089 }
1090
1091 return count;
1092}
static bool almostEqual(double value1, double value2, int decimalPlaces=10)
Definition utils.cpp:299

References pappso::Utils::almostEqual().

Referenced by MassSpectrumCombinerInterface.

◆ sort()

void pappso::Trace::sort ( Enums::SortType sort_type,
Enums::SortOrder sort_order = Enums::SortOrder::ascending )

Definition at line 1026 of file trace.cpp.

1027{
1028 if(sort_type == Enums::SortType::none)
1029 return;
1030
1031 if(sort_type == Enums::SortType::x)
1032 return sortX(sort_order);
1033 else
1034 return sortY(sort_order);
1035}
void sortY(Enums::SortOrder sort_order=Enums::SortOrder::ascending)
Definition trace.cpp:1049

References pappso::Enums::none, sortX(), sortY(), and pappso::Enums::x.

Referenced by MassSpectrumCombinerInterface.

◆ sortX()

◆ sortY()

void pappso::Trace::sortY ( Enums::SortOrder sort_order = Enums::SortOrder::ascending)

Definition at line 1049 of file trace.cpp.

1050{
1051 if(sort_order == Enums::SortOrder::ascending)
1052 std::sort(begin(), end(), [](const DataPoint &a, const DataPoint &b) { return (a.y < b.y); });
1053 else
1054 std::sort(begin(), end(), [](const DataPoint &a, const DataPoint &b) { return (a.y > b.y); });
1055}

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

Referenced by pappso::TimsFrameMobilityTraces::extractMobilityTraces(), pappso::FilterChargeDeconvolution::filter(), pappso::FilterMzExclusion::filter(), MassSpectrumCombinerInterface, and sort().

◆ sumY() [1/2]

pappso_double pappso::Trace::sumY ( ) const

Definition at line 978 of file trace.cpp.

979{
980 // double sum = 0;
981
982 // for(auto &&dp : m_dataPoints)
983 // sum += dp.y;
984
985 // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << " ()"
986 //<< "Returning sum/tic:" << sum;
987
988 // return sum;
989
990 return std::accumulate(
991 begin(), end(), (double)0, [](pappso_double sum, const DataPoint &dataPoint) {
992 return (sum + dataPoint.y);
993 });
994}

References pappso::DataPoint::y.

Referenced by MassSpectrumCombinerInterface, 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 998 of file trace.cpp.

999{
1000 auto begin_it = findFirstEqualOrGreaterX(this->begin(), this->end(), mzStart);
1001 auto end_it = findFirstGreaterX(begin_it, this->end(), mzEnd);
1002
1003 return sumYTrace(begin_it, end_it, 0);
1004}
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:231

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

◆ toMap()

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

Definition at line 691 of file trace.cpp.

692{
693 std::map<pappso_double, pappso_double> map;
694
695 std::pair<std::map<pappso_double, pappso_double>::iterator, bool> ret;
696
697 for(auto &&dataPoint : *this)
698 {
699 ret = map.insert(std::pair<pappso_double, pappso_double>(dataPoint.x, dataPoint.y));
700
701 if(ret.second == false)
702 {
703 qDebug() << "It is odd that the Trace contains multiple same keys.";
704
705 // No insertion, then increment the y value.
706 ret.first->second += dataPoint.y;
707 }
708 }
709
710 return map;
711}

Referenced by MassSpectrumCombinerInterface.

◆ toString()

QString pappso::Trace::toString ( ) const

Definition at line 1096 of file trace.cpp.

1097{
1098 // Even if the spectrum is empty, we should return an empty string.
1099 QString text;
1100
1101 for(auto &&dataPoint : *this)
1102 {
1103 text.append(QString("%1\n").arg(dataPoint.toString()));
1104 }
1105
1106 return text;
1107}

Referenced by MassSpectrumCombinerInterface.

◆ unique()

void pappso::Trace::unique ( )

Definition at line 1059 of file trace.cpp.

1060{
1061 auto last = std::unique(
1062 begin(), end(), [](const DataPoint &a, const DataPoint &b) { return (a.x == b.x); });
1063
1064 erase(last, end());
1065}

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

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

◆ xAsBase64Encoded()

QByteArray pappso::Trace::xAsBase64Encoded ( ) const

Definition at line 1111 of file trace.cpp.

1112{
1113 QByteArray unencoded_array;
1114
1115 for(auto &&data_point : *this)
1116 {
1117 QByteArray local_array;
1118 local_array.setNum(data_point.x, 'f', 12);
1119 local_array.append("\n");
1120
1121 unencoded_array.append(local_array);
1122 }
1123
1124 QByteArray base64_encoded_array =
1125 unencoded_array.toBase64(QByteArray::Base64Encoding | QByteArray::OmitTrailingEquals);
1126
1127 return base64_encoded_array;
1128}

Referenced by MassSpectrumCombinerInterface.

◆ xValues()

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

Definition at line 663 of file trace.cpp.

664{
665 std::vector<pappso_double> values;
666
667 for(auto &&dataPoint : *this)
668 {
669 values.push_back(dataPoint.x);
670 }
671
672 return values;
673}

Referenced by pappso::BaseTracePlotWidget::addTrace(), MassSpectrumCombinerInterface, and pappso::masschroq::CborOutputStream::writeTrace().

◆ yAsBase64Encoded()

QByteArray pappso::Trace::yAsBase64Encoded ( ) const

Definition at line 1132 of file trace.cpp.

1133{
1134 QByteArray unencoded_array;
1135
1136 for(auto &&data_point : *this)
1137 {
1138 QByteArray local_array;
1139 local_array.setNum(data_point.y, 'f', 12);
1140 local_array.append("\n");
1141
1142 unencoded_array.append(local_array);
1143 }
1144
1145 QByteArray base64_encoded_array =
1146 unencoded_array.toBase64(QByteArray::Base64Encoding | QByteArray::OmitTrailingEquals);
1147
1148 return base64_encoded_array;
1149}

Referenced by MassSpectrumCombinerInterface.

◆ yValues()

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

Definition at line 677 of file trace.cpp.

678{
679 std::vector<pappso_double> values;
680
681 for(auto &&dataPoint : *this)
682 {
683 values.push_back(dataPoint.y);
684 }
685
686 return values;
687}

Referenced by pappso::BaseTracePlotWidget::addTrace(), pappso::MsRunRetentionTime< T >::align(), MassSpectrumCombinerInterface, pappso::masschroq::CborOutputStream::writeMsRunRetentionTime(), and pappso::masschroq::CborOutputStream::writeTrace().

Friends And Related Symbol Documentation

◆ MassSpectrumCombinerInterface

◆ TraceCombiner

friend class TraceCombiner
friend

Definition at line 150 of file trace.h.

References TraceCombiner.

Referenced by TraceCombiner.

◆ TraceMinusCombiner

friend class TraceMinusCombiner
friend

Definition at line 151 of file trace.h.

References TraceMinusCombiner.

Referenced by TraceMinusCombiner.

◆ TracePlusCombiner

friend class TracePlusCombiner
friend

Definition at line 152 of file trace.h.

References TracePlusCombiner.

Referenced by TracePlusCombiner.


The documentation for this class was generated from the following files: