libpappsomspp
Library for mass spectrometry
massspectrumcombiner.cpp
Go to the documentation of this file.
1 #include <numeric>
2 #include <limits>
3 #include <vector>
4 #include <map>
5 #include <cmath>
6 
7 #include <QDebug>
8 #include <QFile>
9 
10 #if 0
11 // For debugging purposes.
12 #include <QFile>
13 #endif
14 
15 #include "massspectrumcombiner.h"
16 #include "../../types.h"
17 #include "../../utils.h"
18 #include "../../pappsoexception.h"
19 #include "../../exception/exceptionoutofrange.h"
20 #include "../../exception/exceptionnotpossible.h"
21 
22 
23 namespace pappso
24 {
25 
26 
27 //! Construct an uninitialized instance.
29 {
30 }
31 
32 
34  : MassDataCombinerInterface(decimal_places)
35 {
36 }
37 
38 
39 MassSpectrumCombiner::MassSpectrumCombiner(std::vector<pappso_double> bins,
40  int decimalPlaces)
41  : MassDataCombinerInterface(decimalPlaces)
42 {
43  m_bins.assign(bins.begin(), bins.end());
44 }
45 
46 
48  : MassDataCombinerInterface(other.m_decimalPlaces)
49 {
50  m_bins.assign(other.m_bins.begin(), other.m_bins.end());
51 
52  //QString debug_string = QString(
53  //"Number of bins: %1\n"
54  //"First bins: %2 %3 %4 -- Last bins: %5 %6 %7\n")
55  //.arg(m_bins.size())
56  //.arg(m_bins[0], 0, 'f', 6)
57  //.arg(m_bins[1], 0, 'f', 6)
58  //.arg(m_bins[2], 0, 'f', 6)
59  //.arg(m_bins[m_bins.size() - 3], 0, 'f', 6)
60  //.arg(m_bins[m_bins.size() - 2], 0, 'f', 6)
61  //.arg(m_bins[m_bins.size() - 1], 0, 'f', 6);
62 
63  //qDebug().noquote() << debug_string;
64 }
65 
66 
68  : MassDataCombinerInterface(other->m_decimalPlaces)
69 {
70  m_bins.assign(other->m_bins.begin(), other->m_bins.end());
71 }
72 
73 
74 //! Destruct the instance.
76 {
77  m_bins.clear();
78 }
79 
80 
81 void
82 MassSpectrumCombiner::setBins(std::vector<pappso_double> bins)
83 {
84  m_bins.assign(bins.begin(), bins.end());
85 
86  //QString debug_string = QString(
87  //"Number of bins: %1\n"
88  //"First bins: %2 %3 %4 -- Last bins: %5 %6 %7\n")
89  //.arg(m_bins.size())
90  //.arg(m_bins[0], 0, 'f', 6)
91  //.arg(m_bins[1], 0, 'f', 6)
92  //.arg(m_bins[2], 0, 'f', 6)
93  //.arg(m_bins[m_bins.size() - 3], 0, 'f', 6)
94  //.arg(m_bins[m_bins.size() - 2], 0, 'f', 6)
95  //.arg(m_bins[m_bins.size() - 1], 0, 'f', 6);
96 
97  //qDebug().noquote() << debug_string;
98 }
99 
100 
101 const std::vector<pappso_double> &
103 {
104  return m_bins;
105 }
106 
107 
108 std::size_t
110 {
111  return m_bins.size();
112 }
113 
114 
115 //! Find the bin that will contain \p mz.
116 std::vector<pappso_double>::iterator
118 {
119  return std::find_if(m_bins.begin(), m_bins.end(), [mz](pappso_double bin) {
120  return (mz <= bin);
121  });
122 }
123 
124 
125 QString
127 {
128  QString text;
129 
130  for(auto &bin : m_bins)
131  text += QString("%1\n").arg(bin, 0, 'f', 6);
132 
133  text += "\n";
134 
135  return text;
136 }
137 
138 } // namespace pappso
MassSpectrumCombiner()
Construct an uninitialized instance.
std::vector< pappso_double > m_bins
void setBins(std::vector< pappso_double > bins)
const std::vector< pappso_double > & getBins() const
virtual ~MassSpectrumCombiner()
Destruct the instance.
std::vector< pappso_double >::iterator findBin(pappso_double mz)
Find the bin that will contain mz.
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition: aa.cpp:39
double pappso_double
A type definition for doubles.
Definition: types.h:49
std::shared_ptr< const MassSpectrumCombiner > MassSpectrumCombinerCstSPtr