libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
pappso::MsRunDataSetTreeNode Class Reference

#include <msrundatasettreenode.h>

Public Member Functions

 MsRunDataSetTreeNode ()
 MsRunDataSetTreeNode (const MsRunDataSetTreeNode &other)
 MsRunDataSetTreeNode (QualifiedMassSpectrumCstSPtr mass_spectrum_csp, MsRunDataSetTreeNode *parent_p=nullptr)
virtual ~MsRunDataSetTreeNode ()
MsRunDataSetTreeNodeoperator= (const MsRunDataSetTreeNode &other)
void setQualifiedMassSpectrum (QualifiedMassSpectrumCstSPtr qualified_mass_spectrum_csp)
QualifiedMassSpectrumCstSPtr getQualifiedMassSpectrum () const
void setParent (MsRunDataSetTreeNode *parent)
MsRunDataSetTreeNodegetParent () const
bool hasParent () const
void size (std::size_t &cumulative_node_count) const
MsRunDataSetTreeNodefindNode (std::size_t spectrum_index)
MsRunDataSetTreeNodefindNode (QualifiedMassSpectrumCstSPtr mass_spectrum_csp)
void flattenedView (std::vector< MsRunDataSetTreeNode * > &nodes, bool with_descendants=false)
void flattenedViewChildrenOnly (std::vector< MsRunDataSetTreeNode * > &nodes, bool with_descendants=false)
void flattenedViewMsLevelNodes (std::size_t ms_level, std::size_t depth, std::vector< MsRunDataSetTreeNode * > &nodes, bool with_descendants=false)
std::vector< MsRunDataSetTreeNode * > productNodesByPrecursorMz (pappso_double precursor_mz, PrecisionPtr precision_ptr, std::vector< MsRunDataSetTreeNode * > &nodes)
std::vector< MsRunDataSetTreeNode * > precursorIonNodesByPrecursorMz (pappso_double precursor_mz, PrecisionPtr precision_ptr, std::vector< MsRunDataSetTreeNode * > &nodes)
void accept (MsRunDataSetTreeNodeVisitorInterface &visitor)
std::size_t depth (std::size_t depth) const
QString toString (bool with_data=false) const

Private Attributes

QualifiedMassSpectrumCstSPtr mcsp_massSpectrum = nullptr
MsRunDataSetTreeNodemp_parent = nullptr
std::vector< MsRunDataSetTreeNode * > m_children

Friends

class MsRunDataSetTree

Detailed Description

Definition at line 32 of file msrundatasettreenode.h.

Constructor & Destructor Documentation

◆ MsRunDataSetTreeNode() [1/3]

pappso::MsRunDataSetTreeNode::MsRunDataSetTreeNode ( )

◆ MsRunDataSetTreeNode() [2/3]

pappso::MsRunDataSetTreeNode::MsRunDataSetTreeNode ( const MsRunDataSetTreeNode & other)

Definition at line 40 of file msrundatasettreenode.cpp.

41 : mcsp_massSpectrum(other.mcsp_massSpectrum), mp_parent(other.mp_parent)
42{
43 for(auto &&node : other.m_children)
44 m_children.push_back(new MsRunDataSetTreeNode(*node));
45}
QualifiedMassSpectrumCstSPtr mcsp_massSpectrum
MsRunDataSetTreeNode * mp_parent
std::vector< MsRunDataSetTreeNode * > m_children

References MsRunDataSetTreeNode(), m_children, mcsp_massSpectrum, and mp_parent.

◆ MsRunDataSetTreeNode() [3/3]

pappso::MsRunDataSetTreeNode::MsRunDataSetTreeNode ( QualifiedMassSpectrumCstSPtr mass_spectrum_csp,
MsRunDataSetTreeNode * parent_p = nullptr )

Definition at line 33 of file msrundatasettreenode.cpp.

35 : mcsp_massSpectrum(mass_spectrum_csp), mp_parent(parent_p)
36{
37}

References MsRunDataSetTreeNode(), mcsp_massSpectrum, and mp_parent.

◆ ~MsRunDataSetTreeNode()

pappso::MsRunDataSetTreeNode::~MsRunDataSetTreeNode ( )
virtual

Definition at line 48 of file msrundatasettreenode.cpp.

49{
50 for(auto &&node : m_children)
51 delete node;
52
53 m_children.clear();
54}

References m_children.

Member Function Documentation

◆ accept()

void pappso::MsRunDataSetTreeNode::accept ( MsRunDataSetTreeNodeVisitorInterface & visitor)

Definition at line 363 of file msrundatasettreenode.cpp.

364{
365 // qDebug() << "now calling visitor.visit(*this);";
366
367 visitor.visit(*this);
368
369 // qDebug() << "and now calling node->accept(visitor) for each child node.";
370
371 visitor.setNodesToProcessCount(m_children.size());
372
373 for(auto &&node : m_children)
374 node->accept(visitor);
375}

References m_children, pappso::MsRunDataSetTreeNodeVisitorInterface::setNodesToProcessCount(), and pappso::MsRunDataSetTreeNodeVisitorInterface::visit().

Referenced by MsRunDataSetTree.

◆ depth()

std::size_t pappso::MsRunDataSetTreeNode::depth ( std::size_t depth) const

Definition at line 379 of file msrundatasettreenode.cpp.

380{
381
382 // qDebug() << "Got depth:" << depth;
383
384 // If there are no children in this node, that is the end of the tree.
385 // Do not change anything an return.
386
387 if(!m_children.size())
388 {
389 // qDebug() << "No children, returning" << depth;
390
391 return depth;
392 }
393
394 // qDebug() << "There are" << m_children.size() << "children nodes";
395
396
397 // At this point we know we can already increment depth by one because
398 // we go down one level by iterating in the m_children vector of nodes.
399
400 // qDebug() << "Children found, incrementing depth to" << depth + 1;
401
402 std::size_t local_depth = depth + 1;
403
404 std::size_t tmp_depth = 0;
405 std::size_t greatest_depth = 0;
406
407 for(auto &node : m_children)
408 {
409 // qDebug() << "In the children for loop";
410
411 tmp_depth = node->depth(local_depth);
412
413 // qDebug() << "Got depth from iterated node:" << tmp_depth;
414
415 if(tmp_depth > greatest_depth)
416 greatest_depth = tmp_depth;
417 }
418
419 // qDebug() << "Returning:" << greatest_depth;
420
421 return greatest_depth;
422}
std::size_t depth(std::size_t depth) const

References depth(), and m_children.

Referenced by depth(), flattenedViewMsLevelNodes(), and MsRunDataSetTree.

◆ findNode() [1/2]

MsRunDataSetTreeNode * pappso::MsRunDataSetTreeNode::findNode ( QualifiedMassSpectrumCstSPtr mass_spectrum_csp)

Definition at line 168 of file msrundatasettreenode.cpp.

169{
170 // qDebug();
171
172 // Finding a node that contains a qualified mass spectrum requires checking if
173 // that node is not *this and if not if it is not one of the children. By
174 // essence, this work is recursive.
175
176 if(mass_spectrum_csp == mcsp_massSpectrum)
177 {
178 // qDebug() << "The mass spectrum's node is this node.";
179
180 return this;
181 }
182
183 // qDebug() << "Need to go searching in the children.";
184
185 for(auto &node : m_children)
186 {
187 MsRunDataSetTreeNode *iterNode = node->findNode(mass_spectrum_csp);
188
189 if(iterNode != nullptr)
190 {
191 // qDebug() << "Found the mass spectrum's node.";
192
193 return iterNode;
194 }
195 }
196
197 return nullptr;
198}

References MsRunDataSetTreeNode(), m_children, and mcsp_massSpectrum.

◆ findNode() [2/2]

MsRunDataSetTreeNode * pappso::MsRunDataSetTreeNode::findNode ( std::size_t spectrum_index)

Definition at line 133 of file msrundatasettreenode.cpp.

134{
135 // qDebug();
136
137 // Finding a node that contains a qualified mass spectrum that has been
138 // acquired at spectrum_index, requires checking if that node is not *this and
139 // if not if it is not one of the children. By essence, this work is
140 // recursive.
141
142 if(mcsp_massSpectrum->getMassSpectrumId().getSpectrumIndex() == spectrum_index)
143 {
144 // qDebug() << "The mass spectrum's node is this node.";
145
146 return this;
147 }
148
149 // qDebug() << "Need to go searching in the children.";
150
151 for(auto &node : m_children)
152 {
153 MsRunDataSetTreeNode *iterNode = node->findNode(spectrum_index);
154
155 if(iterNode != nullptr)
156 {
157 // qDebug() << "Found the mass spectrum's node.";
158
159 return iterNode;
160 }
161 }
162
163 return nullptr;
164}

References MsRunDataSetTreeNode(), m_children, and mcsp_massSpectrum.

Referenced by pappso::MsRunDataSetTree::findNode(), pappso::MsRunDataSetTree::findNode(), MsRunDataSetTree, and precursorIonNodesByPrecursorMz().

◆ flattenedView()

void pappso::MsRunDataSetTreeNode::flattenedView ( std::vector< MsRunDataSetTreeNode * > & nodes,
bool with_descendants = false )

Definition at line 202 of file msrundatasettreenode.cpp.

204{
205
206 // Do store this.
207
208 nodes.push_back(this);
209
210 // And now the descendants.
211
212 if(with_descendants)
213 {
214 for(auto &&node : m_children)
215 {
216 node->flattenedView(nodes, with_descendants);
217 }
218 }
219 else
220 {
221 }
222}

References m_children.

Referenced by flattenedViewMsLevelNodes(), and MsRunDataSetTree.

◆ flattenedViewChildrenOnly()

void pappso::MsRunDataSetTreeNode::flattenedViewChildrenOnly ( std::vector< MsRunDataSetTreeNode * > & nodes,
bool with_descendants = false )

Definition at line 226 of file msrundatasettreenode.cpp.

228{
229
230 // Do not store this, only this->m_children !
231
232 for(auto &&node : m_children)
233 node->flattenedView(nodes, with_descendants);
234}

References m_children.

Referenced by MsRunDataSetTree.

◆ flattenedViewMsLevelNodes()

void pappso::MsRunDataSetTreeNode::flattenedViewMsLevelNodes ( std::size_t ms_level,
std::size_t depth,
std::vector< MsRunDataSetTreeNode * > & nodes,
bool with_descendants = false )

Definition at line 238 of file msrundatasettreenode.cpp.

242{
243
244 if(ms_level == (depth + 1))
245 {
246
247 // There we are. The ms_level that is asked matches the current depth of
248 // the node we are in.
249
250 flattenedView(nodes, with_descendants);
251 }
252 else if(ms_level > (depth + 1))
253 {
254 // We still do not have to store the nodes, because what we are
255 // searching is down the tree...
256
257 for(auto &&node : m_children)
258 {
259 node->flattenedViewMsLevelNodes(ms_level, depth + 1, nodes, with_descendants);
260 }
261 }
262}
void flattenedView(std::vector< MsRunDataSetTreeNode * > &nodes, bool with_descendants=false)

References depth(), flattenedView(), and m_children.

Referenced by MsRunDataSetTree.

◆ getParent()

MsRunDataSetTreeNode * pappso::MsRunDataSetTreeNode::getParent ( ) const

Definition at line 95 of file msrundatasettreenode.cpp.

96{
97 // qDebug();
98
99 return mp_parent;
100}

References mp_parent.

Referenced by MsRunDataSetTree.

◆ getQualifiedMassSpectrum()

QualifiedMassSpectrumCstSPtr pappso::MsRunDataSetTreeNode::getQualifiedMassSpectrum ( ) const

Definition at line 81 of file msrundatasettreenode.cpp.

82{
83 return mcsp_massSpectrum;
84}

References mcsp_massSpectrum.

Referenced by MsRunDataSetTree.

◆ hasParent()

bool pappso::MsRunDataSetTreeNode::hasParent ( ) const

Definition at line 104 of file msrundatasettreenode.cpp.

105{
106 // qDebug();
107
108 if(mp_parent != nullptr)
109 return true;
110 else
111 return false;
112}

References mp_parent.

Referenced by MsRunDataSetTree.

◆ operator=()

MsRunDataSetTreeNode & pappso::MsRunDataSetTreeNode::operator= ( const MsRunDataSetTreeNode & other)

Definition at line 58 of file msrundatasettreenode.cpp.

59{
60 if(this == &other)
61 return *this;
62
63 mcsp_massSpectrum = other.mcsp_massSpectrum;
64 mp_parent = other.mp_parent;
65
66 for(auto &&node : other.m_children)
67 m_children.push_back(new MsRunDataSetTreeNode(*node));
68
69 return *this;
70}

References MsRunDataSetTreeNode(), m_children, mcsp_massSpectrum, and mp_parent.

Referenced by MsRunDataSetTree.

◆ precursorIonNodesByPrecursorMz()

std::vector< MsRunDataSetTreeNode * > pappso::MsRunDataSetTreeNode::precursorIonNodesByPrecursorMz ( pappso_double precursor_mz,
PrecisionPtr precision_ptr,
std::vector< MsRunDataSetTreeNode * > & nodes )

Definition at line 309 of file msrundatasettreenode.cpp.

312{
313 if(precision_ptr == nullptr)
314 throw ExceptionNotPossible(
315 QObject::tr("Fatal error at msrundatasettreenode.cpp "
316 "-- ERROR precision_ptr cannot be nullptr. "
317 "Program aborted."));
318
319 // Calculate the mz range using the tolerance.
320 pappso_double lower_mz = precursor_mz - (precision_ptr->delta(precursor_mz) / 2);
321 pappso_double upper_mz = precursor_mz + (precision_ptr->delta(precursor_mz) / 2);
322
323 // Check if this node matches the requirements.
324
325 pappso_double mz = mcsp_massSpectrum->getPrecursorMz();
326
327 if(mz != std::numeric_limits<double>::max())
328 {
329 if(mz >= lower_mz && mz <= upper_mz)
330 {
331 // We are iterating in a node that hold a mass spectrum that was
332 // acquired by fragmenting an ion matching the searched mz value. We
333 // can extract the spectrum index of that precursor mass spectrum and
334 // then get its corresponding node, that we'll store.
335
336 std::size_t precursor_spectrum_index = mcsp_massSpectrum->getPrecursorSpectrumIndex();
337
338 MsRunDataSetTreeNode *found_node = findNode(precursor_spectrum_index);
339
340 if(precursor_spectrum_index !=
341 found_node->mcsp_massSpectrum->getMassSpectrumId().getSpectrumIndex())
342 throw ExceptionNotPossible(
343 QObject::tr("Fatal error at msrundatasettreenode.cpp "
344 "-- ERROR precursor_spectrum_index bad value. "
345 "Program aborted."));
346
347 nodes.push_back(found_node);
348 }
349 }
350
351 // Now handle in the same way, but recursively, all the children of this node.
352
353 for(auto &&node : m_children)
354 {
355 node->precursorIonNodesByPrecursorMz(precursor_mz, precision_ptr, nodes);
356 }
357
358 return nodes;
359}
MsRunDataSetTreeNode * findNode(std::size_t spectrum_index)
double pappso_double
A type definition for doubles.
Definition types.h:60

References MsRunDataSetTreeNode(), pappso::PrecisionBase::delta(), findNode(), m_children, and mcsp_massSpectrum.

Referenced by MsRunDataSetTree.

◆ productNodesByPrecursorMz()

std::vector< MsRunDataSetTreeNode * > pappso::MsRunDataSetTreeNode::productNodesByPrecursorMz ( pappso_double precursor_mz,
PrecisionPtr precision_ptr,
std::vector< MsRunDataSetTreeNode * > & nodes )

Definition at line 266 of file msrundatasettreenode.cpp.

269{
270 if(precision_ptr == nullptr)
271 throw ExceptionNotPossible(
272 QObject::tr("Fatal error at msrundatasettreenode.cpp "
273 "-- ERROR precision_ptr cannot be nullptr. "
274 "Program aborted."));
275
276 // Check if this node matches the requirements.
277
278 pappso_double mz = mcsp_massSpectrum->getPrecursorMz();
279
280 if(mz != std::numeric_limits<double>::max())
281 {
282
283 // Calculate the mz range using the tolerance.
284
285 pappso_double lower_mz = precursor_mz - (precision_ptr->delta(precursor_mz) / 2);
286 pappso_double upper_mz = precursor_mz + (precision_ptr->delta(precursor_mz) / 2);
287
288 if(mz >= lower_mz && mz <= upper_mz)
289 {
290 // We are iterating in a node that holds a mass spectrum that was
291 // acquired by fragmenting an ion that matches the searched mz value.
292
293 nodes.push_back(this);
294 }
295 }
296
297 // Now handle in the same way, but recursively, all the children of this node.
298
299 for(auto &&node : m_children)
300 {
301 node->productNodesByPrecursorMz(precursor_mz, precision_ptr, nodes);
302 }
303
304 return nodes;
305}

References pappso::PrecisionBase::delta(), m_children, and mcsp_massSpectrum.

Referenced by MsRunDataSetTree.

◆ setParent()

void pappso::MsRunDataSetTreeNode::setParent ( MsRunDataSetTreeNode * parent)

Definition at line 88 of file msrundatasettreenode.cpp.

89{
90 mp_parent = parent;
91}

References MsRunDataSetTreeNode(), and mp_parent.

Referenced by MsRunDataSetTree.

◆ setQualifiedMassSpectrum()

void pappso::MsRunDataSetTreeNode::setQualifiedMassSpectrum ( QualifiedMassSpectrumCstSPtr qualified_mass_spectrum_csp)

Definition at line 73 of file msrundatasettreenode.cpp.

75{
76 mcsp_massSpectrum = qualified_mass_spectrum_csp;
77}

References mcsp_massSpectrum.

Referenced by MsRunDataSetTree.

◆ size()

void pappso::MsRunDataSetTreeNode::size ( std::size_t & cumulative_node_count) const

Definition at line 116 of file msrundatasettreenode.cpp.

117{
118
119 // First account for this node.
120 ++cumulative_node_count;
121
122 // Then ask for each child to recursively account for themselves and their
123 // children.
124
125 for(auto &&node : m_children)
126 {
127 node->size(cumulative_node_count);
128 }
129}

References m_children.

Referenced by MsRunDataSetTree.

◆ toString()

QString pappso::MsRunDataSetTreeNode::toString ( bool with_data = false) const

Definition at line 426 of file msrundatasettreenode.cpp.

427{
428 QString text =
429 QString("mcsp_massSpectrum: %1 ; to string: %2 ; children: %3\n")
430 .arg(Utils::pointerToString(const_cast<QualifiedMassSpectrum *>(mcsp_massSpectrum.get())))
431 .arg(mcsp_massSpectrum->toString())
432 .arg(m_children.size());
433
434 if(with_data)
435 text += mcsp_massSpectrum->getMassSpectrumCstSPtr()->toString();
436
437 return text;
438}
static QString pointerToString(const void *const pointer)
Definition utils.cpp:317

References m_children, mcsp_massSpectrum, and pappso::Utils::pointerToString().

Referenced by MsRunDataSetTree.

◆ MsRunDataSetTree

Member Data Documentation

◆ m_children

◆ mcsp_massSpectrum

◆ mp_parent

MsRunDataSetTreeNode* pappso::MsRunDataSetTreeNode::mp_parent = nullptr
private

The documentation for this class was generated from the following files: