Line |
Branch |
Exec |
Source |
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 |
|
|
/////////////////////// Qt includes |
35 |
|
|
#include <QtGlobal> |
36 |
|
|
#include <QDebug> |
37 |
|
|
|
38 |
|
|
/////////////////////// Local includes |
39 |
|
|
#include "Ponderable.hpp" |
40 |
|
|
|
41 |
|
|
|
42 |
|
|
namespace MsXpS |
43 |
|
|
{ |
44 |
|
|
|
45 |
|
|
namespace libXpertMass |
46 |
|
|
{ |
47 |
|
|
|
48 |
|
|
/*! |
49 |
|
|
\class MsXpS::libXpertMass::Ponderable |
50 |
|
|
\inmodule libXpertMass |
51 |
|
|
\ingroup PolChemDefBuildingdBlocks |
52 |
|
|
\inheaderfile Ponderable.hpp |
53 |
|
|
|
54 |
|
|
\brief The Ponderable class provides an abstraction for any chemical entity |
55 |
|
|
having a monoisotopic and an average mass. |
56 |
|
|
|
57 |
|
|
Functions are provided to modify the member masses. |
58 |
|
|
|
59 |
|
|
\sa Modif, Monomer |
60 |
|
|
*/ |
61 |
|
|
|
62 |
|
|
|
63 |
|
|
/*! |
64 |
|
|
\variable MsXpS::libXpertMass::Ponderable::m_mono |
65 |
|
|
|
66 |
|
|
\brief The monoisotopic mass. |
67 |
|
|
*/ |
68 |
|
|
|
69 |
|
|
|
70 |
|
|
/*! |
71 |
|
|
\variable MsXpS::libXpertMass::Ponderable::m_avg |
72 |
|
|
|
73 |
|
|
\brief The average mass. |
74 |
|
|
*/ |
75 |
|
|
|
76 |
|
|
/*! |
77 |
|
|
\brief Constructs a ponderable initializing its masses with \a mono and |
78 |
|
|
\a avg. |
79 |
|
|
*/ |
80 |
|
51203 |
Ponderable::Ponderable(double mono, double avg) |
81 |
|
|
{ |
82 |
|
51203 |
m_mono = mono; |
83 |
|
51203 |
m_avg = avg; |
84 |
|
51203 |
} |
85 |
|
|
|
86 |
|
|
/*! |
87 |
|
|
\brief Constructs a ponderable initializing it using \a other. |
88 |
|
|
*/ |
89 |
|
2432 |
Ponderable::Ponderable(const Ponderable &other) |
90 |
|
2432 |
: m_mono(other.m_mono), m_avg(other.m_avg) |
91 |
|
|
{ |
92 |
|
2432 |
} |
93 |
|
|
|
94 |
|
|
/*! |
95 |
|
|
\brief Destructs the ponderable. |
96 |
|
|
*/ |
97 |
|
68830 |
Ponderable::~Ponderable() |
98 |
|
|
{ |
99 |
|
68830 |
} |
100 |
|
|
|
101 |
|
|
/*! |
102 |
|
|
\brief Assigns to this Ponderable' member data the values in \a |
103 |
|
|
other. |
104 |
|
|
|
105 |
|
|
Returns a reference to this Ponderable |
106 |
|
|
*/ |
107 |
|
|
Ponderable & |
108 |
|
30516 |
Ponderable::operator=(const Ponderable &other) |
109 |
|
|
{ |
110 |
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 30516 times.
|
30516 |
if(&other == this) |
111 |
|
✗ |
return *this; |
112 |
|
|
|
113 |
|
30516 |
m_mono = other.m_mono; |
114 |
|
30516 |
m_avg = other.m_avg; |
115 |
|
|
|
116 |
|
30516 |
return *this; |
117 |
|
|
} |
118 |
|
|
|
119 |
|
|
/*! |
120 |
|
|
\brief Initializes the member data using \a mono and \a avg. |
121 |
|
|
*/ |
122 |
|
|
void |
123 |
|
8 |
Ponderable::setMasses(double mono, double avg) |
124 |
|
|
{ |
125 |
|
8 |
m_mono = mono; |
126 |
|
8 |
m_avg = avg; |
127 |
|
8 |
} |
128 |
|
|
|
129 |
|
|
/*! |
130 |
|
|
\brief Initializes the member data using \a mass. |
131 |
|
|
|
132 |
|
|
The member datum that is initialized depends on the value of \a type. |
133 |
|
|
*/ |
134 |
|
|
void |
135 |
|
✗ |
Ponderable::setMass(double mass, MassType type) |
136 |
|
|
{ |
137 |
|
✗ |
if(type & MassType::MASS_MONO) |
138 |
|
✗ |
m_mono = mass; |
139 |
|
✗ |
else if(type & MassType::MASS_AVG) |
140 |
|
✗ |
m_avg = mass; |
141 |
|
|
|
142 |
|
✗ |
return; |
143 |
|
|
} |
144 |
|
|
|
145 |
|
|
/*! |
146 |
|
|
\brief Add to the member data the mass value in \a mass. |
147 |
|
|
|
148 |
|
|
The member datum that is modified depends on the value of \a type. |
149 |
|
|
*/ |
150 |
|
|
void |
151 |
|
8 |
Ponderable::incrementMass(double mass, MassType type) |
152 |
|
|
{ |
153 |
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
|
8 |
if(type & MassType::MASS_MONO) |
154 |
|
4 |
m_mono += mass; |
155 |
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 |
else if(type & MassType::MASS_AVG) |
156 |
|
4 |
m_avg += mass; |
157 |
|
|
|
158 |
|
8 |
return; |
159 |
|
|
} |
160 |
|
|
|
161 |
|
|
/*! |
162 |
|
|
\brief Add to the member data the mass value in \a mass. |
163 |
|
|
|
164 |
|
|
The member datum that is modified depends on the value of \a type. |
165 |
|
|
*/ |
166 |
|
|
void |
167 |
|
8 |
Ponderable::decrementMass(double mass, MassType type) |
168 |
|
|
{ |
169 |
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
|
8 |
if(type & MassType::MASS_MONO) |
170 |
|
4 |
m_mono -= mass; |
171 |
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 |
else if(type & MassType::MASS_AVG) |
172 |
|
4 |
m_avg -= mass; |
173 |
|
|
|
174 |
|
8 |
return; |
175 |
|
|
} |
176 |
|
|
|
177 |
|
|
/*! |
178 |
|
|
\brief Sets the \a mono and \a avg to the corresponding member data values. |
179 |
|
|
|
180 |
|
|
The pointer arguments cannot be nullptr. |
181 |
|
|
*/ |
182 |
|
|
void |
183 |
|
4 |
Ponderable::masses(double *mono, double *avg) const |
184 |
|
|
{ |
185 |
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
|
4 |
Q_ASSERT(mono != nullptr && avg != nullptr); |
186 |
|
|
|
187 |
|
4 |
*mono = m_mono; |
188 |
|
4 |
*avg = m_avg; |
189 |
|
4 |
} |
190 |
|
|
|
191 |
|
|
/*! |
192 |
|
|
\brief Returns the mass depending on the \a type. |
193 |
|
|
*/ |
194 |
|
|
double |
195 |
|
16 |
Ponderable::mass(MassType type) const |
196 |
|
|
{ |
197 |
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 8 times.
|
16 |
if(type == MassType::MASS_MONO) |
198 |
|
8 |
return m_mono; |
199 |
|
|
|
200 |
|
8 |
return m_avg; |
201 |
|
|
} |
202 |
|
|
|
203 |
|
|
/*! |
204 |
|
|
\brief Sets the member data masses to 0.0. |
205 |
|
|
*/ |
206 |
|
|
void |
207 |
|
4 |
Ponderable::clearMasses() |
208 |
|
|
{ |
209 |
|
4 |
m_mono = 0.0; |
210 |
|
4 |
m_avg = 0.0; |
211 |
|
4 |
} |
212 |
|
|
|
213 |
|
|
/*! |
214 |
|
|
\brief Sets the monoisotopic mass to \a mass. |
215 |
|
|
*/ |
216 |
|
|
void |
217 |
|
40 |
Ponderable::setMono(double mass) |
218 |
|
|
{ |
219 |
|
40 |
m_mono = mass; |
220 |
|
40 |
} |
221 |
|
|
|
222 |
|
|
/*! |
223 |
|
|
\brief Sets the monoisotopic mass to \a mass. |
224 |
|
|
|
225 |
|
|
The \a mass string is converted to double. |
226 |
|
|
|
227 |
|
|
Returns true if the conversion succceeded, false otherwise. |
228 |
|
|
*/ |
229 |
|
|
bool |
230 |
|
✗ |
Ponderable::setMono(const QString &mass) |
231 |
|
|
{ |
232 |
|
✗ |
bool ok = false; |
233 |
|
|
|
234 |
|
✗ |
double value = mass.toDouble(&ok); |
235 |
|
|
|
236 |
|
✗ |
if(!ok) |
237 |
|
✗ |
return false; |
238 |
|
|
|
239 |
|
✗ |
m_mono = value; |
240 |
|
|
|
241 |
|
✗ |
return true; |
242 |
|
|
} |
243 |
|
|
|
244 |
|
|
/*! |
245 |
|
|
\brief Increments the monoisotopic mass by adding \a mass. |
246 |
|
|
*/ |
247 |
|
|
void |
248 |
|
4 |
Ponderable::incrementMono(double mass) |
249 |
|
|
{ |
250 |
|
4 |
m_mono += mass; |
251 |
|
4 |
} |
252 |
|
|
|
253 |
|
|
/*! |
254 |
|
|
\brief Decrements the monoisotopic mass by subtracting \a mass. |
255 |
|
|
*/ |
256 |
|
|
void |
257 |
|
4 |
Ponderable::decrementMono(double mass) |
258 |
|
|
{ |
259 |
|
4 |
m_mono -= mass; |
260 |
|
4 |
} |
261 |
|
|
|
262 |
|
|
/*! |
263 |
|
|
\brief Returns the monoisotopic mass. |
264 |
|
|
*/ |
265 |
|
|
double |
266 |
|
316 |
Ponderable::mono() const |
267 |
|
|
{ |
268 |
|
316 |
return m_mono; |
269 |
|
|
} |
270 |
|
|
|
271 |
|
|
/*! |
272 |
|
|
\brief Returns a reference to the monoisotopic mass. |
273 |
|
|
*/ |
274 |
|
|
double & |
275 |
|
36 |
Ponderable::rmono() |
276 |
|
|
{ |
277 |
|
36 |
return m_mono; |
278 |
|
|
} |
279 |
|
|
|
280 |
|
|
/*! |
281 |
|
|
\brief Returns a string representing the monoisotopic mass using \a |
282 |
|
|
decimalPlaces for the precision. |
283 |
|
|
*/ |
284 |
|
|
QString |
285 |
|
32 |
Ponderable::monoString(int decimalPlaces) const |
286 |
|
|
{ |
287 |
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
|
32 |
if(decimalPlaces < 0) |
288 |
|
✗ |
decimalPlaces = 0; |
289 |
|
|
|
290 |
|
32 |
QString mass; |
291 |
1/2
✓ Branch 1 taken 32 times.
✗ Branch 2 not taken.
|
32 |
mass.setNum(m_mono, 'f', decimalPlaces); |
292 |
|
|
|
293 |
|
32 |
return mass; |
294 |
|
✗ |
} |
295 |
|
|
|
296 |
|
|
/*! |
297 |
|
|
\brief Sets the average mass to \a mass. |
298 |
|
|
*/ |
299 |
|
|
void |
300 |
|
40 |
Ponderable::setAvg(double mass) |
301 |
|
|
{ |
302 |
|
40 |
m_avg = mass; |
303 |
|
40 |
} |
304 |
|
|
|
305 |
|
|
/*! |
306 |
|
|
\brief Sets the average mass to \a mass. |
307 |
|
|
|
308 |
|
|
The \a mass string is converted to double. |
309 |
|
|
|
310 |
|
|
Returns true if the conversion succceeded, false otherwise. |
311 |
|
|
*/ |
312 |
|
|
bool |
313 |
|
✗ |
Ponderable::setAvg(const QString &mass) |
314 |
|
|
{ |
315 |
|
✗ |
bool ok = false; |
316 |
|
|
|
317 |
|
✗ |
double value = mass.toDouble(&ok); |
318 |
|
|
|
319 |
|
✗ |
if(!ok) |
320 |
|
✗ |
return false; |
321 |
|
|
|
322 |
|
✗ |
m_avg = value; |
323 |
|
|
|
324 |
|
✗ |
return true; |
325 |
|
|
} |
326 |
|
|
|
327 |
|
|
/*! |
328 |
|
|
\brief Increments the average mass by adding \a mass. |
329 |
|
|
*/ |
330 |
|
|
void |
331 |
|
4 |
Ponderable::incrementAvg(double mass) |
332 |
|
|
{ |
333 |
|
4 |
m_avg += mass; |
334 |
|
4 |
} |
335 |
|
|
|
336 |
|
|
/*! |
337 |
|
|
\brief Decrements the average mass by subtracting \a mass. |
338 |
|
|
*/ |
339 |
|
|
void |
340 |
|
4 |
Ponderable::decrementAvg(double mass) |
341 |
|
|
{ |
342 |
|
4 |
m_avg -= mass; |
343 |
|
4 |
} |
344 |
|
|
|
345 |
|
|
/*! |
346 |
|
|
\brief Returns the average mass. |
347 |
|
|
*/ |
348 |
|
|
double |
349 |
|
316 |
Ponderable::avg() const |
350 |
|
|
{ |
351 |
|
316 |
return m_avg; |
352 |
|
|
} |
353 |
|
|
|
354 |
|
|
/*! |
355 |
|
|
\brief Returns a reference to the average mass. |
356 |
|
|
*/ |
357 |
|
|
double & |
358 |
|
36 |
Ponderable::ravg() |
359 |
|
|
{ |
360 |
|
36 |
return m_avg; |
361 |
|
|
} |
362 |
|
|
|
363 |
|
|
/*! |
364 |
|
|
\brief Returns a string representing the average mass using \a |
365 |
|
|
decimalPlaces for the precision. |
366 |
|
|
*/ |
367 |
|
|
QString |
368 |
|
32 |
Ponderable::avgString(int decimalPlaces) const |
369 |
|
|
{ |
370 |
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
|
32 |
if(decimalPlaces < 0) |
371 |
|
✗ |
decimalPlaces = 0; |
372 |
|
|
|
373 |
|
32 |
QString mass; |
374 |
1/2
✓ Branch 1 taken 32 times.
✗ Branch 2 not taken.
|
32 |
mass.setNum(m_avg, 'f', decimalPlaces); |
375 |
|
|
|
376 |
|
32 |
return mass; |
377 |
|
✗ |
} |
378 |
|
|
|
379 |
|
|
/*! |
380 |
|
|
Returns true if \a other and this ponderable have the same masses, false |
381 |
|
|
otherwise. |
382 |
|
|
*/ |
383 |
|
|
bool |
384 |
|
2672 |
Ponderable::operator==(const Ponderable &other) const |
385 |
|
|
{ |
386 |
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2672 times.
|
2672 |
if(&other == this) |
387 |
|
✗ |
return true; |
388 |
|
|
|
389 |
3/4
✓ Branch 0 taken 2608 times.
✓ Branch 1 taken 64 times.
✓ Branch 2 taken 2608 times.
✗ Branch 3 not taken.
|
2672 |
return (m_mono == other.m_mono && m_avg == other.m_avg); |
390 |
|
|
} |
391 |
|
|
|
392 |
|
|
/*! |
393 |
|
|
Returns true if \a other and this ponderable have at least one differing mass, |
394 |
|
|
false otherwise. |
395 |
|
|
*/ |
396 |
|
|
bool |
397 |
|
2672 |
Ponderable::operator!=(const Ponderable &other) const |
398 |
|
|
{ |
399 |
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2672 times.
|
2672 |
if(&other == this) |
400 |
|
✗ |
return false; |
401 |
|
|
|
402 |
|
2672 |
return !operator==(other); |
403 |
|
|
} |
404 |
|
|
|
405 |
|
|
|
406 |
|
|
bool |
407 |
|
✗ |
Ponderable::calculateMasses() |
408 |
|
|
{ |
409 |
|
✗ |
return true; |
410 |
|
|
} |
411 |
|
|
|
412 |
|
|
/*! |
413 |
|
|
\brief Increases \a mono and \a avg by the corresponding member masses first |
414 |
|
|
compounded by \a times. |
415 |
|
|
|
416 |
|
|
Always returns true. |
417 |
|
|
*/ |
418 |
|
|
bool |
419 |
|
4 |
Ponderable::accountMasses(double *mono, double *avg, int times) const |
420 |
|
|
{ |
421 |
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 |
Q_ASSERT(mono != nullptr); |
422 |
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 |
Q_ASSERT(avg != nullptr); |
423 |
|
|
|
424 |
|
4 |
*mono += m_mono * times; |
425 |
|
4 |
*avg += m_avg * times; |
426 |
|
|
|
427 |
|
4 |
return true; |
428 |
|
|
} |
429 |
|
|
|
430 |
|
|
} // namespace libXpertMass |
431 |
|
|
|
432 |
|
|
} // namespace MsXpS |
433 |
|
|
|