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
43
44/////////////////////// Local includes
48
49namespace pappso
50{
51
52/*! The MzIntegrationParams class provides the parameters definining how m/z
53 * integrations must be performed.
54 *
55 * Depending on the various mass spectrometer vendors, the mass spectrometry
56 * data files are structured in different ways and the software for mass data
57 * format conversion from raw files to mzML or mzXML produce mass data
58 * characterized by different behaviours.
59 *
60 * The different characteristics of mass spectrometry data set are:
61 *
62 * The size of the various mass spectra in the file is constant or variable;
63 *
64 * The first m/z value of the various spectra is identical or not (that is,
65 * the spectra are root in a constant or variable root m/z value);
66 *
67 * The m/z delta between two consecutive m/z values of a given spectrum are
68 * constant or variable;
69 *
70 * The spectra contain or not 0-value m/z data points;
71 */
72
74{
75 Q_OBJECT
76
77 public:
78 enum class BinningType
79 {
80 //! < no binning
81 NONE = 0,
82
83 //! binning based on mass spectral data
84 DATA_BASED,
85
86 //! binning based on arbitrary bin size value
87 ARBITRARY,
88
89 LAST,
90 };
91 Q_ENUM(BinningType)
92
93 enum class InitializationResult : uint32_t
94 {
95 // The order is important.
96 // See end of class declaration for overload of bitwise operators
97 DEFAULT = 0x000,
98 BINNING_TYPE = 1 << 0,
99 BIN_SIZE_MODEL = 1 << 1,
100 BIN_SIZE_DIVISOR = 1 << 2,
101 DECIMAL_PLACES = 1 << 3,
102 BINNING_LOGIC_PARTIAL = (BINNING_TYPE | BIN_SIZE_MODEL),
103 BINNING_LOGIC_FULL =
104 (BINNING_LOGIC_PARTIAL | BIN_SIZE_DIVISOR | DECIMAL_PLACES),
105 REMOVE_ZERO_DATA_POINTS = 1 << 4,
106 FULL = (REMOVE_ZERO_DATA_POINTS | BINNING_LOGIC_FULL),
107 };
108 Q_ENUM(InitializationResult)
109
110 explicit MzIntegrationParams(QObject *parent = nullptr);
111 explicit MzIntegrationParams(const QString &text, QObject *parent = nullptr);
112 explicit MzIntegrationParams(double minMz,
113 double maxMz,
114 BinningType binningType,
115 pappso::PrecisionPtr precisionPtr,
116 int binSizeDivisor,
117 int decimalPlaces,
118 bool removeZeroValDataPoints,
119 QObject *parent = nullptr);
120 virtual ~MzIntegrationParams();
121
122 MzIntegrationParams *clone(QObject *parent = nullptr) const;
123
124 InitializationResult initialize(const QString &text);
125
126 void initialize(double minMz,
127 double maxMz,
128 BinningType binningType,
129 pappso::PrecisionPtr precisionPtr,
130 int binSizeDivisor,
131 int decimalPlaces,
132 bool removeZeroValDataPoints,
133 QObject *parent = nullptr);
134
135 void initialize(const MzIntegrationParams &other, QObject *parent = nullptr);
136 void initialize(const MzIntegrationParams *other_p, QObject *parent = nullptr);
137
138 void initialize(MzIntegrationParams &other,
139 InitializationResult initialization_results);
140
141 void setSmallestMz(double value);
142 void updateSmallestMz(double value);
143 double getSmallestMz() const;
144
145 void setGreatestMz(double value);
146 void updateGreatestMz(double value);
147 double getGreatestMz() const;
148
149 void setMzValues(double smallest, double greatest);
150
151 void setBinningType(BinningType binningType);
152 BinningType getBinningType() const;
153
154 void setBinSizeModel(pappso::PrecisionPtr bin_size_model_p);
155 pappso::PrecisionPtr getBinSizeModel() const;
156
157 void setBinSizeDivisor(int divisor);
158 int getBinSizeDivisor() const;
159
160 void setIndicativeBinSize(double value);
161 double getIndicativeBinSize() const;
162
163 void setDecimalPlaces(int decimal_places);
164 int getDecimalPlaces() const;
165
166 void setRemoveZeroValDataPoints(bool removeOrNot = true);
167 bool isRemoveZeroValDataPoints() const;
168
169 void reset();
170
171 bool isValid() const;
172
173 bool hasValidMzRange() const;
174
175 std::vector<double> createBins();
176 std::vector<double> createBins(pappso::MassSpectrumCstSPtr mass_spectrum_csp);
177
178 QString toString(int offset, const QString &spacer = " ") const;
179 // The string below is used to recreate the MzIntegrationParams from string
180 QString toString() const;
181 QString binsToStringWithDeltas(const std::vector<double> bins) const;
182
183 signals:
192
193 protected:
194 // That smallest value needs to be set to max, because it will be necessary
195 // compare any new m/z valut to it.
196 double m_smallestMz = std::numeric_limits<double>::max();
197
198 // That greatest value needs to be set to min, because it will be necessary
199 // compare any new m/z valut to it.
200 double m_greatestMz = std::numeric_limits<double>::min();
201
202 ///////////// The binning size logic ///////////////////
203 ///////////// The binning size logic ///////////////////
204
206
210 // If one selects Res as the binning logic and sets a value of 40000, for
211 // example, that binning logic will create bins (that is, final m/z data
212 // points in the trace) apart of a delta of (m/z / 40000). But this interval
213 // does not make a fully profiled peak, it only governs the distance between
214 // two m/z adjacent values in the abscissae. Empirically, it takes between 5
215 // and 8 points to shape reasonably well a mass peak. This is what
216 // m_binSizeDivisor is about: divide the m/z delta computed using the m/z
217 // value and the res value by this divisor value reduces by such factor the
218 // distance between one m/z data point and the next in the abscissae. The
219 // effect of this is that there will be enough data points to craft a
220 // reasonably well shaped mass peak with a FWHM corresponding to Res.
222 // -1 means that there is no restriction on the number of digits after the
223 // decimal point. Upon integration, the bin size will be checked to determine
224 // the number of zero decimals it has (0.004 has two) and the number of
225 // decimals used will be that value plus 1 (3 decimals in the example).
227
228 ///////////// The binning size logic ///////////////////
229 ///////////// The binning size logic ///////////////////
230
232
233 std::vector<double> createArbitraryBins();
234 std::vector<double>
236 std::vector<double>
238};
239
240
241// Overload bitwise operators
245{
247 static_cast<uint32_t>(a) | static_cast<uint32_t>(b));
248}
249
253{
255 static_cast<uint32_t>(a) & static_cast<uint32_t>(b));
256}
257
265
266extern std::map<MzIntegrationParams::BinningType, QString> binningTypeMap;
268
269} // namespace pappso
The MzIntegrationParams class provides the parameters definining how m/z integrations must be perform...
MzIntegrationParams(QObject *parent=nullptr)
std::vector< double > createDataBasedBinsOld(pappso::MassSpectrumCstSPtr massSpectrum)
std::vector< double > createArbitraryBins()
pappso::PrecisionPtr m_binSizeModel
@ ARBITRARY
binning based on arbitrary bin size value
std::vector< double > createDataBasedBins(pappso::MassSpectrumCstSPtr massSpectrum)
static PrecisionPtr getResInstance(pappso_double value)
get a resolution precision pointer
#define PMSPP_LIB_DECL
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)