libpappsomspp
Library for mass spectrometry
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 
18 namespace pappso
19 {
20 
21 
23 {
24 }
25 
26 
28  : TraceCombiner(decimal_places)
29 {
30 }
31 
32 
34  : TraceCombiner(other.m_decimalPlaces)
35 {
36 }
37 
38 
40  : TraceCombiner(other->m_decimalPlaces)
41 {
42 }
43 
44 
46 {
47 }
48 
49 
50 MapTrace &
51 TraceMinusCombiner::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  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  result = map_trace.insert(
74  std::pair<pappso_double, pappso_double>(x, current_data_point.y));
75 
76  if(result.second)
77  {
78  // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << " ()";
79  // The new element was inserted, we have nothing to do.
80  }
81  else
82  {
83  // The key already existed! The item was not inserted. We need to
84  // update the value.
85 
86  result.first->second -= current_data_point.y;
87  }
88  }
89 
90  // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << " ()"
91  //<< "Prior to returning map_trace, its size is:" << map_trace.size();
92 
93  return map_trace;
94 }
95 
96 
97 MapTrace &
99  const MapTrace &map_trace_in) const
100 {
101  // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << " ()"
102  //<< "map trace size:" << map_trace_out.size()
103  //<< "trace size:" << trace.size();
104 
105  if(!map_trace_in.size())
106  return map_trace_out;
107 
108  for(auto &map_pair : map_trace_in)
109  {
110 
111  // If the data point is 0-intensity, then do nothing!
112  if(!map_pair.second)
113  continue;
114 
115  double x = Utils::roundToDecimals(map_pair.first, m_decimalPlaces);
116 
117  std::map<double, double>::iterator map_iterator;
118 
119  std::pair<std::map<pappso_double, pappso_double>::iterator, bool> result;
120 
121  result = map_trace_out.insert(
122  std::pair<pappso_double, pappso_double>(x, map_pair.second));
123 
124  if(result.second)
125  {
126  // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << " ()";
127  // The new element was inserted, we have nothing to do.
128  }
129  else
130  {
131  // The key already existed! The item was not inserted. We need to
132  // update the value.
133 
134  result.first->second -= map_pair.second;
135  }
136  }
137 
138  // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << " ()"
139  //<< "Prior to returning map_trace_out, its size is:" << map_trace_out.size();
140 
141  return map_trace_out;
142 }
143 
144 
145 } // namespace pappso
pappso::TraceMinusCombinerCstSPtr
std::shared_ptr< const TraceMinusCombiner > TraceMinusCombinerCstSPtr
Definition: traceminuscombiner.h:20
pappso::MassDataCombinerInterface::m_decimalPlaces
int m_decimalPlaces
Number of decimals to use for the keys (x values)
Definition: massdatacombinerinterface.h:44
pappso
tries to keep as much as possible monoisotopes, removing any possible C13 peaks
Definition: aa.cpp:39
pappso::TraceMinusCombiner::TraceMinusCombiner
TraceMinusCombiner()
Definition: traceminuscombiner.cpp:22
traceminuscombiner.h
pappso::TraceMinusCombiner::combine
virtual MapTrace & combine(MapTrace &map_trace, const Trace &trace) const override
Definition: traceminuscombiner.cpp:51
pappso::MapTrace
Definition: maptrace.h:33
pappso::PeptideIonCter::y
@ y
pappso::TraceMinusCombiner::~TraceMinusCombiner
virtual ~TraceMinusCombiner()
Definition: traceminuscombiner.cpp:45
pappso::Trace
A simple container of DataPoint instances.
Definition: trace.h:132
pappso::TraceMinusCombiner
Definition: traceminuscombiner.h:27
pappso::Utils::roundToDecimals
static pappso_double roundToDecimals(pappso_double value, int decimal_places)
Definition: utils.cpp:104
pappso::TraceCombiner
Definition: tracecombiner.h:28