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"
31 std::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)
45 std::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)
59 std::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)
73 std::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)
87 std::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)
101 std::vector<DataPoint>::const_iterator
103 std::vector<DataPoint>::const_iterator end,
104 const double &y_value)
106 return std::find_if(begin, end, [y_value](
const DataPoint &to_compare) {
107 if(to_compare.
y != y_value)
116 std::vector<DataPoint>::const_iterator
118 std::vector<DataPoint>::const_iterator end)
120 return std::min_element(
127 std::vector<DataPoint>::iterator
129 std::vector<DataPoint>::iterator end)
131 return std::min_element(
138 std::vector<DataPoint>::const_iterator
140 std::vector<DataPoint>::const_iterator end)
142 return std::max_element(
149 std::vector<DataPoint>::iterator
151 std::vector<DataPoint>::iterator end)
153 return std::max_element(
163 std::vector<DataPoint>::const_iterator
165 std::vector<DataPoint>::const_iterator begin)
167 if(begin == trace.end())
173 while((it != trace.end()) && (it->y <= result->y))
181 std::vector<DataPoint>::const_iterator
183 std::vector<DataPoint>::const_iterator begin)
185 if(begin == trace.begin())
193 while((it != trace.begin()) && (it->y <= result->y))
204 std::vector<DataPoint>::const_iterator end,
207 return std::accumulate(
208 begin, end, init, [](
double a,
const DataPoint &
b) {
return a +
b.y; });
213 std::vector<DataPoint>::const_iterator end)
218 QObject::tr(
"unable to compute mean on a trace of size 0"));
219 return (
sumYTrace(begin, end, 0) / nb_element);
224 std::vector<DataPoint>::const_iterator end)
229 QObject::tr(
"unable to compute median on a trace of size 0"));
231 std::vector<DataPoint> data(begin, end);
234 data.begin() + data.size() / 2,
237 return data[data.size() / 2].y;
242 std::vector<DataPoint>::const_iterator end)
247 auto previous = begin;
248 auto next = begin + 1;
252 area += ((next->x - previous->x) * (previous->y + next->y)) / (
double)2;
262 std::vector<DataPoint>::const_iterator end,
265 Trace local_maxima_trace;
267 Trace single_peak_trace;
271 for(
auto iter = begin; iter != end; ++iter)
273 DataPoint iterated_data_point(iter->x, iter->y);
278 if(iterated_data_point.
y < y_floor)
282 if(single_peak_trace.size())
286 local_maxima_trace.push_back(single_peak_trace.
maxYDataPoint());
292 single_peak_trace.clear();
294 previous_data_point = iterated_data_point;
302 previous_data_point = iterated_data_point;
314 if(iterated_data_point.
y == previous_data_point.
y)
320 else if(iterated_data_point.
y > previous_data_point.
y)
329 single_peak_trace.push_back(iterated_data_point);
334 previous_data_point = iterated_data_point;
345 single_peak_trace.push_back(iterated_data_point);
350 previous_data_point = iterated_data_point;
362 if(single_peak_trace.size())
365 local_maxima_trace.push_back(single_peak_trace.
maxYDataPoint());
372 return local_maxima_trace;
382 const std::vector<pappso_double> &yVector)
389 const std::vector<std::pair<pappso_double, pappso_double>> &dataPoints)
391 reserve(dataPoints.size());
393 for(
auto &dataPoint : dataPoints)
416 : std::vector<
DataPoint>(std::move(dataPoints))
429 for(
auto &&item : map_trace)
430 push_back(
DataPoint(item.first, item.second));
455 const std::vector<pappso_double> &yVector)
458 if(xVector.size() != yVector.size())
460 "trace.cpp -- ERROR xVector and yVector must have the same size.");
463 erase(begin(), end());
465 for(std::size_t iter = 0; iter < xVector.size(); ++iter)
467 push_back(
DataPoint(xVector.at(iter), yVector.at(iter)));
476 for(
auto &item : *
this)
478 std::cout << item.x <<
"-" << item.y;
491 erase(begin(), end());
493 for(
auto &&item : map)
495 push_back(
DataPoint(item.first, item.second));
516 assign(other.begin(), other.end());
525 vector<DataPoint>::operator=(std::move(other));
533 return std::make_shared<Trace>(*
this);
540 return std::make_shared<const Trace>(*
this);
544 std::vector<pappso_double>
547 std::vector<pappso_double> values;
549 for(
auto &&dataPoint : *
this)
551 values.push_back(dataPoint.x);
558 std::vector<pappso_double>
561 std::vector<pappso_double> values;
563 for(
auto &&dataPoint : *
this)
565 values.push_back(dataPoint.y);
572 std::map<pappso_double, pappso_double>
575 std::map<pappso_double, pappso_double> map;
577 std::pair<std::map<pappso_double, pappso_double>::iterator,
bool> ret;
579 for(
auto &&dataPoint : *
this)
582 std::pair<pappso_double, pappso_double>(dataPoint.x, dataPoint.y));
584 if(ret.second ==
false)
586 qDebug() << __FILE__ <<
"@" << __LINE__ << __FUNCTION__ <<
"()"
587 <<
"It is odd that the Trace contains multiple same keys.";
590 ret.first->second += dataPoint.y;
619 std::vector<DataPoint>::iterator
623 std::find_if(begin(), end(), [value](
const DataPoint &dataPoint) {
624 return (dataPoint.
x == value);
631 std::vector<DataPoint>::const_iterator
635 std::find_if(begin(), end(), [value](
const DataPoint &dataPoint) {
636 return (dataPoint.
x == value);
646 std::vector<DataPoint>::const_iterator iterator =
649 if(iterator != end())
650 return std::distance(begin(), iterator);
652 return std::numeric_limits<std::size_t>::max();
664 double left_most = value - delta;
665 double right_most = value + delta;
672 std::find_if(begin(),
674 [value, precision_p, delta, left_most, right_most](
691 double diff_to_left_most = data_point.
x - left_most;
692 double diff_to_right_most = data_point.
x - right_most;
740 if(diff_to_left_most >= 0 && diff_to_right_most <= 0)
758 return (data_point.
x == value);
762 if(iterator != end())
778 auto dataPoint = std::min_element(
783 if(dataPoint == end())
786 QObject::tr(
"unable to get min peak intensity on spectrum size %1")
797 auto dataPoint = std::max_element(
802 if(dataPoint == end())
805 QObject::tr(
"unable to get max peak intensity on spectrum size %1")
840 return std::accumulate(begin(),
844 return (
sum + dataPoint.
y);
862 std::vector<DataPoint>::const_iterator begin_it =
869 if(begin_it->y > max_y)
911 for(
auto &&dataPoint : *
this)
913 text.append(QString(
"%1 %2\n")
914 .arg(dataPoint.x, 0,
'f', 10)
915 .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
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 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)
Trace flooredLocalMaxima(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end, double y_floor)