15#include "../processing/combiners/tracepluscombiner.h"
16#include "../processing/combiners/traceminuscombiner.h"
18#include "../pappsoexception.h"
19#include "../exception/exceptionoutofrange.h"
20#include "../exception/exceptionnotpossible.h"
21#include "../processing/filters/filterresample.h"
22#include "../processing/filters/filterpass.h"
35 for(
auto &dataPoint : trace)
53 QString(
"error in QDataStream unserialize operator>> of trace:\n"
54 "read datastream failed status=%1")
58 for(
auto &dataPoint : trace)
68std::vector<DataPoint>::iterator
70 std::vector<DataPoint>::iterator end,
73 return std::find_if(begin, end, [value](
const DataPoint &to_compare) {
74 if(to_compare.
x < value)
82std::vector<DataPoint>::const_iterator
84 std::vector<DataPoint>::const_iterator end,
87 return std::find_if(begin, end, [value](
const DataPoint &to_compare) {
88 if(to_compare.
x < value)
96std::vector<DataPoint>::iterator
98 std::vector<DataPoint>::iterator end,
101 return std::find_if(begin, end, [value](
const DataPoint &to_compare) {
102 if(to_compare.
x > value)
110std::vector<DataPoint>::const_iterator
112 std::vector<DataPoint>::const_iterator end,
115 return std::find_if(begin, end, [value](
const DataPoint &to_compare) {
116 if(to_compare.
x > value)
124std::vector<DataPoint>::iterator
126 std::vector<DataPoint>::iterator end,
127 const double &y_value)
129 return std::find_if(begin, end, [y_value](
const DataPoint &to_compare) {
130 if(to_compare.
y != y_value)
139std::vector<DataPoint>::const_iterator
141 std::vector<DataPoint>::const_iterator end,
142 const double &y_value)
144 return std::find_if(begin, end, [y_value](
const DataPoint &to_compare) {
145 if(to_compare.
y != y_value)
155std::vector<DataPoint>::const_iterator
157 std::vector<DataPoint>::const_iterator end)
159 return std::min_element(
166std::vector<DataPoint>::iterator
168 std::vector<DataPoint>::iterator end)
170 return std::min_element(
177std::vector<DataPoint>::const_iterator
179 std::vector<DataPoint>::const_iterator end)
181 return std::max_element(
188std::vector<DataPoint>::iterator
190 std::vector<DataPoint>::iterator end)
192 return std::max_element(
202std::vector<DataPoint>::const_iterator
204 std::vector<DataPoint>::const_iterator begin)
206 if(begin == trace.end())
212 while((it != trace.end()) && (it->y <= result->y))
220std::vector<DataPoint>::const_iterator
222 std::vector<DataPoint>::const_iterator begin)
224 if(begin == trace.begin())
232 while((it != trace.begin()) && (it->y <= result->y))
243 std::vector<DataPoint>::const_iterator end,
246 return std::accumulate(
247 begin, end, init, [](
double a,
const DataPoint &
b) {
return a +
b.y; });
252 std::vector<DataPoint>::const_iterator end)
257 QObject::tr(
"unable to compute mean on a trace of size 0"));
258 return (
sumYTrace(begin, end, 0) / nb_element);
264 std::vector<DataPoint>::const_iterator end,
267 std::size_t nb_element = distance(begin, end);
270 QObject::tr(
"unable to compute quantile on a trace of size 0"));
273 std::size_t ieth_element = std::round((
double)nb_element * quantile);
274 if(ieth_element > nb_element)
276 QObject::tr(
"quantile value must be lower than 1"));
279 std::vector<DataPoint> data(begin, end);
282 data.begin() + ieth_element,
285 return data[ieth_element].y;
290 std::vector<DataPoint>::const_iterator end)
292 std::size_t nb_element = distance(begin, end);
295 QObject::tr(
"unable to compute median on a trace of size 0"));
297 std::vector<DataPoint> data(begin, end);
300 data.begin() + data.size() / 2,
303 return data[data.size() / 2].y;
308 std::vector<DataPoint>::const_iterator end)
313 auto previous = begin;
314 auto next = begin + 1;
318 area += ((next->x - previous->x) * (previous->y + next->y)) / (
double)2;
328 std::vector<DataPoint>::const_iterator end)
333 auto previous = begin;
334 auto next = begin + 1;
340 area += ((next->x - previous->x) * (previous->y + next->y)) / (
double)2;
347 area -= (((
last->y + begin->y) * (
last->x - begin->x)) / 2);
357 std::vector<DataPoint>::const_iterator end,
360 Trace local_maxima_trace;
362 Trace single_peak_trace;
366 for(
auto iter = begin; iter != end; ++iter)
368 DataPoint iterated_data_point(iter->x, iter->y);
373 if(iterated_data_point.
y < y_floor)
377 if(single_peak_trace.size())
381 local_maxima_trace.push_back(single_peak_trace.
maxYDataPoint());
387 single_peak_trace.clear();
389 previous_data_point = iterated_data_point;
397 previous_data_point = iterated_data_point;
409 if(iterated_data_point.
y == previous_data_point.
y)
415 else if(iterated_data_point.
y > previous_data_point.
y)
424 single_peak_trace.push_back(iterated_data_point);
429 previous_data_point = iterated_data_point;
440 single_peak_trace.push_back(iterated_data_point);
445 previous_data_point = iterated_data_point;
457 if(single_peak_trace.size())
460 local_maxima_trace.push_back(single_peak_trace.
maxYDataPoint());
467 return local_maxima_trace;
477 const std::vector<pappso_double> &yVector)
484 const std::vector<std::pair<pappso_double, pappso_double>> &dataPoints)
486 reserve(dataPoints.size());
488 for(
auto &dataPoint : dataPoints)
511 : std::vector<
DataPoint>(std::move(dataPoints))
524 for(
auto &&item : map_trace)
525 push_back(
DataPoint(item.first, item.second));
536 : std::vector<
DataPoint>(std::move(other))
551 const std::vector<pappso_double> &yVector)
554 if(xVector.size() != yVector.size())
556 "trace.cpp -- ERROR xVector and yVector must have the same size.");
559 erase(begin(), end());
561 for(std::size_t iter = 0; iter < xVector.size(); ++iter)
563 push_back(
DataPoint(xVector.at(iter), yVector.at(iter)));
572 for(
auto &item : *
this)
574 std::cout << item.x <<
"-" << item.y;
587 erase(begin(), end());
589 for(
auto &&item : map)
591 push_back(
DataPoint(item.first, item.second));
612 push_back(data_point);
621 assign(other.begin(), other.end());
630 vector<DataPoint>::operator=(std::move(other));
638 return std::make_shared<Trace>(*
this);
645 return std::make_shared<const Trace>(*
this);
649std::vector<pappso_double>
652 std::vector<pappso_double> values;
654 for(
auto &&dataPoint : *
this)
656 values.push_back(dataPoint.x);
663std::vector<pappso_double>
666 std::vector<pappso_double> values;
668 for(
auto &&dataPoint : *
this)
670 values.push_back(dataPoint.y);
677std::map<pappso_double, pappso_double>
680 std::map<pappso_double, pappso_double> map;
682 std::pair<std::map<pappso_double, pappso_double>::iterator,
bool> ret;
684 for(
auto &&dataPoint : *
this)
687 std::pair<pappso_double, pappso_double>(dataPoint.x, dataPoint.y));
689 if(ret.second ==
false)
691 qDebug() << __FILE__ <<
"@" << __LINE__ << __FUNCTION__ <<
"()"
692 <<
"It is odd that the Trace contains multiple same keys.";
695 ret.first->second += dataPoint.y;
724std::vector<DataPoint>::iterator
728 std::find_if(begin(), end(), [value](
const DataPoint &dataPoint) {
729 return (dataPoint.
x == value);
736std::vector<DataPoint>::const_iterator
740 std::find_if(begin(), end(), [value](
const DataPoint &dataPoint) {
741 return (dataPoint.
x == value);
751 std::vector<DataPoint>::const_iterator iterator =
754 if(iterator != end())
755 return std::distance(begin(), iterator);
757 return std::numeric_limits<std::size_t>::max();
769 double left_most = value - delta;
770 double right_most = value + delta;
777 std::find_if(begin(),
779 [value, precision_p, delta, left_most, right_most](
796 double diff_to_left_most = data_point.
x - left_most;
797 double diff_to_right_most = data_point.
x - right_most;
845 if(diff_to_left_most >= 0 && diff_to_right_most <= 0)
863 return (data_point.
x == value);
867 if(iterator != end())
883 auto dataPoint = std::min_element(
888 if(dataPoint == end())
891 QObject::tr(
"unable to get min peak intensity on spectrum size %1")
902 auto dataPoint = std::max_element(
907 if(dataPoint == end())
910 QObject::tr(
"unable to get max peak intensity on spectrum size %1")
945 return std::accumulate(begin(),
949 return (
sum + dataPoint.
y);
967 std::vector<DataPoint>::const_iterator begin_it =
974 if(begin_it->y > max_y)
1003 return (
a.x ==
b.x);
1016 for(
auto &&dataPoint : *
this)
1018 text.append(QString(
"%1 %2\n")
1019 .arg(dataPoint.x, 0,
'f', 10)
1020 .arg(dataPoint.y, 0,
'f', 10));
generic interface to apply a filter on a trace
virtual pappso_double delta(pappso_double value) const =0
A simple container of DataPoint instances.
virtual Q_INVOKABLE Trace & operator=(const Trace &x)
Q_INVOKABLE void unique()
Q_INVOKABLE pappso_double maxY() const
Q_INVOKABLE pappso_double sumY() const
Q_INVOKABLE const DataPoint & maxYDataPoint() const
std::map< pappso_double, pappso_double > toMap() const
Q_INVOKABLE std::vector< pappso_double > xValues() const
TraceCstSPtr makeTraceCstSPtr() const
virtual Trace & filter(const FilterInterface &filter) final
apply a filter on this trace
DataPoint containsX(pappso_double value, PrecisionPtr precision_p=nullptr) const
Q_INVOKABLE std::vector< pappso_double > yValues() const
Q_INVOKABLE pappso_double minY() const
Q_INVOKABLE size_t initialize(const std::vector< pappso_double > &xVector, const std::vector< pappso_double > &yVector)
Q_INVOKABLE size_t append(const DataPoint &data_point)
std::size_t dataPointIndexWithX(pappso_double value) const
std::vector< DataPoint >::const_iterator dataPointCstIteratorWithX(pappso_double value) const
find datapoint with exactly x value
std::vector< DataPoint >::iterator dataPointIteratorWithX(pappso_double value)
Q_INVOKABLE const DataPoint & minYDataPoint() const
TraceSPtr makeTraceSPtr() const
Q_INVOKABLE QString toString() const
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
std::shared_ptr< const Trace > TraceCstSPtr
std::vector< DataPoint >::iterator findDifferentYvalue(std::vector< DataPoint >::iterator begin, std::vector< DataPoint >::iterator end, const double &y_value)
find the first element in which Y is different of value
std::vector< DataPoint >::iterator findFirstEqualOrGreaterX(std::vector< DataPoint >::iterator begin, std::vector< DataPoint >::iterator end, const double &value)
find the first element in which X is equal or greater than the value searched important : it implies ...
std::vector< DataPoint >::iterator findFirstGreaterX(std::vector< DataPoint >::iterator begin, std::vector< DataPoint >::iterator end, const double &value)
find the first element in which X is greater than the value searched important : it implies that Trac...
QDataStream & operator<<(QDataStream &outstream, const MassSpectrum &massSpectrum)
QDataStream & operator>>(QDataStream &instream, MassSpectrum &massSpectrum)
std::vector< DataPoint >::const_iterator moveLowerYLeftDataPoint(const Trace &trace, std::vector< DataPoint >::const_iterator begin)
Move left to the lower value.
std::vector< DataPoint >::const_iterator maxYDataPoint(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end)
double medianYTrace(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end)
calculate the median of y value of a trace
double areaTrace(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end)
calculate the area of a trace
std::shared_ptr< Trace > TraceSPtr
double pappso_double
A type definition for doubles.
double areaTraceMinusBase(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end)
double meanYTrace(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end)
calculate the mean of y value of a trace
std::vector< DataPoint >::const_iterator moveLowerYRigthDataPoint(const Trace &trace, std::vector< DataPoint >::const_iterator begin)
Move right to the lower value.
double sumYTrace(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end, double init)
calculate the sum of y value of a trace
std::vector< DataPoint >::const_iterator minYDataPoint(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end)
double quantileYTrace(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end, double quantile)
calculate the quantile of y value of a trace
Trace flooredLocalMaxima(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end, double y_floor)