Loading...
Searching...
No Matches
trace.h
Go to the documentation of this file.
#pragma once
#include <qjsonobject.h>
#include <vector>
#include <memory>
#include <QDataStream>
#include "pappsomspp/export-import-config.h"
#include "pappsomspp/core/types.h"
#include "pappsomspp/core/precision.h"
#include "pappsomspp/core/trace/datapoint.h"
#include "pappsomspp/core/processing/filters/filterinterface.h"
namespace pappso
{
class Trace;
// @TODO function is not implemented :
PMSPP_LIB_DECL QDataStream &operator<<(QDataStream &out, const Trace &trace);
// @TODO function is not implemented :
PMSPP_LIB_DECL QDataStream &operator>>(QDataStream &out, Trace &trace);
/** @brief find the first element in which X is equal or greater than the value
* searched important : it implies that Trace is sorted by X
* */
PMSPP_LIB_DECL std::vector<DataPoint>::iterator
findFirstEqualOrGreaterX(std::vector<DataPoint>::iterator begin,
std::vector<DataPoint>::iterator end,
const double &value);
PMSPP_LIB_DECL std::vector<DataPoint>::const_iterator
findFirstEqualOrGreaterX(std::vector<DataPoint>::const_iterator begin,
std::vector<DataPoint>::const_iterator end,
const double &value);
/** @brief find the first element in which Y is different of value
* */
PMSPP_LIB_DECL std::vector<DataPoint>::iterator
findDifferentYvalue(std::vector<DataPoint>::iterator begin,
std::vector<DataPoint>::iterator end,
const double &y_value);
PMSPP_LIB_DECL std::vector<DataPoint>::const_iterator
findDifferentYvalue(std::vector<DataPoint>::const_iterator begin,
std::vector<DataPoint>::const_iterator end,
const double &y_value);
/** @brief find the first element in which X is greater than the value
* searched important : it implies that Trace is sorted by X
* */
PMSPP_LIB_DECL std::vector<DataPoint>::iterator
findFirstGreaterX(std::vector<DataPoint>::iterator begin,
std::vector<DataPoint>::iterator end,
const double &value);
PMSPP_LIB_DECL std::vector<DataPoint>::const_iterator
findFirstGreaterX(std::vector<DataPoint>::const_iterator begin,
std::vector<DataPoint>::const_iterator end,
const double &value);
/** @brief find the element with the smallest Y value (intensity)
* */
PMSPP_LIB_DECL std::vector<DataPoint>::iterator
minYDataPoint(std::vector<DataPoint>::iterator begin, std::vector<DataPoint>::iterator end);
PMSPP_LIB_DECL std::vector<DataPoint>::const_iterator
minYDataPoint(std::vector<DataPoint>::const_iterator begin,
std::vector<DataPoint>::const_iterator end);
/** @brief find the element with the greatest Y value (intensity)
* */
PMSPP_LIB_DECL std::vector<DataPoint>::iterator
maxYDataPoint(std::vector<DataPoint>::iterator begin, std::vector<DataPoint>::iterator end);
PMSPP_LIB_DECL std::vector<DataPoint>::const_iterator
maxYDataPoint(std::vector<DataPoint>::const_iterator begin,
std::vector<DataPoint>::const_iterator end);
/** @brief Move right to the lower value
* */
PMSPP_LIB_DECL std::vector<DataPoint>::const_iterator
moveLowerYRigthDataPoint(const Trace &trace, std::vector<DataPoint>::const_iterator begin);
/** @brief Move left to the lower value
* */
PMSPP_LIB_DECL std::vector<DataPoint>::const_iterator
moveLowerYLeftDataPoint(const Trace &trace, std::vector<DataPoint>::const_iterator begin);
/** @brief calculate the sum of y value of a trace
* */
PMSPP_LIB_DECL double sumYTrace(std::vector<DataPoint>::const_iterator begin,
std::vector<DataPoint>::const_iterator end,
double init);
/** @brief calculate the mean of y value of a trace
* */
PMSPP_LIB_DECL double meanYTrace(std::vector<DataPoint>::const_iterator begin,
std::vector<DataPoint>::const_iterator end);
/** @brief calculate the median of y value of a trace
* */
PMSPP_LIB_DECL double medianYTrace(std::vector<DataPoint>::const_iterator begin,
std::vector<DataPoint>::const_iterator end);
/** @brief calculate the quantile of y value of a trace
* @param begin begin iterator
* @param end end iterator
* @param quantile the quantile value between 0 and 1
* @return Y value at the quantile
* */
PMSPP_LIB_DECL double quantileYTrace(std::vector<DataPoint>::const_iterator begin,
std::vector<DataPoint>::const_iterator end,
double quantile);
/** @brief calculate the area of a trace
* */
PMSPP_LIB_DECL double areaTrace(std::vector<DataPoint>::const_iterator begin,
std::vector<DataPoint>::const_iterator end);
PMSPP_LIB_DECL Trace flooredLocalMaxima(std::vector<DataPoint>::const_iterator begin,
std::vector<DataPoint>::const_iterator end,
double y_floor);
PMSPP_LIB_DECL Trace incrementByValueX(std::vector<DataPoint>::const_iterator begin,
std::vector<DataPoint>::const_iterator end,
double increment);
PMSPP_LIB_DECL Trace incrementByValueY(std::vector<DataPoint>::const_iterator begin,
std::vector<DataPoint>::const_iterator end,
double increment);
typedef std::shared_ptr<Trace> TraceSPtr;
typedef std::shared_ptr<const Trace> TraceCstSPtr;
class MapTrace;
class TraceCombiner;
class TracePlusCombiner;
class TraceMinusCombiner;
/**
* \class Trace
* \brief A simple container of DataPoint instances
*/
class PMSPP_LIB_DECL Trace : public std::vector<DataPoint>
{
friend class TraceCombiner;
friend class TraceMinusCombiner;
friend class TracePlusCombiner;
friend class MassSpectrumCombinerInterface;
public:
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);
explicit Trace(const MapTrace &map_trace);
Trace(const Trace &other);
Trace(const Trace &&other); // move constructor
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 Trace &operator=(const Trace &x);
virtual Trace &operator=(Trace &&x);
TraceSPtr makeTraceSPtr() const;
TraceCstSPtr makeTraceCstSPtr() const;
/** @brief appends a datapoint and return new size
*/
size_t append(const DataPoint &data_point);
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 Peak & Spectrum::getLowestIntensity() const;
const DataPoint &minXDataPoint() const;
// was const Peak & Spectrum::getMaxIntensity() const;
const DataPoint &maxXDataPoint() const;
// const Peak & Spectrum::getLowestIntensity() const;
const DataPoint &minYDataPoint() const;
// was const Peak & Spectrum::getMaxIntensity() const;
const DataPoint &maxYDataPoint() 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;
// was void Spectrum::sortByMz();
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();
/** @brief apply a filter on this trace
* @param filter to process the signal
* @return reference on the modified Trace.
*/
virtual Trace &filter(const FilterInterface &filter) final;
QString toString() const;
/** @brief serialize a PAPPSO trace object to JSON
* @param x_label label for first dimension (x by default)
* @param y_label label for second dimension (y by default)
* @return a JSON object
*/
QJsonObject toJsonObject(const QString &x_label = "x", const QString &y_label = "y") const;
QByteArray xAsBase64Encoded() const;
QByteArray yAsBase64Encoded() const;
/** @brief find datapoint with exactly x value
*/
std::vector<DataPoint>::const_iterator dataPointCstIteratorWithX(pappso_double value) const;
protected:
//! Return a reference to the DataPoint instance that has its x member equal
//! to \p value.
// const DataPoint &dataPointWithX(pappso_double value) const;
std::size_t dataPointIndexWithX(pappso_double value) const;
std::vector<DataPoint>::iterator dataPointIteratorWithX(pappso_double value);
};
} // namespace pappso
Q_DECLARE_METATYPE(pappso::Trace);
Q_DECLARE_METATYPE(pappso::Trace *);
extern int traceMetaTypeId;
extern int tracePtrMetaTypeId;
pappso::FilterInterface
generic interface to apply a filter on a trace
Definition filterinterface.h:40
pappso::MapTrace
Definition maptrace.h:36
pappso::TraceCombiner
Definition tracecombiner.h:24
pappso::TraceMinusCombiner
Definition traceminuscombiner.h:27
pappso::TracePlusCombiner
Definition tracepluscombiner.h:27
pappso::Trace
A simple container of DataPoint instances.
Definition trace.h:152
pappso::Trace::operator=
virtual Trace & operator=(const Trace &x)
Definition trace.cpp:666
pappso::Trace::unique
void unique()
Definition trace.cpp:1091
pappso::Trace::maxY
pappso_double maxY() const
Definition trace.cpp:1003
pappso::Trace::sumY
pappso_double sumY() const
Definition trace.cpp:1010
pappso::Trace::maxYDataPoint
const DataPoint & maxYDataPoint() const
Definition trace.cpp:966
pappso::Trace::toMap
std::map< pappso_double, pappso_double > toMap() const
Definition trace.cpp:725
pappso::Trace::xValues
std::vector< pappso_double > xValues() const
Definition trace.cpp:697
pappso::Trace::maxXDataPoint
const DataPoint & maxXDataPoint() const
Definition trace.cpp:934
pappso::Trace::minX
pappso_double minX() const
Definition trace.cpp:982
pappso::Trace::TraceCombiner
friend class TraceCombiner
Definition trace.h:154
pappso::Trace::yAsBase64Encoded
QByteArray yAsBase64Encoded() const
Definition trace.cpp:1164
pappso::Trace::TracePlusCombiner
friend class TracePlusCombiner
Definition trace.h:156
pappso::Trace::maxX
pappso_double maxX() const
Definition trace.cpp:989
pappso::Trace::sort
void sort(Enums::SortType sort_type, Enums::SortOrder sort_order=Enums::SortOrder::ascending)
Definition trace.cpp:1058
pappso::Trace::xAsBase64Encoded
QByteArray xAsBase64Encoded() const
Definition trace.cpp:1143
pappso::Trace::sortY
void sortY(Enums::SortOrder sort_order=Enums::SortOrder::ascending)
Definition trace.cpp:1081
pappso::Trace::makeTraceCstSPtr
TraceCstSPtr makeTraceCstSPtr() const
Definition trace.cpp:690
pappso::Trace::filter
virtual Trace & filter(const FilterInterface &filter) final
apply a filter on this trace
Definition trace.cpp:1185
pappso::Trace::toJsonObject
QJsonObject toJsonObject(const QString &x_label="x", const QString &y_label="y") const
serialize a PAPPSO trace object to JSON
Definition trace.cpp:1191
pappso::Trace::containsX
DataPoint containsX(pappso_double value, PrecisionPtr precision_p=nullptr) const
Definition trace.cpp:802
pappso::Trace::yValues
std::vector< pappso_double > yValues() const
Definition trace.cpp:711
pappso::Trace::minY
pappso_double minY() const
Definition trace.cpp:996
pappso::Trace::TraceMinusCombiner
friend class TraceMinusCombiner
Definition trace.h:155
pappso::Trace::initialize
size_t initialize(const std::vector< pappso_double > &xVector, const std::vector< pappso_double > &yVector)
Definition trace.cpp:597
pappso::Trace::sortX
void sortX(Enums::SortOrder sort_order=Enums::SortOrder::ascending)
Definition trace.cpp:1071
pappso::Trace::append
size_t append(const DataPoint &data_point)
appends a datapoint and return new size
Definition trace.cpp:657
pappso::Trace::dataPointIndexWithX
std::size_t dataPointIndexWithX(pappso_double value) const
Return a reference to the DataPoint instance that has its x member equal to value.
Definition trace.cpp:790
pappso::Trace::minXDataPoint
const DataPoint & minXDataPoint() const
Definition trace.cpp:918
pappso::Trace::dataPointCstIteratorWithX
std::vector< DataPoint >::const_iterator dataPointCstIteratorWithX(pappso_double value) const
find datapoint with exactly x value
Definition trace.cpp:780
pappso::Trace::dataPointIteratorWithX
std::vector< DataPoint >::iterator dataPointIteratorWithX(pappso_double value)
Definition trace.cpp:770
pappso::Trace::minYDataPoint
const DataPoint & minYDataPoint() const
Definition trace.cpp:950
pappso::Trace::MassSpectrumCombinerInterface
friend class MassSpectrumCombinerInterface
Definition trace.h:158
pappso::Trace::makeTraceSPtr
TraceSPtr makeTraceSPtr() const
Definition trace.cpp:683
pappso::Trace::Trace
Trace()
Definition trace.cpp:455
pappso::Trace::removeZeroYDataPoints
std::size_t removeZeroYDataPoints()
Definition trace.cpp:1101
pappso::Trace::toString
QString toString() const
Definition trace.cpp:1128
datapoint.h
export-import-config.h
PMSPP_LIB_DECL
#define PMSPP_LIB_DECL
Definition export-import-config.h:14
filterinterface.h
pappso::Enums::SortOrder
SortOrder
Definition types.h:231
pappso::Enums::SortOrder::ascending
@ ascending
Definition types.h:232
pappso::Enums::SortType
SortType
Definition types.h:223
pappso
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39
pappso::TraceCstSPtr
std::shared_ptr< const Trace > TraceCstSPtr
Definition trace.h:140
pappso::findDifferentYvalue
std::vector< DataPoint >::iterator findDifferentYvalue(std::vector< DataPoint >::iterator begin, std::vector< DataPoint >::iterator end, const double &y_value)
find the first element in which Y is different of value
Definition trace.cpp:121
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:65
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:93
pappso::operator<<
QDataStream & operator<<(QDataStream &outstream, const MassSpectrum &massSpectrum)
Definition massspectrum.cpp:339
pappso::operator>>
QDataStream & operator>>(QDataStream &instream, MassSpectrum &massSpectrum)
Definition massspectrum.cpp:353
pappso::moveLowerYLeftDataPoint
std::vector< DataPoint >::const_iterator moveLowerYLeftDataPoint(const Trace &trace, std::vector< DataPoint >::const_iterator begin)
Move left to the lower value.
Definition trace.cpp:206
pappso::maxYDataPoint
std::vector< DataPoint >::const_iterator maxYDataPoint(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end)
Definition trace.cpp:169
pappso::incrementByValueX
Trace incrementByValueX(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end, double increment)
Definition trace.cpp:418
pappso::medianYTrace
double medianYTrace(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end)
calculate the median of y value of a trace
Definition trace.cpp:267
pappso::incrementByValueY
Trace incrementByValueY(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end, double increment)
Definition trace.cpp:437
pappso::areaTrace
double areaTrace(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end)
calculate the area of a trace
Definition trace.cpp:283
pappso::TraceSPtr
std::shared_ptr< Trace > TraceSPtr
Definition trace.h:139
pappso::pappso_double
double pappso_double
A type definition for doubles.
Definition types.h:60
pappso::meanYTrace
double meanYTrace(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end)
calculate the mean of y value of a trace
Definition trace.cpp:234
pappso::PrecisionPtr
const PrecisionBase * PrecisionPtr
Definition precision.h:122
pappso::moveLowerYRigthDataPoint
std::vector< DataPoint >::const_iterator moveLowerYRigthDataPoint(const Trace &trace, std::vector< DataPoint >::const_iterator begin)
Move right to the lower value.
Definition trace.cpp:189
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:226
pappso::minYDataPoint
std::vector< DataPoint >::const_iterator minYDataPoint(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end)
Definition trace.cpp:152
pappso::quantileYTrace
double quantileYTrace(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end, double quantile)
calculate the quantile of y value of a trace
Definition trace.cpp:244
pappso::flooredLocalMaxima
Trace flooredLocalMaxima(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end, double y_floor)
Definition trace.cpp:302
precision.h
pappso::DataPoint
Definition datapoint.h:22
traceMetaTypeId
int traceMetaTypeId
Definition trace.cpp:22
tracePtrMetaTypeId
int tracePtrMetaTypeId
Definition trace.cpp:23
Q_DECLARE_METATYPE
Q_DECLARE_METATYPE(pappso::Trace)
types.h