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 PMSPP_LIB_DECL Trace
130 flooredLocalMaxima(std::vector<DataPoint>::const_iterator begin,
131  std::vector<DataPoint>::const_iterator end,
132  double y_floor);
133 
134 typedef std::shared_ptr<Trace> TraceSPtr;
135 typedef std::shared_ptr<const Trace> TraceCstSPtr;
136 
137 class MapTrace;
138 class TraceCombiner;
139 class TracePlusCombiner;
140 class TraceMinusCombiner;
141 
142 /**
143  * \class Trace
144  * \brief A simple container of DataPoint instances
145  */
146 class PMSPP_LIB_DECL Trace : public std::vector<DataPoint>
147 {
148 
149  friend class TraceCombiner;
150  friend class TraceMinusCombiner;
151  friend class TracePlusCombiner;
152 
153  friend class MassSpectrumCombinerInterface;
154 
155  public:
156  Trace();
157  Trace(const std::vector<pappso_double> &xVector,
158  const std::vector<pappso_double> &yVector);
159  Trace(const std::vector<std::pair<pappso_double, pappso_double>> &dataPoints);
160  Trace(const std::vector<DataPoint> &dataPoints);
161  Trace(const std::vector<DataPoint> &&dataPoints);
162  explicit Trace(const MapTrace &map_trace);
163  Trace(const Trace &other);
164  Trace(const Trace &&other); // move constructor
165  virtual ~Trace();
166 
167  size_t initialize(const std::vector<pappso_double> &xVector,
168  const std::vector<pappso_double> &yVector);
169 
170  size_t initialize(const Trace &other);
171 
172  size_t initialize(const std::map<pappso_double, pappso_double> &map);
173 
174  virtual Trace &operator=(const Trace &x);
175  virtual Trace &operator=(Trace &&x);
176 
177  TraceSPtr makeTraceSPtr() const;
178  TraceCstSPtr makeTraceCstSPtr() const;
179 
180  std::vector<pappso_double> xValues() const;
181  std::vector<pappso_double> yValues() const;
182 
183  std::map<pappso_double, pappso_double> toMap() const;
184 
185  DataPoint containsX(pappso_double value,
186  PrecisionPtr precision_p = nullptr) const;
187 
188  // const Peak & Spectrum::getLowestIntensity() const;
189  const DataPoint &minYDataPoint() const;
190 
191  // was const Peak & Spectrum::getMaxIntensity() const;
192  const DataPoint &maxYDataPoint() const;
193 
194  pappso_double minY() const;
195  pappso_double maxY() const;
196  pappso_double maxY(double mzStart, double mzEnd) const;
197  pappso_double sumY() const;
198  pappso_double sumY(double mzStart, double mzEnd) const;
199 
200  // was void Spectrum::sortByMz();
201  void sortX();
202  void sortY();
203  void unique();
204 
205  /** @brief apply a filter on this trace
206  * @param filter to process the signal
207  * @return reference on the modified Trace
208  */
209  virtual Trace &filter(const FilterInterface &filter) final;
210  QString toString() const;
211 
212  /** @brief find datapoint with exactly x value
213  */
214  std::vector<DataPoint>::const_iterator
215  dataPointCstIteratorWithX(pappso_double value) const;
216 
217  protected:
218  //! Return a reference to the DataPoint instance that has its y member equal
219  //! to \p value.
220  // const DataPoint &dataPointWithX(pappso_double value) const;
221  std::size_t dataPointIndexWithX(pappso_double value) const;
222  std::vector<DataPoint>::iterator dataPointIteratorWithX(pappso_double value);
223 };
224 
225 
226 } // namespace pappso
227 
230 
231 extern int traceMetaTypeId;
232 extern int tracePtrMetaTypeId;
generic interface to apply a filter on a trace
A simple container of DataPoint instances.
Definition: trace.h:147
#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:135
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:88
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:32
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:60
std::vector< DataPoint >::const_iterator moveLowerYLeftDataPoint(const Trace &trace, std::vector< DataPoint >::const_iterator begin)
Move left to the lower value.
Definition: trace.cpp:184
std::vector< DataPoint >::const_iterator maxYDataPoint(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end)
Definition: trace.cpp:141
QDataStream & operator>>(QDataStream &instream, MassSpectrum &massSpectrum)
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:252
QDataStream & operator<<(QDataStream &outstream, const MassSpectrum &massSpectrum)
double areaTrace(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end)
calculate the area of a trace
Definition: trace.cpp:270
std::shared_ptr< Trace > TraceSPtr
Definition: trace.h:134
double pappso_double
A type definition for doubles.
Definition: types.h:48
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:214
std::vector< DataPoint >::const_iterator moveLowerYRigthDataPoint(const Trace &trace, std::vector< DataPoint >::const_iterator begin)
Move right to the lower value.
Definition: trace.cpp:166
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:205
std::vector< DataPoint >::const_iterator minYDataPoint(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end)
Definition: trace.cpp:119
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:226
Trace flooredLocalMaxima(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end, double y_floor)
Definition: trace.cpp:319
int traceMetaTypeId
Definition: trace.cpp:24
int tracePtrMetaTypeId
Definition: trace.cpp:25
Q_DECLARE_METATYPE(pappso::Trace)