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 
19 namespace pappso
20 {
21 
22 
24 {
25 }
26 
27 
29  : TraceCombiner(decimal_places)
30 {
31 }
32 
33 
35  : TraceCombiner(other.m_decimalPlaces)
36 {
37 }
38 
39 
41  : TraceCombiner(other->m_decimalPlaces)
42 {
43 }
44 
45 
47 {
48 }
49 
50 
51 MapTrace &
52 TracePlusCombiner::combine(MapTrace &map_trace, const Trace &trace) const
53 {
54  // qDebug();
55 
56  if(!trace.size())
57  return map_trace;
58 
59  // Let's check if we need to apply a filter to the input data.
60 
61  Trace filtered_trace(trace);
62 
64  {
65  m_filterXRange.filter(filtered_trace);
66 
67  if(!filtered_trace.size())
68  return map_trace;
69  }
70 
71  for(auto &current_data_point : filtered_trace)
72  {
73 
74  // If the data point is 0-intensity, then do nothing!
75  if(!current_data_point.y)
76  continue;
77 
78  double x = Utils::roundToDecimals(current_data_point.x, m_decimalPlaces);
79 
80  std::map<double, double>::iterator map_iterator;
81 
82  std::pair<std::map<pappso_double, pappso_double>::iterator, bool> result;
83 
84  result = map_trace.insert(
85  std::pair<pappso_double, pappso_double>(x, current_data_point.y));
86 
87  if(result.second)
88  {
89  // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << " ()";
90  // The new element was inserted, we have nothing to do.
91  }
92  else
93  {
94  // The key already existed! The item was not inserted. We need to
95  // update the value.
96 
97  result.first->second += current_data_point.y;
98  }
99  }
100 
101  // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << " ()"
102  //<< "Prior to returning map_trace, its size is:" << map_trace.size();
103  // qDebug();
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  // The call below will ensure that if there are filtering steps to apply, they
120  // are actually applied.
121  return combine(map_trace_out, map_trace_in.toTrace());
122 }
123 
124 
125 } // namespace pappso
pappso::TracePlusCombiner::combine
virtual MapTrace & combine(MapTrace &map_trace, const Trace &trace) const override
Definition: tracepluscombiner.cpp:52
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::FilterResampleKeepXRange::filter
Trace & filter(Trace &trace) const override
Definition: filterresample.cpp:162
pappso::TracePlusCombiner::TracePlusCombiner
TracePlusCombiner()
Definition: tracepluscombiner.cpp:23
pappso::MapTrace
Definition: maptrace.h:33
pappso::PeptideIonCter::y
@ y
pappso::TracePlusCombinerCstSPtr
std::shared_ptr< const TracePlusCombiner > TracePlusCombinerCstSPtr
Definition: tracepluscombiner.h:20
pappso::Trace
A simple container of DataPoint instances.
Definition: trace.h:132
pappso::MassDataCombinerInterface::m_filterXRange
FilterResampleKeepXRange m_filterXRange
Definition: massdatacombinerinterface.h:48
pappso::Utils::roundToDecimals
static pappso_double roundToDecimals(pappso_double value, int decimal_places)
Definition: utils.cpp:104
pappso::TraceCombiner
Definition: tracecombiner.h:28
pappso::MapTrace::toTrace
Trace toTrace() const
Definition: maptrace.cpp:191
pappso::TracePlusCombiner::~TracePlusCombiner
virtual ~TracePlusCombiner()
Definition: tracepluscombiner.cpp:46
pappso::TracePlusCombiner
Definition: tracepluscombiner.h:27
tracepluscombiner.h
pappso::MassDataCombinerInterface::m_isApplyXRangeFilter
bool m_isApplyXRangeFilter
Definition: massdatacombinerinterface.h:46