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