libpappsomspp
Library for mass spectrometry
maptrace.cpp
Go to the documentation of this file.
1 #include <numeric>
2 #include <limits>
3 #include <vector>
4 #include <map>
5 #include <cmath>
6 #include <algorithm>
7 #include <iostream>
8 #include <iomanip>
9 
10 /////////////////////// Qt includes
11 #include <QDebug>
12 
13 
14 #include "../exception/exceptionnotpossible.h"
15 #include "maptrace.h"
16 #include "../processing/combiners/tracepluscombiner.h"
17 #include "../processing/combiners/traceminuscombiner.h"
18 #include "../types.h"
19 
20 
22  qRegisterMetaType<pappso::MapTrace>("pappso::MapTrace");
24  qRegisterMetaType<pappso::MapTrace *>("pappso::MapTrace *");
25 
26 
27 namespace pappso
28 {
29 
31 {
32 }
33 
34 
36  const std::vector<std::pair<pappso_double, pappso_double>> &dataPoints)
37 {
38  for(auto &dataPoint : dataPoints)
39  {
40  insert(dataPoint);
41  }
42 }
43 
44 
45 MapTrace::MapTrace(const std::vector<DataPoint> &dataPoints)
46 {
47  for(auto &dataPoint : dataPoints)
48  {
49  insert(std::pair<pappso_double, pappso_double>(dataPoint.x, dataPoint.y));
50  }
51 }
52 
53 
55  : std::map<pappso_double, pappso_double>(other)
56 {
57 }
58 
59 
61 {
62  // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << " ()";
63 
64  for(auto &dataPoint : trace)
65  {
66  // std::cout << __FILE__ << " @ " << __LINE__ << " " << __FUNCTION__ << "
67  // () "
68  //<< std::setprecision(15)
69  //<< "Current data point: " << dataPoint.toString().toStdString() <<
70  // std::endl;
71 
72  insert(std::pair<pappso_double, pappso_double>(dataPoint.x, dataPoint.y));
73  }
74 
75  // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << " ()"
76  //<< "After construction, map size: " << size();
77 }
78 
79 
81 {
82  // Calls the destructor for each DataPoint object in the vector.
83  clear();
84 }
85 
86 
87 size_t
88 MapTrace::initialize(const std::vector<pappso_double> &xVector,
89  const std::vector<pappso_double> &yVector)
90 {
91  // Clear *this, because initialize supposes that *this will contain only the
92  // data in the vectors.
93 
94  clear();
95 
96  // Sanity check
97  if(xVector.size() != yVector.size())
99  QObject::tr("Fatal error at msrundatasettreenode.cpp "
100  "-- ERROR xVector and yVector must have the same size."
101  "Program aborted."));
102 
103  for(std::size_t iter = 0; iter < xVector.size(); ++iter)
104  {
105  insert(std::pair<pappso_double, pappso_double>(xVector.at(iter),
106  yVector.at(iter)));
107  }
108 
109  return size();
110 }
111 
112 
113 size_t
114 MapTrace::initialize(const std::map<pappso_double, pappso_double> &map)
115 {
116 
117  // Clear *this, because initialize supposes that *this will be identical to
118  // map.
119 
120  clear();
121 
122  for(auto &&pair : map)
123  {
124  insert(pair);
125  }
126 
127  return size();
128 }
129 
130 
131 MapTrace &
133 {
134 
135  if(&other == this)
136  return *this;
137 
138  // Clear *this, because initialize supposes that *this will be identical to
139  // other.
140 
141  clear();
142 
143  for(auto &pair : other)
144  {
145  insert(pair);
146  }
147 
148  return *this;
149 }
150 
151 
154 {
155  return std::make_shared<MapTrace>(*this);
156 }
157 
158 
161 {
162  return std::make_shared<const MapTrace>(*this);
163 }
164 
165 
166 std::vector<pappso_double>
168 {
169  std::vector<pappso_double> vector;
170 
171  for(auto &&pair : *this)
172  vector.push_back(pair.first);
173 
174  return vector;
175 }
176 
177 
178 std::vector<pappso_double>
180 {
181  std::vector<pappso_double> vector;
182 
183  for(auto &&pair : *this)
184  vector.push_back(pair.second);
185 
186  return vector;
187 }
188 
189 
190 Trace
192 {
193  Trace trace;
194 
195  for(auto &&pair : *this)
196  trace.push_back(DataPoint(pair.first, pair.second));
197 
198  return trace;
199 }
200 
201 
202 QString
204 {
205  // Even if the spectrum is empty, we should return an empty string.
206  QString text;
207 
208  for(auto &&pair : *this)
209  {
210 // For debugging
211 #if 0
212 
213  QString new_data_point_text = QString("%1 %2\n")
214  .arg(pair.first, 0, 'f', 10)
215  .arg(pair.second, 0, 'f', 10);
216 
217  qDebug() << "new data point text:" << new_data_point_text;
218  text.append(new_data_point_text);
219 #endif
220 
221  text.append(QString("%1 %2\n")
222  .arg(pair.first, 0, 'f', 10)
223  .arg(pair.second, 0, 'f', 10));
224  }
225 
226  return text;
227 }
228 
229 
230 } // namespace pappso
pappso::pappso_double
double pappso_double
A type definition for doubles.
Definition: types.h:48
pappso::MapTraceCstSPtr
std::shared_ptr< const MapTrace > MapTraceCstSPtr
Definition: maptrace.h:26
pappso::MapTrace::xValues
std::vector< pappso_double > xValues()
Definition: maptrace.cpp:167
pappso
tries to keep as much as possible monoisotopes, removing any possible C13 peaks
Definition: aa.cpp:39
pappso::DataPoint
Definition: datapoint.h:21
pappso::MapTrace
Definition: maptrace.h:33
pappso::MapTrace::makeMapTraceCstSPtr
MapTraceCstSPtr makeMapTraceCstSPtr() const
Definition: maptrace.cpp:160
pappso::MapTraceSPtr
std::shared_ptr< MapTrace > MapTraceSPtr
Definition: maptrace.h:25
pappso::ExceptionNotPossible
Definition: exceptionnotpossible.h:32
pappso::MapTrace::initialize
size_t initialize(const std::vector< pappso_double > &xVector, const std::vector< pappso_double > &yVector)
Definition: maptrace.cpp:88
pappso::MapTrace::operator=
virtual MapTrace & operator=(const MapTrace &other)
Definition: maptrace.cpp:132
pappso::MapTrace::yValues
std::vector< pappso_double > yValues()
Definition: maptrace.cpp:179
pappso::Trace
A simple container of DataPoint instances.
Definition: trace.h:132
pappso::MapTrace::toString
QString toString() const
Definition: maptrace.cpp:203
mapTracePtrMetaTypeId
int mapTracePtrMetaTypeId
Definition: maptrace.cpp:23
pappso::MapTrace::~MapTrace
virtual ~MapTrace()
Definition: maptrace.cpp:80
maptrace.h
mapTraceMetaTypeId
int mapTraceMetaTypeId
Definition: maptrace.cpp:21
pappso::MapTrace::toTrace
Trace toTrace() const
Definition: maptrace.cpp:191
pappso::MapTrace::makeMapTraceSPtr
MapTraceSPtr makeMapTraceSPtr() const
Definition: maptrace.cpp:153
pappso::MapTrace::MapTrace
MapTrace()
Definition: maptrace.cpp:30