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 32 of file maptrace.h.

Constructor & Destructor Documentation

◆ MapTrace() [1/5]

pappso::MapTrace::MapTrace ( )

Definition at line 30 of file maptrace.cpp.

31{
32}

◆ MapTrace() [2/5]

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

Definition at line 35 of file maptrace.cpp.

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

◆ MapTrace() [3/5]

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

Definition at line 45 of file maptrace.cpp.

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

◆ MapTrace() [4/5]

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

Definition at line 54 of file maptrace.cpp.

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

◆ MapTrace() [5/5]

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

Definition at line 60 of file maptrace.cpp.

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}

◆ ~MapTrace()

pappso::MapTrace::~MapTrace ( )
virtual

Definition at line 80 of file maptrace.cpp.

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

Member Function Documentation

◆ initialize() [1/2]

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

Definition at line 114 of file maptrace.cpp.

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}

◆ initialize() [2/2]

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

Definition at line 88 of file maptrace.cpp.

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())
98 throw ExceptionNotPossible(
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}

◆ insertOrUpdate() [1/2]

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

Definition at line 191 of file maptrace.cpp.

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

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 210 of file maptrace.cpp.

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

References insertOrUpdate().

◆ makeMapTraceCstSPtr()

MapTraceCstSPtr pappso::MapTrace::makeMapTraceCstSPtr ( ) const

Definition at line 160 of file maptrace.cpp.

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

◆ makeMapTraceSPtr()

MapTraceSPtr pappso::MapTrace::makeMapTraceSPtr ( ) const

Definition at line 153 of file maptrace.cpp.

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

◆ operator=()

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

Definition at line 132 of file maptrace.cpp.

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}

◆ toString()

QString pappso::MapTrace::toString ( ) const

Definition at line 230 of file maptrace.cpp.

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

◆ toTrace()

Trace pappso::MapTrace::toTrace ( ) const

Definition at line 218 of file maptrace.cpp.

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

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

◆ xValues()

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

Definition at line 167 of file maptrace.cpp.

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

◆ yValues()

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

Definition at line 179 of file maptrace.cpp.

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

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