libpappsomspp
Library for mass spectrometry
tracedetectionzivy.cpp
Go to the documentation of this file.
1 
2 /*******************************************************************************
3  * Copyright (c) 2015 Olivier Langella <Olivier.Langella@moulon.inra.fr>.
4  *
5  * This file is part of the PAPPSOms++ library.
6  *
7  * PAPPSOms++ is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * PAPPSOms++ is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with PAPPSOms++. If not, see <http://www.gnu.org/licenses/>.
19  *
20  * Contributors:
21  * Olivier Langella <Olivier.Langella@moulon.inra.fr> - initial API and
22  *implementation
23  ******************************************************************************/
24 
25 #include "tracedetectionzivy.h"
26 #include "tracepeak.h"
27 #include "../../exception/exceptionoutofrange.h"
28 #include "../../exception/exceptionnotpossible.h"
29 
30 namespace pappso
31 {
33  unsigned int smoothing_half_window_length,
34  unsigned int minmax_half_window_length,
35  unsigned int maxmin_half_window_length,
36  pappso_double detection_threshold_on_minmax,
37  pappso_double detection_threshold_on_maxmin)
38  : m_smooth(smoothing_half_window_length),
39  m_minMax(minmax_half_window_length),
40  m_maxMin(maxmin_half_window_length)
41 {
42  m_detectionThresholdOnMaxMin = detection_threshold_on_maxmin;
43  m_detectionThresholdOnMinMax = detection_threshold_on_minmax;
44 }
46 {
47 }
48 
49 void
50 TraceDetectionZivy::setFilterMorphoMean(const FilterMorphoMean &smooth)
51 {
52  m_smooth = smooth;
53 }
54 void
56 {
57  m_minMax = minMax;
58 }
59 void
60 TraceDetectionZivy::setFilterMorphoMaxMin(const FilterMorphoMaxMin &maxMin)
61 {
62  m_maxMin = maxMin;
63 }
64 
65 void
67  double detectionThresholdOnMinMax)
68 {
69  m_detectionThresholdOnMinMax = detectionThresholdOnMinMax;
70 }
71 void
73  double detectionThresholdOnMaxMin)
74 {
75  m_detectionThresholdOnMaxMin = detectionThresholdOnMaxMin;
76 }
77 unsigned int
79 {
81 };
82 unsigned int
84 {
86 };
87 
88 unsigned int
90 {
92 };
95 {
97 };
100 {
102 };
103 
104 
105 void
107  TraceDetectionSinkInterface &sink) const
108 {
109 
110  // detect peak positions on close curve : a peak is an intensity value
111  // strictly greater than the two surrounding values. In case of
112  // equality (very rare, can happen with some old old spectrometers) we
113  // take the last equal point to be the peak
114  qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
115  Trace xic_minmax(xic); //"close" courbe du haut
117  {
118  m_smooth.filter(xic_minmax);
119  }
120 
121  qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
122  Trace xic_maxmin(xic_minmax); //"open" courbe du bas
123 
124  qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
125  try
126  {
127  m_minMax.filter(xic_minmax);
128  m_maxMin.filter(xic_maxmin);
129  }
130  catch(const ExceptionOutOfRange &e)
131  {
132  throw ExceptionNotPossible(
133  QObject::tr("The original XIC is too small to detect peaks (%1) :\n%2")
134  .arg(xic.size())
135  .arg(e.qwhat()));
136  }
137  qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
138  std::vector<DataPoint>::const_iterator previous_rt = xic_minmax.begin();
139  std::vector<DataPoint>::const_iterator current_rt = (previous_rt + 1);
140  std::vector<DataPoint>::const_iterator last_rt = (xic_minmax.end() - 1);
141 
142  std::vector<DataPoint>::const_iterator current_rt_on_maxmin =
143  (xic_maxmin.begin() + 1);
144 
145  std::vector<DataPoint>::const_iterator xic_position = xic.begin();
146  qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
147  while(current_rt != last_rt)
148  // for (unsigned int i = 1, count = 0; i < xic_minmax.size() - 1; )
149  {
150  // conditions to have a peak
151  if((previous_rt->y < current_rt->y) &&
152  (current_rt->y > m_detectionThresholdOnMinMax) &&
153  (current_rt_on_maxmin->y > m_detectionThresholdOnMaxMin))
154  {
155  // here we test the last condition to have a peak
156 
157  // no peak case
158  if(current_rt->y < (current_rt + 1)->y)
159  {
160  //++i;
161  previous_rt = current_rt;
162  current_rt++;
163  current_rt_on_maxmin++;
164  }
165  // there is a peak here ! case
166  else if(current_rt->y > (current_rt + 1)->y)
167  {
168  // peak.setMaxXicElement(*current_rt);
169 
170  // find left boundary
171  std::vector<DataPoint>::const_iterator it_left =
172  moveLowerYLeftDataPoint(xic_minmax, current_rt);
173  // walk back
174  it_left = moveLowerYRigthDataPoint(xic_minmax, it_left);
175  // peak.setLeftBoundary(*it_left);
176 
177  // find right boundary
178  std::vector<DataPoint>::const_iterator it_right =
179  moveLowerYRigthDataPoint(xic_minmax, current_rt);
180  // walk back
181  it_right = moveLowerYLeftDataPoint(xic_minmax, it_right);
182  // peak.setRightBoundary(*it_right);
183 
184  // integrate peak surface :
185  auto it =
186  findFirstEqualOrGreaterX(xic_position, xic.end(), it_left->x);
187  xic_position =
188  findFirstEqualOrGreaterX(it, xic.end(), it_right->x) + 1;
189  // peak.setArea(areaTrace(it, xic_position));
190 
191  // find the maximum :
192  // peak.setMaxXicElement(*maxYDataPoint(it, xic_position));
193 
194  // areaTrace()
195  TracePeak peak(it, xic_position);
196  sink.setTracePeak(peak);
197  // }
198  //++i;
199  previous_rt = current_rt;
200  current_rt++;
201  current_rt_on_maxmin++;
202  }
203  // equality case, skipping equal points
204  else
205  {
206  // while (v_minmax[i] == v_minmax[i + 1]) {
207  //++i;
208  current_rt++;
209  current_rt_on_maxmin++;
210 
211  //++count;
212  }
213  }
214  // no chance to have a peak at all, continue looping
215  else
216  {
217  //++i;
218  previous_rt = current_rt;
219  current_rt++;
220  current_rt_on_maxmin++;
221  }
222  } // end loop for peaks
223  qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
224 }
225 } // namespace pappso
pappso::moveLowerYLeftDataPoint
std::vector< DataPoint >::const_iterator moveLowerYLeftDataPoint(const Trace &trace, std::vector< DataPoint >::const_iterator begin)
Move left to the lower value.
Definition: trace.cpp:165
pappso::TraceDetectionZivy::getSmoothingHalfEdgeWindows
unsigned int getSmoothingHalfEdgeWindows() const
Definition: tracedetectionzivy.cpp:99
pappso::pappso_double
double pappso_double
A type definition for doubles.
Definition: types.h:69
pappso::TraceDetectionZivy::setDetectionThresholdOnMaxmin
void setDetectionThresholdOnMaxmin(double detectionThresholdOnMaxMin)
Definition: tracedetectionzivy.cpp:93
pappso::moveLowerYRigthDataPoint
std::vector< DataPoint >::const_iterator moveLowerYRigthDataPoint(const Trace &trace, std::vector< DataPoint >::const_iterator begin)
Move right to the lower value.
Definition: trace.cpp:149
pappso::TraceDetectionZivy::m_maxMin
FilterMorphoMaxMin m_maxMin
Definition: tracedetectionzivy.h:83
pappso::TraceDetectionZivy::m_smooth
FilterMorphoMean m_smooth
Definition: tracedetectionzivy.h:81
pappso::TraceDetectionZivy::setFilterMorphoMaxMin
void setFilterMorphoMaxMin(const FilterMorphoMaxMin &maxMin)
Definition: tracedetectionzivy.cpp:81
pappso
Definition: aa.cpp:38
pappso::FilterMorphoWindowBase::filter
virtual Trace & filter(Trace &data_points) const override
Definition: filtermorpho.cpp:60
pappso::TraceDetectionZivy::getDetectionThresholdOnMinmax
pappso_double getDetectionThresholdOnMinmax() const
Definition: tracedetectionzivy.cpp:115
pappso::TraceDetectionZivy::~TraceDetectionZivy
virtual ~TraceDetectionZivy()
Definition: tracedetectionzivy.cpp:66
pappso::TraceDetectionZivy::setDetectionThresholdOnMinmax
void setDetectionThresholdOnMinmax(double detectionThresholdOnMinMax)
Definition: tracedetectionzivy.cpp:87
pappso::TraceDetectionSinkInterface
Definition: tracedetectioninterface.h:58
pappso::ExceptionNotPossible
Definition: exceptionnotpossible.h:52
pappso::TraceDetectionZivy::m_detectionThresholdOnMinMax
pappso_double m_detectionThresholdOnMinMax
Definition: tracedetectionzivy.h:84
pappso::TraceDetectionZivy::getMaxMinHalfEdgeWindows
unsigned int getMaxMinHalfEdgeWindows() const
Definition: tracedetectionzivy.cpp:104
pappso::TraceDetectionZivy::setFilterMorphoMean
void setFilterMorphoMean(const FilterMorphoMean &smooth)
Definition: tracedetectionzivy.cpp:71
pappso::TraceDetectionSinkInterface::setTracePeak
virtual void setTracePeak(TracePeak &xic_peak)=0
pappso::TraceDetectionZivy::m_minMax
FilterMorphoMinMax m_minMax
Definition: tracedetectionzivy.h:82
pappso::ExceptionOutOfRange
Definition: exceptionoutofrange.h:52
pappso::FilterMorphoMinMax::filter
Trace & filter(Trace &data_points) const override
Definition: filtermorpho.cpp:224
pappso::Trace
A simple container of DataPoint instances.
Definition: trace.h:126
pappso::TraceDetectionZivy::getMinMaxHalfEdgeWindows
unsigned int getMinMaxHalfEdgeWindows() const
Definition: tracedetectionzivy.cpp:110
pappso::FilterMorphoMaxMin::filter
Trace & filter(Trace &data_points) const override
Definition: filtermorpho.cpp:258
pappso::TraceDetectionZivy::m_detectionThresholdOnMaxMin
pappso_double m_detectionThresholdOnMaxMin
Definition: tracedetectionzivy.h:85
pappso::FilterMorphoMinMax::getMinMaxHalfEdgeWindows
std::size_t getMinMaxHalfEdgeWindows() const
Definition: filtermorpho.cpp:233
pappso::FilterMorphoMinMax
transform the trace with the minimum of the maximum equivalent of the dilate filter for pictures
Definition: filtermorpho.h:135
tracedetectionzivy.h
pappso::TraceDetectionZivy::TraceDetectionZivy
TraceDetectionZivy(unsigned int smoothing_half_window_length, unsigned int minmax_half_window_length, unsigned int maxmin_half_window_length, pappso_double detection_threshold_on_minmax, pappso_double detection_threshold_on_maxmin)
Definition: tracedetectionzivy.cpp:53
tracepeak.h
pappso::TraceDetectionZivy::setFilterMorphoMinMax
void setFilterMorphoMinMax(const FilterMorphoMinMax &m_minMax)
Definition: tracedetectionzivy.cpp:76
pappso::PappsoException::qwhat
virtual const QString & qwhat() const
Definition: pappsoexception.h:108
pappso::FilterMorphoMaxMin::getMaxMinHalfEdgeWindows
std::size_t getMaxMinHalfEdgeWindows() const
Definition: filtermorpho.cpp:267
pappso::findFirstEqualOrGreaterX
std::vector< DataPoint >::iterator findFirstEqualOrGreaterX(std::vector< DataPoint >::iterator begin, std::vector< DataPoint >::iterator end, const double &value)
find the first element in which X is equal or greater than the value searched important : it implies ...
Definition: trace.cpp:30
pappso::TraceDetectionZivy::detect
void detect(const Trace &xic, TraceDetectionSinkInterface &sink) const override
Definition: tracedetectionzivy.cpp:127
pappso::FilterMorphoMean::getMeanHalfEdgeWindows
std::size_t getMeanHalfEdgeWindows() const
Definition: filtermorpho.cpp:379
pappso::TraceDetectionZivy::getDetectionThresholdOnMaxmin
pappso_double getDetectionThresholdOnMaxmin() const
Definition: tracedetectionzivy.cpp:120