libpappsomspp
Library for mass spectrometry
trace.h
Go to the documentation of this file.
1#pragma once
2
3#include <vector>
4#include <memory>
5
6#include <QObject>
7#include <QDataStream>
8
9
10#include "../exportinmportconfig.h"
11#include "../types.h"
12#include "datapoint.h"
13#include "../mzrange.h"
14#include "../processing/filters/filterinterface.h"
15
16namespace pappso
17{
18
19
20// For a large number of Trace filters, find them below the Trace class declaration
21// For a large number of Trace filters, find them below the Trace class declaration
22// For a large number of Trace filters, find them below the Trace class declaration
23
24
25typedef std::shared_ptr<Trace> TraceSPtr;
26typedef std::shared_ptr<const Trace> TraceCstSPtr;
27
28class MapTrace;
29class TraceCombiner;
32
33/**
34 * \class Trace
35 * \brief A simple container of DataPoint instances
36 */
37class PMSPP_LIB_DECL Trace : public std::vector<DataPoint>
38{
39 friend class TraceCombiner;
40 friend class TraceMinusCombiner;
41 friend class TracePlusCombiner;
42
43 friend class MassSpectrumCombinerInterface;
44
45 public:
46 Q_INVOKABLE Trace();
47 Q_INVOKABLE Trace(const std::vector<pappso_double> &xVector,
48 const std::vector<pappso_double> &yVector);
49 Q_INVOKABLE
50 Trace(const std::vector<std::pair<pappso_double, pappso_double>> &dataPoints);
51 Q_INVOKABLE Trace(const std::vector<DataPoint> &dataPoints);
52 Q_INVOKABLE Trace(const std::vector<DataPoint> &&dataPoints);
53 explicit Trace(const MapTrace &map_trace);
54 Q_INVOKABLE Trace(const Trace &other);
55 Q_INVOKABLE Trace(const Trace &&other); // move constructor
56 virtual ~Trace();
57
58 Q_INVOKABLE size_t initialize(const std::vector<pappso_double> &xVector,
59 const std::vector<pappso_double> &yVector);
60
61 Q_INVOKABLE size_t initialize(const Trace &other);
62
63 Q_INVOKABLE size_t
64 initialize(const std::map<pappso_double, pappso_double> &map);
65
66 Q_INVOKABLE size_t
67 append(const DataPoint &data_point);
68
69 Q_INVOKABLE virtual Trace &operator=(const Trace &x);
70 virtual Trace &operator =(Trace &&x);
71
72 TraceSPtr makeTraceSPtr() const;
73 TraceCstSPtr makeTraceCstSPtr() const;
74
75 Q_INVOKABLE std::vector<pappso_double> xValues() const;
76 Q_INVOKABLE std::vector<pappso_double> yValues() const;
77
78 std::map<pappso_double, pappso_double> toMap() const;
79
80 DataPoint containsX(pappso_double value,
81 PrecisionPtr precision_p = nullptr) const;
82
83 // const Peak & Spectrum::getLowestIntensity() const;
84 Q_INVOKABLE const DataPoint &minYDataPoint() const;
85
86 // was const Peak & Spectrum::getMaxIntensity() const;
87 Q_INVOKABLE const DataPoint &maxYDataPoint() const;
88
89 Q_INVOKABLE pappso_double minY() const;
90 Q_INVOKABLE pappso_double maxY() const;
91 Q_INVOKABLE pappso_double maxY(double mzStart, double mzEnd) const;
92 Q_INVOKABLE pappso_double sumY() const;
93 Q_INVOKABLE pappso_double sumY(double mzStart, double mzEnd) const;
94
95 // was void Spectrum::sortByMz();
96 Q_INVOKABLE void sortX();
97 Q_INVOKABLE void sortY();
98 Q_INVOKABLE void unique();
99
100 /** @brief apply a filter on this trace
101 * @param filter to process the signal
102 * @return reference on the modified Trace
103 */
104 virtual Trace &filter(const FilterInterface &filter) final;
105 Q_INVOKABLE QString toString() const;
106
107 /** @brief find datapoint with exactly x value
108 */
109 std::vector<DataPoint>::const_iterator
110 dataPointCstIteratorWithX(pappso_double value) const;
111
112 protected:
113 //! Return a reference to the DataPoint instance that has its y member equal
114 //! to \p value.
115 // const DataPoint &dataPointWithX(pappso_double value) const;
116 std::size_t dataPointIndexWithX(pappso_double value) const;
117 std::vector<DataPoint>::iterator dataPointIteratorWithX(pappso_double value);
118};
119
120//////////////////////////////////// Filters //////////////////////////////////
121//////////////////////////////////// Filters //////////////////////////////////
122//////////////////////////////////// Filters //////////////////////////////////
123
124// @TODO function is not implemented :
125PMSPP_LIB_DECL QDataStream &operator<<(QDataStream &out, const Trace &trace);
126
127// @TODO function is not implemented :
128PMSPP_LIB_DECL QDataStream &operator>>(QDataStream &out, Trace &trace);
129
130/** @brief find the first element in which X is equal or greater than the value
131 * searched important : it implies that Trace is sorted by X
132 * */
133PMSPP_LIB_DECL std::vector<DataPoint>::iterator
134findFirstEqualOrGreaterX(std::vector<DataPoint>::iterator begin,
135 std::vector<DataPoint>::iterator end,
136 const double &value);
137
138PMSPP_LIB_DECL std::vector<DataPoint>::const_iterator
139findFirstEqualOrGreaterX(std::vector<DataPoint>::const_iterator begin,
140 std::vector<DataPoint>::const_iterator end,
141 const double &value);
142
143/** @brief find the first element in which Y is different of value
144 * */
145PMSPP_LIB_DECL std::vector<DataPoint>::iterator
146findDifferentYvalue(std::vector<DataPoint>::iterator begin,
147 std::vector<DataPoint>::iterator end,
148 const double &y_value);
149
150PMSPP_LIB_DECL std::vector<DataPoint>::const_iterator
151findDifferentYvalue(std::vector<DataPoint>::const_iterator begin,
152 std::vector<DataPoint>::const_iterator end,
153 const double &y_value);
154
155/** @brief find the first element in which X is greater than the value
156 * searched important : it implies that Trace is sorted by X
157 * */
158PMSPP_LIB_DECL std::vector<DataPoint>::iterator
159findFirstGreaterX(std::vector<DataPoint>::iterator begin,
160 std::vector<DataPoint>::iterator end,
161 const double &value);
162
163PMSPP_LIB_DECL std::vector<DataPoint>::const_iterator
164findFirstGreaterX(std::vector<DataPoint>::const_iterator begin,
165 std::vector<DataPoint>::const_iterator end,
166 const double &value);
167
168/** @brief find the element with the smallest Y value (intensity)
169 * */
170
171PMSPP_LIB_DECL std::vector<DataPoint>::iterator
172minYDataPoint(std::vector<DataPoint>::iterator begin,
173 std::vector<DataPoint>::iterator end);
174
175PMSPP_LIB_DECL std::vector<DataPoint>::const_iterator
176minYDataPoint(std::vector<DataPoint>::const_iterator begin,
177 std::vector<DataPoint>::const_iterator end);
178
179/** @brief find the element with the greatest Y value (intensity)
180 * */
181PMSPP_LIB_DECL std::vector<DataPoint>::iterator
182maxYDataPoint(std::vector<DataPoint>::iterator begin,
183 std::vector<DataPoint>::iterator end);
184
185PMSPP_LIB_DECL std::vector<DataPoint>::const_iterator
186maxYDataPoint(std::vector<DataPoint>::const_iterator begin,
187 std::vector<DataPoint>::const_iterator end);
188
189/** @brief Move right to the lower value
190 * */
191PMSPP_LIB_DECL std::vector<DataPoint>::const_iterator
193 std::vector<DataPoint>::const_iterator begin);
194/** @brief Move left to the lower value
195 * */
196PMSPP_LIB_DECL std::vector<DataPoint>::const_iterator
197moveLowerYLeftDataPoint(const Trace &trace,
198 std::vector<DataPoint>::const_iterator begin);
199
200/** @brief calculate the sum of y value of a trace
201 * */
202PMSPP_LIB_DECL double sumYTrace(std::vector<DataPoint>::const_iterator begin,
203 std::vector<DataPoint>::const_iterator end,
204 double init);
205
206/** @brief calculate the mean of y value of a trace
207 * */
208PMSPP_LIB_DECL double meanYTrace(std::vector<DataPoint>::const_iterator begin,
209 std::vector<DataPoint>::const_iterator end);
210
211/** @brief calculate the median of y value of a trace
212 * */
213PMSPP_LIB_DECL double medianYTrace(std::vector<DataPoint>::const_iterator begin,
214 std::vector<DataPoint>::const_iterator end);
215
216
217/** @brief calculate the quantile of y value of a trace
218 * @param begin begin iterator
219 * @param end end iterator
220 * @param quantile the quantile value between 0 and 1
221 * @return Y value at the quantile
222 * */
223PMSPP_LIB_DECL double
224quantileYTrace(std::vector<DataPoint>::const_iterator begin,
225 std::vector<DataPoint>::const_iterator end,
226 double quantile);
227
228
229/** @brief calculate the area of a trace
230 * */
231PMSPP_LIB_DECL double areaTrace(std::vector<DataPoint>::const_iterator begin,
232 std::vector<DataPoint>::const_iterator end);
233
235flooredLocalMaxima(std::vector<DataPoint>::const_iterator begin,
236 std::vector<DataPoint>::const_iterator end,
237 double y_floor);
238
239
240} // namespace pappso
241
244
245extern int traceMetaTypeId;
246extern int tracePtrMetaTypeId;
generic interface to apply a filter on a trace
A simple container of DataPoint instances.
Definition: trace.h:38
#define PMSPP_LIB_DECL
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition: aa.cpp:39
std::shared_ptr< const Trace > TraceCstSPtr
Definition: trace.h:26
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:125
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:69
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:97
QDataStream & operator<<(QDataStream &outstream, const MassSpectrum &massSpectrum)
QDataStream & operator>>(QDataStream &instream, MassSpectrum &massSpectrum)
std::vector< DataPoint >::const_iterator moveLowerYLeftDataPoint(const Trace &trace, std::vector< DataPoint >::const_iterator begin)
Move left to the lower value.
Definition: trace.cpp:221
std::vector< DataPoint >::const_iterator maxYDataPoint(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end)
Definition: trace.cpp:178
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:289
double areaTrace(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end)
calculate the area of a trace
Definition: trace.cpp:307
std::shared_ptr< Trace > TraceSPtr
Definition: trace.h:25
double pappso_double
A type definition for doubles.
Definition: types.h:49
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:251
std::vector< DataPoint >::const_iterator moveLowerYRigthDataPoint(const Trace &trace, std::vector< DataPoint >::const_iterator begin)
Move right to the lower value.
Definition: trace.cpp:203
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:242
std::vector< DataPoint >::const_iterator minYDataPoint(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end)
Definition: trace.cpp:156
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:263
Trace flooredLocalMaxima(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end, double y_floor)
Definition: trace.cpp:356
int traceMetaTypeId
Definition: trace.cpp:25
int tracePtrMetaTypeId
Definition: trace.cpp:26
Q_DECLARE_METATYPE(pappso::Trace)