libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
mzintegrationparams.h
Go to the documentation of this file.
1/* BEGIN software license
2 *
3 * msXpertSuite - mass spectrometry software suite
4 * -----------------------------------------------
5 * Copyright(C) 2009,...,2018 Filippo Rusconi
6 *
7 * http://www.msxpertsuite.org
8 *
9 * This file is part of the msXpertSuite project.
10 *
11 * The msXpertSuite project is the successor of the massXpert project. This
12 * project now includes various independent modules:
13 *
14 * - massXpert, model polymer chemistries and simulate mass spectrometric data;
15 * - mineXpert, a powerful TIC chromatogram/mass spectrum viewer/miner;
16 *
17 * This program is free software: you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation, either version 3 of the License, or
20 * (at your option) any later version.
21 *
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * You should have received a copy of the GNU General Public License
28 * along with this program. If not, see <http://www.gnu.org/licenses/>.
29 *
30 * END software license
31 */
32
33
34#pragma once
35
36/////////////////////// stdlib includes
37#include <map>
38
39
40/////////////////////// Qt includes
41#include <QObject>
42#include <QQmlEngine>
43
44
45/////////////////////// Local includes
49
50namespace pappso
51{
52
53/*! The MzIntegrationParams class provides the parameters definining how m/z
54 * integrations must be performed.
55 *
56 * Depending on the various mass spectrometer vendors, the mass spectrometry
57 * data files are structured in different ways and the software for mass data
58 * format conversion from raw files to mzML or mzXML produce mass data
59 * characterized by different behaviours.
60 *
61 * The different characteristics of mass spectrometry data set are:
62 *
63 * The size of the various mass spectra in the file is constant or variable;
64 *
65 * The first m/z value of the various spectra is identical or not (that is,
66 * the spectra are root in a constant or variable root m/z value);
67 *
68 * The m/z delta between two consecutive m/z values of a given spectrum are
69 * constant or variable;
70 *
71 * The spectra contain or not 0-value m/z data points;
72 */
73
74/* BEGIN CLASS JS REFERENCE
75 * namespace: pappso
76 * class name: MzIntegrationParams
77 *
78 * BEGIN DESCRIPTION
79 * This class configures the way mass spectra are computed,
80 * in particular with respect of the m/z binning.
81 * END DESCRIPTION
82 */
84{
85 Q_OBJECT
86
87 /*$ JS PROP REF Smallest m/z value of the set of mass spectra. This value is
88 * used as the smallest m/z value upon calculation of the bins.*/
89 Q_PROPERTY(double smallestMz READ getSmallestMz WRITE setSmallestMz NOTIFY
91 /*$ JS PROP REF Greatest m/z value of the set of mass spectra. This value is
92 * used as the greatest m/z value upon calculation of the bins.*/
93 Q_PROPERTY(double greatestMz READ getGreatestMz WRITE setGreatestMz NOTIFY
95 /*$ JS PROP REF Smallest m/z value to be used as an anchor to phase the
96 * bins.*/
97 Q_PROPERTY(double lowerAnchorMz READ getLowerAnchorMz WRITE setLowerAnchorMz
99 /*$ JS PROP REF Greatetest m/z value to be used as an anchor to phase the
100 * bins.*/
104 NOTIFY binningTypeChanged)
105 Q_PROPERTY(int decimalPlaces READ getDecimalPlaces WRITE setDecimalPlaces
107 Q_PROPERTY(pappso::PrecisionPtr binSizeModel READ getBinSizeModel WRITE
109 Q_PROPERTY(int binSizeDivisor READ getBinSizeDivisor WRITE setBinSizeDivisor
113
114 QML_ELEMENT
115
116 public:
117 enum class BinningType
118 {
119 //! < no binning
120 NONE = 0,
121
122 //! binning based on mass spectral data
123 DATA_BASED,
124
125 //! binning based on arbitrary bin size value
126 ARBITRARY,
128 LAST,
129 };
132 enum class InitializationResult : uint32_t
134 // The order is important.
135 // See end of class declaration for overload of bitwise operators
136 DEFAULT = 0x000,
137 BINNING_TYPE = 1 << 0,
138 BIN_SIZE_MODEL = 1 << 1,
139 BIN_SIZE_DIVISOR = 1 << 2,
140 DECIMAL_PLACES = 1 << 3,
141 BINNING_LOGIC_PARTIAL = (BINNING_TYPE | BIN_SIZE_MODEL),
142 BINNING_LOGIC_FULL =
143 (BINNING_LOGIC_PARTIAL | BIN_SIZE_DIVISOR | DECIMAL_PLACES),
144 REMOVE_ZERO_DATA_POINTS = 1 << 4,
145 FULL = (REMOVE_ZERO_DATA_POINTS | BINNING_LOGIC_FULL),
146 };
147 Q_ENUM(InitializationResult)
148
149 Q_INVOKABLE explicit MzIntegrationParams(QObject *parent = nullptr);
150 Q_INVOKABLE explicit MzIntegrationParams(const QString &text,
151 QObject *parent = nullptr);
152 Q_INVOKABLE explicit MzIntegrationParams(double minMz,
153 double maxMz,
154 BinningType binningType,
155 pappso::PrecisionPtr precisionPtr,
156 int binSizeDivisor,
157 int decimalPlaces,
158 bool removeZeroValDataPoints,
159 QObject *parent = nullptr);
160 virtual ~MzIntegrationParams();
161
162 Q_INVOKABLE MzIntegrationParams *clone(QObject *parent = nullptr) const;
163
164 Q_INVOKABLE InitializationResult initialize(const QString &text);
165
166 Q_INVOKABLE void initialize(double minMz,
167 double maxMz,
168 BinningType binningType,
169 pappso::PrecisionPtr precisionPtr,
170 int binSizeDivisor,
171 int decimalPlaces,
172 bool removeZeroValDataPoints,
173 QObject *parent = nullptr);
174
175 void initialize(const MzIntegrationParams &other, QObject *parent = nullptr);
176 Q_INVOKABLE void initialize(const MzIntegrationParams *other_p,
177 QObject *parent = nullptr);
178
179 void initialize(MzIntegrationParams &other,
180 InitializationResult initialization_results);
181
182 Q_INVOKABLE void setSmallestMz(double value);
183 Q_INVOKABLE void updateSmallestMz(double value);
184 Q_INVOKABLE double getSmallestMz() const;
185
186 Q_INVOKABLE void setGreatestMz(double value);
187 Q_INVOKABLE void updateGreatestMz(double value);
188 Q_INVOKABLE double getGreatestMz() const;
189
190 Q_INVOKABLE void setLowerAnchorMz(double value);
191 Q_INVOKABLE void updateLowerAnchorMz(double value);
192 Q_INVOKABLE double getLowerAnchorMz() const;
193
194 Q_INVOKABLE void setUpperAnchorMz(double value);
195 Q_INVOKABLE void updateUpperAnchorMz(double value);
196 Q_INVOKABLE double getUpperAnchorMz() const;
197
198 Q_INVOKABLE void setMzValues(double smallest, double greatest);
199
200 Q_INVOKABLE void setBinningType(BinningType binningType);
201 Q_INVOKABLE BinningType getBinningType() const;
202
203 Q_INVOKABLE void setBinSizeModel(pappso::PrecisionPtr bin_size_model_p);
204 Q_INVOKABLE pappso::PrecisionPtr getBinSizeModel() const;
205
206 Q_INVOKABLE void setBinSizeDivisor(int divisor);
207 Q_INVOKABLE int getBinSizeDivisor() const;
208
209 Q_INVOKABLE void setDecimalPlaces(int decimal_places);
210 Q_INVOKABLE int getDecimalPlaces() const;
211
212 Q_INVOKABLE void setRemoveZeroValDataPoints(bool removeOrNot = true);
213 Q_INVOKABLE bool isRemoveZeroValDataPoints() const;
214
215 Q_INVOKABLE void reset();
216
217 Q_INVOKABLE bool isValid() const;
218
219 Q_INVOKABLE bool hasValidMzRange() const;
220
221 Q_INVOKABLE std::vector<double> createBins();
222 Q_INVOKABLE std::vector<double>
223 createBins(pappso::MassSpectrumCstSPtr mass_spectrum_csp);
224
225 Q_INVOKABLE QString toString(int offset, const QString &spacer = " ") const;
226 // The string below is used to recreate the MzIntegrationParams from string
227 Q_INVOKABLE QString toString() const;
228 Q_INVOKABLE QString
229 binsToStringWithDeltas(const std::vector<double> bins) const;
231 // # pragma message "This pragma is inside"
232 static void registerJsConstructor(QJSEngine *engine);
234 signals:
235 void smallestMzChanged();
236 void greatestMzChanged();
241 void binSizeModelChanged();
244
245 protected:
246 // That smallest value needs to be set to max, because it will be necessary
247 // compare any new m/z valut to it.
248 double m_smallestMz = std::numeric_limits<double>::max();
249
250 // That greatest value needs to be set to min, because it will be necessary
251 // compare any new m/z valut to it.
252 double m_greatestMz = std::numeric_limits<double>::min();
253
254 // The m/z value that will serve as an anchor point for the creation of the
255 // bins.
256 double m_lowerAnchorMz = std::numeric_limits<double>::max();
257 // The m/z value that will serve as an anchor point for the creation of the
258 // bins.
259 double m_upperAnchorMz = std::numeric_limits<double>::min();
260
261 ///////////// The binning size logic ///////////////////
262 ///////////// The binning size logic ///////////////////
263
267 // If one selects Res as the binning logic and sets a value of 40000, for
268 // example, that binning logic will create bins (that is, final m/z data
269 // points in the trace) apart of a delta of (m/z / 40000). But this interval
270 // does not make a fully profiled peak, it only governs the distance between
271 // two m/z adjacent values in the abscissae. Empirically, it takes between 5
272 // and 8 points to shape reasonably well a mass peak. This is what
273 // m_binSizeDivisor is about: divide the m/z delta computed using the m/z
274 // value and the res value by this divisor value reduces by such factor the
275 // distance between one m/z data point and the next in the abscissae. The
276 // effect of this is that there will be enough data points to craft a
277 // reasonably well shaped mass peak with a FWHM corresponding to Res.
278 int m_binSizeDivisor = 6;
279 // -1 means that there is no restriction on the number of digits after the
280 // decimal point. Upon integration, the bin size will be checked to determine
281 // the number of zero decimals it has (0.004 has two) and the number of
282 // decimals used will be that value plus 1 (3 decimals in the example).
283 int m_decimalPlaces = -1;
284
285 ///////////// The binning size logic ///////////////////
286 ///////////// The binning size logic ///////////////////
287
288 bool m_removeZeroValDataPoints = true;
289
290 std::vector<double> createArbitraryBins();
291 std::vector<double>
293 std::vector<double>
295};
296
297/* END CLASS JS REFERENCE
298 * namespace: pappso
299 * class name: MzIntegrationParams
300 */
301
302
303// Overload bitwise operators
307{
309 static_cast<uint32_t>(a) | static_cast<uint32_t>(b));
310}
311
315{
317 static_cast<uint32_t>(a) & static_cast<uint32_t>(b));
318}
319
327
328extern std::map<MzIntegrationParams::BinningType, QString> binningTypeMap;
330
331PAPPSO_REGISTER_JS_CLASS(pappso, MzIntegrationParams)
332
333} // namespace pappso
334
335/*
336Q_DECLARE_METATYPE(pappso::MzIntegrationParams);
337Q_DECLARE_METATYPE(pappso::MzIntegrationParams *);
338
339extern int mzIntegrationParamsMetaTypeId;
340extern int mzIntegrationParamsPtrMetaTypeId;*/
The MzIntegrationParams class provides the parameters definining how m/z integrations must be perform...
Q_INVOKABLE int getDecimalPlaces() const
Q_INVOKABLE MzIntegrationParams(QObject *parent=nullptr)
Q_INVOKABLE int getBinSizeDivisor() const
std::vector< double > createDataBasedBinsOld(pappso::MassSpectrumCstSPtr massSpectrum)
Q_INVOKABLE double getLowerAnchorMz() const
Q_INVOKABLE void setBinSizeModel(pappso::PrecisionPtr bin_size_model_p)
Q_INVOKABLE void setBinSizeDivisor(int divisor)
std::vector< double > createArbitraryBins()
pappso::PrecisionPtr binSizeModel
Q_INVOKABLE void setGreatestMz(double value)
Q_INVOKABLE void setSmallestMz(double value)
Q_INVOKABLE QString binsToStringWithDeltas(const std::vector< double > bins) const
Q_INVOKABLE bool isRemoveZeroValDataPoints() const
Q_INVOKABLE double getSmallestMz() const
pappso::PrecisionPtr m_binSizeModel
Q_INVOKABLE BinningType getBinningType() const
Q_INVOKABLE pappso::PrecisionPtr getBinSizeModel() const
@ ARBITRARY
binning based on arbitrary bin size value
static void registerJsConstructor(QJSEngine *engine)
Q_INVOKABLE QString toString(int offset, const QString &spacer=" ") const
Q_INVOKABLE void setBinningType(BinningType binningType)
std::vector< double > createDataBasedBins(pappso::MassSpectrumCstSPtr massSpectrum)
Q_INVOKABLE void setDecimalPlaces(int decimal_places)
Q_INVOKABLE void setRemoveZeroValDataPoints(bool removeOrNot=true)
Q_INVOKABLE double getGreatestMz() const
Q_INVOKABLE void setLowerAnchorMz(double value)
static PrecisionPtr getResInstance(pappso_double value)
get a resolution precision pointer
#define PMSPP_LIB_DECL
#define PAPPSO_REGISTER_JS_CLASS(NS_IDENT, CLASS_NAME)
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39
constexpr MzIntegrationParams::InitializationResult operator|=(MzIntegrationParams::InitializationResult &a, MzIntegrationParams::InitializationResult b)
MzIntegrationParams::BinningType getBinningTypeFromString(const QString &text)
std::map< MzIntegrationParams::BinningType, QString > binningTypeMap
Map relating the BinningType to a textual representation.
std::shared_ptr< const MassSpectrum > MassSpectrumCstSPtr
const PrecisionBase * PrecisionPtr
Definition precision.h:122
constexpr MzIntegrationParams::InitializationResult operator|(MzIntegrationParams::InitializationResult a, MzIntegrationParams::InitializationResult b)
constexpr MzIntegrationParams::InitializationResult operator&(MzIntegrationParams::InitializationResult a, MzIntegrationParams::InitializationResult b)