libpappsomspp
Library for mass spectrometry
tracepluscombiner.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#include <iomanip>
8
9#include <QDebug>
10
11#include "tracepluscombiner.h"
12#include "../../trace/trace.h"
13#include "../../types.h"
14#include "../../utils.h"
15#include "../../pappsoexception.h"
16#include "../../exception/exceptionoutofrange.h"
17
18
19namespace pappso
20{
21
22
24{
25}
26
27
29 : TraceCombiner(decimal_places)
30{
31}
32
33
35 : TraceCombiner(other)
36{
37}
38
39
41 : TraceCombiner(other)
42{
43 qDebug();
44}
45
46
48{
49}
50
51
54 const Trace &trace) const
55{
56 //qDebug();
57
58 if(!trace.size())
59 return map_trace;
60
61 for(auto &current_data_point : trace)
62 {
63
64 // If the data point is 0-intensity, then do nothing!
65 if(!current_data_point.y)
66 continue;
67
68 double x = Utils::roundToDecimals(current_data_point.x, m_decimalPlaces);
69
70 std::map<double, double>::iterator map_iterator;
71
72 std::pair<std::map<pappso_double, pappso_double>::iterator, bool> result;
73
74 result = map_trace.insert(
75 std::pair<pappso_double, pappso_double>(x, current_data_point.y));
76
77 if(result.second)
78 {
79 // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << " ()";
80 // The new element was inserted, we have nothing to do.
81 }
82 else
83 {
84 // The key already existed! The item was not inserted. We need to
85 // update the value.
86
87 result.first->second += current_data_point.y;
88 }
89 }
90
91 // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << " ()"
92 //<< "Prior to returning map_trace, its size is:" << map_trace.size();
93 // qDebug();
94 return map_trace;
95}
96
97
100 const MapTrace &map_trace_in) const
101{
102 // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << " ()"
103 //<< "map trace size:" << map_trace_out.size()
104 //<< "trace size:" << trace.size();
105
106 if(!map_trace_in.size())
107 return map_trace_out;
108
109 return combine(map_trace_out, map_trace_in.toTrace());
110}
111
112
113} // 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:38
static pappso_double roundToDecimals(pappso_double value, int decimal_places)
Definition: utils.cpp:120
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition: aa.cpp:39
std::shared_ptr< const TracePlusCombiner > TracePlusCombinerCstSPtr