14#include "../processing/combiners/tracepluscombiner.h"
15#include "../processing/combiners/traceminuscombiner.h"
17#include "../pappsoexception.h"
18#include "../exception/exceptionoutofrange.h"
19#include "../exception/exceptionnotpossible.h"
20#include "../processing/filters/filterresample.h"
21#include "../processing/filters/filterpass.h"
31std::vector<DataPoint>::iterator
33 std::vector<DataPoint>::iterator end,
36 return std::find_if(begin, end, [value](
const DataPoint &to_compare) {
37 if(to_compare.
x < value)
45std::vector<DataPoint>::const_iterator
47 std::vector<DataPoint>::const_iterator end,
50 return std::find_if(begin, end, [value](
const DataPoint &to_compare) {
51 if(to_compare.
x < value)
59std::vector<DataPoint>::iterator
61 std::vector<DataPoint>::iterator end,
64 return std::find_if(begin, end, [value](
const DataPoint &to_compare) {
65 if(to_compare.
x > value)
73std::vector<DataPoint>::const_iterator
75 std::vector<DataPoint>::const_iterator end,
78 return std::find_if(begin, end, [value](
const DataPoint &to_compare) {
79 if(to_compare.
x > value)
87std::vector<DataPoint>::iterator
89 std::vector<DataPoint>::iterator end,
90 const double &y_value)
92 return std::find_if(begin, end, [y_value](
const DataPoint &to_compare) {
93 if(to_compare.
y != y_value)
102std::vector<DataPoint>::const_iterator
104 std::vector<DataPoint>::const_iterator end,
105 const double &y_value)
107 return std::find_if(begin, end, [y_value](
const DataPoint &to_compare) {
108 if(to_compare.
y != y_value)
118std::vector<DataPoint>::const_iterator
120 std::vector<DataPoint>::const_iterator end)
122 return std::min_element(
129std::vector<DataPoint>::iterator
131 std::vector<DataPoint>::iterator end)
133 return std::min_element(
140std::vector<DataPoint>::const_iterator
142 std::vector<DataPoint>::const_iterator end)
144 return std::max_element(
151std::vector<DataPoint>::iterator
153 std::vector<DataPoint>::iterator end)
155 return std::max_element(
165std::vector<DataPoint>::const_iterator
167 std::vector<DataPoint>::const_iterator begin)
169 if(begin == trace.end())
175 while((it != trace.end()) && (it->y <= result->y))
183std::vector<DataPoint>::const_iterator
185 std::vector<DataPoint>::const_iterator begin)
187 if(begin == trace.begin())
195 while((it != trace.begin()) && (it->y <= result->y))
206 std::vector<DataPoint>::const_iterator end,
209 return std::accumulate(
210 begin, end, init, [](
double a,
const DataPoint &
b) {
return a +
b.y; });
215 std::vector<DataPoint>::const_iterator end)
220 QObject::tr(
"unable to compute mean on a trace of size 0"));
221 return (
sumYTrace(begin, end, 0) / nb_element);
227 std::vector<DataPoint>::const_iterator end,
230 std::size_t nb_element = distance(begin, end);
233 QObject::tr(
"unable to compute quantile on a trace of size 0"));
236 std::size_t ieth_element = std::round((
double)nb_element * quantile);
237 if(ieth_element > nb_element)
239 QObject::tr(
"quantile value must be lower than 1"));
242 std::vector<DataPoint> data(begin, end);
245 data.begin() + ieth_element,
248 return data[ieth_element].y;
253 std::vector<DataPoint>::const_iterator end)
255 std::size_t nb_element = distance(begin, end);
258 QObject::tr(
"unable to compute median on a trace of size 0"));
260 std::vector<DataPoint> data(begin, end);
263 data.begin() + data.size() / 2,
266 return data[data.size() / 2].y;
271 std::vector<DataPoint>::const_iterator end)
276 auto previous = begin;
277 auto next = begin + 1;
281 area += ((next->x - previous->x) * (previous->y + next->y)) / (
double)2;
291 std::vector<DataPoint>::const_iterator end)
296 auto previous = begin;
297 auto next = begin + 1;
303 area += ((next->x - previous->x) * (previous->y + next->y)) / (
double)2;
310 area -= (((
last->y + begin->y) * (
last->x - begin->x)) / 2);
320 std::vector<DataPoint>::const_iterator end,
323 Trace local_maxima_trace;
325 Trace single_peak_trace;
329 for(
auto iter = begin; iter != end; ++iter)
331 DataPoint iterated_data_point(iter->x, iter->y);
336 if(iterated_data_point.
y < y_floor)
340 if(single_peak_trace.size())
344 local_maxima_trace.push_back(single_peak_trace.
maxYDataPoint());
350 single_peak_trace.clear();
352 previous_data_point = iterated_data_point;
360 previous_data_point = iterated_data_point;
372 if(iterated_data_point.
y == previous_data_point.
y)
378 else if(iterated_data_point.
y > previous_data_point.
y)
387 single_peak_trace.push_back(iterated_data_point);
392 previous_data_point = iterated_data_point;
403 single_peak_trace.push_back(iterated_data_point);
408 previous_data_point = iterated_data_point;
420 if(single_peak_trace.size())
423 local_maxima_trace.push_back(single_peak_trace.
maxYDataPoint());
430 return local_maxima_trace;
440 const std::vector<pappso_double> &yVector)
447 const std::vector<std::pair<pappso_double, pappso_double>> &dataPoints)
449 reserve(dataPoints.size());
451 for(
auto &dataPoint : dataPoints)
474 : std::vector<
DataPoint>(std::move(dataPoints))
487 for(
auto &&item : map_trace)
488 push_back(
DataPoint(item.first, item.second));
513 const std::vector<pappso_double> &yVector)
516 if(xVector.size() != yVector.size())
518 "trace.cpp -- ERROR xVector and yVector must have the same size.");
521 erase(begin(), end());
523 for(std::size_t iter = 0; iter < xVector.size(); ++iter)
525 push_back(
DataPoint(xVector.at(iter), yVector.at(iter)));
534 for(
auto &item : *
this)
536 std::cout << item.x <<
"-" << item.y;
549 erase(begin(), end());
551 for(
auto &&item : map)
553 push_back(
DataPoint(item.first, item.second));
574 assign(other.begin(), other.end());
583 vector<DataPoint>::operator=(std::move(other));
591 return std::make_shared<Trace>(*
this);
598 return std::make_shared<const Trace>(*
this);
602std::vector<pappso_double>
605 std::vector<pappso_double> values;
607 for(
auto &&dataPoint : *
this)
609 values.push_back(dataPoint.x);
616std::vector<pappso_double>
619 std::vector<pappso_double> values;
621 for(
auto &&dataPoint : *
this)
623 values.push_back(dataPoint.y);
630std::map<pappso_double, pappso_double>
633 std::map<pappso_double, pappso_double> map;
635 std::pair<std::map<pappso_double, pappso_double>::iterator,
bool> ret;
637 for(
auto &&dataPoint : *
this)
640 std::pair<pappso_double, pappso_double>(dataPoint.x, dataPoint.y));
642 if(ret.second ==
false)
644 qDebug() << __FILE__ <<
"@" << __LINE__ << __FUNCTION__ <<
"()"
645 <<
"It is odd that the Trace contains multiple same keys.";
648 ret.first->second += dataPoint.y;
677std::vector<DataPoint>::iterator
681 std::find_if(begin(), end(), [value](
const DataPoint &dataPoint) {
682 return (dataPoint.
x == value);
689std::vector<DataPoint>::const_iterator
693 std::find_if(begin(), end(), [value](
const DataPoint &dataPoint) {
694 return (dataPoint.
x == value);
704 std::vector<DataPoint>::const_iterator iterator =
707 if(iterator != end())
708 return std::distance(begin(), iterator);
710 return std::numeric_limits<std::size_t>::max();
722 double left_most = value - delta;
723 double right_most = value + delta;
730 std::find_if(begin(),
732 [value, precision_p, delta, left_most, right_most](
749 double diff_to_left_most = data_point.
x - left_most;
750 double diff_to_right_most = data_point.
x - right_most;
798 if(diff_to_left_most >= 0 && diff_to_right_most <= 0)
816 return (data_point.
x == value);
820 if(iterator != end())
836 auto dataPoint = std::min_element(
841 if(dataPoint == end())
844 QObject::tr(
"unable to get min peak intensity on spectrum size %1")
855 auto dataPoint = std::max_element(
860 if(dataPoint == end())
863 QObject::tr(
"unable to get max peak intensity on spectrum size %1")
898 return std::accumulate(begin(),
902 return (
sum + dataPoint.
y);
920 std::vector<DataPoint>::const_iterator begin_it =
927 if(begin_it->y > max_y)
969 for(
auto &&dataPoint : *
this)
971 text.append(QString(
"%1 %2\n")
972 .arg(dataPoint.x, 0,
'f', 10)
973 .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 Trace & operator=(const Trace &x)
pappso_double maxY() const
pappso_double sumY() const
const DataPoint & maxYDataPoint() const
std::map< pappso_double, pappso_double > toMap() const
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
std::vector< pappso_double > yValues() const
pappso_double minY() const
size_t initialize(const std::vector< pappso_double > &xVector, const std::vector< pappso_double > &yVector)
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)
const DataPoint & minYDataPoint() const
TraceSPtr makeTraceSPtr() 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...
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)