GCC Code Coverage Report


./
File: src/XpertMass/CalcOptions.cpp
Date: 2024-08-24 11:26:06
Lines:
30/93
32.3%
Functions:
10/21
47.6%
Branches:
4/78
5.1%

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 <QChar>
36 #include <QDebug>
37 #include <QString>
38
39
40 /////////////////////// Local includes
41 #include "CalcOptions.hpp"
42
43
44 namespace MsXpS
45 {
46
47 namespace libXpertMass
48 {
49
50
51 /*!
52 \class MsXpS::libXpertMass::CalcOptions
53 \inmodule libXpertMass
54 \ingroup XpertMassMassCalculations
55 \inheaderfile CalcOptions.hpp
56
57 \brief The CalcOptions class provides the specifications that
58 configure the way masses are calculated for \l{Oligomer}s, \l{Polymer}s and
59 product ions.
60 */
61
62 /*!
63 \variable MsXpS::libXpertMass::CalcOptions::m_deepCalculation
64
65 \brief Tells if the calculations must involve the recalculation of all
66 the masses of the \l{Monomer}s in the sequence.
67 */
68
69 /*!
70 \variable MsXpS::libXpertMass::CalcOptions::m_coordinateList
71
72 \brief The list of Coordinates.
73 */
74
75 /*!
76 \variable MsXpS::libXpertMass::CalcOptions::m_massType
77
78 \brief The mass type, monoisotopic or average to compute.
79
80 \sa MassType
81 */
82
83 /*!
84 \variable MsXpS::libXpertMass::CalcOptions::m_capping
85
86 \brief The cap type, left or right to account for in the calculations.
87
88 \sa CapType
89 */
90
91 /*!
92 \variable MsXpS::libXpertMass::CalcOptions::m_monomerEntities
93
94 \brief The \l Monomer entities to account for in the calculations.
95
96 \sa MonomerChemEnt
97 */
98
99 /*!
100 \variable MsXpS::libXpertMass::CalcOptions::m_polymerEntities
101
102 \brief The \l Polymer entities to account for in the calculations.
103
104 \sa PolymerChemEnt
105 */
106
107 /*!
108 \variable MsXpS::libXpertMass::CalcOptions::m_selectionType
109
110 \brief The manner the monomers need to be accounted for: as residual chains
111 or as finished-polymerization state \l{Oligomer}s.
112
113 The calculations might consider only the residual chain. In that case, only
114 the mass of the monomers is considered and then the polymer is not in its
115 finished polymerization state. If that latter state is required, then, the
116 residual chain must be capped with the left end cap and the right end cap.
117
118 \sa MsXpS::libXpertMass::SelectionType
119 */
120
121 /*!
122 \brief Constructs a CalcOptions instance.
123 */
124 CalcOptions::CalcOptions()
125 {
126 m_deepCalculation = false;
127 m_massType = MassType::MASS_BOTH;
128 m_capping = CAP_BOTH;
129 m_monomerEntities = MONOMER_CHEMENT_NONE;
130 m_polymerEntities = POLYMER_CHEMENT_NONE;
131 }
132
133 /*!
134 \brief Constructs a CalcOptions instance.
135
136 All the members are initialized using the parameters:
137
138 \a deepCalculation: m_deepCalculation
139
140 \a massType: m_massType
141
142 \a capping: m_capping
143
144 \a monomerEntities: m_monomerEntities
145
146 \a polymerEntities: m_polymerEntities
147 */
148 72 CalcOptions::CalcOptions(bool deepCalculation,
149 int massType,
150 int capping,
151 int monomerEntities,
152 72 int polymerEntities)
153 72 : m_deepCalculation(deepCalculation),
154 72 m_massType(massType),
155 72 m_capping(capping),
156 72 m_monomerEntities(monomerEntities),
157
1/2
✓ Branch 2 taken 72 times.
✗ Branch 3 not taken.
72 m_polymerEntities(polymerEntities)
158 {
159 72 }
160
161 /*!
162 \brief Construct a CalcOptions instance as a copy of \a other.
163 */
164 CalcOptions::CalcOptions(const CalcOptions &other)
165 : m_deepCalculation(other.m_deepCalculation),
166 m_coordinateList(other.m_coordinateList),
167 m_massType(other.m_massType),
168 m_capping(other.m_capping),
169 m_monomerEntities(other.m_monomerEntities),
170 m_polymerEntities(other.m_polymerEntities),
171 m_selectionType(other.m_selectionType)
172 {
173 }
174
175
176 /*!
177 \brief Destructs this CalcOptions object.
178
179 All the Coordinates in the member CoordinateList are deleted.
180 */
181 72 CalcOptions::~CalcOptions()
182 {
183 // Free all the coordinates from the list.
184
2/2
✓ Branch 1 taken 72 times.
✓ Branch 2 taken 72 times.
216 while(!m_coordinateList.isEmpty())
185
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 72 times.
72 delete(m_coordinateList.takeFirst());
186 72 }
187
188
189 /*!
190 \brief Assigns \a other to this CalcOptions instance.
191
192 The copy is deep, with all the Coordinates in the \a{other}'s CoordinateList
193 being copied to this CalcOptions instance.
194
195 Returns a reference to this CalcOptions object.
196 */
197
198 CalcOptions &
199 CalcOptions::operator=(const CalcOptions &other)
200 {
201 if(&other == this)
202 return *this;
203
204 m_deepCalculation = other.m_deepCalculation;
205 m_massType = other.m_massType;
206 m_capping = other.m_capping;
207 m_monomerEntities = other.m_monomerEntities;
208 m_polymerEntities = other.m_polymerEntities;
209
210 m_coordinateList.empty();
211 setCoordinateList(other.m_coordinateList);
212
213 setSelectionType(other.m_selectionType);
214
215 return *this;
216 }
217
218 /*!
219 \brief Sets to \a deep the configuration defining if the mass calculations must
220 involve the recalculation of the masses of all the monomers.
221
222 \sa m_deepCalculation
223 */
224 void
225 CalcOptions::setDeepCalculation(bool deep)
226 {
227 m_deepCalculation = deep;
228 }
229
230
231 //! Returns if the calculation is deep.
232 /*!
233 \brief Returns if the calculation should be deep.
234
235 \sa m_deepCalculation
236 */
237 bool
238 5544 CalcOptions::isDeepCalculation() const
239 {
240 5544 return m_deepCalculation;
241 }
242
243 /*!
244 \brief Adds a copy of \a coordinates to the CoordinateList.
245
246 \note The CoordinateList' is first emptied,
247 essentially replacing its contents with a copy of \a coordinates.
248 */
249 void
250 CalcOptions::setCoordinateList(const Coordinates &coordinates)
251 {
252 m_coordinateList.setCoordinates(coordinates);
253 }
254
255 /*!
256 \brief Allocates a copy of each Coordinates instance in \a list and adds
257 it to the CoordinateList.
258
259 \note The CoordinateList is first emptied, essentially replacing its contents
260 with a copy of those in \a list.
261 */
262 void
263 72 CalcOptions::setCoordinateList(const CoordinateList &list)
264 {
265 72 m_coordinateList.setCoordinates(list);
266 72 }
267
268 /*!
269 \brief Returns the CoordinateList member.
270 */
271 const CoordinateList &
272 368 CalcOptions::coordinateList() const
273 {
274 368 return m_coordinateList;
275 }
276
277 /*!
278 \brief Sets the mass type to \a mass_type.
279
280 \sa m_massType
281 */
282 void
283 CalcOptions::setMassType(int mass_type)
284 {
285 m_massType = mass_type;
286 }
287
288
289 /*!
290 \brief Returns the mass type.
291
292 \sa m_massType
293 */
294 int
295 CalcOptions::massType() const
296 {
297 return m_massType;
298 }
299
300 /*!
301 \brief Set the selection type to \a type.
302
303 \sa m_selectionType
304 */
305 void
306 40 CalcOptions::setSelectionType(SelectionType type)
307 {
308 40 m_selectionType = type;
309 40 }
310
311 /*!
312 \brief Returns the selection type.
313
314 \sa m_selectionType
315 */
316 SelectionType
317 72 CalcOptions::selectionType() const
318 {
319 72 return m_selectionType;
320 }
321
322 /*!
323 \brief Set the cap type to \a cap_type.
324
325 \sa m_capping
326 */
327 void
328 CalcOptions::setCapping(int cap_type)
329 {
330 m_capping = cap_type;
331 }
332
333 /*!
334 \brief Returns the cap type .
335
336 \sa m_capping
337 */
338 int
339 144 CalcOptions::capping() const
340 {
341 144 return m_capping;
342 }
343
344 /*!
345 \brief Sets the monomer entities to \a entities.
346
347 \sa m_monomerEntities
348 */
349 void
350 CalcOptions::setMonomerEntities(int entities)
351 {
352 m_monomerEntities = entities;
353 }
354
355
356 /*!
357 \brief Returns the monomer entities.
358
359 \sa m_monomerEntities
360 */
361 int
362 752 CalcOptions::monomerEntities() const
363 {
364 752 return m_monomerEntities;
365 }
366
367
368 /*!
369 \brief Sets the polymer entities to \a entities.
370
371 \sa m_polymerEntities
372 */
373 void
374 CalcOptions::setPolymerEntities(int entities)
375 {
376 m_polymerEntities = entities;
377 }
378
379 /*!
380 \brief Returns the polymer entities.
381
382 \sa m_polymerEntities
383 */
384 int
385 204 CalcOptions::polymerEntities() const
386 {
387 204 return m_polymerEntities;
388 }
389
390 /*!
391 \brief Outputs a string describing this CalcOptions instance using qDebug().
392 */
393 void
394 CalcOptions::debugPutStdErr() const
395 {
396 qDebug() << "\n~~~~~~~~~~~~~~CalcOptions instance:\n"
397 << this << "\n"
398 << "m_deepCalculation:" << m_deepCalculation << "\n"
399 << "m_coordinateList: \n";
400
401 for(int iter = 0; iter < m_coordinateList.size(); ++iter)
402 {
403 Coordinates *coord = m_coordinateList.at(iter);
404 qDebug() << "Iterated Coordinates at index" << iter << ":"
405 << "[" << coord->start() << "-" << coord->end() << "]\n";
406 }
407
408 qDebug() << "m_capping:" << m_capping << "\n"
409 << "m_monomerEntities:" << m_monomerEntities << "\n"
410 << "m_polymerEntities:" << m_polymerEntities << "\n"
411 << "m_selectionType:" << m_selectionType << "\n"
412 << "~~~~~~~~~~~~~~\n";
413 }
414
415 } // namespace libXpertMass
416
417 } // namespace MsXpS
418