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);
225 std::vector<DataPoint>::const_iterator end,
228 std::size_t nb_element = distance(begin, end);
231 QObject::tr(
"unable to compute quantile on a trace of size 0"));
234 std::size_t ieth_element = std::round((
double)nb_element * quantile);
235 if(ieth_element > nb_element)
237 QObject::tr(
"quantile value must be lower than 1"));
240 std::vector<DataPoint> data(begin, end);
243 data.begin() + ieth_element,
246 return data[ieth_element].y;
251 std::vector<DataPoint>::const_iterator end)
253 std::size_t nb_element = distance(begin, end);
256 QObject::tr(
"unable to compute median on a trace of size 0"));
258 std::vector<DataPoint> data(begin, end);
261 data.begin() + data.size() / 2,
264 return data[data.size() / 2].y;
269 std::vector<DataPoint>::const_iterator end)
274 auto previous = begin;
275 auto next = begin + 1;
279 area += ((next->x - previous->x) * (previous->y + next->y)) / (
double)2;
289 std::vector<DataPoint>::const_iterator end,
292 Trace local_maxima_trace;
294 Trace single_peak_trace;
298 for(
auto iter = begin; iter != end; ++iter)
300 DataPoint iterated_data_point(iter->x, iter->y);
305 if(iterated_data_point.
y < y_floor)
309 if(single_peak_trace.size())
313 local_maxima_trace.push_back(single_peak_trace.
maxYDataPoint());
319 single_peak_trace.clear();
321 previous_data_point = iterated_data_point;
329 previous_data_point = iterated_data_point;
341 if(iterated_data_point.
y == previous_data_point.
y)
347 else if(iterated_data_point.
y > previous_data_point.
y)
356 single_peak_trace.push_back(iterated_data_point);
361 previous_data_point = iterated_data_point;
372 single_peak_trace.push_back(iterated_data_point);
377 previous_data_point = iterated_data_point;
389 if(single_peak_trace.size())
392 local_maxima_trace.push_back(single_peak_trace.
maxYDataPoint());
399 return local_maxima_trace;
409 const std::vector<pappso_double> &yVector)
416 const std::vector<std::pair<pappso_double, pappso_double>> &dataPoints)
418 reserve(dataPoints.size());
420 for(
auto &dataPoint : dataPoints)
443 : std::vector<
DataPoint>(std::move(dataPoints))
456 for(
auto &&item : map_trace)
457 push_back(
DataPoint(item.first, item.second));
482 const std::vector<pappso_double> &yVector)
485 if(xVector.size() != yVector.size())
487 "trace.cpp -- ERROR xVector and yVector must have the same size.");
490 erase(begin(), end());
492 for(std::size_t iter = 0; iter < xVector.size(); ++iter)
494 push_back(
DataPoint(xVector.at(iter), yVector.at(iter)));
503 for(
auto &item : *
this)
505 std::cout << item.x <<
"-" << item.y;
518 erase(begin(), end());
520 for(
auto &&item : map)
522 push_back(
DataPoint(item.first, item.second));
543 assign(other.begin(), other.end());
552 vector<DataPoint>::operator=(std::move(other));
560 return std::make_shared<Trace>(*
this);
567 return std::make_shared<const Trace>(*
this);
571 std::vector<pappso_double>
574 std::vector<pappso_double> values;
576 for(
auto &&dataPoint : *
this)
578 values.push_back(dataPoint.x);
585 std::vector<pappso_double>
588 std::vector<pappso_double> values;
590 for(
auto &&dataPoint : *
this)
592 values.push_back(dataPoint.y);
599 std::map<pappso_double, pappso_double>
602 std::map<pappso_double, pappso_double> map;
604 std::pair<std::map<pappso_double, pappso_double>::iterator,
bool> ret;
606 for(
auto &&dataPoint : *
this)
609 std::pair<pappso_double, pappso_double>(dataPoint.x, dataPoint.y));
611 if(ret.second ==
false)
613 qDebug() << __FILE__ <<
"@" << __LINE__ << __FUNCTION__ <<
"()"
614 <<
"It is odd that the Trace contains multiple same keys.";
617 ret.first->second += dataPoint.y;
646 std::vector<DataPoint>::iterator
650 std::find_if(begin(), end(), [value](
const DataPoint &dataPoint) {
651 return (dataPoint.
x == value);
658 std::vector<DataPoint>::const_iterator
662 std::find_if(begin(), end(), [value](
const DataPoint &dataPoint) {
663 return (dataPoint.
x == value);
673 std::vector<DataPoint>::const_iterator iterator =
676 if(iterator != end())
677 return std::distance(begin(), iterator);
679 return std::numeric_limits<std::size_t>::max();
691 double left_most = value - delta;
692 double right_most = value + delta;
699 std::find_if(begin(),
701 [value, precision_p, delta, left_most, right_most](
718 double diff_to_left_most = data_point.
x - left_most;
719 double diff_to_right_most = data_point.
x - right_most;
767 if(diff_to_left_most >= 0 && diff_to_right_most <= 0)
785 return (data_point.
x == value);
789 if(iterator != end())
805 auto dataPoint = std::min_element(
810 if(dataPoint == end())
813 QObject::tr(
"unable to get min peak intensity on spectrum size %1")
824 auto dataPoint = std::max_element(
829 if(dataPoint == end())
832 QObject::tr(
"unable to get max peak intensity on spectrum size %1")
867 return std::accumulate(begin(),
871 return (
sum + dataPoint.
y);
889 std::vector<DataPoint>::const_iterator begin_it =
896 if(begin_it->y > max_y)
938 for(
auto &&dataPoint : *
this)
940 text.append(QString(
"%1 %2\n")
941 .arg(dataPoint.x, 0,
'f', 10)
942 .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)
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)