pappsomspp
Library for mass spectrometry
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 () 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 ( )

Definition at line 27 of file msrundatasettreenode.cpp.

28 {
29 }

Referenced by MsRunDataSetTreeNode(), and operator=().

◆ 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 }

References m_children, and MsRunDataSetTreeNode().

◆ MsRunDataSetTreeNode() [3/3]

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

Definition at line 32 of file msrundatasettreenode.cpp.

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

◆ ~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 385 of file msrundatasettreenode.cpp.

386 {
387  // qDebug() << "now calling visitor.visit(*this);";
388 
389  visitor.visit(*this);
390 
391  // qDebug() << "and now calling node->accept(visitor) for each child node.";
392 
393  visitor.setNodesToProcessCount(m_children.size());
394 
395  for(auto &&node : m_children)
396  node->accept(visitor);
397 }

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

◆ depth()

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

Definition at line 401 of file msrundatasettreenode.cpp.

402 {
403 
404  // qDebug() << "Got depth:" << depth;
405 
406  // If there are no children in this node, that is the end of the tree.
407  // Do not change anything an return.
408 
409  if(!m_children.size())
410  {
411  // qDebug() << "No children, returning" << depth;
412 
413  return depth;
414  }
415 
416  // qDebug() << "There are" << m_children.size() << "children nodes";
417 
418 
419  // At this point we know we can already increment depth by one because
420  // we go down one level by iterating in the m_children vector of nodes.
421 
422  // qDebug() << "Children found, incrementing depth to" << depth + 1;
423 
424  std::size_t local_depth = depth + 1;
425 
426  std::size_t tmp_depth = 0;
427  std::size_t greatest_depth = 0;
428 
429  for(auto &node : m_children)
430  {
431  // qDebug() << "In the children for loop";
432 
433  tmp_depth = node->depth(local_depth);
434 
435  // qDebug() << "Got depth from iterated node:" << tmp_depth;
436 
437  if(tmp_depth > greatest_depth)
438  greatest_depth = tmp_depth;
439  }
440 
441  // qDebug() << "Returning:" << greatest_depth;
442 
443  return greatest_depth;
444 }

References m_children.

Referenced by flattenedViewMsLevelNodes().

◆ findNode() [1/2]

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

Definition at line 169 of file msrundatasettreenode.cpp.

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

References findNode(), 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() ==
143  spectrum_index)
144  {
145  // qDebug() << "The mass spectrum's node is this node.";
146 
147  return this;
148  }
149 
150  // qDebug() << "Need to go searching in the children.";
151 
152  for(auto &node : m_children)
153  {
154  MsRunDataSetTreeNode *iterNode = node->findNode(spectrum_index);
155 
156  if(iterNode != nullptr)
157  {
158  // qDebug() << "Found the mass spectrum's node.";
159 
160  return iterNode;
161  }
162  }
163 
164  return nullptr;
165 }

References findNode(), m_children, and mcsp_massSpectrum.

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

◆ flattenedView()

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

Definition at line 203 of file msrundatasettreenode.cpp.

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

References m_children.

Referenced by flattenedViewMsLevelNodes().

◆ flattenedViewChildrenOnly()

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

Definition at line 227 of file msrundatasettreenode.cpp.

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

References m_children.

◆ 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 239 of file msrundatasettreenode.cpp.

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

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

◆ 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.

◆ getQualifiedMassSpectrum()

QualifiedMassSpectrumCstSPtr pappso::MsRunDataSetTreeNode::getQualifiedMassSpectrum ( ) const

Definition at line 81 of file msrundatasettreenode.cpp.

82 {
83  return mcsp_massSpectrum;
84 }

References mcsp_massSpectrum.

◆ 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.

◆ 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 m_children, mcsp_massSpectrum, mp_parent, and MsRunDataSetTreeNode().

◆ precursorIonNodesByPrecursorMz()

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

Definition at line 319 of file msrundatasettreenode.cpp.

323 {
324  if(precision_ptr == nullptr)
325  qFatal(
326  "Fatal error at %s@%d -- %s(). "
327  "precision_ptr cannot be nullptr."
328  "Program aborted.",
329  __FILE__,
330  __LINE__,
331  __FUNCTION__);
332 
333 
334  // Calculate the mz range using the tolerance.
335  pappso_double lower_mz =
336  precursor_mz - (precision_ptr->delta(precursor_mz) / 2);
337  pappso_double upper_mz =
338  precursor_mz + (precision_ptr->delta(precursor_mz) / 2);
339 
340  // Check if this node matches the requirements.
341 
342  pappso_double mz = mcsp_massSpectrum->getPrecursorMz();
343 
344  if(mz != std::numeric_limits<double>::max())
345  {
346  if(mz >= lower_mz && mz <= upper_mz)
347  {
348  // We are iterating in a node that hold a mass spectrum that was
349  // acquired by fragmenting an ion matching the searched mz value. We
350  // can extract the spectrum index of that precursor mass spectrum and
351  // then get its corresponding node, that we'll store.
352 
353  std::size_t precursor_spectrum_index =
354  mcsp_massSpectrum->getPrecursorSpectrumIndex();
355 
356  MsRunDataSetTreeNode *found_node = findNode(precursor_spectrum_index);
357 
358  if(precursor_spectrum_index !=
359  found_node->mcsp_massSpectrum->getMassSpectrumId()
360  .getSpectrumIndex())
361  qFatal(
362  "Fatal error at %s@%d -- %s(). "
363  "."
364  "Program aborted.",
365  __FILE__,
366  __LINE__,
367  __FUNCTION__);
368 
369  nodes.push_back(found_node);
370  }
371  }
372 
373  // Now handle in the same way, but recursively, all the children of this node.
374 
375  for(auto &&node : m_children)
376  {
377  node->precursorIonNodesByPrecursorMz(precursor_mz, precision_ptr, nodes);
378  }
379 
380  return nodes;
381 }

References findNode(), m_children, mcsp_massSpectrum, and pappso::mz.

◆ productNodesByPrecursorMz()

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

Definition at line 269 of file msrundatasettreenode.cpp.

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

References m_children, mcsp_massSpectrum, and pappso::mz.

◆ setParent()

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

Definition at line 88 of file msrundatasettreenode.cpp.

89 {
90  mp_parent = parent;
91 }

References mp_parent.

◆ 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.

◆ 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.

◆ toString()

QString pappso::MsRunDataSetTreeNode::toString ( ) const

Definition at line 448 of file msrundatasettreenode.cpp.

449 {
450  return QString("mcsp_massSpectrum: %1 ; to string: %2 ; children: %3\n")
452  const_cast<QualifiedMassSpectrum *>(mcsp_massSpectrum.get())))
453  .arg(mcsp_massSpectrum->toString())
454  .arg(m_children.size());
455 }

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

Friends And Related Function Documentation

◆ MsRunDataSetTree

friend class MsRunDataSetTree
friend

Definition at line 34 of file msrundatasettreenode.h.

Member Data Documentation

◆ m_children

◆ mcsp_massSpectrum

◆ mp_parent

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

Definition at line 93 of file msrundatasettreenode.h.

Referenced by getParent(), hasParent(), operator=(), and setParent().


The documentation for this class was generated from the following files:
pappso::pappso_double
double pappso_double
A type definition for doubles.
Definition: types.h:67
pappso::MsRunDataSetTreeNode::depth
std::size_t depth(std::size_t depth) const
Definition: msrundatasettreenode.cpp:401
pappso::MsRunDataSetTreeNode::m_children
std::vector< MsRunDataSetTreeNode * > m_children
Definition: msrundatasettreenode.h:95
pappso::MsRunDataSetTreeNode::mcsp_massSpectrum
QualifiedMassSpectrumCstSPtr mcsp_massSpectrum
Definition: msrundatasettreenode.h:91
pappso::MsRunDataSetTreeNode::MsRunDataSetTreeNode
MsRunDataSetTreeNode()
Definition: msrundatasettreenode.cpp:27
pappso::MsRunDataSetTreeNode::flattenedView
void flattenedView(std::vector< MsRunDataSetTreeNode * > &nodes, bool with_descendants=false)
Definition: msrundatasettreenode.cpp:203
pappso::Utils::pointerToString
static QString pointerToString(const void *const pointer)
Definition: utils.cpp:229
pappso::MsRunDataSetTreeNode::findNode
MsRunDataSetTreeNode * findNode(std::size_t spectrum_index)
Definition: msrundatasettreenode.cpp:133
pappso::MsRunDataSetTreeNode::mp_parent
MsRunDataSetTreeNode * mp_parent
Definition: msrundatasettreenode.h:93
pappso::PrecisionUnit::mz