GCC Code Coverage Report


source/XpertMassCore/src/
File: source/XpertMassCore/src/CrossLinkedRegion.cpp
Date: 2025-11-20 01:41:33
Lines:
48/63
76.2%
Functions:
13/15
86.7%
Branches:
9/48
18.8%

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 /////////////////////// Local includes
35 #include "MsXpS/libXpertMassCore/CrossLinkedRegion.hpp"
36
37
38 namespace MsXpS
39 {
40 namespace libXpertMassCore
41 {
42
43
44 // [3] [4] [5] [6] [9] [11]
45 // o---o---o---o---o--o---o---o---o---o---o---o---o---o---o
46 // | |__| | | | | |
47 // | +-----------+ +-------+
48 // | |
49 // +------------------+
50 //
51 //
52 // In the example above, there are two cross-linked regions: [3--9]
53 // and [11--13].
54
55
56 /*!
57 \class MsXpS::libXpertMassCore::CrossLinkedRegion
58 \inmodule libXpertMassCore
59 \ingroup PolChemDefAqueousChemicalReactions
60 \inheaderfile CrossLinkedRegion.hpp
61
62 \brief The CrossLinkedRegion class provides abstractions to work with
63 cross-links and detect the region of oligomers that are linked together.
64
65 In the following representation, a polymer sequence has a number of CrossLink
66 instances that are intertwined:
67
68 \code
69
70 [3] [4] [5] [6] [9] [11] [13]
71 o---o---o---o---o--o---o---o---o---o---o---o---o---o---o
72 | |__| | | | | |
73 | +-----------+ +-------+
74 | |
75 +------------------+
76
77 \endcode
78
79 In this example, there are two cross-linked regions: [3--9]
80 and [11--13].
81
82 The first cross-linked region has a start index of 3 and a stop index of 9 and
83 involves three cross-links.
84
85 The second cross-linked region only involves a single cross-link involving two
86 monomers at indices 11 and 13.
87
88 This class is most useful when performing fragmentations of Oligomer instances.
89 */
90
91 /*!
92 \variable MsXpS::libXpertMassCore::CrossLinkedRegion::m_startIndex
93
94 \brief The start index of this cross-linked region.
95 */
96
97 /*!
98 \variable MsXpS::libXpertMassCore::CrossLinkedRegion::m_stopIndex
99
100 \brief The stop index of this cross-linked region.
101 */
102
103 /*!
104 \variable MsXpS::libXpertMassCore::CrossLinkedRegion::m_crossLinks
105
106 \brief The CrossLink instances that are contained in this CrossLinkedRegion
107 instance.
108 */
109
110
111 /*!
112 \brief
113 */
114 2 CrossLinkedRegion::CrossLinkedRegion()
115 {
116 2 m_startIndex = 0;
117 2 m_stopIndex = 0;
118 2 }
119
120 /*!
121 \brief Constructs a CrossLinkedRegion instance with indices \a index_start and
122 \a index_stop.
123 */
124 3 CrossLinkedRegion::CrossLinkedRegion(std::size_t index_start,
125 3 std::size_t index_stop)
126 {
127 3 m_startIndex = index_start;
128 3 m_stopIndex = index_stop;
129 3 }
130
131 /*!
132 \brief Constructs a CrossLinkedRegion instance as a copy of \a other.
133
134 The copy of the CrossLink instances is shallow (the shared pointers are copied).
135 */
136 CrossLinkedRegion::CrossLinkedRegion(const CrossLinkedRegion &other)
137 : m_startIndex(other.m_startIndex),
138 m_stopIndex(other.m_stopIndex),
139 m_crossLinks(other.m_crossLinks)
140 {
141 }
142
143 /*!
144 \brief Destructs a CrossLinkedRegion instance.
145 */
146 5 CrossLinkedRegion::~CrossLinkedRegion()
147 {
148 5 }
149
150 /*!
151 \brief Sets the start index of this instance to \a index.
152 */
153 void
154 1 CrossLinkedRegion::setStartIndex(std::size_t index)
155 {
156 1 m_startIndex = index;
157 1 }
158
159 /*!
160 \brief Returns the start index of this instance.
161 */
162 std::size_t
163 3 CrossLinkedRegion::getStartIndex()
164 {
165 3 return m_startIndex;
166 }
167
168 /*!
169 \brief Sets the stop index of this instance to \a index.
170 */
171 void
172 1 CrossLinkedRegion::setStopIndex(std::size_t index)
173 {
174 1 m_stopIndex = index;
175 1 }
176
177 /*!
178 \brief Returns the stop index of this instance.
179 */
180 std::size_t
181 3 CrossLinkedRegion::getStopIndex()
182 {
183 3 return m_stopIndex;
184 }
185
186
187 /*!
188 \brief Returns a const reference to the container of CrossLink instances.
189 */
190 const std::vector<CrossLinkSPtr> &
191 9 CrossLinkedRegion::getCrossLinksCstRef() const
192 {
193 9 return m_crossLinks;
194 }
195
196
197 /*!
198 \brief Returns a reference to the container of CrossLink instances.
199 */
200 std::vector<CrossLinkSPtr> &
201 3 CrossLinkedRegion::getCrossLinksRef()
202 {
203 3 return m_crossLinks;
204 }
205
206
207 /*!
208 \brief Adds a the \a cross_link_sp CrossLink to the back of the CrossLink container.
209
210 Returns the size of the container of CrossLink instances.
211 */
212 std::size_t
213 1 CrossLinkedRegion::appendCrossLink(const CrossLinkSPtr &cross_link_sp)
214 {
215
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if(cross_link_sp == nullptr || cross_link_sp.get() == nullptr)
216 qFatalStream() << "Programming error. Pointer cannot be nullptr.";
217
218 // Only append the cross-link if it is not already in the list.
219
220 1 std::vector<CrossLinkSPtr>::const_iterator the_iterator_cst =
221
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 std::find_if(m_crossLinks.cbegin(),
222 m_crossLinks.cend(),
223 [&cross_link_sp](const CrossLinkSPtr &iter_cross_link_sp) {
224 return iter_cross_link_sp == cross_link_sp;
225 });
226
227
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(the_iterator_cst == m_crossLinks.cend())
228 1 m_crossLinks.push_back(cross_link_sp);
229
230 1 return m_crossLinks.size();
231 }
232
233 /*!
234 \brief Adds the CrossLink item in the \a cross_links container to the back of
235 the member CrossLink container.
236
237 Returns the size of the container of CrossLink instances.
238 */
239 std::size_t
240 1 CrossLinkedRegion::appendCrossLinks(
241 const std::vector<CrossLinkSPtr> &cross_links)
242 {
243
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 for(const CrossLinkSPtr &cross_link_sp : cross_links)
244 2 m_crossLinks.push_back(cross_link_sp);
245
246 1 return m_crossLinks.size();
247 }
248
249 /*!
250 \brief Removes the \a cross_link_sp CrossLink item from the member CrossLink
251 container.
252
253 Returns the size of the container of CrossLink instances.
254 */
255 std::size_t
256 1 CrossLinkedRegion::removeCrossLink(CrossLinkSPtr &cross_link_sp)
257 {
258 1 std::vector<CrossLinkSPtr>::iterator the_iterator =
259
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 std::find_if(m_crossLinks.begin(),
260 m_crossLinks.end(),
261 1 [&cross_link_sp](const CrossLinkSPtr &iter_cross_link_sp) {
262
1/14
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
1 return iter_cross_link_sp == cross_link_sp;
263 });
264
265
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(the_iterator != m_crossLinks.end())
266 1 m_crossLinks.erase(the_iterator);
267
268 1 return m_crossLinks.size();
269 }
270
271 /*!
272 \brief Removes the CrossLink at \a index from the member CrossLink
273 container.
274
275 Returns the size of the container of CrossLink instances.
276 */
277 std::size_t
278 1 CrossLinkedRegion::removeCrossLinkAt(std::size_t index)
279 {
280
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if(index >= m_crossLinks.size())
281 qFatalStream() << "Programming error. Index is out of bounds.";
282
283 1 m_crossLinks.erase(m_crossLinks.begin() + index);
284
285 1 return m_crossLinks.size();
286 }
287
288 /*!
289 \brief Assigns \a other to this instance.
290
291 The copy of the CrossLink instances is shallow (the shared pointers are copied).
292 */
293 CrossLinkedRegion &
294 CrossLinkedRegion::operator=(const CrossLinkedRegion &other)
295 {
296 if(this == &other)
297 return *this;
298
299 m_startIndex = other.m_startIndex;
300 m_stopIndex = other.m_stopIndex;
301 m_crossLinks.assign(other.m_crossLinks.begin(), other.m_crossLinks.end());
302
303 return *this;
304 }
305
306 } // namespace libXpertMassCore
307 } // namespace MsXpS
308