39 #include "../trace/datapoint.h"
40 #include "../trace/trace.h"
42 #include "../processing/combiners/massspectrumcombiner.h"
43 #include "../mzrange.h"
44 #include "../pappsoexception.h"
46 #include "../peptide/peptidefragmentionlistbase.h"
47 #include "../exception/exceptionoutofrange.h"
48 #include "../processing/filters/filterresample.h"
61 std::vector<std::pair<pappso_double, pappso_double>> &dataPoints)
62 : Trace::Trace(dataPoints)
106 assign(other.begin(), other.end());
114 vector<DataPoint>::operator=(std::move(other));
122 return std::make_shared<MassSpectrum>(*
this);
129 return std::make_shared<const MassSpectrum>(*
this);
215 if(size() != other.size())
217 qDebug() << __FILE__ <<
"@" << __LINE__ << __FUNCTION__ <<
"()"
218 <<
"The other mass spectrum size is not equal to *this size"
219 <<
"*this size:" << size() <<
"trace size:" << other.size();
226 auto trace_it = other.begin();
228 for(
auto &&data_point : *
this)
230 qDebug() <<
"first:" << data_point.x <<
"," << data_point.y
231 <<
" second:" << trace_it->x <<
"," << trace_it->y;
235 qDebug() <<
"x:" << data_point.x <<
" != " << trace_it->x;
241 qDebug() <<
"y:" << data_point.y <<
" != " << trace_it->y;
257 std::vector<DataPoint>::const_iterator it = begin();
258 std::vector<DataPoint>::const_iterator itEnd = end();
260 std::vector<DataPoint>::const_reverse_iterator itRev = rbegin();
261 std::vector<DataPoint>::const_reverse_iterator itRevEnd = rend();
266 while((it != itEnd) && (it->x <= itRev->x) && (itRev != itRevEnd))
274 else if(sumX > upper)
280 massSpectrum.push_back(*it);
281 massSpectrum.push_back(*itRev);
283 std::vector<DataPoint>::const_reverse_iterator itRevIn = itRev;
287 sumX = it->x + itRevIn->x;
288 while((sumX > lower) && (it->x <= itRevIn->x) &&
289 (itRevIn != itRevEnd))
291 sumX = it->x + itRevIn->x;
293 massSpectrum.push_back(*itRevIn);
301 std::sort(massSpectrum.begin(),
303 [](
const DataPoint &a,
const DataPoint &b) { return (a.x < b.x); });
307 std::vector<DataPoint>::iterator itEndFix =
308 std::unique(massSpectrum.begin(),
310 [](
const DataPoint &a,
const DataPoint &b) {
312 return (a.x == b.x) && (a.y == b.y);
315 massSpectrum.resize(std::distance(massSpectrum.begin(), itEndFix));
325 qDebug() << __FILE__ <<
" " << __FUNCTION__ <<
" " << __LINE__ << size();
326 for(std::size_t i = 0; i < size(); i++)
328 qDebug() << __FILE__ <<
" " << __FUNCTION__ <<
" " << __LINE__;
329 qDebug() <<
"mz = " << this->operator[](i).x
330 <<
", int = " << this->operator[](i).y;
333 qDebug() << __FILE__ <<
" " << __FUNCTION__ <<
" " << __LINE__;
338 operator<<(QDataStream &outstream,
const MassSpectrum &massSpectrum)
340 quint32 vector_size = massSpectrum.size();
341 outstream << vector_size;
342 for(
auto &&peak : massSpectrum)
352 operator>>(QDataStream &instream, MassSpectrum &massSpectrum)
358 if(!instream.atEnd())
360 instream >> vector_size;
361 qDebug() << __FILE__ <<
" " << __FUNCTION__ <<
" " << __LINE__
362 <<
" vector_size=" << vector_size;
364 for(quint32 i = 0; i < vector_size; i++)
367 if(instream.status() != QDataStream::Ok)
370 QString(
"error in QDataStream unserialize operator>> of "
371 "massSpectrum :\nread datastream failed status=%1 "
374 .arg(instream.status())
379 massSpectrum.push_back(peak);
381 if(instream.status() != QDataStream::Ok)
383 throw PappsoException(
385 "error in QDataStream unserialize operator>> of massSpectrum "
386 ":\nread datastream failed status=%1")
387 .arg(instream.status()));