libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
massspectrumcombiner.cpp
Go to the documentation of this file.
1#include <cmath>
2
3#include <QDebug>
4#include <QFile>
5
6#if 0
7// For debugging purposes.
8#include <QFile>
9#endif
10
11#include "../../types.h"
13
14namespace pappso
15{
16
17
18//! Construct an uninitialized instance.
19MassSpectrumCombiner::MassSpectrumCombiner(QObject *parent_p): QObject(parent_p)
20{
21}
22
24 QObject *parent_p)
25 : QObject(parent_p), MassDataCombinerInterface(decimal_places)
26{
27}
28
29MassSpectrumCombiner::MassSpectrumCombiner(std::vector<pappso_double> bins,
30 int decimalPlaces,
31 QObject *parent_p)
32 : QObject(parent_p), MassDataCombinerInterface(decimalPlaces)
33{
34 m_bins.assign(bins.begin(), bins.end());
35}
36
38 QObject *parent_p)
39 : QObject(parent_p), MassDataCombinerInterface(other.m_decimalPlaces)
40{
41 m_bins.assign(other.m_bins.begin(), other.m_bins.end());
42
43 // QString debug_string = QString(
44 //"Number of bins: %1\n"
45 //"First bins: %2 %3 %4 -- Last bins: %5 %6 %7\n")
46 //.arg(m_bins.size())
47 //.arg(m_bins[0], 0, 'f', 6)
48 //.arg(m_bins[1], 0, 'f', 6)
49 //.arg(m_bins[2], 0, 'f', 6)
50 //.arg(m_bins[m_bins.size() - 3], 0, 'f', 6)
51 //.arg(m_bins[m_bins.size() - 2], 0, 'f', 6)
52 //.arg(m_bins[m_bins.size() - 1], 0, 'f', 6);
53
54 // qDebug().noquote() << debug_string;
55}
56
58 QObject *parent_p)
59 : QObject(parent_p), MassDataCombinerInterface(other->m_decimalPlaces)
60{
61 m_bins.assign(other->m_bins.begin(), other->m_bins.end());
62}
63
64//! Destruct the instance.
69
70void
71MassSpectrumCombiner::setBins(std::vector<pappso_double> bins)
72{
73 m_bins.assign(bins.begin(), bins.end());
74
75 // QString debug_string = QString(
76 //"Number of bins: %1\n"
77 //"First bins: %2 %3 %4 -- Last bins: %5 %6 %7\n")
78 //.arg(m_bins.size())
79 //.arg(m_bins[0], 0, 'f', 6)
80 //.arg(m_bins[1], 0, 'f', 6)
81 //.arg(m_bins[2], 0, 'f', 6)
82 //.arg(m_bins[m_bins.size() - 3], 0, 'f', 6)
83 //.arg(m_bins[m_bins.size() - 2], 0, 'f', 6)
84 //.arg(m_bins[m_bins.size() - 1], 0, 'f', 6);
85
86 // qDebug().noquote() << debug_string;
87
88 emit binCountChanged();
89}
90
91const std::vector<pappso_double> &
93{
94 return m_bins;
95}
96
97std::size_t
99{
100 return m_bins.size();
101}
102
103//! Find the bin that will contain \p mz.
104std::vector<pappso_double>::iterator
106{
107 return std::find_if(m_bins.begin(), m_bins.end(), [mz](pappso_double bin) {
108 return (mz <= bin);
109 });
110}
111
112QString
114{
115 QString text;
116
117 for(auto &bin : m_bins)
118 text += QString("%1\n").arg(bin, 0, 'f', 6);
119
120 text += "\n";
121
122 return text;
123}
124
125void
127{
128 // qDebug() << "registerJsConstructor for MassSpectrumCombiner to QJSEngine.";
129
130 if(engine == nullptr)
131 {
132 qFatal() << "Cannot register class: engine is null";
133 }
134
135 // Register the meta object as a constructor
136 QJSValue jsMetaObject =
137 engine->newQMetaObject(&MassSpectrumCombiner::staticMetaObject);
138 engine->globalObject().setProperty("MassSpectrumCombiner", jsMetaObject);
139}
140
141} // namespace pappso
int m_decimalPlaces
Number of decimals to use for the keys (x values).
MassSpectrumCombiner(QObject *parent_p=nullptr)
Construct an uninitialized instance.
std::vector< pappso_double > m_bins
Q_INVOKABLE void setBins(std::vector< pappso_double > bins)
Q_INVOKABLE std::size_t binCount() const
Q_INVOKABLE const std::vector< pappso_double > & getBins() const
static void registerJsConstructor(QJSEngine *engine)
virtual ~MassSpectrumCombiner()
Destruct the instance.
Q_INVOKABLE QString binsAsString() const
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:60
std::shared_ptr< const MassSpectrumCombiner > MassSpectrumCombinerCstSPtr