libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
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"
29
30#include <QObject>
31
32
33namespace pappso
34{
35TraceDetectionZivy::TraceDetectionZivy(unsigned int smoothing_half_window_length,
36 unsigned int minmax_half_window_length,
37 unsigned int maxmin_half_window_length,
38 double detection_threshold_on_minmax,
39 double detection_threshold_on_maxmin)
40 : m_smooth(smoothing_half_window_length),
41 m_minMax(minmax_half_window_length),
42 m_maxMin(maxmin_half_window_length)
43{
44 m_detectionThresholdOnMaxMin = detection_threshold_on_maxmin;
45 m_detectionThresholdOnMinMax = detection_threshold_on_minmax;
46}
47
57
58void
63void
68void
73
74void
75TraceDetectionZivy::setDetectionThresholdOnMinmax(double detectionThresholdOnMinMax)
76{
77 m_detectionThresholdOnMinMax = detectionThresholdOnMinMax;
78}
79void
80TraceDetectionZivy::setDetectionThresholdOnMaxmin(double detectionThresholdOnMaxMin)
81{
82 m_detectionThresholdOnMaxMin = detectionThresholdOnMaxMin;
83}
84unsigned int
86{
87 return m_smooth.getHalfWindowSize();
88};
89unsigned int
91{
92 return m_maxMin.getMaxMinHalfEdgeWindows();
93};
94
95unsigned int
97{
98 return m_minMax.getMinMaxHalfEdgeWindows();
99};
110
111
112void
115 bool remove_peak_base) const
116{
117
118 // detect peak positions on close curve : a peak is an intensity value
119 // strictly greater than the two surrounding values. In case of
120 // equality (very rare, can happen with some old old spectrometers) we
121 // take the last equal point to be the peak
122 qDebug();
123 std::size_t size = xic.size();
124 if(size < 4)
125 {
126 qDebug() << QObject::tr("The original XIC is too small to detect peaks (%1)").arg(xic.size());
127 return;
128 }
129 if(size <= m_maxMin.getMaxMinHalfEdgeWindows())
130 return;
131 if(size <= m_minMax.getMinMaxHalfEdgeWindows())
132 return;
133
134 Trace xic_minmax(xic); //"close" courbe du haut
135 if(m_smooth.getHalfWindowSize() != 0)
136 {
137 qDebug() << "f";
138 m_smooth.filter(xic_minmax);
139 }
140
141 qDebug();
142 Trace xic_maxmin(xic_minmax); //"open" courbe du bas
143
144 qDebug();
145
146 try
147 {
148 qDebug() << "f1";
149 m_minMax.filter(xic_minmax);
150 qDebug() << "f2";
151 m_maxMin.filter(xic_maxmin);
152 }
153 catch(const ExceptionOutOfRange &e)
154 {
155 qDebug() << QObject::tr("The original XIC is too small to detect peaks (%1) :\n%2")
156 .arg(xic.size())
157 .arg(e.qwhat());
158 return;
159 }
160 qDebug() << "a";
161
162 std::vector<DataPoint>::const_iterator previous_rt = xic_minmax.begin();
163 std::vector<DataPoint>::const_iterator current_rt = (previous_rt + 1);
164 std::vector<DataPoint>::const_iterator last_rt = (xic_minmax.end() - 1);
165
166 std::vector<DataPoint>::const_iterator current_rt_on_maxmin = (xic_maxmin.begin() + 1);
167
168 std::vector<DataPoint>::const_iterator xic_position = xic.begin();
169 qDebug() << "b";
170 while(current_rt != last_rt)
171 // for (unsigned int i = 1, count = 0; i < xic_minmax.size() - 1; )
172 {
173 // conditions to have a peak
174 if((previous_rt->y < current_rt->y) && (current_rt->y > m_detectionThresholdOnMinMax) &&
175 (current_rt_on_maxmin->y > m_detectionThresholdOnMaxMin))
176 {
177 // here we test the last condition to have a peak
178
179 // no peak case
180 if(current_rt->y < (current_rt + 1)->y)
181 {
182 //++i;
183 previous_rt = current_rt;
184 current_rt++;
185 current_rt_on_maxmin++;
186 }
187 // there is a peak here ! case
188 else if(current_rt->y > (current_rt + 1)->y)
189 {
190 // peak.setMaxXicElement(*current_rt);
191
192 // find left boundary
193 std::vector<DataPoint>::const_iterator it_left =
194 moveLowerYLeftDataPoint(xic_minmax, current_rt);
195 // walk back
196 it_left = moveLowerYRigthDataPoint(xic_minmax, it_left);
197 // peak.setLeftBoundary(*it_left);
198
199 // find right boundary
200 std::vector<DataPoint>::const_iterator it_right =
201 moveLowerYRigthDataPoint(xic_minmax, current_rt);
202 // walk back
203 it_right = moveLowerYLeftDataPoint(xic_minmax, it_right);
204 // peak.setRightBoundary(*it_right);
205
206 // integrate peak surface :
207 auto it = findFirstEqualOrGreaterX(xic_position, xic.end(), it_left->x);
208 xic_position = findFirstEqualOrGreaterX(it, xic.end(), it_right->x) + 1;
209 // peak.setArea(areaTrace(it, xic_position));
210
211 // find the maximum :
212 // peak.setMaxXicElement(*maxYDataPoint(it, xic_position));
213
214 // areaTrace()
215 TracePeak peak(it, xic_position, remove_peak_base);
216 sink.setTracePeak(peak);
217 // }
218 //++i;
219 previous_rt = current_rt;
220 current_rt++;
221 current_rt_on_maxmin++;
222 }
223 // equality case, skipping equal points
224 else
225 {
226 // while (v_minmax[i] == v_minmax[i + 1]) {
227 //++i;
228 current_rt++;
229 current_rt_on_maxmin++;
230
231 //++count;
232 }
233 }
234 // no chance to have a peak at all, continue looping
235 else
236 {
237 //++i;
238 previous_rt = current_rt;
239 current_rt++;
240 current_rt_on_maxmin++;
241 }
242 } // end loop for peaks
243 qDebug();
244}
245} // namespace pappso
246
247void
249{
250 // reader.
251}
transform the trace with the maximum of the minimum equivalent of the erode filter for pictures
mean filter apply mean of y values inside the window : this results in a kind of smoothing
transform the trace with the minimum of the maximum equivalent of the dilate filter for pictures
base class to read MSrun the only way to build a MsRunReader object is to use the MsRunReaderFactory
Definition msrunreader.h:64
virtual const QString & qwhat() const
virtual void setTracePeak(TracePeak &xic_peak)=0
void setFilterMorphoMinMax(const FilterMorphoMinMax &m_minMax)
void setDetectionThresholdOnMaxmin(double detectionThresholdOnMaxMin)
TraceDetectionZivy(unsigned int smoothing_half_window_length, unsigned int minmax_half_window_length, unsigned int maxmin_half_window_length, double detection_threshold_on_minmax, double detection_threshold_on_maxmin)
unsigned int getMinMaxHalfEdgeWindows() const
void detect(const Trace &xic, TraceDetectionSinkInterface &sink, bool remove_peak_base) const override
detect peaks on a trace
unsigned int getSmoothingHalfEdgeWindows() const
void setFilterMorphoMaxMin(const FilterMorphoMaxMin &maxMin)
void setFilterMorphoMean(const FilterMorphoMean &smooth)
void guessParametersFromMsRunReader(const MsRunReader &reader)
unsigned int getMaxMinHalfEdgeWindows() const
void setDetectionThresholdOnMinmax(double detectionThresholdOnMinMax)
A simple container of DataPoint instances.
Definition trace.h:148
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39
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:70
std::vector< DataPoint >::const_iterator moveLowerYLeftDataPoint(const Trace &trace, std::vector< DataPoint >::const_iterator begin)
Move left to the lower value.
Definition trace.cpp:211
double pappso_double
A type definition for doubles.
Definition types.h:61
std::vector< DataPoint >::const_iterator moveLowerYRigthDataPoint(const Trace &trace, std::vector< DataPoint >::const_iterator begin)
Move right to the lower value.
Definition trace.cpp:194