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

#include <massspectrumpluscombiner.h>

Inheritance diagram for pappso::MassSpectrumPlusCombiner:
pappso::MassSpectrumCombiner pappso::MassDataCombinerInterface

Public Member Functions

Q_INVOKABLE MassSpectrumPlusCombiner (QObject *parent_p=nullptr)
 Construct an uninitialized instance.
Q_INVOKABLE MassSpectrumPlusCombiner (int decimal_places, QObject *parent_p=nullptr)
 MassSpectrumPlusCombiner (const MassSpectrumPlusCombiner &other, QObject *parent_p=nullptr)
 MassSpectrumPlusCombiner (MassSpectrumPlusCombinerCstSPtr other, QObject *parent_p=nullptr)
virtual ~MassSpectrumPlusCombiner ()
 Destruct the instance.
MassSpectrumPlusCombineroperator= (const MassSpectrumPlusCombiner &other)
virtual Q_INVOKABLE MapTracecombine (MapTrace &map_trace, const Trace &trace) const override
virtual Q_INVOKABLE MapTracecombine (MapTrace &map_trace_out, const MapTrace &map_trace_in) const override
Public Member Functions inherited from pappso::MassSpectrumCombiner
 MassSpectrumCombiner (QObject *parent_p=nullptr)
 Construct an uninitialized instance.
 MassSpectrumCombiner (int decimal_places, QObject *parent_p=nullptr)
 MassSpectrumCombiner (std::vector< pappso_double > bins, int decimalPlaces=-1, QObject *parent_p=nullptr)
 MassSpectrumCombiner (MassSpectrumCombinerCstSPtr other, QObject *parent_p=nullptr)
 MassSpectrumCombiner (const MassSpectrumCombiner &other, QObject *parent_p=nullptr)
 MassSpectrumCombiner (const MassSpectrumCombiner &&other, QObject *parent_p=nullptr)
virtual ~MassSpectrumCombiner ()
 Destruct the instance.
Q_INVOKABLE void setBins (std::vector< pappso_double > bins)
Q_INVOKABLE const std::vector< pappso_double > & getBins () const
Q_INVOKABLE std::size_t binCount () const
Q_INVOKABLE QString binsAsString () const
Public Member Functions inherited from pappso::MassDataCombinerInterface
 MassDataCombinerInterface (int decimal_places=-1)
virtual ~MassDataCombinerInterface ()
void setDecimalPlaces (int value)
int getDecimalPlaces () const
virtual MapTracecombine (MapTrace &map_trace, Iterator begin, Iterator end)

Static Public Member Functions

static void registerJsConstructor (QJSEngine *engine)
Static Public Member Functions inherited from pappso::MassSpectrumCombiner
static void registerJsConstructor (QJSEngine *engine)

Additional Inherited Members

Public Types inherited from pappso::MassDataCombinerInterface
using Iterator = std::vector<const Trace *>::const_iterator
Signals inherited from pappso::MassSpectrumCombiner
void binCountChanged ()
Protected Member Functions inherited from pappso::MassSpectrumCombiner
std::vector< pappso_double >::iterator findBin (pappso_double mz)
 Find the bin that will contain mz.
Protected Attributes inherited from pappso::MassSpectrumCombiner
std::vector< pappso_doublem_bins
Protected Attributes inherited from pappso::MassDataCombinerInterface
int m_decimalPlaces = -1
 Number of decimals to use for the keys (x values).
Properties inherited from pappso::MassSpectrumCombiner
int size

Detailed Description

Definition at line 20 of file massspectrumpluscombiner.h.

Constructor & Destructor Documentation

◆ MassSpectrumPlusCombiner() [1/4]

pappso::MassSpectrumPlusCombiner::MassSpectrumPlusCombiner ( QObject * parent_p = nullptr)

Construct an uninitialized instance.

Definition at line 27 of file massspectrumpluscombiner.cpp.

28 : MassSpectrumCombiner(parent_p)
29{
30}
MassSpectrumCombiner(QObject *parent_p=nullptr)
Construct an uninitialized instance.

References pappso::MassSpectrumCombiner::MassSpectrumCombiner().

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

◆ MassSpectrumPlusCombiner() [2/4]

pappso::MassSpectrumPlusCombiner::MassSpectrumPlusCombiner ( int decimal_places,
QObject * parent_p = nullptr )

Definition at line 32 of file massspectrumpluscombiner.cpp.

34 : MassSpectrumCombiner(decimal_places, parent_p)
35{
36}

References pappso::MassSpectrumCombiner::MassSpectrumCombiner().

◆ MassSpectrumPlusCombiner() [3/4]

pappso::MassSpectrumPlusCombiner::MassSpectrumPlusCombiner ( const MassSpectrumPlusCombiner & other,
QObject * parent_p = nullptr )

◆ MassSpectrumPlusCombiner() [4/4]

pappso::MassSpectrumPlusCombiner::MassSpectrumPlusCombiner ( MassSpectrumPlusCombinerCstSPtr other,
QObject * parent_p = nullptr )

Definition at line 45 of file massspectrumpluscombiner.cpp.

47 : MassSpectrumCombiner(other, parent_p)
48
49{
50}

References pappso::MassSpectrumCombiner::MassSpectrumCombiner().

◆ ~MassSpectrumPlusCombiner()

pappso::MassSpectrumPlusCombiner::~MassSpectrumPlusCombiner ( )
virtual

Destruct the instance.

Definition at line 53 of file massspectrumpluscombiner.cpp.

54{
55}

Member Function Documentation

◆ combine() [1/2]

MapTrace & pappso::MassSpectrumPlusCombiner::combine ( MapTrace & map_trace,
const Trace & trace ) const
overridevirtual

Implements pappso::MassDataCombinerInterface.

Definition at line 90 of file massspectrumpluscombiner.cpp.

91{
92 // qDebug();
93
94 // If there is no single point in the trace we need to combine into the
95 // map_trace, then there is nothing to do.
96 if(!trace.size())
97 {
98 // qDebug() << "Thread:" << QThread::currentThreadId()
99 //<< "Returning right away because trace is empty.";
100 return map_trace;
101 }
102
103 // The destination map trace will be filled-in with the result of the
104 // combination.
105
106 // Sanity check:
107 if(!m_bins.size())
108 throw(ExceptionNotPossible("The bin vector cannot be empty."));
109
110 // qDebug() << qSetRealNumberPrecision(6) << "There are " << m_bins.size() <<
111 // "bins running from"
112 // << m_bins.front() << "to" << m_bins.back();
113
114 // Since the map_trace argument is used all along the combination of
115 // potentially thousands of mass spectra, we need to be careful. But
116 // clearly, if that map_trace object is empty, then, one way to accelerate the
117 // whole process is to copy the bins in there and later assume that
118 // the bin is already in it. So that we need not test each time if we have
119 // inserted the new data point or if we simply need to increment its
120 // intensity.
121
122 if(!map_trace.size())
123 {
124 std::transform(m_bins.begin(),
125 m_bins.end(),
126 std::inserter(map_trace, map_trace.end()),
127 [](double key) {
128 return std::make_pair(key, 0.0);
129 });
130 }
131
132 // We will need to only use these iterator variables if we do not want to
133 // loose consistency.
134
135 using TraceIter = std::vector<DataPoint>::const_iterator;
136 TraceIter trace_iter_begin = trace.begin();
137 TraceIter trace_iter = trace_iter_begin;
138 TraceIter trace_iter_end = trace.end();
139
140 // qDebug() << qSetRealNumberPrecision(6) << "The trace to combine has " <<
141 // trace.size()
142 // << "data points, with first a m/z" << trace.front().x << "and last
143 // at m/z"
144 // << trace.back().x;
145
146 // We will iterate in the destination map_trace that has been filled with
147 // the bins initially computed for this combiner.
148 using BinIter = std::map<double, double>::iterator;
149 BinIter map_trace_bin_iter = map_trace.begin();
150 BinIter map_trace_bin_end_iter = map_trace.end();
151
152 // We do not want to iterate in too many map_trace items before arriving
153 // to the map_trace item that matches the m/z value of the first data
154 // point in trace.
155
156 // Get the first map_trace bin that would match the very first data point in
157 // the trace that we need to combine into the map_trace. We want the first
158 // map_trace element having key >= trace_iter->x.
159 BinIter map_trace_bin_iter_for_mz = map_trace.upper_bound(trace_iter->x);
160
161 // If it's not the beginning, the previous element is what we want
162 if(map_trace_bin_iter_for_mz != map_trace.begin())
163 {
164 map_trace_bin_iter =
165 --map_trace_bin_iter_for_mz; // This is the greatest map_trace key <
166 // trace_iter->x
167
168 // qDebug() << "Found map_trace key=" << map_trace_bin_iter_for_mz->first
169 // << ", value=" << map_trace_bin_iter_for_mz->second;
170 }
171 else
172 {
173 // qDebug() << "The first bin found to match the first data point in trace
174 // is:"
175 // << map_trace.begin()->first;
176 }
177
178 // qDebug() << "The first bin found to match the first m/z value in the trace
179 // to combine ("
180 // << trace_iter->x
181 // << ") is at index:" << std::distance(map_trace.begin(),
182 // map_trace_bin_iter);
183
184 while(map_trace_bin_iter != map_trace_bin_end_iter)
185 {
186 // qDebug() << qSetRealNumberPrecision(6)
187 // << "Now iterating in new bin with mz:" <<
188 // map_trace_bin_iter->first
189 // << "at a distance of the first bin:"
190 // << std::distance(map_trace.begin(), map_trace_bin_iter);
191
192 // Now perform a loop over the data points in the mass spectrum.
193
194 // qDebug() << "Start looping in the trace to check if its DataPoint.x "
195 //"value matches that of the current bin."
196 //<< "trace_iter:" << trace_iter->toString()
197 //<< "at data point distance from first point in trace:"
198
199 while(trace_iter != trace_iter_end)
200 {
201 // qDebug() << qSetRealNumberPrecision(6)
202 // << "trace data point being iterated into: " <<
203 // trace_iter->x << " - "
204 // << trace_iter->y;
205
206 // If trace is not to the end and the y value is not 0, perform the
207 // rounding and check if the obtained x value is in the current bin,
208 // that is if it is less or equal to the current bin.
209
210 // qDebug() << "Thread:" << QThread::currentThreadId();
211 // qDebug() << "trace_iter:" << trace_iter->toString()
212 //<< "data point distance:"
213 //<< std::distance(trace_iter_begin, trace_iter);
214
215
216 if(trace_iter->x <= map_trace_bin_iter->first)
217 {
218 // qDebug() << qSetRealNumberPrecision(6) << "Matched because
219 // trace x" << trace_iter->x
220 // << "is <= current bin m/z" <<
221 // map_trace_bin_iter->first;
222
223 // qDebug() << "Incrementing the y value by " << trace_iter->y;
224
225 map_trace_bin_iter->second += trace_iter->y;
226
227 // qDebug() << qSetRealNumberPrecision(6)
228 // << "After incrementation of the intensity: " <<
229 // map_trace_bin_iter->second;
230
231 // Because we matched, we can step-up with the
232 // trace iterator. The idea is that, if the bins are large, then,
233 // multiple data points from a given mass spec acquisition' trace
234 // may fall inside that bin.
235
236 // qDebug() << "Now increment the trace iterator.";
237
238 ++trace_iter;
239 }
240 else
241 {
242 // The trace data point's x did not match the current map_trace
243 // bin m/z value because the former was greater than the latter.
244
245 // Because the DataPoint instances in the trace are sorted in
246 // increasing x order, we know we won't have to add any data point
247 // to this bin. So we break this loop, which will increment the
248 // map_trace bin iterator.
249
250 break;
251 }
252 }
253 // End of
254 // while(trace_iter != trace_iter_end)
255
256 // Each time we get here, that means that we have consumed all
257 // the mass spectra data points that matched the current bin.
258 // So go to the next bin.
259
260 if(trace_iter == trace_iter_end)
261 {
262 // Well, in fact we truly need to exit the loops...
263 break;
264 }
265
266 // qDebug() << "Now increment the bin iterator.";
267 ++map_trace_bin_iter;
268 }
269 // End of
270 // while(bin_iter != bin_end_iter)
271
272 return map_trace;
273}
std::vector< pappso_double > m_bins

References pappso::MassSpectrumCombiner::m_bins.

Referenced by combine().

◆ combine() [2/2]

MapTrace & pappso::MassSpectrumPlusCombiner::combine ( MapTrace & map_trace_out,
const MapTrace & map_trace_in ) const
overridevirtual

Implements pappso::MassDataCombinerInterface.

Definition at line 276 of file massspectrumpluscombiner.cpp.

278{
279 // qDebug();
280
281 if(!map_trace_in.size())
282 {
283 // qDebug() << "Thread:" << QThread::currentThreadId()
284 //<< "Returning right away because map_trace_in is empty.";
285 return map_trace_out;
286 }
287
288 Trace trace(map_trace_in);
289
290 return combine(map_trace_out, trace);
291}
virtual Q_INVOKABLE MapTrace & combine(MapTrace &map_trace, const Trace &trace) const override

References combine().

◆ operator=()

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

Definition at line 58 of file massspectrumpluscombiner.cpp.

59{
60 if(this == &other)
61 return *this;
62
63 MassSpectrumCombiner::m_decimalPlaces = other.m_decimalPlaces;
64
65 m_bins.assign(other.m_bins.begin(), other.m_bins.end());
66
67 return *this;
68}
int m_decimalPlaces
Number of decimals to use for the keys (x values).

References MassSpectrumPlusCombiner(), pappso::MassSpectrumCombiner::m_bins, and pappso::MassDataCombinerInterface::m_decimalPlaces.

◆ registerJsConstructor()

void pappso::MassSpectrumPlusCombiner::registerJsConstructor ( QJSEngine * engine)
static

Definition at line 294 of file massspectrumpluscombiner.cpp.

295{
296 // qDebug() << "registerJsConstructor for MassSpectrumPlusCombiner to
297 // QJSEngine.";
298
299 if(engine == nullptr)
300 {
301 qFatal() << "Cannot register class: engine is null";
302 }
303
304 // Register the meta object as a constructor
305 QJSValue jsMetaObject =
306 engine->newQMetaObject(&MassSpectrumPlusCombiner::staticMetaObject);
307 engine->globalObject().setProperty("MassSpectrumPlusCombiner", jsMetaObject);
308}

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