libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
traceminuscombiner.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 <iostream>
7
8#include <QDebug>
9
10#include "traceminuscombiner.h"
11#include "../../trace/trace.h"
12#include "../../types.h"
16
17
18namespace pappso
19{
20
21
25
26
27TraceMinusCombiner::TraceMinusCombiner(int decimal_places) : TraceCombiner(decimal_places)
28{
29}
30
31
35
36
40
41
45
46
48TraceMinusCombiner::combine(MapTrace &map_trace, const Trace &trace) const
49{
50 // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << " ()"
51 //<< "map trace size:" << map_trace.size()
52 //<< "trace size:" << trace.size();
53
54 if(!trace.size())
55 return map_trace;
56
57 for(auto &current_data_point : trace)
58 {
59
60 // If the data point is 0-intensity, then do nothing!
61 if(!current_data_point.y)
62 continue;
63
64 // qDebug() << "Iterating in new trace data point:"
65 //<< current_data_point.toString(15);
66
67 double x = Utils::roundToDecimals(current_data_point.x, m_decimalPlaces);
68
69 std::map<double, double>::iterator map_iterator;
70
71 std::pair<std::map<pappso_double, pappso_double>::iterator, bool> result;
72
73 // qDebug() << "Willing to insert new data point:" << x << ","
74 //<< -current_data_point.y;
75
76 result = map_trace.insert(std::pair<pappso_double, pappso_double>(x, -current_data_point.y));
77
78 if(result.second)
79 {
80 // qDebug() << "Inserted new data point:" << x << ","
81 //<< -current_data_point.y;
82 // The new element was inserted, we have nothing to do.
83 }
84 else
85 {
86 // qDebug() << "Going to decrement from" << result.first->second
87 //<< "a value of " << current_data_point.y;
88
89 // The key already existed! The item was not inserted. We need to
90 // update the value.
91
92 result.first->second -= current_data_point.y;
93
94 // qDebug() << "New result: " << result.first->second;
95 }
96 }
97
98 // qDebug() << "Prior to returning map_trace, its size is:" <<
99 // map_trace.size();
100
101 return map_trace;
102}
103
104
105MapTrace &
106TraceMinusCombiner::combine(MapTrace &map_trace_out, const MapTrace &map_trace_in) const
107{
108 // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << " ()"
109 //<< "map trace size:" << map_trace_out.size()
110 //<< "trace size:" << trace.size();
111
112 if(!map_trace_in.size())
113 return map_trace_out;
114
115 return combine(map_trace_out, map_trace_in.toTrace());
116}
117
118
119} // namespace pappso
Trace toTrace() const
Definition maptrace.cpp:214
int m_decimalPlaces
Number of decimals to use for the keys (x values).
virtual MapTrace & combine(MapTrace &map_trace, const Trace &trace) const override
A simple container of DataPoint instances.
Definition trace.h:152
static pappso_double roundToDecimals(pappso_double value, int decimal_places)
Definition utils.cpp:140
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39
std::shared_ptr< const TraceMinusCombiner > TraceMinusCombinerCstSPtr