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 
16 namespace 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 
25 typedef std::shared_ptr<Trace> TraceSPtr;
26 typedef std::shared_ptr<const Trace> TraceCstSPtr;
27 
28 class MapTrace;
29 class TraceCombiner;
30 class TracePlusCombiner;
31 class TraceMinusCombiner;
32 
33 /**
34  * \class Trace
35  * \brief A simple container of DataPoint instances
36  */
37 class 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 :
125 PMSPP_LIB_DECL QDataStream &operator<<(QDataStream &out, const Trace &trace);
126 
127 // @TODO function is not implemented :
128 PMSPP_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  * */
133 PMSPP_LIB_DECL std::vector<DataPoint>::iterator
134 findFirstEqualOrGreaterX(std::vector<DataPoint>::iterator begin,
135  std::vector<DataPoint>::iterator end,
136  const double &value);
137 
138 PMSPP_LIB_DECL std::vector<DataPoint>::const_iterator
139 findFirstEqualOrGreaterX(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  * */
145 PMSPP_LIB_DECL std::vector<DataPoint>::iterator
146 findDifferentYvalue(std::vector<DataPoint>::iterator begin,
147  std::vector<DataPoint>::iterator end,
148  const double &y_value);
149 
150 PMSPP_LIB_DECL std::vector<DataPoint>::const_iterator
151 findDifferentYvalue(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  * */
158 PMSPP_LIB_DECL std::vector<DataPoint>::iterator
159 findFirstGreaterX(std::vector<DataPoint>::iterator begin,
160  std::vector<DataPoint>::iterator end,
161  const double &value);
162 
163 PMSPP_LIB_DECL std::vector<DataPoint>::const_iterator
164 findFirstGreaterX(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 
171 PMSPP_LIB_DECL std::vector<DataPoint>::iterator
172 minYDataPoint(std::vector<DataPoint>::iterator begin,
173  std::vector<DataPoint>::iterator end);
174 
175 PMSPP_LIB_DECL std::vector<DataPoint>::const_iterator
176 minYDataPoint(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  * */
181 PMSPP_LIB_DECL std::vector<DataPoint>::iterator
182 maxYDataPoint(std::vector<DataPoint>::iterator begin,
183  std::vector<DataPoint>::iterator end);
184 
185 PMSPP_LIB_DECL std::vector<DataPoint>::const_iterator
186 maxYDataPoint(std::vector<DataPoint>::const_iterator begin,
187  std::vector<DataPoint>::const_iterator end);
188 
189 /** @brief Move right to the lower value
190  * */
191 PMSPP_LIB_DECL std::vector<DataPoint>::const_iterator
192 moveLowerYRigthDataPoint(const Trace &trace,
193  std::vector<DataPoint>::const_iterator begin);
194 /** @brief Move left to the lower value
195  * */
196 PMSPP_LIB_DECL std::vector<DataPoint>::const_iterator
197 moveLowerYLeftDataPoint(const Trace &trace,
198  std::vector<DataPoint>::const_iterator begin);
199 
200 /** @brief calculate the sum of y value of a trace
201  * */
202 PMSPP_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  * */
208 PMSPP_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  * */
213 PMSPP_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  * */
223 PMSPP_LIB_DECL double
224 quantileYTrace(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  * */
231 PMSPP_LIB_DECL double areaTrace(std::vector<DataPoint>::const_iterator begin,
232  std::vector<DataPoint>::const_iterator end);
233 
235 flooredLocalMaxima(std::vector<DataPoint>::const_iterator begin,
236  std::vector<DataPoint>::const_iterator end,
237  double y_floor);
238 
239 
240 } // namespace pappso
241 
244 
245 extern int traceMetaTypeId;
246 extern 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)