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  //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:" << map_trace.size();
103 
104  return map_trace;
105 }
106 
107 
108 MapTrace &
110  const MapTrace &map_trace_in) const
111 {
112  // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << " ()"
113  //<< "map trace size:" << map_trace_out.size()
114  //<< "trace size:" << trace.size();
115 
116  if(!map_trace_in.size())
117  return map_trace_out;
118 
119  for(auto &map_pair : map_trace_in)
120  {
121 
122  // If the data point is 0-intensity, then do nothing!
123  if(!map_pair.second)
124  continue;
125 
126  double x = Utils::roundToDecimals(map_pair.first, m_decimalPlaces);
127 
128  std::map<double, double>::iterator map_iterator;
129 
130  std::pair<std::map<pappso_double, pappso_double>::iterator, bool> result;
131 
132  result = map_trace_out.insert(
133  std::pair<pappso_double, pappso_double>(x, -map_pair.second));
134 
135  if(result.second)
136  {
137  // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << " ()";
138  // The new element was inserted, we have nothing to do.
139  }
140  else
141  {
142  // The key already existed! The item was not inserted. We need to
143  // update the value.
144 
145  result.first->second -= map_pair.second;
146  }
147  }
148 
149  // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << " ()"
150  //<< "Prior to returning map_trace_out, its size is:" << map_trace_out.size();
151 
152  return map_trace_out;
153 }
154 
155 
156 } // 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 and changes multichar...
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::x
@ x
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:125
pappso::TraceCombiner
Definition: tracecombiner.h:28