37  for(
auto &dataPoint : trace)
 
 
   54      throw PappsoException(QString(
"error in QDataStream unserialize operator>> of trace:\n" 
   55                                    "read datastream failed status=%1")
 
   59  for(
auto &dataPoint : trace)
 
 
   69std::vector<DataPoint>::iterator
 
   71                         std::vector<DataPoint>::iterator end,
 
   74  return std::find_if(begin, end, [value](
const DataPoint &to_compare) {
 
   75    if(to_compare.
x < value)
 
 
   83std::vector<DataPoint>::const_iterator
 
   85                         std::vector<DataPoint>::const_iterator end,
 
   88  return std::find_if(begin, end, [value](
const DataPoint &to_compare) {
 
   89    if(to_compare.
x < value)
 
 
   97std::vector<DataPoint>::iterator
 
   99                  std::vector<DataPoint>::iterator end,
 
  102  return std::find_if(begin, end, [value](
const DataPoint &to_compare) {
 
  103    if(to_compare.
x > value)
 
 
  111std::vector<DataPoint>::const_iterator
 
  113                  std::vector<DataPoint>::const_iterator end,
 
  116  return std::find_if(begin, end, [value](
const DataPoint &to_compare) {
 
  117    if(to_compare.
x > value)
 
 
  125std::vector<DataPoint>::iterator
 
  127                    std::vector<DataPoint>::iterator end,
 
  128                    const double &y_value)
 
  130  return std::find_if(begin, end, [y_value](
const DataPoint &to_compare) {
 
  131    if(to_compare.
y != y_value)
 
 
  140std::vector<DataPoint>::const_iterator
 
  142                    std::vector<DataPoint>::const_iterator end,
 
  143                    const double &y_value)
 
  145  return std::find_if(begin, end, [y_value](
const DataPoint &to_compare) {
 
  146    if(to_compare.
y != y_value)
 
 
  156std::vector<DataPoint>::const_iterator
 
  158              std::vector<DataPoint>::const_iterator end)
 
  160  return std::min_element(
 
 
  165std::vector<DataPoint>::iterator
 
  166minYDataPoint(std::vector<DataPoint>::iterator begin, std::vector<DataPoint>::iterator end)
 
  168  return std::min_element(
 
 
  173std::vector<DataPoint>::const_iterator
 
  175              std::vector<DataPoint>::const_iterator end)
 
  177  return std::max_element(
 
 
  182std::vector<DataPoint>::iterator
 
  183maxYDataPoint(std::vector<DataPoint>::iterator begin, std::vector<DataPoint>::iterator end)
 
  185  return std::max_element(
 
 
  193std::vector<DataPoint>::const_iterator
 
  196  if(begin == trace.end())
 
  202  while((it != trace.end()) && (it->y <= result->y))
 
 
  210std::vector<DataPoint>::const_iterator
 
  213  if(begin == trace.begin())
 
  221  while((it != trace.begin()) && (it->y <= result->y))
 
 
  232          std::vector<DataPoint>::const_iterator end,
 
  235  return std::accumulate(begin, end, init, [](
double a, 
const DataPoint &
b) { 
return a + 
b.y; });
 
 
  239meanYTrace(std::vector<DataPoint>::const_iterator begin, std::vector<DataPoint>::const_iterator end)
 
  244  return (
sumYTrace(begin, end, 0) / nb_element);
 
 
  250               std::vector<DataPoint>::const_iterator end,
 
  253  std::size_t nb_element = distance(begin, end);
 
  258  std::size_t ieth_element = std::round((
double)nb_element * quantile);
 
  259  if(ieth_element > nb_element)
 
  263  std::vector<DataPoint> data(begin, end);
 
  264  std::nth_element(data.begin(),
 
  265                   data.begin() + ieth_element,
 
  268  return data[ieth_element].y;
 
 
  273             std::vector<DataPoint>::const_iterator end)
 
  275  std::size_t nb_element = distance(begin, end);
 
  279  std::vector<DataPoint> data(begin, end);
 
  280  std::nth_element(data.begin(),
 
  281                   data.begin() + data.size() / 2,
 
  284  return data[data.size() / 2].y;
 
 
  288areaTrace(std::vector<DataPoint>::const_iterator begin, std::vector<DataPoint>::const_iterator end)
 
  293  auto previous = begin;
 
  294  auto next     = begin + 1;
 
  298      area += ((next->x - previous->x) * (previous->y + next->y)) / (
double)2;
 
 
  308                   std::vector<DataPoint>::const_iterator end,
 
  311  Trace local_maxima_trace;
 
  313  Trace single_peak_trace;
 
  317  for(
auto iter = begin; iter != end; ++iter)
 
  319      DataPoint iterated_data_point(iter->x, iter->y);
 
  324      if(iterated_data_point.
y < y_floor)
 
  328          if(single_peak_trace.size())
 
  332              local_maxima_trace.push_back(single_peak_trace.
maxYDataPoint());
 
  338              single_peak_trace.clear();
 
  340              previous_data_point = iterated_data_point;
 
  348              previous_data_point = iterated_data_point;
 
  360          if(iterated_data_point.
y == previous_data_point.
y)
 
  366          else if(iterated_data_point.
y > previous_data_point.
y)
 
  375              single_peak_trace.push_back(iterated_data_point);
 
  380              previous_data_point = iterated_data_point;
 
  391              single_peak_trace.push_back(iterated_data_point);
 
  396              previous_data_point = iterated_data_point;
 
  408  if(single_peak_trace.size())
 
  411      local_maxima_trace.push_back(single_peak_trace.
maxYDataPoint());
 
  418  return local_maxima_trace;
 
 
  433Trace::Trace(
const std::vector<pappso_double> &xVector, 
const std::vector<pappso_double> &yVector)
 
 
  442  QStringList string_list = space_sep_text.split(
"\n", Qt::SkipEmptyParts);
 
  447  for(
int iter = 0; iter < string_list.size(); ++iter)
 
  449      QString 
line = string_list.at(iter);
 
  464      qDebug() << 
"Now appending DataPoint as this line:" << 
line;
 
 
  475  QStringList x_string_list = x_text.split(
"\n", Qt::SkipEmptyParts);
 
  476  QStringList y_string_list = y_text.split(
"\n", Qt::SkipEmptyParts);
 
  478  if(x_string_list.size() != y_string_list.size())
 
  480      "trace.cpp -- ERROR x_text and y_text must have the same number of " 
  483  for(
int iter = 0; iter < x_string_list.size(); ++iter)
 
  485      QString x_line = x_string_list.at(iter);
 
  486      QString y_line = y_string_list.at(iter);
 
  491      x_line = x_line.simplified();
 
  492      y_line = y_line.simplified();
 
 
  500Trace::Trace(
const std::vector<std::pair<pappso_double, pappso_double>> &dataPoints)
 
  502  reserve(dataPoints.size());
 
  504  for(
auto &dataPoint : dataPoints)
 
 
  526  : std::vector<
DataPoint>(std::move(dataPoints))
 
 
  539  for(
auto &&item : map_trace)
 
  540    push_back(
DataPoint(item.first, item.second));
 
 
  565                  const std::vector<pappso_double> &yVector)
 
  568  if(xVector.size() != yVector.size())
 
  572  erase(begin(), end());
 
  574  for(std::size_t iter = 0; iter < xVector.size(); ++iter)
 
  576      push_back(
DataPoint(xVector.at(iter), yVector.at(iter)));
 
  585  for(
auto &item : *
this)
 
  587    std::cout << item.x << 
"-" << item.y;
 
 
  600  erase(begin(), end());
 
  602  for(
auto &&item : map)
 
  604      push_back(
DataPoint(item.first, item.second));
 
 
  625  push_back(data_point);
 
 
  634  assign(other.begin(), other.end());
 
 
  643  vector<DataPoint>::operator=(std::move(other));
 
 
 
  651  return std::make_shared<Trace>(*
this);
 
 
  658  return std::make_shared<const Trace>(*
this);
 
 
  662std::vector<pappso_double>
 
  665  std::vector<pappso_double> values;
 
  667  for(
auto &&dataPoint : *
this)
 
  669      values.push_back(dataPoint.x);
 
 
  676std::vector<pappso_double>
 
  679  std::vector<pappso_double> values;
 
  681  for(
auto &&dataPoint : *
this)
 
  683      values.push_back(dataPoint.y);
 
 
  690std::map<pappso_double, pappso_double>
 
  693  std::map<pappso_double, pappso_double> map;
 
  695  std::pair<std::map<pappso_double, pappso_double>::iterator, 
bool> ret;
 
  697  for(
auto &&dataPoint : *
this)
 
  699      ret = map.insert(std::pair<pappso_double, pappso_double>(dataPoint.x, dataPoint.y));
 
  701      if(ret.second == 
false)
 
  703          qDebug() << 
"It is odd that the Trace contains multiple same keys.";
 
  706          ret.first->second += dataPoint.y;
 
 
  735std::vector<DataPoint>::iterator
 
  738  auto iterator = std::find_if(
 
  739    begin(), end(), [value](
const DataPoint &dataPoint) { 
return (dataPoint.
x == value); });
 
 
  745std::vector<DataPoint>::const_iterator
 
  748  auto iterator = std::find_if(
 
  749    begin(), end(), [value](
const DataPoint &dataPoint) { 
return (dataPoint.
x == value); });
 
 
  760  if(iterator != end())
 
  761    return std::distance(begin(), iterator);
 
  763  return std::numeric_limits<std::size_t>::max();
 
 
  775  double left_most  = value - delta;
 
  776  double right_most = value + delta;
 
  783    std::find_if(begin(),
 
  785                 [value, precision_p, delta, left_most, right_most](
const DataPoint &data_point) {
 
  801                       double diff_to_left_most  = data_point.
x - left_most;
 
  802                       double diff_to_right_most = data_point.
x - right_most;
 
  850                       if(diff_to_left_most >= 0 && diff_to_right_most <= 0)
 
  868                       return (data_point.
x == value);
 
  872  if(iterator != end())
 
 
  888  auto dataPoint = std::min_element(
 
  891  if(dataPoint == end())
 
  894        QObject::tr(
"unable to get min peak x on spectrum size %1").arg(size()));
 
 
  904  auto dataPoint = std::max_element(
 
  907  if(dataPoint == end())
 
  910        QObject::tr(
"unable to get max peak x on spectrum size %1").arg(size()));
 
 
  920  auto dataPoint = std::min_element(
 
  923  if(dataPoint == end())
 
  926        QObject::tr(
"unable to get min peak intensity on spectrum size %1").arg(size()));
 
 
  936  auto dataPoint = std::max_element(
 
  939  if(dataPoint == end())
 
  942        QObject::tr(
"unable to get max peak intensity on spectrum size %1").arg(size()));
 
 
  990  return std::accumulate(
 
  992      return (sum + dataPoint.
y);
 
 
 1010  std::vector<DataPoint>::const_iterator begin_it =
 
 1017      if(begin_it->y > max_y)
 
 1018        max_y = begin_it->y;
 
 
 1032    return sortX(sort_order);
 
 1034    return sortY(sort_order);
 
 
 1061  auto last = std::unique(
 
 
 1074  auto end_it = end();
 
 1076  std::size_t count = 0;
 
 
 1101  for(
auto &&dataPoint : *
this)
 
 1103      text.append(QString(
"%1\n").arg(dataPoint.toString()));
 
 
 1113  QByteArray unencoded_array;
 
 1115  for(
auto &&data_point : *
this)
 
 1117      QByteArray local_array;
 
 1118      local_array.setNum(data_point.x, 
'f', 12);
 
 1119      local_array.append(
"\n");
 
 1121      unencoded_array.append(local_array);
 
 1124  QByteArray base64_encoded_array =
 
 1125    unencoded_array.toBase64(QByteArray::Base64Encoding | QByteArray::OmitTrailingEquals);
 
 1127  return base64_encoded_array;
 
 
 1134  QByteArray unencoded_array;
 
 1136  for(
auto &&data_point : *
this)
 
 1138      QByteArray local_array;
 
 1139      local_array.setNum(data_point.y, 
'f', 12);
 
 1140      local_array.append(
"\n");
 
 1142      unencoded_array.append(local_array);
 
 1145  QByteArray base64_encoded_array =
 
 1146    unencoded_array.toBase64(QByteArray::Base64Encoding | QByteArray::OmitTrailingEquals);
 
 1148  return base64_encoded_array;
 
 
 1155  return filter.filter(*
this);
 
 
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
 
const DataPoint & maxXDataPoint() const
 
pappso_double minX() const
 
QByteArray yAsBase64Encoded() const
 
pappso_double maxX() const
 
void sort(Enums::SortType sort_type, Enums::SortOrder sort_order=Enums::SortOrder::ascending)
 
QByteArray xAsBase64Encoded() const
 
void sortY(Enums::SortOrder sort_order=Enums::SortOrder::ascending)
 
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)
 
void sortX(Enums::SortOrder sort_order=Enums::SortOrder::ascending)
 
size_t append(const DataPoint &data_point)
appends a datapoint and return new size
 
std::size_t dataPointIndexWithX(pappso_double value) const
 
const DataPoint & minXDataPoint() 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
 
std::size_t removeZeroYDataPoints()
 
static bool almostEqual(double value1, double value2, int decimalPlaces=10)
 
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 meanYTrace(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end)
calculate the mean of y value of a trace
 
const PrecisionBase * PrecisionPtr
 
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)