libpappsomspp
Library for mass spectrometry
massspectrumcombiner.cpp
Go to the documentation of this file.
1 #include <numeric>
2 #include <limits>
3 #include <vector>
4 #include <map>
5 #include <cmath>
6 
7 #include <QDebug>
8 #include <QFile>
9 
10 #if 0
11 // For debugging purposes.
12 #include <QFile>
13 #endif
14 
15 #include "massspectrumcombiner.h"
16 #include "../../types.h"
17 #include "../../utils.h"
18 #include "../../pappsoexception.h"
19 #include "../../exception/exceptionoutofrange.h"
20 #include "../../exception/exceptionnotpossible.h"
21 
22 
23 namespace pappso
24 {
25 
26 
27 //! Construct an uninitialized instance.
29 {
30 }
31 
32 
33 MassSpectrumCombiner::MassSpectrumCombiner(std::vector<pappso_double> bins,
34  int decimalPlaces)
35  : MassDataCombinerInterface(decimalPlaces), m_bins(bins)
36 {
37 }
38 
39 
41  : MassDataCombinerInterface(decimal_places)
42 {
43 }
44 
45 
47  : MassDataCombinerInterface(other.m_decimalPlaces)
48 {
49  // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()";
50 
51  m_bins.assign(other.m_bins.begin(), other.m_bins.end());
52 }
53 
54 
56  : MassDataCombinerInterface(other->m_decimalPlaces)
57 {
58  // qDebug() << __FILE__ << "@" << __LINE__ << __FUNCTION__ << "()";
59 
60  m_bins.assign(other->m_bins.begin(), other->m_bins.end());
61 }
62 
63 
64 //! Destruct the instance.
66 {
67  // Calls the destructor for each DataPoint object in the vector.
68  m_bins.clear();
69 }
70 
71 
72 void
73 MassSpectrumCombiner::setBins(std::vector<pappso_double> bins)
74 {
75  m_bins.assign(bins.begin(), bins.end());
76 
77  // qDebug() << "After bins assignment, local bins are of this size:"
78  //<< m_bins.size() << "Starting at:" << m_bins.front()
79  //<< "and ending at:" << m_bins.back();
80 }
81 
82 
83 const std::vector<pappso_double> &
85 {
86  return m_bins;
87 }
88 
89 
90 std::vector<pappso_double>::iterator
92 {
93  return m_bins.begin();
94 }
95 
96 
97 std::vector<pappso_double>::iterator
99 {
100  return m_bins.end();
101 }
102 
103 
104 std::vector<pappso_double>::const_iterator
106 {
107  return m_bins.begin();
108 }
109 
110 
111 std::vector<pappso_double>::const_iterator
113 {
114  return m_bins.end();
115 }
116 
117 
118 std::size_t
120 {
121  return m_bins.size();
122 }
123 
124 
125 //! Find the bin that will contain \p mz.
126 
127 std::vector<pappso_double>::iterator
129 {
130  return std::find_if(m_bins.begin(), m_bins.end(), [mz](pappso_double bin) {
131  return (mz <= bin);
132  });
133 }
134 
135 
136 MapTrace &
137 MassSpectrumCombiner::combine(MapTrace &map_trace, const Trace &trace) const
138 {
139 
140  // qDebug() << "Thread:" << QThread::currentThreadId()
141  //<< "Going to combine a trace this size:" << trace.size();
142 
143  if(!trace.size())
144  {
145  // qDebug() << "Thread:" << QThread::currentThreadId()
146  //<< "Returning right away because trace is empty.";
147  return map_trace;
148  }
149 
150 
151  // Let's check if we need to apply a filter to the input data.
152 
153  Trace filtered_trace(trace);
154 
156  {
157  m_filterXRange.filter(filtered_trace);
158 
159  if(!filtered_trace.size())
160  return map_trace;
161  }
162 
163  return combineNoFilteringStep(map_trace, filtered_trace);
164 }
165 
166 
167 MapTrace &
169  const MapTrace &map_trace_in) const
170 {
171 
172  // qDebug() << "Thread:" << QThread::currentThreadId()
173  //<< "Going to combine a map_trace_in this size:" << map_trace_in.size();
174 
175  if(!map_trace_in.size())
176  {
177  // qDebug() << "Thread:" << QThread::currentThreadId()
178  //<< "Returning right away because map_trace_in is empty.";
179  return map_trace_out;
180  }
181 
182  // Let's check if we need to apply a filter to the input data.
183 
184  Trace filtered_trace_in(map_trace_in);
185 
187  {
188  m_filterXRange.filter(filtered_trace_in);
189 
190  if(!filtered_trace_in.size())
191  return map_trace_out;
192  }
193 
194  return combineNoFilteringStep(map_trace_out, filtered_trace_in);
195 }
196 
197 
198 } // namespace pappso
pappso::pappso_double
double pappso_double
A type definition for doubles.
Definition: types.h:69
pappso::MassSpectrumCombiner
Definition: massspectrumcombiner.h:30
pappso::MassSpectrumCombiner::MassSpectrumCombiner
MassSpectrumCombiner()
Construct an uninitialized instance.
Definition: massspectrumcombiner.cpp:28
pappso
tries to keep as much as possible monoisotopes, removing any possible C13 peaks
Definition: aa.cpp:39
pappso::MassDataCombinerInterface
Definition: massdatacombinerinterface.h:24
pappso::FilterResampleKeepXRange::filter
Trace & filter(Trace &trace) const override
Definition: filterresample.cpp:162
pappso::MapTrace
Definition: maptrace.h:33
massspectrumcombiner.h
pappso::MassSpectrumCombiner::getBins
const std::vector< pappso_double > & getBins() const
Definition: massspectrumcombiner.cpp:84
pappso::MassSpectrumCombiner::combineNoFilteringStep
virtual MapTrace & combineNoFilteringStep(MapTrace &map_trace, const Trace &trace) const =0
pappso::MassSpectrumCombiner::setBins
void setBins(std::vector< pappso_double > bins)
Definition: massspectrumcombiner.cpp:73
pappso::Trace
A simple container of DataPoint instances.
Definition: trace.h:132
pappso::MassDataCombinerInterface::m_filterXRange
FilterResampleKeepXRange m_filterXRange
Definition: massdatacombinerinterface.h:48
pappso::MassSpectrumCombiner::findBin
std::vector< pappso_double >::iterator findBin(pappso_double mz)
Find the bin that will contain mz.
Definition: massspectrumcombiner.cpp:128
pappso::MassSpectrumCombiner::end
std::vector< pappso_double >::const_iterator end() const
Definition: massspectrumcombiner.cpp:112
pappso::MassSpectrumCombiner::~MassSpectrumCombiner
virtual ~MassSpectrumCombiner()
Destruct the instance.
Definition: massspectrumcombiner.cpp:65
pappso::MassSpectrumCombiner::begin
std::vector< pappso_double >::const_iterator begin() const
Definition: massspectrumcombiner.cpp:105
pappso::MassSpectrumCombiner::combine
virtual MapTrace & combine(MapTrace &map_trace, const Trace &trace) const
Definition: massspectrumcombiner.cpp:137
pappso::MassSpectrumCombiner::binCount
std::size_t binCount() const
Definition: massspectrumcombiner.cpp:119
pappso::PrecisionUnit::mz
@ mz
pappso::MassSpectrumCombiner::m_bins
std::vector< pappso_double > m_bins
Definition: massspectrumcombiner.h:58
pappso::MassSpectrumCombinerCstSPtr
std::shared_ptr< const MassSpectrumCombiner > MassSpectrumCombinerCstSPtr
Definition: massspectrumcombiner.h:23
pappso::MassDataCombinerInterface::m_isApplyXRangeFilter
bool m_isApplyXRangeFilter
Definition: massdatacombinerinterface.h:46