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"
13#include "../../utils.h"
14#include "../../pappsoexception.h"
15#include "../../exception/exceptionoutofrange.h"
16
17
18namespace pappso
19{
20
21
25
26
28 : TraceCombiner(decimal_places)
29{
30}
31
32
37
38
43
44
48
49
51TraceMinusCombiner::combine(MapTrace &map_trace, const Trace &trace) const
52{
53 // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << " ()"
54 //<< "map trace size:" << map_trace.size()
55 //<< "trace size:" << trace.size();
56
57 if(!trace.size())
58 return map_trace;
59
60 for(auto &current_data_point : trace)
61 {
62
63 // If the data point is 0-intensity, then do nothing!
64 if(!current_data_point.y)
65 continue;
66
67 // qDebug() << "Iterating in new trace data point:"
68 //<< current_data_point.toString(15);
69
70 double x = Utils::roundToDecimals(current_data_point.x, m_decimalPlaces);
71
72 std::map<double, double>::iterator map_iterator;
73
74 std::pair<std::map<pappso_double, pappso_double>::iterator, bool> result;
75
76 // qDebug() << "Willing to insert new data point:" << x << ","
77 //<< -current_data_point.y;
78
79 result = map_trace.insert(
80 std::pair<pappso_double, pappso_double>(x, -current_data_point.y));
81
82 if(result.second)
83 {
84 // qDebug() << "Inserted new data point:" << x << ","
85 //<< -current_data_point.y;
86 // The new element was inserted, we have nothing to do.
87 }
88 else
89 {
90 // qDebug() << "Going to decrement from" << result.first->second
91 //<< "a value of " << current_data_point.y;
92
93 // The key already existed! The item was not inserted. We need to
94 // update the value.
95
96 result.first->second -= current_data_point.y;
97
98 // qDebug() << "New result: " << result.first->second;
99 }
100 }
101
102 // qDebug() << "Prior to returning map_trace, its size is:" <<
103 // map_trace.size();
104
105 return map_trace;
106}
107
108
109MapTrace &
111 const MapTrace &map_trace_in) const
112{
113 // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << " ()"
114 //<< "map trace size:" << map_trace_out.size()
115 //<< "trace size:" << trace.size();
116
117 if(!map_trace_in.size())
118 return map_trace_out;
119
120 return combine(map_trace_out, map_trace_in.toTrace());
121}
122
123
124} // namespace pappso
Trace toTrace() const
Definition maptrace.cpp:219
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:148
static pappso_double roundToDecimals(pappso_double value, int decimal_places)
Definition utils.cpp:141
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