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
QJsonObject toJsonObject (const QString &x_label="x", const QString &y_label="y") const
 serialize a PAPPSO trace object to JSON
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
 Return a reference to the DataPoint instance that has its x member equal to value.
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 151 of file trace.h.

Constructor & Destructor Documentation

◆ Trace() [1/9]

◆ Trace() [2/9]

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

Definition at line 460 of file trace.cpp.

461{
462 initialize(text);
463}
size_t initialize(const std::vector< pappso_double > &xVector, const std::vector< pappso_double > &yVector)
Definition trace.cpp:597

References initialize().

◆ Trace() [3/9]

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

Definition at line 466 of file trace.cpp.

467{
468 initialize(xVector, yVector);
469}

References initialize().

◆ Trace() [4/9]

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

Definition at line 533 of file trace.cpp.

534{
535 reserve(dataPoints.size());
536
537 for(auto &dataPoint : dataPoints)
538 {
539 push_back(DataPoint(dataPoint));
540 }
541
542 sortX();
543 // std::sort(begin(), end(), [](const DataPoint &a, const DataPoint &b) {
544 // return (a.x < b.x);
545 //});
546}
void sortX(Enums::SortOrder sort_order=Enums::SortOrder::ascending)
Definition trace.cpp:1071

References sortX().

◆ Trace() [5/9]

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

Definition at line 549 of file trace.cpp.

549 : std::vector<DataPoint>(dataPoints)
550{
551 sortX();
552 // std::sort(begin(), end(), [](const DataPoint &a, const DataPoint &b) {
553 // return (a.x < b.x);
554 //});
555}

References sortX().

◆ Trace() [6/9]

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

Definition at line 558 of file trace.cpp.

559 : std::vector<DataPoint>(std::move(dataPoints))
560{
561 // This constructor used by the MassSpectrum && constructor.
562
563 sortX();
564 // std::sort(begin(), end(), [](const DataPoint &a, const DataPoint &b) {
565 // return (a.x < b.x);
566 //});
567}

References sortX().

◆ Trace() [7/9]

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

Definition at line 570 of file trace.cpp.

571{
572 for(auto &&item : map_trace)
573 push_back(DataPoint(item.first, item.second));
574
575 // No need to sort, maps are sorted by key (that is, x).
576}

◆ Trace() [8/9]

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

Definition at line 578 of file trace.cpp.

578 : std::vector<DataPoint>(other)
579{
580}

References Trace().

◆ Trace() [9/9]

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

Definition at line 583 of file trace.cpp.

583 : std::vector<DataPoint>(std::move(other))
584{
585 // This constructor used by the MassSpectrum && constructor.
586}

References Trace().

◆ ~Trace()

pappso::Trace::~Trace ( )
virtual

Definition at line 589 of file trace.cpp.

590{
591 // Calls the destructor for each DataPoint object in the vector.
592 clear();
593}

Member Function Documentation

◆ append()

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

appends a datapoint and return new size

Definition at line 657 of file trace.cpp.

658{
659 push_back(data_point);
660
661 return size();
662}

Referenced by pappso::TimsFramesMsRunReader::computeTicChromatogram(), pappso::incrementByValueX(), pappso::incrementByValueY(), initialize(), initialize(), MassSpectrumCombinerInterface, and pappso::HighResPeakPicker::pick().

◆ containsX()

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

Definition at line 802 of file trace.cpp.

803{
804 // std::cout << std::setprecision(10) << "getting value: " << value
805 //<< " and precision: " << precision_p->getNominal() << std::endl;
806
807 pappso_double delta = precision_p->delta(value);
808
809 double left_most = value - delta;
810 double right_most = value + delta;
811
812 // std::cout << std::setprecision(10) << "delta: " << delta
813 //<< " left_most: " << left_most << " right_most: " << right_most
814 //<< std::endl;
815
816 auto iterator = std::find_if(
817 begin(), end(), [value, precision_p, left_most, right_most](const DataPoint &data_point) {
818 if(precision_p)
819 {
820
821 // FIXME: unbelievable behaviour: when building in
822 // release mode this code, under i386 (but not x86_64),
823 // this code fails if the following%S statement is
824 // missing.
825
826 // std::cout << std::setprecision(10)
827 //<< "Testing data_point.x: " << data_point.x
828 //<< std::endl;
829
830 // For this reason I had to deactivate the related tests
831 // for i386 in tests/test_trace.cpp
832
833 double diff_to_left_most = data_point.x - left_most;
834 double diff_to_right_most = data_point.x - right_most;
835
836 // std::cout << std::setprecision(10)
837 //<< "diff_to_left_most: " << diff_to_left_most
838 //<< " diff_to_right_most: " << diff_to_right_most <<
839 // std::endl;
840
841 // if(diff_to_left_most > 0)
842 //{
843 // std::cout << std::setprecision(10)
844 //<< " point is right of left_most: " <<
845 // diff_to_left_most
846 //<< std::endl;
847 //}
848 // if(diff_to_left_most < 0)
849 //{
850 // std::cout << std::setprecision(10)
851 //<< "point is left of left_most: " << diff_to_left_most
852 //<< std::endl;
853 //}
854 // if(!diff_to_left_most)
855 //{
856 // std::cout << std::setprecision(10)
857 //<< "point is spot on left_most: " << diff_to_left_most
858 //<< std::endl;
859 //}
860
861 // if(diff_to_right_most > 0)
862 //{
863 // std::cout << std::setprecision(10)
864 //<< "point is right of right_most: " <<
865 // diff_to_right_most
866 //<< std::endl;
867 //}
868 // if(diff_to_right_most < 0)
869 //{
870 // std::cout << std::setprecision(10)
871 //<< "point is left or of right_most: "
872 //<< diff_to_right_most << std::endl;
873 //}
874 // if(!diff_to_right_most)
875 //{
876 // std::cout << std::setprecision(10)
877 //<< "point is spot on right_most: " <<
878 // diff_to_right_most
879 //<< std::endl;
880 //}
881
882 if(diff_to_left_most >= 0 && diff_to_right_most <= 0)
883 {
884 // std::cout << "The point is inside the range,
885 // should return true."
886 //<< std::endl;
887 return true;
888 }
889 else
890 {
891 // std::cout
892 //<< "The point is outside the range, should return
893 // false."
894 //<< std::endl;
895 return false;
896 }
897 }
898 else
899 {
900 return (data_point.x == value);
901 }
902 });
903
904 if(iterator != end())
905 {
906 // The returned data point is valid.
907 return *iterator;
908 }
909 else
910 {
911 // The returned data point is invalid because it is not initialized.
912 return DataPoint();
913 }
914}
double pappso_double
A type definition for doubles.
Definition types.h:60

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

781{
782 auto iterator = std::find_if(
783 begin(), end(), [value](const DataPoint &dataPoint) { return (dataPoint.x == value); });
784
785 return iterator;
786}

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

791{
792 std::vector<DataPoint>::const_iterator iterator = dataPointCstIteratorWithX(value);
793
794 if(iterator != end())
795 return std::distance(begin(), iterator);
796
797 return std::numeric_limits<std::size_t>::max();
798}
std::vector< DataPoint >::const_iterator dataPointCstIteratorWithX(pappso_double value) const
find datapoint with exactly x value
Definition trace.cpp:780

References dataPointCstIteratorWithX().

Referenced by MassSpectrumCombinerInterface.

◆ dataPointIteratorWithX()

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

Definition at line 770 of file trace.cpp.

771{
772 auto iterator = std::find_if(
773 begin(), end(), [value](const DataPoint &dataPoint) { return (dataPoint.x == value); });
774
775 return iterator;
776}

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

1186{
1187 return filter.filter(*this);
1188}
virtual Trace & filter(const FilterInterface &filter) final
apply a filter on this trace
Definition trace.cpp:1185

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

474{
475 QStringList string_list = space_sep_text.split("\n", Qt::SkipEmptyParts);
476
477 // qDebug() << "Split text into" << string_list.size()
478 //<< "substrings:" << string_list;
479
480 for(int iter = 0; iter < string_list.size(); ++iter)
481 {
482 QString line = string_list.at(iter);
483 // qDebug() << "Now processing line:" << line;
484
485 // Returns a string that has whitespace removed from the start and the
486 // end, and that has each sequence of internal whitespace replaced with a
487 // single space.
488 line = line.simplified();
489
490 // Remove any parentheses and replace comma and semicolumn with space.
491 // line.remove(QChar('('));
492 // line.remove(QChar(')'));
493
494 // line.replace(QChar(','), QChar(' '));
495 // line.replace(QChar(';'), QChar(' '));
496
497 qDebug() << "Now appending DataPoint as this line:" << line;
498 append(DataPoint(line));
499 }
500
501 return size();
502}
size_t append(const DataPoint &data_point)
appends a datapoint and return new size
Definition trace.cpp:657

References append(), and line.

◆ initialize() [2/5]

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

Definition at line 506 of file trace.cpp.

507{
508 QStringList x_string_list = x_text.split("\n", Qt::SkipEmptyParts);
509 QStringList y_string_list = y_text.split("\n", Qt::SkipEmptyParts);
510
511 if(x_string_list.size() != y_string_list.size())
512 throw ExceptionNotPossible(
513 "trace.cpp -- ERROR x_text and y_text must have the same number of "
514 "lines.");
515
516 for(int iter = 0; iter < x_string_list.size(); ++iter)
517 {
518 QString x_line = x_string_list.at(iter);
519 QString y_line = y_string_list.at(iter);
520
521 // Returns a string that has whitespace removed from the start and the
522 // end, and that has each sequence of internal whitespace replaced with a
523 // single space.
524 x_line = x_line.simplified();
525 y_line = y_line.simplified();
526
527 append(DataPoint(x_line + " " + y_line));
528 }
529 return size();
530}

References append().

◆ initialize() [3/5]

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

Definition at line 629 of file trace.cpp.

630{
631
632 // We are initializing, not appending.
633 erase(begin(), end());
634
635 for(auto &&item : map)
636 {
637 push_back(DataPoint(item.first, item.second));
638 }
639
640 // No need to sort, maps are sorted by key (that is, x).
641
642 return size();
643}

◆ initialize() [4/5]

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

Definition at line 597 of file trace.cpp.

599{
600 // Sanity check
601 if(xVector.size() != yVector.size())
602 throw ExceptionNotPossible("trace.cpp -- ERROR xVector and yVector must have the same size.");
603
604 // We are initializing, not appending.
605 erase(begin(), end());
606
607 for(std::size_t iter = 0; iter < xVector.size(); ++iter)
608 {
609 push_back(DataPoint(xVector.at(iter), yVector.at(iter)));
610 }
611
612 sortX();
613 // std::sort(begin(), end(), [](const DataPoint &a, const DataPoint &b) {
614 // return (a.x < b.x);
615 //});
616
617#if 0
618 for(auto &item : *this)
619 {
620 std::cout << item.x << "-" << item.y;
621 }
622#endif
623
624 return size();
625}

References sortX().

Referenced by Trace(), Trace(), pappso::cbor::mzcbor::Spectrum::decodeTrace(), and MassSpectrumCombinerInterface.

◆ initialize() [5/5]

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

Definition at line 647 of file trace.cpp.

648{
649 clear();
650 *this = other;
651
652 return size();
653}

References Trace().

◆ makeTraceCstSPtr()

TraceCstSPtr pappso::Trace::makeTraceCstSPtr ( ) const

Definition at line 690 of file trace.cpp.

691{
692 return std::make_shared<const Trace>(*this);
693}

Referenced by MassSpectrumCombinerInterface.

◆ makeTraceSPtr()

TraceSPtr pappso::Trace::makeTraceSPtr ( ) const

Definition at line 683 of file trace.cpp.

684{
685 return std::make_shared<Trace>(*this);
686}

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

◆ maxX()

pappso_double pappso::Trace::maxX ( ) const

Definition at line 989 of file trace.cpp.

990{
991 return maxXDataPoint().x;
992}
const DataPoint & maxXDataPoint() const
Definition trace.cpp:934
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 934 of file trace.cpp.

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

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

Referenced by MassSpectrumCombinerInterface, and maxX().

◆ maxY() [1/2]

pappso_double pappso::Trace::maxY ( ) const

Definition at line 1003 of file trace.cpp.

1004{
1005 return maxYDataPoint().y;
1006}
const DataPoint & maxYDataPoint() const
Definition trace.cpp:966
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 1040 of file trace.cpp.

1041{
1042 std::vector<DataPoint>::const_iterator begin_it =
1043 findFirstEqualOrGreaterX(this->begin(), this->end(), mzStart);
1044
1045 double max_y = 0;
1046
1047 while(begin_it != findFirstGreaterX(begin_it, this->end(), mzEnd))
1048 {
1049 if(begin_it->y > max_y)
1050 max_y = begin_it->y;
1051 begin_it++;
1052 }
1053 return max_y;
1054}
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:65
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:93

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

◆ maxYDataPoint()

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

Definition at line 966 of file trace.cpp.

967{
968 auto dataPoint = std::max_element(
969 begin(), end(), [](const DataPoint &a, const DataPoint &b) { return (a.y < b.y); });
970
971 if(dataPoint == end())
972 {
973 throw ExceptionOutOfRange(
974 QObject::tr("unable to get max peak intensity on spectrum size %1").arg(size()));
975 }
976
977 return (*dataPoint);
978}

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

983{
984 return minXDataPoint().x;
985}
const DataPoint & minXDataPoint() const
Definition trace.cpp:918

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

Referenced by MassSpectrumCombinerInterface.

◆ minXDataPoint()

const DataPoint & pappso::Trace::minXDataPoint ( ) 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.x < b.x); });
922
923 if(dataPoint == end())
924 {
925 throw ExceptionOutOfRange(
926 QObject::tr("unable to get min peak x on spectrum size %1").arg(size()));
927 }
928
929 return (*dataPoint);
930}

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

Referenced by MassSpectrumCombinerInterface, and minX().

◆ minY()

pappso_double pappso::Trace::minY ( ) const

Definition at line 996 of file trace.cpp.

997{
998 return minYDataPoint().y;
999}
const DataPoint & minYDataPoint() const
Definition trace.cpp:950

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

Referenced by MassSpectrumCombinerInterface.

◆ minYDataPoint()

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

Definition at line 950 of file trace.cpp.

951{
952 auto dataPoint = std::min_element(
953 begin(), end(), [](const DataPoint &a, const DataPoint &b) { return (a.y < b.y); });
954
955 if(dataPoint == end())
956 {
957 throw ExceptionOutOfRange(
958 QObject::tr("unable to get min peak intensity on spectrum size %1").arg(size()));
959 }
960
961 return (*dataPoint);
962}

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

667{
668 assign(other.begin(), other.end());
669
670 return *this;
671}

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

676{
677 vector<DataPoint>::operator=(std::move(other));
678 return *this;
679}

References Trace().

◆ removeZeroYDataPoints()

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

Definition at line 1101 of file trace.cpp.

1102{
1103 qDebug();
1104
1105 auto it = begin();
1106 auto end_it = end();
1107
1108 std::size_t count = 0;
1109
1110 while(it != end_it)
1111 {
1112 if(Utils::almostEqual(it->y, 0))
1113 {
1114 // erase returns an iterator to the next item in the vector.
1115 it = erase(it);
1116 ++count;
1117 }
1118 else
1119 // We need to increment (no call to erase here).
1120 ++it;
1121 }
1122
1123 return count;
1124}
static bool almostEqual(double value1, double value2, int decimalPlaces=10)
Tell if both double values, are equal within the double representation capabilities of the platform.
Definition utils.cpp:326

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

1059{
1060 if(sort_type == Enums::SortType::none)
1061 return;
1062
1063 if(sort_type == Enums::SortType::x)
1064 return sortX(sort_order);
1065 else
1066 return sortY(sort_order);
1067}
void sortY(Enums::SortOrder sort_order=Enums::SortOrder::ascending)
Definition trace.cpp:1081

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

1082{
1083 if(sort_order == Enums::SortOrder::ascending)
1084 std::sort(begin(), end(), [](const DataPoint &a, const DataPoint &b) { return (a.y < b.y); });
1085 else
1086 std::sort(begin(), end(), [](const DataPoint &a, const DataPoint &b) { return (a.y > b.y); });
1087}

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

1011{
1012 // double sum = 0;
1013
1014 // for(auto &&dp : m_dataPoints)
1015 // sum += dp.y;
1016
1017 // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << " ()"
1018 //<< "Returning sum/tic:" << sum;
1019
1020 // return sum;
1021
1022 return std::accumulate(
1023 begin(), end(), (double)0, [](pappso_double sum, const DataPoint &dataPoint) {
1024 return (sum + dataPoint.y);
1025 });
1026}

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

1031{
1032 auto begin_it = findFirstEqualOrGreaterX(this->begin(), this->end(), mzStart);
1033 auto end_it = findFirstGreaterX(begin_it, this->end(), mzEnd);
1034
1035 return sumYTrace(begin_it, end_it, 0);
1036}
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:226

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

◆ toJsonObject()

QJsonObject pappso::Trace::toJsonObject ( const QString & x_label = "x",
const QString & y_label = "y" ) const

serialize a PAPPSO trace object to JSON

Parameters
x_labellabel for first dimension (x by default)
y_labellabel for second dimension (y by default)
Returns
a JSON object

Definition at line 1191 of file trace.cpp.

1192{
1193 QJsonObject json_trace;
1194 QJsonArray x_arr;
1195 QJsonArray y_arr;
1196
1197 for(auto &&data_point : *this)
1198 {
1199 x_arr.push_back(data_point.x);
1200 y_arr.push_back(data_point.y);
1201 }
1202 json_trace.insert(x_label, x_arr);
1203 json_trace.insert(y_label, y_arr);
1204
1205 return json_trace;
1206}

Referenced by MassSpectrumCombinerInterface, and pappso::cbor::mzcbor::Spectrum::toJsonObject().

◆ toMap()

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

Definition at line 725 of file trace.cpp.

726{
727 std::map<pappso_double, pappso_double> map;
728
729 std::pair<std::map<pappso_double, pappso_double>::iterator, bool> ret;
730
731 for(auto &&dataPoint : *this)
732 {
733 ret = map.insert(std::pair<pappso_double, pappso_double>(dataPoint.x, dataPoint.y));
734
735 if(ret.second == false)
736 {
737 qDebug() << "It is odd that the Trace contains multiple same keys.";
738
739 // No insertion, then increment the y value.
740 ret.first->second += dataPoint.y;
741 }
742 }
743
744 return map;
745}

Referenced by MassSpectrumCombinerInterface.

◆ toString()

QString pappso::Trace::toString ( ) const

Definition at line 1128 of file trace.cpp.

1129{
1130 // Even if the spectrum is empty, we should return an empty string.
1131 QString text;
1132
1133 for(auto &&dataPoint : *this)
1134 {
1135 text.append(QString("%1\n").arg(dataPoint.toString()));
1136 }
1137
1138 return text;
1139}

Referenced by MassSpectrumCombinerInterface.

◆ unique()

void pappso::Trace::unique ( )

Definition at line 1091 of file trace.cpp.

1092{
1093 auto last = std::unique(
1094 begin(), end(), [](const DataPoint &a, const DataPoint &b) { return (a.x == b.x); });
1095
1096 erase(last, end());
1097}

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

1144{
1145 QByteArray unencoded_array;
1146
1147 for(auto &&data_point : *this)
1148 {
1149 QByteArray local_array;
1150 local_array.setNum(data_point.x, 'f', 12);
1151 local_array.append("\n");
1152
1153 unencoded_array.append(local_array);
1154 }
1155
1156 QByteArray base64_encoded_array =
1157 unencoded_array.toBase64(QByteArray::Base64Encoding | QByteArray::OmitTrailingEquals);
1158
1159 return base64_encoded_array;
1160}

Referenced by MassSpectrumCombinerInterface.

◆ xValues()

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

Definition at line 697 of file trace.cpp.

698{
699 std::vector<pappso_double> values;
700
701 for(auto &&dataPoint : *this)
702 {
703 values.push_back(dataPoint.x);
704 }
705
706 return values;
707}

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

◆ yAsBase64Encoded()

QByteArray pappso::Trace::yAsBase64Encoded ( ) const

Definition at line 1164 of file trace.cpp.

1165{
1166 QByteArray unencoded_array;
1167
1168 for(auto &&data_point : *this)
1169 {
1170 QByteArray local_array;
1171 local_array.setNum(data_point.y, 'f', 12);
1172 local_array.append("\n");
1173
1174 unencoded_array.append(local_array);
1175 }
1176
1177 QByteArray base64_encoded_array =
1178 unencoded_array.toBase64(QByteArray::Base64Encoding | QByteArray::OmitTrailingEquals);
1179
1180 return base64_encoded_array;
1181}

Referenced by MassSpectrumCombinerInterface.

◆ yValues()

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

Definition at line 711 of file trace.cpp.

712{
713 std::vector<pappso_double> values;
714
715 for(auto &&dataPoint : *this)
716 {
717 values.push_back(dataPoint.y);
718 }
719
720 return values;
721}

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

◆ MassSpectrumCombinerInterface

◆ TraceCombiner

friend class TraceCombiner
friend

Definition at line 154 of file trace.h.

References TraceCombiner.

Referenced by TraceCombiner.

◆ TraceMinusCombiner

friend class TraceMinusCombiner
friend

Definition at line 155 of file trace.h.

References TraceMinusCombiner.

Referenced by TraceMinusCombiner.

◆ TracePlusCombiner

friend class TracePlusCombiner
friend

Definition at line 156 of file trace.h.

References TracePlusCombiner.

Referenced by TracePlusCombiner.


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