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 greatestMzChanged)
100 Q_PROPERTY(pappso::PrecisionPtr binSizeModel READ getBinSizeModel WRITE
102 Q_PROPERTY(int binSizeDivisor READ getBinSizeDivisor WRITE setBinSizeDivisor
104 Q_PROPERTY(bool removeZeroValDataPoints READ isRemoveZeroValDataPoints WRITE
107 QML_ELEMENT
108
109 public:
110 enum class BinningType
111 {
112 //! < no binning
113 NONE = 0,
115 //! binning based on mass spectral data
116 DATA_BASED,
117
118 //! binning based on arbitrary bin size value
119 ARBITRARY,
120
121 LAST,
122 };
125 enum class InitializationResult : uint32_t
127 // The order is important.
128 // See end of class declaration for overload of bitwise operators
129 DEFAULT = 0x000,
130 BINNING_TYPE = 1 << 0,
131 BIN_SIZE_MODEL = 1 << 1,
132 BIN_SIZE_DIVISOR = 1 << 2,
133 DECIMAL_PLACES = 1 << 3,
134 BINNING_LOGIC_PARTIAL = (BINNING_TYPE | BIN_SIZE_MODEL),
135 BINNING_LOGIC_FULL =
136 (BINNING_LOGIC_PARTIAL | BIN_SIZE_DIVISOR | DECIMAL_PLACES),
137 REMOVE_ZERO_DATA_POINTS = 1 << 4,
138 FULL = (REMOVE_ZERO_DATA_POINTS | BINNING_LOGIC_FULL),
139 };
140 Q_ENUM(InitializationResult)
141
142 Q_INVOKABLE explicit MzIntegrationParams(QObject *parent = nullptr);
143 Q_INVOKABLE explicit MzIntegrationParams(const QString &text,
144 QObject *parent = nullptr);
145 Q_INVOKABLE explicit MzIntegrationParams(double minMz,
146 double maxMz,
147 BinningType binningType,
148 pappso::PrecisionPtr precisionPtr,
149 int binSizeDivisor,
150 int decimalPlaces,
151 bool removeZeroValDataPoints,
152 QObject *parent = nullptr);
153 virtual ~MzIntegrationParams();
154
155 Q_INVOKABLE MzIntegrationParams *clone(QObject *parent = nullptr) const;
156
157 Q_INVOKABLE InitializationResult initialize(const QString &text);
158
159 Q_INVOKABLE void initialize(double minMz,
160 double maxMz,
161 BinningType binningType,
162 pappso::PrecisionPtr precisionPtr,
163 int binSizeDivisor,
164 int decimalPlaces,
165 bool removeZeroValDataPoints,
166 QObject *parent = nullptr);
167
168 void initialize(const MzIntegrationParams &other, QObject *parent = nullptr);
169 Q_INVOKABLE void initialize(const MzIntegrationParams *other_p,
170 QObject *parent = nullptr);
171
172 void initialize(MzIntegrationParams &other,
173 InitializationResult initialization_results);
174
175 Q_INVOKABLE void setSmallestMz(double value);
176 Q_INVOKABLE void updateSmallestMz(double value);
177 Q_INVOKABLE double getSmallestMz() const;
178
179 Q_INVOKABLE void setGreatestMz(double value);
180 Q_INVOKABLE void updateGreatestMz(double value);
181 Q_INVOKABLE double getGreatestMz() const;
182
183 Q_INVOKABLE void setMzValues(double smallest, double greatest);
184
185 Q_INVOKABLE void setBinningType(BinningType binningType);
186 Q_INVOKABLE BinningType getBinningType() const;
187
188 Q_INVOKABLE void setBinSizeModel(pappso::PrecisionPtr bin_size_model_p);
189 Q_INVOKABLE pappso::PrecisionPtr getBinSizeModel() const;
190
191 Q_INVOKABLE void setBinSizeDivisor(int divisor);
192 Q_INVOKABLE int getBinSizeDivisor() const;
193
194 Q_INVOKABLE void setIndicativeBinSize(double value);
195 Q_INVOKABLE double getIndicativeBinSize() const;
196
197 Q_INVOKABLE void setDecimalPlaces(int decimal_places);
198 Q_INVOKABLE int getDecimalPlaces() const;
199
200 Q_INVOKABLE void setRemoveZeroValDataPoints(bool removeOrNot = true);
201 Q_INVOKABLE bool isRemoveZeroValDataPoints() const;
202
203 Q_INVOKABLE void reset();
204
205 Q_INVOKABLE bool isValid() const;
206
207 Q_INVOKABLE bool hasValidMzRange() const;
208
209 Q_INVOKABLE std::vector<double> createBins();
210 Q_INVOKABLE std::vector<double>
211 createBins(pappso::MassSpectrumCstSPtr mass_spectrum_csp);
212
213 Q_INVOKABLE QString toString(int offset, const QString &spacer = " ") const;
214 // The string below is used to recreate the MzIntegrationParams from string
215 Q_INVOKABLE QString toString() const;
216 Q_INVOKABLE QString
217 binsToStringWithDeltas(const std::vector<double> bins) const;
219 // # pragma message "This pragma is inside"
220 static void registerJsConstructor(QJSEngine *engine);
222 signals:
224 void greatestMzChanged();
225 void binningTypeChanged();
231
232 protected:
233 // That smallest value needs to be set to max, because it will be necessary
234 // compare any new m/z valut to it.
235 double m_smallestMz = std::numeric_limits<double>::max();
236
237 // That greatest value needs to be set to min, because it will be necessary
238 // compare any new m/z valut to it.
239 double m_greatestMz = std::numeric_limits<double>::min();
241 ///////////// The binning size logic ///////////////////
242 ///////////// The binning size logic ///////////////////
243
244 double m_indicativeBinSize = 0;
245
249 // If one selects Res as the binning logic and sets a value of 40000, for
250 // example, that binning logic will create bins (that is, final m/z data
251 // points in the trace) apart of a delta of (m/z / 40000). But this interval
252 // does not make a fully profiled peak, it only governs the distance between
253 // two m/z adjacent values in the abscissae. Empirically, it takes between 5
254 // and 8 points to shape reasonably well a mass peak. This is what
255 // m_binSizeDivisor is about: divide the m/z delta computed using the m/z
256 // value and the res value by this divisor value reduces by such factor the
257 // distance between one m/z data point and the next in the abscissae. The
258 // effect of this is that there will be enough data points to craft a
259 // reasonably well shaped mass peak with a FWHM corresponding to Res.
260 int m_binSizeDivisor = 6;
261 // -1 means that there is no restriction on the number of digits after the
262 // decimal point. Upon integration, the bin size will be checked to determine
263 // the number of zero decimals it has (0.004 has two) and the number of
264 // decimals used will be that value plus 1 (3 decimals in the example).
265 int m_decimalPlaces = -1;
266
267 ///////////// The binning size logic ///////////////////
268 ///////////// The binning size logic ///////////////////
269
270 bool m_removeZeroValDataPoints = true;
271
272 std::vector<double> createArbitraryBins();
273 std::vector<double>
275 std::vector<double>
277};
278
279/* END CLASS JS REFERENCE
280 * namespace: pappso
281 * class name: MzIntegrationParams
282 */
283
284
285// Overload bitwise operators
289{
291 static_cast<uint32_t>(a) | static_cast<uint32_t>(b));
292}
293
297{
299 static_cast<uint32_t>(a) & static_cast<uint32_t>(b));
300}
301
309
310extern std::map<MzIntegrationParams::BinningType, QString> binningTypeMap;
312
313PAPPSO_REGISTER_JS_CLASS(pappso, MzIntegrationParams)
314
315} // namespace pappso
316
317/*
318Q_DECLARE_METATYPE(pappso::MzIntegrationParams);
319Q_DECLARE_METATYPE(pappso::MzIntegrationParams *);
320
321extern int mzIntegrationParamsMetaTypeId;
322extern 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
Q_INVOKABLE void setIndicativeBinSize(double value)
std::vector< double > createDataBasedBinsOld(pappso::MassSpectrumCstSPtr massSpectrum)
Q_INVOKABLE void setBinSizeModel(pappso::PrecisionPtr bin_size_model_p)
Q_INVOKABLE void setBinSizeDivisor(int divisor)
std::vector< double > createArbitraryBins()
Q_INVOKABLE double getIndicativeBinSize() const
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 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
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)