libpappsomspp
Library for mass spectrometry
pappso::MsRunDataSetTree Class Reference

#include <msrundatasettree.h>

Public Types

using NodeVector = std::vector< MsRunDataSetTreeNode * >
 
using QualMassSpectraVector = std::vector< QualifiedMassSpectrumCstSPtr >
 
using DoubleNodeVectorMap = std::map< double, NodeVector >
 

Public Member Functions

 MsRunDataSetTree (MsRunIdCstSPtr ms_run_id_csp)
 
virtual ~MsRunDataSetTree ()
 
MsRunDataSetTreeNodeaddMassSpectrum (QualifiedMassSpectrumCstSPtr mass_spectrum)
 
const std::map< std::size_t, MsRunDataSetTreeNode * > & getIndexNodeMap () const
 
const std::vector< MsRunDataSetTreeNode * > & getRootNodes () const
 
void accept (MsRunDataSetTreeNodeVisitorInterface &visitor)
 
void accept (MsRunDataSetTreeNodeVisitorInterface &visitor, std::vector< pappso::MsRunDataSetTreeNode * >::const_iterator nodes_begin_iterator, std::vector< pappso::MsRunDataSetTreeNode * >::const_iterator nodes_end_iterator)
 
MsRunDataSetTreeNodefindNode (QualifiedMassSpectrumCstSPtr mass_spectrum_csp) const
 
MsRunDataSetTreeNodefindNode (std::size_t spectrum_index) const
 
std::size_t massSpectrumIndex (const MsRunDataSetTreeNode *node) const
 
std::size_t massSpectrumIndex (QualifiedMassSpectrumCstSPtr qualified_mass_spectrum_csp) const
 
std::vector< MsRunDataSetTreeNode * > flattenedView ()
 
std::vector< MsRunDataSetTreeNode * > flattenedViewMsLevel (std::size_t ms_level, bool with_descendants=false)
 
MsRunDataSetTreeNodeprecursorNodeByProductSpectrumIndex (std::size_t product_spectrum_index)
 
std::vector< MsRunDataSetTreeNode * > productNodesByPrecursorSpectrumIndex (std::size_t precursor_spectrum_index)
 
std::vector< MsRunDataSetTreeNode * > precursorNodesByPrecursorMz (pappso_double mz, PrecisionPtr precision_ptr)
 
std::size_t depth () const
 
std::size_t size () const
 
std::size_t indexNodeMapSize () const
 
std::size_t getSpectrumCount () const
 
std::size_t addDataSetTreeNodesInsideDtRtRange (double start, double end, NodeVector &nodes, DataKind data_kind) const
 
std::size_t removeDataSetTreeNodesOutsideDtRtRange (double start, double end, NodeVector &nodes, DataKind data_kind) const
 
std::size_t addDataSetQualMassSpectraInsideDtRtRange (double start, double end, QualMassSpectraVector &mass_spectra, DataKind data_kind) const
 
std::size_t removeDataSetQualMassSpectraOutsideDtRtRange (double start, double end, QualMassSpectraVector &mass_spectra, DataKind data_kind) const
 

Private Member Functions

bool documentNodeInDtRtMap (double time, MsRunDataSetTreeNode *node_p, DataKind data_kind)
 
MsRunDataSetTreeNodeaddMassSpectrum (QualifiedMassSpectrumCstSPtr mass_spectrum, MsRunDataSetTreeNode *parent)
 
MsRunDataSetTreeNodeaddMassSpectrum (QualifiedMassSpectrumCstSPtr mass_spectrum, std::size_t precursor_spectrum_index)
 

Private Attributes

MsRunIdCstSPtr mcsp_msRunId
 
std::size_t m_spectrumCount = std::numeric_limits<std::size_t>::min()
 
std::vector< MsRunDataSetTreeNode * > m_rootNodes
 
std::map< std::size_t, MsRunDataSetTreeNode * > m_indexNodeMap
 
DoubleNodeVectorMap m_dtDoubleNodeVectorMap
 
DoubleNodeVectorMap m_rtDoubleNodeVectorMap
 

Detailed Description

Definition at line 28 of file msrundatasettree.h.

Member Typedef Documentation

◆ DoubleNodeVectorMap

Definition at line 87 of file msrundatasettree.h.

◆ NodeVector

Definition at line 84 of file msrundatasettree.h.

◆ QualMassSpectraVector

Constructor & Destructor Documentation

◆ MsRunDataSetTree()

pappso::MsRunDataSetTree::MsRunDataSetTree ( MsRunIdCstSPtr  ms_run_id_csp)

Definition at line 21 of file msrundatasettree.cpp.

21 : mcsp_msRunId(ms_run_id_csp)
22{
23}

◆ ~MsRunDataSetTree()

pappso::MsRunDataSetTree::~MsRunDataSetTree ( )
virtual

Definition at line 26 of file msrundatasettree.cpp.

27{
28 // qDebug();
29
30 for(auto &&node : m_rootNodes)
31 {
32 // Each node is responsible for freeing its children nodes!
33
34 delete node;
35 }
36
37 m_rootNodes.clear();
38
39 // Beware not to delete the node member of the map, as we have already
40 // destroyed them above!
41 //
42 // for(auto iterator = m_indexNodeMap.begin(); iterator !=
43 // m_indexNodeMap.end();
44 //++iterator)
45 //{
46 // delete(iterator->second);
47 //}
48
49 // qDebug();
50}
std::vector< MsRunDataSetTreeNode * > m_rootNodes

References m_rootNodes.

Member Function Documentation

◆ accept() [1/2]

void pappso::MsRunDataSetTree::accept ( MsRunDataSetTreeNodeVisitorInterface visitor)

Definition at line 252 of file msrundatasettree.cpp.

253{
254 // qDebug() << "Going to call node->accept(visitor) for each root node.";
255
256 for(auto &&node : m_rootNodes)
257 {
258 // qDebug() << "Calling accept for root node:" << node;
259
260 if(visitor.shouldStop())
261 break;
262
263 node->accept(visitor);
264 }
265}

References m_rootNodes, and pappso::MsRunDataSetTreeNodeVisitorInterface::shouldStop().

◆ accept() [2/2]

void pappso::MsRunDataSetTree::accept ( MsRunDataSetTreeNodeVisitorInterface visitor,
std::vector< pappso::MsRunDataSetTreeNode * >::const_iterator  nodes_begin_iterator,
std::vector< pappso::MsRunDataSetTreeNode * >::const_iterator  nodes_end_iterator 
)

Definition at line 269 of file msrundatasettree.cpp.

272{
273 // qDebug() << "Visitor:" << &visitor << "The distance is between iterators
274 // is:"
275 //<< std::distance(nodes_begin_iterator, nodes_end_iterator);
276
277 using Iterator = std::vector<MsRunDataSetTreeNode *>::const_iterator;
278
279 Iterator iter = nodes_begin_iterator;
280
281 // Inform the visitor of the number of nodes to work on.
282
283 std::size_t node_count = std::distance(nodes_begin_iterator, nodes_end_iterator);
284
285 visitor.setNodesToProcessCount(node_count);
286
287 while(iter != nodes_end_iterator)
288 {
289 // qDebug() << "Visitor:" << &visitor
290 //<< "The distance is between iterators is:"
291 //<< std::distance(nodes_begin_iterator, nodes_end_iterator);
292
293 // qDebug() << "Node visited:" << (*iter)->toString();
294
295 if(visitor.shouldStop())
296 break;
297
298 (*iter)->accept(visitor);
299 ++iter;
300 }
301}

References pappso::MsRunDataSetTreeNodeVisitorInterface::setNodesToProcessCount(), and pappso::MsRunDataSetTreeNodeVisitorInterface::shouldStop().

◆ addDataSetQualMassSpectraInsideDtRtRange()

std::size_t pappso::MsRunDataSetTree::addDataSetQualMassSpectraInsideDtRtRange ( double  start,
double  end,
QualMassSpectraVector mass_spectra,
DataKind  data_kind 
) const

Definition at line 853 of file msrundatasettree.cpp.

857{
858 // qDebug() << "With start:" << start << "and end:" << end;
859
860 if(start == end)
861 qDebug() << "Special case, start and end are equal:" << start;
862
863 // We will use the maps that relate rt | dt to a vector of data tree nodes.
864 // Indeed, we may have more than one mass spectrum acquired for a given rt, in
865 // case of ion mobility mass spectrometry. Same for dt: we will have as many
866 // spectra for each dt as there are retention time values...
867
868 using DoubleNodeVectorMap = std::map<double, NodeVector>;
869 using MapIterator = DoubleNodeVectorMap::const_iterator;
870
871 const DoubleNodeVectorMap *map_p;
872
873 if(data_kind == DataKind::rt)
874 {
876
877 // qDebug() << "The RT map has size:" << map_p->size() << "start:" <<
878 // start
879 //<< "end:" << end;
880 }
881 else if(data_kind == DataKind::dt)
882 {
884
885 // qDebug() << "The DT map has size:" << map_p->size() << "start:" <<
886 // start
887 //<< "end:" << end;
888 }
889 else
890 qFatal("Programming error.");
891
892 // qDebug() << "The rt |dt / mass spectra map has size:" << map_p->size()
893 //<< "The start:" << start << "the end:" << end;
894
895 std::size_t added_mass_spectra = 0;
896
897 // Get the iterator to the map item that has the key greater or equal to
898 // start.
899
900 MapIterator start_iterator = map_p->lower_bound(start);
901
902 if(start_iterator == map_p->end())
903 {
904 qDebug() << "The start iterator is end()!";
905 return 0;
906 }
907
908 // qDebug() << "The start_iterator points to:" << start_iterator->first
909 //<< "as a rt|dt time.";
910
911 // Now get the end of the map's useful range of items.
912
913 // Returns an iterator pointing to the first element in the container whose
914 // key is considered to go after 'end'.
915
916 MapIterator end_iterator = map_p->upper_bound(end);
917
918 // Immediately verify if there is no distance between start and end.
919 if(!std::distance(start_iterator, end_iterator))
920 {
921 qDebug() << "No range of mass spectra could be selected.";
922 return 0;
923 }
924
925 if(end_iterator == map_p->end())
926 {
927 // qDebug() << "The end_iterator points to the end of the map."
928 //<< "The last map item is prev() at key value: "
929 //<< std::prev(end_iterator)->first;
930 }
931 else
932 {
933 // qDebug() << "The end_iterator points to:" << end_iterator->first
934 //<< "as a rt|dt time and the accounted key value is actually"
935 //<< std::prev(end_iterator)->first;
936 }
937
938 // qDebug() << "The number of time values to iterate through:"
939 //<< std::distance(start_iterator, end_iterator)
940 //<< "with values: start: " << start_iterator->first
941 //<< "and end: " << std::prev(end_iterator)->first;
942
943 // Now that we have the iterator range, iterate in it and get the mass
944 // spectra from each item's pair.second node vector.
945
946 for(MapIterator iterator = start_iterator; iterator != end_iterator; ++iterator)
947 {
948 // We are iterating in DoubleNodeVectorMap MapPair items,
949 // with double = rt or dt and NodeVector being just that.
950
951 NodeVector node_vector = iterator->second;
952
953 // All the nodes' mass spectra in the node vector need to be copied to
954 // the mass_spectra vector passed as parameter.
955
956 for(auto &&node_p : node_vector)
957 {
958 QualifiedMassSpectrumCstSPtr qualified_mass_spectrum_csp =
959 node_p->getQualifiedMassSpectrum();
960
961#if 0
962 // Sanity check only for deep debugging.
963
964 if(qualified_mass_spectrum_csp == nullptr ||
965 qualified_mass_spectrum_csp.get() == nullptr)
966 {
967 throw ExceptionNotPossible(
968 "The QualifiedMassSpectrumCstSPtr cannot be nullptr.");
969 }
970 else
971 {
972 //qDebug() << "Current mass spectrum is valid with rt:"
973 //<< qualified_mass_spectrum_csp->getRtInMinutes();
974 }
975#endif
976
977 mass_spectra.push_back(qualified_mass_spectrum_csp);
978
979 ++added_mass_spectra;
980 }
981 }
982
983 // qDebug() << "Returning added_mass_spectra:" << added_mass_spectra;
984
985 return added_mass_spectra;
986}
std::map< double, NodeVector > DoubleNodeVectorMap
std::vector< MsRunDataSetTreeNode * > NodeVector
DoubleNodeVectorMap m_rtDoubleNodeVectorMap
DoubleNodeVectorMap m_dtDoubleNodeVectorMap
std::shared_ptr< const QualifiedMassSpectrum > QualifiedMassSpectrumCstSPtr
@ dt
Drift time.
@ rt
Retention time.

References pappso::dt, m_dtDoubleNodeVectorMap, m_rtDoubleNodeVectorMap, and pappso::rt.

◆ addDataSetTreeNodesInsideDtRtRange()

std::size_t pappso::MsRunDataSetTree::addDataSetTreeNodesInsideDtRtRange ( double  start,
double  end,
NodeVector nodes,
DataKind  data_kind 
) const

Definition at line 688 of file msrundatasettree.cpp.

692{
693 using NodeVector = std::vector<MsRunDataSetTreeNode *>;
694 using DoubleNodeVectorMap = std::map<double, NodeVector>;
695 using MapIterator = DoubleNodeVectorMap::const_iterator;
696
697 const DoubleNodeVectorMap *map_p;
698
699 if(data_kind == DataKind::rt)
700 {
702 }
703 else if(data_kind == DataKind::dt)
704 {
706 }
707 else
708 qFatal("Programming error.");
709
710 std::size_t added_nodes = 0;
711
712 // Get the iterator to the map item that has the key greater or equal to
713 // start.
714
715 MapIterator start_iterator = map_p->lower_bound(start);
716
717 if(start_iterator == map_p->end())
718 return 0;
719
720 // Now get the end of the map useful range of items.
721
722 MapIterator end_iterator = map_p->upper_bound(end);
723
724 // Now that we have the iterator range, iterate in it and get the mass spectra
725 // from each item's pair.second node vector.
726
727 for(MapIterator iterator = start_iterator; iterator != end_iterator; ++iterator)
728 {
729 // We are iterating in MapPair items.
730
731 NodeVector node_vector = iterator->second;
732
733 // All the nodes in the node vector need to be copied to the mass_spectra
734 // vector passed as parameter.
735
736 for(auto &&node_p : node_vector)
737 {
738 nodes.push_back(node_p);
739
740 ++added_nodes;
741 }
742 }
743
744 return added_nodes;
745}

References pappso::dt, m_dtDoubleNodeVectorMap, m_rtDoubleNodeVectorMap, and pappso::rt.

◆ addMassSpectrum() [1/3]

MsRunDataSetTreeNode * pappso::MsRunDataSetTree::addMassSpectrum ( QualifiedMassSpectrumCstSPtr  mass_spectrum)

Definition at line 54 of file msrundatasettree.cpp.

55{
56 qDebug();
57
58 if(mass_spectrum_csp == nullptr)
59 qFatal("Cannot be nullptr");
60
61 if(mass_spectrum_csp.get() == nullptr)
62 qFatal("Cannot be nullptr");
63
64 // We need to get the precursor spectrum index, in case this spectrum is a
65 // fragmentation index.
66
67 MsRunDataSetTreeNode *new_node_p = nullptr;
68
69 std::size_t precursor_spectrum_index = mass_spectrum_csp->getPrecursorSpectrumIndex();
70
71 qDebug() << "The precursor_spectrum_index:" << precursor_spectrum_index;
72
73 if(precursor_spectrum_index == std::numeric_limits<std::size_t>::max())
74 {
75 // This spectrum is a full scan spectrum, not a fragmentation spectrum.
76 // Create a new node with no parent and push it back to the root nodes
77 // vector.
78
79 new_node_p = new MsRunDataSetTreeNode(mass_spectrum_csp, nullptr);
80
81 // Since there is no parent in this overload, it is assumed that the node
82 // to be populated with the new node is the root node.
83
84 m_rootNodes.push_back(new_node_p);
85
86 // true: with_data
87 // qDebug().noquote() << "Pushed back to the roots node vector node:"
88 //<< new_node_p->toString(true);
89 }
90 else
91 {
92 // This spectrum is a fragmentation spectrum.
93
94 // Sanity check
95
96 if(mass_spectrum_csp->getMsLevel() <= 1)
97 {
98 throw ExceptionNotPossible(
99 "msrundatasettree.cpp -- ERROR the MS level needs to be > 1 in a "
100 "fragmentation spectrum.");
101 }
102
103 // Get the node that contains the precursor ion mass spectrum.
104 MsRunDataSetTreeNode *parent_node_p = findNode(precursor_spectrum_index);
105
106 if(parent_node_p == nullptr)
107 {
108 throw ExceptionNotPossible(QString("%1 @ %2 - %3\n")
109 .arg(__FILE__)
110 .arg(__LINE__)
111 .arg("msrundatasettree.cpp -- ERROR could not find "
112 "a tree node matching the index."));
113 }
114
115 // qDebug() << "Fragmentation spectrum"
116 //<< "Found parent node:" << parent_node_p
117 //<< "for precursor index:" << precursor_spectrum_index;
118
119 // At this point, create a new node with the right parent.
120
121 new_node_p = new MsRunDataSetTreeNode(mass_spectrum_csp, parent_node_p);
122
123 parent_node_p->m_children.push_back(new_node_p);
124 }
125
126 // And now document that addition in the node index map.
127 m_indexNodeMap.insert(std::pair<std::size_t, MsRunDataSetTreeNode *>(
128 mass_spectrum_csp->getMassSpectrumId().getSpectrumIndex(), new_node_p));
129
130 // We also want to document the new node relating to the
131 // retention time.
132
133 documentNodeInDtRtMap(mass_spectrum_csp->getRtInMinutes(), new_node_p, DataKind::rt);
134
135 // Likewise for the ion mobility time.
136
137 double ion_mobility_value = -1;
138
139 MsDataFormat file_format = mcsp_msRunId->getMsDataFormat();
140 bool ok = false;
141
142 if(file_format == MsDataFormat::brukerTims)
143 {
144 // Start by looking if there is a OneOverK0 valid value, which
145 // means we have effectively handled a genuine mobility scan spectrum.
146 QVariant ion_mobility_variant_value =
147 mass_spectrum_csp->getParameterValue(QualifiedMassSpectrumParameter::IonMobOneOverK0);
148
149 if(ion_mobility_variant_value.isValid())
150 {
151 // Yes, genuine ion mobility scan handled here.
152
153 ion_mobility_value = ion_mobility_variant_value.toDouble(&ok);
154
155 if(!ok)
156 {
157 qFatal(
158 "The data are Bruker timsTOF data but failed to convert valid "
159 "QVariant 1/K0 value to double.");
160 }
161 }
162 else
163 {
164 // We are not handling a genuine single ion mobility scan here.
165 // We must be handling a mass spectrum that correspond to
166 // the combination of all the ion mobility scans for a single
167 // frame. This is when the user asks that ion mobility scans
168 // be flattended. In this case, the OneOverK0 value is not valid
169 // but there are two values that are set:
170 // TimsFrameInvKoBegin and TimsFrameInvKoEnd.
171 // See TimsFramesMsRunReader::readSpectrumCollection2.
172
173 // Test one of these values as a sanity check. But
174 // give the value of -1 for the ion mobility because we do not
175 // have ion mobility data here.
176
177 ion_mobility_variant_value = mass_spectrum_csp->getParameterValue(
179
180 if(!ion_mobility_variant_value.isValid())
181 {
182 qFatal(
183 "The data are Bruker timsTOF data but failed to get correct "
184 "ion mobility data. Inconsistency found.");
185 }
186 }
187 }
188 else
189 {
190 ion_mobility_value = mass_spectrum_csp->getDtInMilliSeconds();
191 }
192
193 if(ion_mobility_value != -1)
194 documentNodeInDtRtMap(ion_mobility_value, new_node_p, DataKind::dt);
195
197
198 // qDebug() << "New index/node map:"
199 //<< mass_spectrum_csp->getMassSpectrumId().getSpectrumIndex() << "/"
200 //<< new_node_p;
201
202 return new_node_p;
203}
MsRunDataSetTreeNode * findNode(QualifiedMassSpectrumCstSPtr mass_spectrum_csp) const
bool documentNodeInDtRtMap(double time, MsRunDataSetTreeNode *node_p, DataKind data_kind)
std::map< std::size_t, MsRunDataSetTreeNode * > m_indexNodeMap
MsDataFormat
Definition: types.h:131
@ IonMobOneOverK0Begin
1/K0 range's begin value

References pappso::brukerTims, documentNodeInDtRtMap(), pappso::dt, findNode(), pappso::IonMobOneOverK0, pappso::IonMobOneOverK0Begin, pappso::MsRunDataSetTreeNode::m_children, m_indexNodeMap, m_rootNodes, m_spectrumCount, mcsp_msRunId, and pappso::rt.

Referenced by addMassSpectrum().

◆ addMassSpectrum() [2/3]

MsRunDataSetTreeNode * pappso::MsRunDataSetTree::addMassSpectrum ( QualifiedMassSpectrumCstSPtr  mass_spectrum,
MsRunDataSetTreeNode parent 
)
private

Definition at line 548 of file msrundatasettree.cpp.

550{
551 // qDebug();
552
553 // We want to add a mass spectrum. Either the parent_p argument is nullptr or
554 // not. If it is nullptr, then we just append the mass spectrum to the vector
555 // of root nodes. If it is not nullptr, we need to append the mass spectrum to
556 // that node.
557
558 MsRunDataSetTreeNode *new_node_p = new MsRunDataSetTreeNode(mass_spectrum_csp, parent_p);
559
560 if(parent_p == nullptr)
561 {
562 m_rootNodes.push_back(new_node_p);
563
564 // qDebug() << "Pushed back" << new_node << "to root nodes:" <<
565 // &m_rootNodes;
566 }
567 else
568 {
569 parent_p->m_children.push_back(new_node_p);
570
571 // qDebug() << "Pushed back" << new_node << "with parent:" << parent_p;
572 }
573
575
576 // And now document that addition in the node index map.
577 m_indexNodeMap.insert(std::pair<std::size_t, MsRunDataSetTreeNode *>(
578 mass_spectrum_csp->getMassSpectrumId().getSpectrumIndex(), new_node_p));
579
580 // We also want to document the new node relating to the
581 // retention time.
582
583 documentNodeInDtRtMap(mass_spectrum_csp->getRtInMinutes(), new_node_p, DataKind::rt);
584
585 // Likewise for the ion mobility time.
586
587 double ion_mobility_value = -1;
588
589 MsDataFormat file_format = mcsp_msRunId->getMsDataFormat();
590 bool ok = false;
591
592 if(file_format == MsDataFormat::brukerTims)
593 {
594 // Start by looking if there is a OneOverK0 valid value, which
595 // means we have effectively handled a genuine mobility scan spectrum.
596 QVariant ion_mobility_variant_value =
597 mass_spectrum_csp->getParameterValue(QualifiedMassSpectrumParameter::IonMobOneOverK0);
598
599 if(ion_mobility_variant_value.isValid())
600 {
601 // Yes, genuine ion mobility scan handled here.
602
603 ion_mobility_value = ion_mobility_variant_value.toDouble(&ok);
604
605 if(!ok)
606 {
607 qFatal(
608 "The data are Bruker timsTOF data but failed to convert valid "
609 "QVariant 1/K0 value to double.");
610 }
611 }
612 else
613 {
614 // We are not handling a genuine single ion mobility scan here.
615 // We must be handling a mass spectrum that correspond to
616 // the combination of all the ion mobility scans for a single
617 // frame. This is when the user asks that ion mobility scans
618 // be flattended. In this case, the OneOverK0 value is not valid
619 // but there are two values that are set:
620 // TimsFrameInvKoBegin and TimsFrameInvKoEnd.
621 // See TimsFramesMsRunReader::readSpectrumCollection2.
622
623 // Test one of these values as a sanity check. But
624 // give the value of -1 for the ion mobility because we do not
625 // have ion mobility data here.
626
627 ion_mobility_variant_value = mass_spectrum_csp->getParameterValue(
629
630 if(!ion_mobility_variant_value.isValid())
631 {
632 qFatal(
633 "The data are Bruker timsTOF data but failed to get correct "
634 "ion mobility data. Inconsistency found.");
635 }
636 }
637 }
638 else
639 {
640 ion_mobility_value = mass_spectrum_csp->getDtInMilliSeconds();
641 }
642
643 if(ion_mobility_value != -1)
644 documentNodeInDtRtMap(ion_mobility_value, new_node_p, DataKind::dt);
645
646 // qDebug() << "New index/node map:"
647 //<< mass_spectrum_csp->getMassSpectrumId().getSpectrumIndex() << "/"
648 //<< new_node;
649
650 return new_node_p;
651}

References pappso::brukerTims, documentNodeInDtRtMap(), pappso::dt, pappso::IonMobOneOverK0, pappso::IonMobOneOverK0Begin, pappso::MsRunDataSetTreeNode::m_children, m_indexNodeMap, m_rootNodes, m_spectrumCount, mcsp_msRunId, and pappso::rt.

◆ addMassSpectrum() [3/3]

MsRunDataSetTreeNode * pappso::MsRunDataSetTree::addMassSpectrum ( QualifiedMassSpectrumCstSPtr  mass_spectrum,
std::size_t  precursor_spectrum_index 
)
private

Definition at line 655 of file msrundatasettree.cpp.

657{
658 // qDebug();
659
660 // First get the node containing the mass spectrum that was acquired at index
661 // precursor_spectrum_index.
662
663 // qDebug() << "Need to find the precursor's mass spectrum node for precursor
664 // "
665 //"spectrum index:"
666 //<< precursor_spectrum_index;
667
668 MsRunDataSetTreeNode *mass_spec_data_node_p = findNode(precursor_spectrum_index);
669
670 // qDebug() << "Found node" << mass_spec_data_node_p
671 //<< "for precursor index:" << precursor_spectrum_index;
672
673 if(mass_spec_data_node_p == nullptr)
674 {
675 throw ExceptionNotPossible(
676 "msrundatasettree.cpp -- ERROR could not find a a "
677 "tree node matching the index.");
678 }
679
680 // qDebug() << "Calling addMassSpectrum with parent node:"
681 //<< mass_spec_data_node_p;
682
683 return addMassSpectrum(mass_spectrum_csp, mass_spec_data_node_p);
684}
MsRunDataSetTreeNode * addMassSpectrum(QualifiedMassSpectrumCstSPtr mass_spectrum)

References addMassSpectrum(), and findNode().

◆ depth()

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

Definition at line 1120 of file msrundatasettree.cpp.

1121{
1122 // We want to know what is the depth of the tree, that is the highest level
1123 // of MSn, that is, n.
1124
1125 if(!m_rootNodes.size())
1126 return 0;
1127
1128 // qDebug() << "There are" << m_rootNodes.size() << "root nodes";
1129
1130 // By essence, we are at MS0: only if we have at least one root node do we
1131 // know we have MS1 data. So we already know that we have at least one
1132 // child, so start with depth 1.
1133
1134 std::size_t depth = 1;
1135 std::size_t tmp_depth = 0;
1136 std::size_t greatest_depth = 0;
1137
1138 for(auto &node : m_rootNodes)
1139 {
1140 tmp_depth = node->depth(depth);
1141
1142 // qDebug() << "Returned depth:" << tmp_depth;
1143
1144 if(tmp_depth > greatest_depth)
1145 greatest_depth = tmp_depth;
1146 }
1147
1148 return greatest_depth;
1149}

References depth(), and m_rootNodes.

Referenced by depth(), and flattenedViewMsLevel().

◆ documentNodeInDtRtMap()

bool pappso::MsRunDataSetTree::documentNodeInDtRtMap ( double  time,
MsRunDataSetTreeNode node_p,
DataKind  data_kind 
)
private

Definition at line 490 of file msrundatasettree.cpp.

493{
494 // qDebug();
495
496 using NodeVector = std::vector<MsRunDataSetTreeNode *>;
497 using DoubleNodeVectorMap = std::map<double, NodeVector>;
498 using MapPair = std::pair<double, NodeVector>;
499 using MapIterator = DoubleNodeVectorMap::iterator;
500
501 DoubleNodeVectorMap *map_p;
502
503 if(data_kind == DataKind::rt)
504 {
506 }
507 else if(data_kind == DataKind::dt)
508 {
510 }
511 else
512 qFatal("Programming error.");
513
514 // There are two possibilities:
515 //
516 // 1. The time was never encountered yet. We won't find it. We need to
517 // allocate a vector of Node's and set it associated to time in the map.
518 //
519 // 2. The time was encountered already, we will find it in the maps, we'll
520 // just push_back the Node in the vector of nodes.
521
522 MapIterator found_iterator = map_p->find(time);
523
524 if(found_iterator != map_p->end())
525 {
526 // The time value was encountered already.
527
528 found_iterator->second.push_back(node_p);
529
530 // qDebug() << "Found iterator for time:" << time;
531 }
532 else
533 {
534 // We need to create a new vector with the node.
535
536 NodeVector node_vector = {node_p};
537
538 map_p->insert(MapPair(time, node_vector));
539
540 // qDebug() << "Inserted new time:node_vector pair.";
541 }
542
543 return true;
544}

References pappso::dt, m_dtDoubleNodeVectorMap, m_rtDoubleNodeVectorMap, and pappso::rt.

Referenced by addMassSpectrum().

◆ findNode() [1/2]

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

Definition at line 305 of file msrundatasettree.cpp.

306{
307 // qDebug();
308
309 for(auto &node : m_rootNodes)
310 {
311 // qDebug() << "In one node of the root nodes.";
312
313 MsRunDataSetTreeNode *iterNode = node->findNode(mass_spectrum_csp);
314 if(iterNode != nullptr)
315 return iterNode;
316 }
317
318 return nullptr;
319}

References pappso::MsRunDataSetTreeNode::findNode(), and m_rootNodes.

Referenced by addMassSpectrum(), massSpectrumIndex(), precursorNodeByProductSpectrumIndex(), precursorNodesByPrecursorMz(), and productNodesByPrecursorSpectrumIndex().

◆ findNode() [2/2]

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

Definition at line 323 of file msrundatasettree.cpp.

324{
325 // qDebug();
326
327 for(auto &node : m_rootNodes)
328 {
329 // qDebug() << "In one node of the root nodes.";
330
331 MsRunDataSetTreeNode *iterNode = node->findNode(spectrum_index);
332 if(iterNode != nullptr)
333 return iterNode;
334 }
335
336 return nullptr;
337}

References pappso::MsRunDataSetTreeNode::findNode(), and m_rootNodes.

◆ flattenedView()

std::vector< MsRunDataSetTreeNode * > pappso::MsRunDataSetTree::flattenedView ( )

Definition at line 341 of file msrundatasettree.cpp.

342{
343 // We want to push back all the nodes of the tree in a flat vector of nodes.
344
345 std::vector<MsRunDataSetTreeNode *> nodes;
346
347 for(auto &&node : m_rootNodes)
348 {
349 // The node will store itself and all of its children.
350 node->flattenedView(nodes, true /* with_descendants */);
351 }
352
353 return nodes;
354}

References m_rootNodes.

◆ flattenedViewMsLevel()

std::vector< MsRunDataSetTreeNode * > pappso::MsRunDataSetTree::flattenedViewMsLevel ( std::size_t  ms_level,
bool  with_descendants = false 
)

Definition at line 358 of file msrundatasettree.cpp.

359{
360 std::vector<MsRunDataSetTreeNode *> nodes;
361
362 // Logically, ms_level cannot be 0.
363
364 if(!ms_level)
365 {
366 throw ExceptionNotPossible("msrundatasettree.cpp -- ERROR the MS level cannot be 0.");
367
368 return nodes;
369 }
370
371 // The depth of the tree at which we are right at this point is 0, we have not
372 // gone into the children yet.
373
374 std::size_t depth = 0;
375
376 // If ms_level is 1, then that means that we want the nodes starting right at
377 // the root nodes with or without the descendants.
378
379 // std::cout << __FILE__ << " @ " << __LINE__ << " " << __FUNCTION__ << " () "
380 //<< "ms_level: " << ms_level << " depth: " << depth << std::endl;
381
382 if(ms_level == 1)
383 {
384 for(auto &&node : m_rootNodes)
385 {
386 // std::cout << __FILE__ << " @ " << __LINE__ << " " << __FUNCTION__
387 //<< " () "
388 //<< "Handling one of the root nodes at ms_level = 1."
389 //<< std::endl;
390
391 node->flattenedView(nodes, with_descendants);
392 }
393
394 return nodes;
395 }
396
397 // At this point, we know that we want the descendants of the root nodes since
398 // we want ms_level > 1, so we need go to to the children of the root nodes.
399
400 // Let depth to 0, because if we go to the children of the root nodes we will
401 // still be at depth 0, that is MS level 1.
402
403 for(auto &node : m_rootNodes)
404 {
405 // std::cout
406 //<< __FILE__ << " @ " << __LINE__ << " " << __FUNCTION__ << " () "
407 //<< std::setprecision(15)
408 //<< "Requesting a flattened view of the root's child nodes with depth: "
409 //<< depth << std::endl;
410
411 node->flattenedViewMsLevelNodes(ms_level, depth, nodes, with_descendants);
412 }
413
414 return nodes;
415}

References depth(), and m_rootNodes.

◆ getIndexNodeMap()

const std::map< std::size_t, MsRunDataSetTreeNode * > & pappso::MsRunDataSetTree::getIndexNodeMap ( ) const

Definition at line 207 of file msrundatasettree.cpp.

208{
209 return m_indexNodeMap;
210}

References m_indexNodeMap.

◆ getRootNodes()

const std::vector< MsRunDataSetTreeNode * > & pappso::MsRunDataSetTree::getRootNodes ( ) const

Definition at line 245 of file msrundatasettree.cpp.

246{
247 return m_rootNodes;
248}

References m_rootNodes.

◆ getSpectrumCount()

std::size_t pappso::MsRunDataSetTree::getSpectrumCount ( ) const

Definition at line 1177 of file msrundatasettree.cpp.

1178{
1179 return m_spectrumCount;
1180}

References m_spectrumCount.

◆ indexNodeMapSize()

std::size_t pappso::MsRunDataSetTree::indexNodeMapSize ( ) const

Definition at line 1170 of file msrundatasettree.cpp.

1171{
1172 return m_indexNodeMap.size();
1173}

References m_indexNodeMap.

◆ massSpectrumIndex() [1/2]

std::size_t pappso::MsRunDataSetTree::massSpectrumIndex ( const MsRunDataSetTreeNode node) const

Definition at line 214 of file msrundatasettree.cpp.

215{
216 // We have a node and we want to get the matching mass spectrum index.
217
218 if(node == nullptr)
219 throw("Cannot be that the node pointer is nullptr");
220
221 std::map<std::size_t, MsRunDataSetTreeNode *>::const_iterator iterator =
222 std::find_if(m_indexNodeMap.begin(),
223 m_indexNodeMap.end(),
224 [node](const std::pair<std::size_t, MsRunDataSetTreeNode *> pair) {
225 return pair.second == node;
226 });
227
228 if(iterator != m_indexNodeMap.end())
229 return iterator->first;
230
231 return std::numeric_limits<std::size_t>::max();
232}

References m_indexNodeMap.

Referenced by massSpectrumIndex().

◆ massSpectrumIndex() [2/2]

std::size_t pappso::MsRunDataSetTree::massSpectrumIndex ( QualifiedMassSpectrumCstSPtr  qualified_mass_spectrum_csp) const

Definition at line 236 of file msrundatasettree.cpp.

237{
238 MsRunDataSetTreeNode *node_p = findNode(qualified_mass_spectrum_csp);
239
240 return massSpectrumIndex(node_p);
241}
std::size_t massSpectrumIndex(const MsRunDataSetTreeNode *node) const

References findNode(), and massSpectrumIndex().

◆ precursorNodeByProductSpectrumIndex()

MsRunDataSetTreeNode * pappso::MsRunDataSetTree::precursorNodeByProductSpectrumIndex ( std::size_t  product_spectrum_index)

Definition at line 419 of file msrundatasettree.cpp.

420{
421
422 // qDebug();
423
424 // Find the node that holds the mass spectrum that was acquired as the
425 // precursor that when fragmented gave a spectrum at spectrum_index;
426
427 // Get the node that contains the product_spectrum_index first.
428 MsRunDataSetTreeNode *node = nullptr;
429 node = findNode(product_spectrum_index);
430
431 // Now get the node that contains the precursor_spectrum_index.
432
433 return findNode(node->mcsp_massSpectrum->getPrecursorSpectrumIndex());
434}

References findNode(), and pappso::MsRunDataSetTreeNode::mcsp_massSpectrum.

◆ precursorNodesByPrecursorMz()

std::vector< MsRunDataSetTreeNode * > pappso::MsRunDataSetTree::precursorNodesByPrecursorMz ( pappso_double  mz,
PrecisionPtr  precision_ptr 
)

Definition at line 456 of file msrundatasettree.cpp.

457{
458
459 // Find all the precursor nodes holding a mass spectrum that contained a
460 // precursor mz-value.
461
462 if(precision_ptr == nullptr)
463 throw ExceptionNotPossible("msrundatasettree.cpp -- ERROR precision_ptr cannot be nullptr.");
464
465 std::vector<MsRunDataSetTreeNode *> product_nodes;
466
467 // As a first step, find all the nodes that hold a mass spectrum that was
468 // acquired as a fragmentation spectrum of an ion of mz, that is, search all
469 // the product ion nodes for which precursor was mz.
470
471 for(auto &&node : m_rootNodes)
472 {
473 node->productNodesByPrecursorMz(mz, precision_ptr, product_nodes);
474 }
475
476 // Now, for each node found get the precursor node
477
478 std::vector<MsRunDataSetTreeNode *> precursor_nodes;
479
480 for(auto &&node : product_nodes)
481 {
482 precursor_nodes.push_back(findNode(node->mcsp_massSpectrum->getPrecursorSpectrumIndex()));
483 }
484
485 return precursor_nodes;
486}

References findNode(), m_rootNodes, and pappso::mz.

◆ productNodesByPrecursorSpectrumIndex()

std::vector< MsRunDataSetTreeNode * > pappso::MsRunDataSetTree::productNodesByPrecursorSpectrumIndex ( std::size_t  precursor_spectrum_index)

Definition at line 438 of file msrundatasettree.cpp.

439{
440 std::vector<MsRunDataSetTreeNode *> nodes;
441
442 // First get the node of the precursor spectrum index.
443
444 MsRunDataSetTreeNode *precursor_node = findNode(precursor_spectrum_index);
445
446 if(precursor_node == nullptr)
447 return nodes;
448
449 nodes.assign(precursor_node->m_children.begin(), precursor_node->m_children.end());
450
451 return nodes;
452}

References findNode(), and pappso::MsRunDataSetTreeNode::m_children.

◆ removeDataSetQualMassSpectraOutsideDtRtRange()

std::size_t pappso::MsRunDataSetTree::removeDataSetQualMassSpectraOutsideDtRtRange ( double  start,
double  end,
QualMassSpectraVector mass_spectra,
DataKind  data_kind 
) const

Definition at line 990 of file msrundatasettree.cpp.

994{
995 using QualMassSpectraVectorIterator = QualMassSpectraVector::iterator;
996
997 using DoubleNodeVectorMap = std::map<double, NodeVector>;
998 using MapIterator = DoubleNodeVectorMap::const_iterator;
999
1000 const DoubleNodeVectorMap *map_p;
1001
1002 if(data_kind == DataKind::rt)
1003 {
1004 map_p = &m_rtDoubleNodeVectorMap;
1005
1006 // qDebug() << "The RT map has size:" << map_p->size() << "start:" <<
1007 // start
1008 //<< "end:" << end;
1009 }
1010 else if(data_kind == DataKind::dt)
1011 {
1012 map_p = &m_dtDoubleNodeVectorMap;
1013
1014 // qDebug() << "The DT map has size:" << map_p->size() << "start:" <<
1015 // start
1016 //<< "end:" << end;
1017 }
1018 else
1019 qFatal("Programming error.");
1020
1021 std::size_t removed_vector_items = 0;
1022
1023 // We want to remove from the nodes vector all the nodes that contain a mass
1024 // spectrum acquired at a time range outside of [ start-end ], that is, the
1025 // time values [begin() - start [ and ]end -- end()[.
1026
1027 // Looking for an iterator that points to an item having a time < start.
1028
1029 // lower_bound returns an iterator pointing to the first element in the
1030 // range [first, last) that is not less than (i.e. greater or equal to)
1031 // value, or last if no such element is found.
1032
1033 MapIterator first_end_iterator = (*map_p).lower_bound(start);
1034
1035 // first_end_iterator points to the item that has the next time value with
1036 // respect to start. This is fine because we'll not remove that point
1037 // because the for loop below will stop one item short of
1038 // first_end_iterator. That means that we effectively remove all the items
1039 // [begin() -> start[ (start not include). Exactly what we want.
1040
1041 // qDebug() << "lower_bound for start:" << first_end_iterator->first;
1042
1043 // Now that we have the first_end_iterator, we can iterate between [begin --
1044 // first_end_iterator[
1045
1046 for(MapIterator iterator = map_p->begin(); iterator != first_end_iterator; ++iterator)
1047 {
1048 // Remove from the nodes vector the nodes.
1049
1050 // We are iterating in MapPair items.
1051
1052 NodeVector node_vector = iterator->second;
1053
1054 // All the nodes in the node vector need to be removed from the
1055 // mass_spectra vector passed as parameter if found.
1056
1057 for(auto &&node_p : node_vector)
1058 {
1059 QualMassSpectraVectorIterator iterator =
1060 std::find(mass_spectra.begin(), mass_spectra.end(), node_p->getQualifiedMassSpectrum());
1061
1062 if(iterator != mass_spectra.end())
1063 {
1064 // We found the mass spectrum: remove it.
1065
1066 mass_spectra.erase(iterator);
1067
1068 ++removed_vector_items;
1069 }
1070 }
1071 }
1072
1073 // Now the second begin iterator, so that we can remove all the items
1074 // contained in the second range, that is, ]end--end()[.
1075
1076 // The second_first_iterator will point to the item having its time value
1077 // less or equal to end. But we do not want to get items having their time
1078 // equal to end, only < end. So, if the iterator is not begin(), we just
1079 // need to decrement it once.
1080
1081 MapIterator second_first_iterator = map_p->upper_bound(end);
1082
1083 // second_first_iterator now points to the item after the one having time
1084 // end. Which is exactly what we want: we want to remove ]end--end()[ and
1085 // this is exactly what the loop starting a the point after end below.
1086
1087 // qDebug() << "second_first_iterator for end:" <<
1088 // second_first_iterator->first;
1089
1090 for(MapIterator iterator = second_first_iterator; iterator != map_p->end(); ++iterator)
1091 {
1092 // We are iterating in MapPair items.
1093
1094 NodeVector node_vector = iterator->second;
1095
1096 // All the nodes in the node vector need to be removed from the
1097 // mass_spectra vector passed as parameter if found.
1098
1099 for(auto &&node_p : node_vector)
1100 {
1101 QualMassSpectraVectorIterator iterator =
1102 std::find(mass_spectra.begin(), mass_spectra.end(), node_p->getQualifiedMassSpectrum());
1103
1104 if(iterator != mass_spectra.end())
1105 {
1106 // We found the node: remove it.
1107
1108 mass_spectra.erase(iterator);
1109
1110 ++removed_vector_items;
1111 }
1112 }
1113 }
1114
1115 return removed_vector_items;
1116}

References pappso::dt, m_dtDoubleNodeVectorMap, m_rtDoubleNodeVectorMap, and pappso::rt.

◆ removeDataSetTreeNodesOutsideDtRtRange()

std::size_t pappso::MsRunDataSetTree::removeDataSetTreeNodesOutsideDtRtRange ( double  start,
double  end,
NodeVector nodes,
DataKind  data_kind 
) const

Definition at line 749 of file msrundatasettree.cpp.

753{
754 using NodeVector = std::vector<MsRunDataSetTreeNode *>;
755 using NodeVectorIterator = NodeVector::iterator;
756
757 using DoubleNodeVectorMap = std::map<double, NodeVector>;
758 using MapIterator = DoubleNodeVectorMap::const_iterator;
759
760 const DoubleNodeVectorMap *map_p;
761
762 if(data_kind == DataKind::rt)
763 {
765 }
766 else if(data_kind == DataKind::dt)
767 {
769 }
770 else
771 qFatal("Programming error.");
772
773 std::size_t removed_vector_items = 0;
774
775 // We want to remove from the nodes vector all the nodes that contain a mass
776 // spectrum acquired at a time range outside of [ start-end ], that is, the
777 // time values [begin() - start [ and ]end -- end()[.
778
779 // Get the iterator to the map item that has the key less to
780 // start (we want to keep the map item having key == start).
781
782 MapIterator first_end_iterator = (*map_p).upper_bound(start);
783
784 // Now that we have the first_end_iterator, we can iterate between [begin --
785 // first_end_iterator[
786
787 for(MapIterator iterator = map_p->begin(); iterator != first_end_iterator; ++iterator)
788 {
789 // Remove from the nodes vector the nodes.
790
791 // We are iterating in MapPair items.
792
793 NodeVector node_vector = iterator->second;
794
795 // All the nodes in the node vector need to be removed from the
796 // mass_spectra vector passed as parameter if found.
797
798 for(auto &&node_p : node_vector)
799 {
800 NodeVectorIterator iterator = std::find(nodes.begin(), nodes.end(), node_p);
801
802 if(iterator != nodes.end())
803 {
804 // We found the node: remove it.
805
806 nodes.erase(iterator);
807
808 ++removed_vector_items;
809 }
810 }
811 }
812
813 // Now the second begin iterator, so that we can remove all the items
814 // contained in the second range, that is, ]end--end()[.
815
816 // The second_first_iterator will point to the item having its time value less
817 // or equal to end. But we do not want to get items having their time equal to
818 // end, only < end. So, if the iterator is not begin(), we just need to
819 // decrement it once.
820 MapIterator second_first_iterator = map_p->upper_bound(end);
821 if(second_first_iterator != map_p->begin())
822 --second_first_iterator;
823
824 for(MapIterator iterator = second_first_iterator; iterator != map_p->end(); ++iterator)
825 {
826 // We are iterating in MapPair items.
827
828 NodeVector node_vector = iterator->second;
829
830 // All the nodes in the node vector need to be removed from the
831 // mass_spectra vector passed as parameter if found.
832
833 for(auto &&node_p : node_vector)
834 {
835 NodeVectorIterator iterator = std::find(nodes.begin(), nodes.end(), node_p);
836
837 if(iterator != nodes.end())
838 {
839 // We found the node: remove it.
840
841 nodes.erase(iterator);
842
843 ++removed_vector_items;
844 }
845 }
846 }
847
848 return removed_vector_items;
849}

References pappso::dt, m_dtDoubleNodeVectorMap, m_rtDoubleNodeVectorMap, and pappso::rt.

◆ size()

std::size_t pappso::MsRunDataSetTree::size ( ) const

Definition at line 1153 of file msrundatasettree.cpp.

1154{
1155
1156 std::size_t cumulative_node_count = 0;
1157
1158 for(auto &node : m_rootNodes)
1159 {
1160 node->size(cumulative_node_count);
1161
1162 // qDebug() << "Returned node_count:" << node_count;
1163 }
1164
1165 return cumulative_node_count;
1166}

References m_rootNodes.

Member Data Documentation

◆ m_dtDoubleNodeVectorMap

◆ m_indexNodeMap

std::map<std::size_t, MsRunDataSetTreeNode *> pappso::MsRunDataSetTree::m_indexNodeMap
private

◆ m_rootNodes

std::vector<MsRunDataSetTreeNode *> pappso::MsRunDataSetTree::m_rootNodes
private

◆ m_rtDoubleNodeVectorMap

◆ m_spectrumCount

std::size_t pappso::MsRunDataSetTree::m_spectrumCount = std::numeric_limits<std::size_t>::min()
private

Definition at line 114 of file msrundatasettree.h.

Referenced by addMassSpectrum(), and getSpectrumCount().

◆ mcsp_msRunId

MsRunIdCstSPtr pappso::MsRunDataSetTree::mcsp_msRunId
private

Definition at line 112 of file msrundatasettree.h.

Referenced by addMassSpectrum().


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