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 
15 namespace pappso
16 {
17 
18 
19 class Trace;
20 // @TODO function is not implemented :
21 PMSPP_LIB_DECL QDataStream &operator<<(QDataStream &out, const Trace &trace);
22 // @TODO function is not implemented :
23 PMSPP_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  * */
28 PMSPP_LIB_DECL std::vector<DataPoint>::iterator
29 findFirstEqualOrGreaterX(std::vector<DataPoint>::iterator begin,
30  std::vector<DataPoint>::iterator end,
31  const double &value);
32 
33 PMSPP_LIB_DECL std::vector<DataPoint>::const_iterator
34 findFirstEqualOrGreaterX(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  * */
40 PMSPP_LIB_DECL std::vector<DataPoint>::iterator
41 findDifferentYvalue(std::vector<DataPoint>::iterator begin,
42  std::vector<DataPoint>::iterator end,
43  const double &y_value);
44 
45 PMSPP_LIB_DECL std::vector<DataPoint>::const_iterator
46 findDifferentYvalue(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  * */
53 PMSPP_LIB_DECL std::vector<DataPoint>::iterator
54 findFirstGreaterX(std::vector<DataPoint>::iterator begin,
55  std::vector<DataPoint>::iterator end,
56  const double &value);
57 
58 PMSPP_LIB_DECL std::vector<DataPoint>::const_iterator
59 findFirstGreaterX(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 
66 PMSPP_LIB_DECL std::vector<DataPoint>::iterator
67 minYDataPoint(std::vector<DataPoint>::iterator begin,
68  std::vector<DataPoint>::iterator end);
69 
70 PMSPP_LIB_DECL std::vector<DataPoint>::const_iterator
71 minYDataPoint(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  * */
76 PMSPP_LIB_DECL std::vector<DataPoint>::iterator
77 maxYDataPoint(std::vector<DataPoint>::iterator begin,
78  std::vector<DataPoint>::iterator end);
79 
80 PMSPP_LIB_DECL std::vector<DataPoint>::const_iterator
81 maxYDataPoint(std::vector<DataPoint>::const_iterator begin,
82  std::vector<DataPoint>::const_iterator end);
83 
84 /** @brief Move right to the lower value
85  * */
86 PMSPP_LIB_DECL std::vector<DataPoint>::const_iterator
87 moveLowerYRigthDataPoint(const Trace &trace,
88  std::vector<DataPoint>::const_iterator begin);
89 /** @brief Move left to the lower value
90  * */
91 PMSPP_LIB_DECL std::vector<DataPoint>::const_iterator
92 moveLowerYLeftDataPoint(const Trace &trace,
93  std::vector<DataPoint>::const_iterator begin);
94 
95 /** @brief calculate the sum of y value of a trace
96  * */
97 PMSPP_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  * */
103 PMSPP_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  * */
108 PMSPP_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  * */
118 PMSPP_LIB_DECL double
119 quantileYTrace(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  * */
126 PMSPP_LIB_DECL double areaTrace(std::vector<DataPoint>::const_iterator begin,
127  std::vector<DataPoint>::const_iterator end);
128 
129 
130 PMSPP_LIB_DECL Trace
131 flooredLocalMaxima(std::vector<DataPoint>::const_iterator begin,
132  std::vector<DataPoint>::const_iterator end,
133  double y_floor);
134 
135 typedef std::shared_ptr<Trace> TraceSPtr;
136 typedef std::shared_ptr<const Trace> TraceCstSPtr;
137 
138 class MapTrace;
139 class TraceCombiner;
140 class TracePlusCombiner;
141 class TraceMinusCombiner;
142 
143 /**
144  * \class Trace
145  * \brief A simple container of DataPoint instances
146  */
147 class 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 
236 extern int traceMetaTypeId;
237 extern 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)