pappso::Trace Class Reference

A simple container of DataPoint instances. More...

`#include <trace.h>`

Inheritance diagram for pappso::Trace:

## 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 Trace & | operator= (const Trace &x)
virtual Trace & | operator= (Trace &&x)
TraceSPtr | makeTraceSPtr () const
TraceCstSPtr | makeTraceCstSPtr () const
std::vector< pappso_double > | xValues () const
std::vector< pappso_double > | yValues () const
std::map< pappso_double, pappso_double > | toMap () const
DataPoint | containsX (pappso_double value, PrecisionPtr precision_p=nullptr) const
const DataPoint & | minYDataPoint () const
const DataPoint & | maxYDataPoint () 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 Trace & | filter (const FilterInterface &filter) final
| apply a filter on this trace More...
QString | toString () const

## Protected Member Functions

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

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

{
}

## Trace() [2/8]

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

Definition at line 408 of file trace.cpp.

{
initialize(xVector, yVector);
}
pappso::Trace::initialize
size_t initialize(const std::vector< pappso_double > &xVector, const std::vector< pappso_double > &yVector)
Definition: trace.cpp:481

References initialize().

## Trace() [3/8]

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

Definition at line 415 of file trace.cpp.

{
reserve(dataPoints.size());
for(auto &dataPoint : dataPoints)
{
push_back(DataPoint(dataPoint));
}
sortX();
// std::sort(begin(), end(), [](const DataPoint &a, const DataPoint &b) {
// return (a.x < b.x);
//});
}
pappso::Trace::sortX
void sortX()
Definition: trace.cpp:905

References sortX().

## Trace() [4/8]

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

Definition at line 432 of file trace.cpp.

: std::vector<DataPoint>(dataPoints)
{
sortX();
// std::sort(begin(), end(), [](const DataPoint &a, const DataPoint &b) {
// return (a.x < b.x);
//});
}

References sortX().

## Trace() [5/8]

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

Definition at line 442 of file trace.cpp.

: std::vector<DataPoint>(std::move(dataPoints))
{
// This constructor used by the MassSpectrum && constructor.
sortX();
// std::sort(begin(), end(), [](const DataPoint &a, const DataPoint &b) {
// return (a.x < b.x);
//});
}

References sortX().

## Trace() [6/8]

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

explicit

Definition at line 454 of file trace.cpp.

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

## Trace() [7/8]

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

Definition at line 462 of file trace.cpp.

: std::vector<DataPoint>(other)
{
}

## Trace() [8/8]

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

Definition at line 467 of file trace.cpp.

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

## ~Trace()

pappso::Trace::~Trace | ( |  | ) |

virtual

Definition at line 473 of file trace.cpp.

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

## Member Function Documentation

## containsX()

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

Definition at line 684 of file trace.cpp.

{
// std::cout << std::setprecision(10) << "getting value: " << value
//<< " and precision: " << precision_p->getNominal() << std::endl;
pappso_double delta = precision_p->delta(value);
double left_most = value - delta;
double right_most = value + delta;
// std::cout << std::setprecision(10) << "delta: " << delta
//<< " left_most: " << left_most << " right_most: " << right_most
//<< std::endl;
auto iterator =
std::find_if(begin(),
end(),
[value, precision_p, delta, left_most, right_most](
const DataPoint &data_point) {
if(precision_p)
{
// FIXME: unbelievable behaviour: when building in
// release mode this code, under i386 (but not x86_64),
// this code fails if the following cout statement is
// missing.
// std::cout << std::setprecision(10)
//<< "Testing data_point.x: " << data_point.x
//<< std::endl;
// For this reason I had to deactivate the related tests
// for i386 in tests/test_trace.cpp
double diff_to_left_most = data_point.x - left_most;
double diff_to_right_most = data_point.x - right_most;
// std::cout << std::setprecision(10)
//<< "diff_to_left_most: " << diff_to_left_most
//<< " diff_to_right_most: " << diff_to_right_most <<
// std::endl;
// if(diff_to_left_most > 0)
//{
// std::cout << std::setprecision(10)
//<< " point is right of left_most: " <<
// diff_to_left_most
//<< std::endl;
//}
// if(diff_to_left_most < 0)
//{
// std::cout << std::setprecision(10)
//<< "point is left of left_most: " << diff_to_left_most
//<< std::endl;
//}
// if(!diff_to_left_most)
//{
// std::cout << std::setprecision(10)
//<< "point is spot on left_most: " << diff_to_left_most
//<< std::endl;
//}
// if(diff_to_right_most > 0)
//{
// std::cout << std::setprecision(10)
//<< "point is right of right_most: " <<
// diff_to_right_most
//<< std::endl;
//}
// if(diff_to_right_most < 0)
//{
// std::cout << std::setprecision(10)
//<< "point is left or of right_most: "
//<< diff_to_right_most << std::endl;
//}
// if(!diff_to_right_most)
//{
// std::cout << std::setprecision(10)
//<< "point is spot on right_most: " <<
// diff_to_right_most
//<< std::endl;
//}
if(diff_to_left_most >= 0 && diff_to_right_most <= 0)
{
// std::cout << "The point is inside the range,
// should return true."
//<< std::endl;
return true;
}
else
{
// std::cout
//<< "The point is outside the range, should return
// false."
//<< std::endl;
return false;
}
}
else
{
return (data_point.x == value);
}
});
if(iterator != end())
{
// The returned data point is valid.
return *iterator;
}
else
{
// The returned data point is invalid because it is not initialized.
return DataPoint();
}
}
pappso::pappso_double
double pappso_double
A type definition for doubles.
Definition: types.h:48

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

## dataPointCstIteratorWithX()

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

protected

Definition at line 659 of file trace.cpp.

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

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

{
std::vector<DataPoint>::const_iterator iterator =
dataPointCstIteratorWithX(value);
if(iterator != end())
return std::distance(begin(), iterator);
return std::numeric_limits<std::size_t>::max();
}
pappso::Trace::dataPointCstIteratorWithX
std::vector< DataPoint >::const_iterator dataPointCstIteratorWithX(pappso_double value) const
Definition: trace.cpp:659

References dataPointCstIteratorWithX().

## dataPointIteratorWithX()

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

protected

Definition at line 647 of file trace.cpp.

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

References pappso::DataPoint::x.

## filter()

Trace & pappso::Trace::filter | ( | const FilterInterface & | filter | ) |

final virtual

apply a filter on this trace

Parameters

  filter | to process the signal

Returns
  reference on the modified Trace

Definition at line 950 of file trace.cpp.

{
return filter.filter(*this);
}
pappso::Trace::filter
virtual Trace & filter(const FilterInterface &filter) final
apply a filter on this trace
Definition: trace.cpp:950

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

{
// We are initializing, not appending.
erase(begin(), end());
for(auto &&item : map)
{
push_back(DataPoint(item.first, item.second));
}
// No need to sort, maps are sorted by key (that is, x).
return size();
}

## initialize() [2/3]

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

Definition at line 481 of file trace.cpp.

{
// Sanity check
if(xVector.size() != yVector.size())
throw ExceptionNotPossible(
"trace.cpp -- ERROR xVector and yVector must have the same size.");
// We are initializing, not appending.
erase(begin(), end());
for(std::size_t iter = 0; iter < xVector.size(); ++iter)
{
push_back(DataPoint(xVector.at(iter), yVector.at(iter)));
}
sortX();
// std::sort(begin(), end(), [](const DataPoint &a, const DataPoint &b) {
// return (a.x < b.x);
//});
#if 0
for(auto &item : *this)
{
std::cout << item.x << "-" << item.y;
}
#endif
return size();
}

References sortX().

Referenced by Trace().

## initialize() [3/3]

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

Definition at line 532 of file trace.cpp.

{
*this = other;
return size();
}

## makeTraceCstSPtr()

TraceCstSPtr pappso::Trace::makeTraceCstSPtr | ( |  | ) | const

Definition at line 565 of file trace.cpp.

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

## makeTraceSPtr()

TraceSPtr pappso::Trace::makeTraceSPtr | ( |  | ) | const

Definition at line 558 of file trace.cpp.

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

## maxY() [1/2]

pappso_double pappso::Trace::maxY | ( |  | ) | const

Definition at line 848 of file trace.cpp.

{
return maxYDataPoint().y;
}
pappso::Trace::maxYDataPoint
const DataPoint & maxYDataPoint() const
Definition: trace.cpp:822
pappso::DataPoint::y
pappso_double y
Definition: datapoint.h:23

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

## maxY() [2/2]

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

Definition at line 887 of file trace.cpp.

{
std::vector<DataPoint>::const_iterator begin_it =
findFirstEqualOrGreaterX(this->begin(), this->end(), mzStart);
double max_y = 0;
while(begin_it != findFirstGreaterX(begin_it, this->end(), mzEnd))
{
if(begin_it->y > max_y)
max_y = begin_it->y;
begin_it++;
}
return max_y;
}
pappso::findFirstEqualOrGreaterX
std::vector< DataPoint >::iterator findFirstEqualOrGreaterX(std::vector< DataPoint >::iterator begin, std::vector< DataPoint >::iterator end, const double &value)
find the first element in which X is equal or greater than the value searched important : it implies ...
Definition: trace.cpp:32
pappso::findFirstGreaterX
std::vector< DataPoint >::iterator findFirstGreaterX(std::vector< DataPoint >::iterator begin, std::vector< DataPoint >::iterator end, const double &value)
find the first element in which X is greater than the value searched important : it implies that Trac...
Definition: trace.cpp:60

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

## maxYDataPoint()

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

Definition at line 822 of file trace.cpp.

{
auto dataPoint = std::max_element(
begin(), end(), [](const DataPoint &a, const DataPoint &b) {
return (a.y < b.y);
});
if(dataPoint == end())
{
throw ExceptionOutOfRange(
QObject::tr("unable to get max peak intensity on spectrum size %1")
.arg(size()));
}
return (*dataPoint);
}
pappso::PeptideIonNter::a
@ a
pappso::PeptideIonNter::b
@ b

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

{
return minYDataPoint().y;
}
pappso::Trace::minYDataPoint
const DataPoint & minYDataPoint() const
Definition: trace.cpp:803

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

## minYDataPoint()

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

Definition at line 803 of file trace.cpp.

{
auto dataPoint = std::min_element(
begin(), end(), [](const DataPoint &a, const DataPoint &b) {
return (a.y < b.y);
});
if(dataPoint == end())
{
throw ExceptionOutOfRange(
QObject::tr("unable to get min peak intensity on spectrum size %1")
.arg(size()));
}
return (*dataPoint);
}

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

{
assign(other.begin(), other.end());
return *this;
}

## operator=() [2/2]

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

virtual

Definition at line 550 of file trace.cpp.

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

## sortX()

void pappso::Trace::sortX | ( |  | ) |

Definition at line 905 of file trace.cpp.

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

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

Referenced by pappso::IonIsotopeRatioScore::IonIsotopeRatioScore(), Trace(), pappso::MsRunRetentionTime< T >::align(), pappso::TimsFrame::cumulateScanToTrace(), pappso::FilterChargeDeconvolution::filter(), pappso::FilterComplementIonEnhancer::filter(), pappso::FilterMzExclusion::filter(), pappso::FilterGreatestYperWindow::filter(), pappso::FilterRemoveC13::filter(), pappso::FilterTriangle::filter(), pappso::MsRunRetentionTime< T >::getCommonDeltaRt(), pappso::TimsFrameBase::getTraceFromCumulatedScans(), pappso::TimsFrameBase::getTraceFromCumulatedScansBuiltinCentroid(), initialize(), pappso::Xic::sortByRetentionTime(), and pappso::MassSpectrum::sortMz().

## sortY()

void pappso::Trace::sortY | ( |  | ) |

Definition at line 913 of file trace.cpp.

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

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

{
// double sum = 0;
// for(auto &&dp : m_dataPoints)
// sum += dp.y;
// qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << " ()"
//<< "Returning sum/tic:" << sum;
// return sum;
return std::accumulate(begin(),
end(),
(double)0,
[](pappso_double sum, const DataPoint &dataPoint) {
return (sum + dataPoint.y);
});
}

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

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

## sumY() [2/2]

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

Definition at line 877 of file trace.cpp.

{
auto begin_it = findFirstEqualOrGreaterX(this->begin(), this->end(), mzStart);
auto end_it = findFirstGreaterX(begin_it, this->end(), mzEnd);
return sumYTrace(begin_it, end_it, 0);
}
pappso::sumYTrace
double sumYTrace(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end, double init)
calculate the sum of y value of a trace
Definition: trace.cpp:203

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

## toMap()

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

Definition at line 600 of file trace.cpp.

{
std::map<pappso_double, pappso_double> map;
std::pair<std::map<pappso_double, pappso_double>::iterator, bool> ret;
for(auto &&dataPoint : *this)
{
ret = map.insert(
std::pair<pappso_double, pappso_double>(dataPoint.x, dataPoint.y));
if(ret.second == false)
{
qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()"
<< "It is odd that the Trace contains multiple same keys.";
// No insertion, then increment the y value.
ret.first->second += dataPoint.y;
}
}
return map;
}

## toString()

QString pappso::Trace::toString | ( |  | ) | const

Definition at line 933 of file trace.cpp.

{
// Even if the spectrum is empty, we should return an empty string.
QString text;
for(auto &&dataPoint : *this)
{
text.append(QString("%1 %2\n")
.arg(dataPoint.x, 0, 'f', 10)
.arg(dataPoint.y, 0, 'f', 10));
}
return text;
}

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

## unique()

void pappso::Trace::unique | ( |  | ) |

Definition at line 921 of file trace.cpp.

{
auto last =
std::unique(begin(), end(), [](const DataPoint &a, const DataPoint &b) {
return (a.x == b.x);
});
erase(last, end());
}
pappso::QualifiedMassSpectrumParameter::last
@ last

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

{
std::vector<pappso_double> values;
for(auto &&dataPoint : *this)
{
values.push_back(dataPoint.x);
}
return values;
}

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

## yValues()

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

Definition at line 586 of file trace.cpp.

{
std::vector<pappso_double> values;
for(auto &&dataPoint : *this)
{
values.push_back(dataPoint.y);
}
return values;
}

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:

- pappsomspp/trace/trace.h
- pappsomspp/trace/trace.cpp