libpappsomspp
Library for mass spectrometry
pappso::MapTrace Class Reference

#include <maptrace.h>

Inheritance diagram for pappso::MapTrace:

Public Member Functions

 MapTrace ()
 
 MapTrace (const std::vector< std::pair< pappso_double, pappso_double > > &dataPoints)
 
 MapTrace (const std::vector< DataPoint > &dataPoints)
 
 MapTrace (const MapTrace &other)
 
 MapTrace (const Trace &trace)
 
virtual ~MapTrace ()
 
size_t initialize (const std::vector< pappso_double > &xVector, const std::vector< pappso_double > &yVector)
 
size_t initialize (const std::map< pappso_double, pappso_double > &map)
 
virtual MapTraceoperator= (const MapTrace &other)
 
MapTraceSPtr makeMapTraceSPtr () const
 
MapTraceCstSPtr makeMapTraceCstSPtr () const
 
std::vector< pappso_doublexValues ()
 
std::vector< pappso_doubleyValues ()
 
void insertOrUpdate (const DataPoint &data_point)
 
void insertOrUpdate (const Trace &trace)
 
Trace toTrace () const
 
QString toString () const
 

Detailed Description

Definition at line 33 of file maptrace.h.

Constructor & Destructor Documentation

◆ MapTrace() [1/5]

pappso::MapTrace::MapTrace ( )

Definition at line 31 of file maptrace.cpp.

32{
33}

◆ MapTrace() [2/5]

pappso::MapTrace::MapTrace ( const std::vector< std::pair< pappso_double, pappso_double > > &  dataPoints)

Definition at line 36 of file maptrace.cpp.

38{
39 for(auto &dataPoint : dataPoints)
40 {
41 insert(dataPoint);
42 }
43}

◆ MapTrace() [3/5]

pappso::MapTrace::MapTrace ( const std::vector< DataPoint > &  dataPoints)

Definition at line 46 of file maptrace.cpp.

47{
48 for(auto &dataPoint : dataPoints)
49 {
50 insert(std::pair<pappso_double, pappso_double>(dataPoint.x, dataPoint.y));
51 }
52}

◆ MapTrace() [4/5]

pappso::MapTrace::MapTrace ( const MapTrace other)

Definition at line 55 of file maptrace.cpp.

56 : std::map<pappso_double, pappso_double>(other)
57{
58}

◆ MapTrace() [5/5]

pappso::MapTrace::MapTrace ( const Trace trace)

Definition at line 61 of file maptrace.cpp.

62{
63 // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << " ()";
64
65 for(auto &dataPoint : trace)
66 {
67 // std::cout << __FILE__ << " @ " << __LINE__ << " " << __FUNCTION__ << "
68 // () "
69 //<< std::setprecision(15)
70 //<< "Current data point: " << dataPoint.toString().toStdString() <<
71 // std::endl;
72
73 insert(std::pair<pappso_double, pappso_double>(dataPoint.x, dataPoint.y));
74 }
75
76 // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << " ()"
77 //<< "After construction, map size: " << size();
78}

◆ ~MapTrace()

pappso::MapTrace::~MapTrace ( )
virtual

Definition at line 81 of file maptrace.cpp.

82{
83 // Calls the destructor for each DataPoint object in the vector.
84 clear();
85}

Member Function Documentation

◆ initialize() [1/2]

size_t pappso::MapTrace::initialize ( const std::map< pappso_double, pappso_double > &  map)

Definition at line 115 of file maptrace.cpp.

116{
117
118 // Clear *this, because initialize supposes that *this will be identical to
119 // map.
120
121 clear();
122
123 for(auto &&pair : map)
124 {
125 insert(pair);
126 }
127
128 return size();
129}

◆ initialize() [2/2]

size_t pappso::MapTrace::initialize ( const std::vector< pappso_double > &  xVector,
const std::vector< pappso_double > &  yVector 
)

Definition at line 89 of file maptrace.cpp.

91{
92 // Clear *this, because initialize supposes that *this will contain only the
93 // data in the vectors.
94
95 clear();
96
97 // Sanity check
98 if(xVector.size() != yVector.size())
99 throw ExceptionNotPossible(
100 QObject::tr("Fatal error at msrundatasettreenode.cpp "
101 "-- ERROR xVector and yVector must have the same size."
102 "Program aborted."));
103
104 for(std::size_t iter = 0; iter < xVector.size(); ++iter)
105 {
106 insert(std::pair<pappso_double, pappso_double>(xVector.at(iter),
107 yVector.at(iter)));
108 }
109
110 return size();
111}

◆ insertOrUpdate() [1/2]

void pappso::MapTrace::insertOrUpdate ( const DataPoint data_point)

Definition at line 192 of file maptrace.cpp.

193{
194
195 // Try to insert the data point into the map. Check if that was done or
196 // not.
197 std::pair<std::map<double, double>::iterator, bool> res =
198 insert(std::pair<double, double>(data_point.x, data_point.y));
199
200 if(!res.second)
201 {
202 // One other same (x,y) value pair was seen already. Only increment the y
203 // value.
204
205 res.first->second += data_point.y;
206 }
207}

References pappso::res, pappso::DataPoint::x, and pappso::DataPoint::y.

Referenced by insertOrUpdate().

◆ insertOrUpdate() [2/2]

void pappso::MapTrace::insertOrUpdate ( const Trace trace)

Definition at line 211 of file maptrace.cpp.

212{
213 for(const DataPoint &data_point : trace)
214 insertOrUpdate(data_point);
215}
void insertOrUpdate(const DataPoint &data_point)
Definition: maptrace.cpp:192

References insertOrUpdate().

◆ makeMapTraceCstSPtr()

MapTraceCstSPtr pappso::MapTrace::makeMapTraceCstSPtr ( ) const

Definition at line 161 of file maptrace.cpp.

162{
163 return std::make_shared<const MapTrace>(*this);
164}

◆ makeMapTraceSPtr()

MapTraceSPtr pappso::MapTrace::makeMapTraceSPtr ( ) const

Definition at line 154 of file maptrace.cpp.

155{
156 return std::make_shared<MapTrace>(*this);
157}

◆ operator=()

MapTrace & pappso::MapTrace::operator= ( const MapTrace other)
virtual

Definition at line 133 of file maptrace.cpp.

134{
135
136 if(&other == this)
137 return *this;
138
139 // Clear *this, because initialize supposes that *this will be identical to
140 // other.
141
142 clear();
143
144 for(auto &pair : other)
145 {
146 insert(pair);
147 }
148
149 return *this;
150}

◆ toString()

QString pappso::MapTrace::toString ( ) const

Definition at line 231 of file maptrace.cpp.

232{
233 // Even if the spectrum is empty, we should return an empty string.
234 QString text;
235
236 for(auto &&pair : *this)
237 {
238// For debugging
239#if 0
240
241 QString new_data_point_text = QString("%1 %2\n")
242 .arg(pair.first, 0, 'f', 10)
243 .arg(pair.second, 0, 'f', 10);
244
245 qDebug() << "new data point text:" << new_data_point_text;
246 text.append(new_data_point_text);
247#endif
248
249 text.append(QString("%1 %2\n")
250 .arg(pair.first, 0, 'f', 10)
251 .arg(pair.second, 0, 'f', 10));
252 }
253
254 return text;
255}

◆ toTrace()

Trace pappso::MapTrace::toTrace ( ) const

Definition at line 219 of file maptrace.cpp.

220{
221 Trace trace;
222
223 for(auto &&pair : *this)
224 trace.push_back(DataPoint(pair.first, pair.second));
225
226 return trace;
227}

Referenced by pappso::TraceMinusCombiner::combine(), pappso::TracePlusCombiner::combine(), pappso::MsRunReaderTicChromatogram::getTicChromatogram(), pappso::TimsData::getTicChromatogram(), and pappso::FilterLowIntensitySignalRemoval::reconstructTrace().

◆ xValues()

std::vector< pappso_double > pappso::MapTrace::xValues ( )

Definition at line 168 of file maptrace.cpp.

169{
170 std::vector<pappso_double> vector;
171
172 for(auto &&pair : *this)
173 vector.push_back(pair.first);
174
175 return vector;
176}

◆ yValues()

std::vector< pappso_double > pappso::MapTrace::yValues ( )

Definition at line 180 of file maptrace.cpp.

181{
182 std::vector<pappso_double> vector;
183
184 for(auto &&pair : *this)
185 vector.push_back(pair.second);
186
187 return vector;
188}

The documentation for this class was generated from the following files: