tracedetectionzivy.cpp
Go to the documentation of this file.
/*******************************************************************************
* Copyright (c) 2015 Olivier Langella <Olivier.Langella@moulon.inra.fr>.
*
* This file is part of the PAPPSOms++ library.
*
* PAPPSOms++ is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PAPPSOms++ is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PAPPSOms++. If not, see <http://www.gnu.org/licenses/>.
*
* Contributors:
* Olivier Langella <Olivier.Langella@moulon.inra.fr> - initial API and
*implementation
******************************************************************************/
#include "tracedetectionzivy.h"
#include "tracepeak.h"
#include "../../exception/exceptionoutofrange.h"
#include "../../exception/exceptionnotpossible.h"
namespace pappso
{
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)
: m_smooth(smoothing_half_window_length),
m_minMax(minmax_half_window_length),
m_maxMin(maxmin_half_window_length)
{
m_detectionThresholdOnMaxMin = detection_threshold_on_maxmin;
m_detectionThresholdOnMinMax = detection_threshold_on_minmax;
}
TraceDetectionZivy::~TraceDetectionZivy()
{
}
void
TraceDetectionZivy::setFilterMorphoMean(const FilterMorphoMean &smooth)
{
m_smooth = smooth;
}
void
TraceDetectionZivy::setFilterMorphoMinMax(const FilterMorphoMinMax &minMax)
{
m_minMax = minMax;
}
void
TraceDetectionZivy::setFilterMorphoMaxMin(const FilterMorphoMaxMin &maxMin)
{
m_maxMin = maxMin;
}
void
TraceDetectionZivy::setDetectionThresholdOnMinmax(
double detectionThresholdOnMinMax)
{
m_detectionThresholdOnMinMax = detectionThresholdOnMinMax;
}
void
TraceDetectionZivy::setDetectionThresholdOnMaxmin(
double detectionThresholdOnMaxMin)
{
m_detectionThresholdOnMaxMin = detectionThresholdOnMaxMin;
}
unsigned int
TraceDetectionZivy::getSmoothingHalfEdgeWindows() const
{
return m_smooth.getMeanHalfEdgeWindows();
};
unsigned int
TraceDetectionZivy::getMaxMinHalfEdgeWindows() const
{
return m_maxMin.getMaxMinHalfEdgeWindows();
};
unsigned int
TraceDetectionZivy::getMinMaxHalfEdgeWindows() const
{
return m_minMax.getMinMaxHalfEdgeWindows();
};
pappso_double
TraceDetectionZivy::getDetectionThresholdOnMinmax() const
{
return m_detectionThresholdOnMinMax;
};
pappso_double
TraceDetectionZivy::getDetectionThresholdOnMaxmin() const
{
return m_detectionThresholdOnMaxMin;
};
void
TraceDetectionZivy::detect(const Trace &xic,
TraceDetectionSinkInterface &sink) const
{
// detect peak positions on close curve : a peak is an intensity value
// strictly greater than the two surrounding values. In case of
// equality (very rare, can happen with some old old spectrometers) we
// take the last equal point to be the peak
qDebug();
std::size_t size = xic.size();
if(size < 4)
{
qDebug() << QObject::tr(
"The original XIC is too small to detect peaks (%1)")
.arg(xic.size());
return;
}
if(size <= m_maxMin.getMaxMinHalfEdgeWindows())
return;
if(size <= m_minMax.getMinMaxHalfEdgeWindows())
return;
Trace xic_minmax(xic); //"close" courbe du haut
if(m_smooth.getMeanHalfEdgeWindows() != 0)
{
qDebug() << "f";
m_smooth.filter(xic_minmax);
}
qDebug();
Trace xic_maxmin(xic_minmax); //"open" courbe du bas
qDebug();
try
{
qDebug() << "f1";
m_minMax.filter(xic_minmax);
qDebug() << "f2";
m_maxMin.filter(xic_maxmin);
}
catch(const ExceptionOutOfRange &e)
{
qDebug() << QObject::tr(
"The original XIC is too small to detect peaks (%1) :\n%2")
.arg(xic.size())
.arg(e.qwhat());
return;
}
qDebug() << "a";
std::vector<DataPoint>::const_iterator previous_rt = xic_minmax.begin();
std::vector<DataPoint>::const_iterator current_rt = (previous_rt + 1);
std::vector<DataPoint>::const_iterator last_rt = (xic_minmax.end() - 1);
std::vector<DataPoint>::const_iterator current_rt_on_maxmin =
(xic_maxmin.begin() + 1);
std::vector<DataPoint>::const_iterator xic_position = xic.begin();
qDebug() << "b";
while(current_rt != last_rt)
// for (unsigned int i = 1, count = 0; i < xic_minmax.size() - 1; )
{
// conditions to have a peak
if((previous_rt->y < current_rt->y) &&
(current_rt->y > m_detectionThresholdOnMinMax) &&
(current_rt_on_maxmin->y > m_detectionThresholdOnMaxMin))
{
// here we test the last condition to have a peak
// no peak case
if(current_rt->y < (current_rt + 1)->y)
{
//++i;
previous_rt = current_rt;
current_rt++;
current_rt_on_maxmin++;
}
// there is a peak here ! case
else if(current_rt->y > (current_rt + 1)->y)
{
// peak.setMaxXicElement(*current_rt);
// find left boundary
std::vector<DataPoint>::const_iterator it_left =
moveLowerYLeftDataPoint(xic_minmax, current_rt);
// walk back
it_left = moveLowerYRigthDataPoint(xic_minmax, it_left);
// peak.setLeftBoundary(*it_left);
// find right boundary
std::vector<DataPoint>::const_iterator it_right =
moveLowerYRigthDataPoint(xic_minmax, current_rt);
// walk back
it_right = moveLowerYLeftDataPoint(xic_minmax, it_right);
// peak.setRightBoundary(*it_right);
// integrate peak surface :
auto it =
findFirstEqualOrGreaterX(xic_position, xic.end(), it_left->x);
xic_position =
findFirstEqualOrGreaterX(it, xic.end(), it_right->x) + 1;
// peak.setArea(areaTrace(it, xic_position));
// find the maximum :
// peak.setMaxXicElement(*maxYDataPoint(it, xic_position));
// areaTrace()
TracePeak peak(it, xic_position);
sink.setTracePeak(peak);
// }
//++i;
previous_rt = current_rt;
current_rt++;
current_rt_on_maxmin++;
}
// equality case, skipping equal points
else
{
// while (v_minmax[i] == v_minmax[i + 1]) {
//++i;
current_rt++;
current_rt_on_maxmin++;
//++count;
}
}
// no chance to have a peak at all, continue looping
else
{
//++i;
previous_rt = current_rt;
current_rt++;
current_rt_on_maxmin++;
}
} // end loop for peaks
qDebug();
}
} // namespace pappso
pappso::ExceptionOutOfRange
Definition: exceptionoutofrange.h:32
pappso::FilterMorphoMaxMin
transform the trace with the maximum of the minimum equivalent of the erode filter for pictures
Definition: filtermorpho.h:138
pappso::FilterMorphoMaxMin::filter
Trace & filter(Trace &data_points) const override
Definition: filtermorpho.cpp:261
pappso::FilterMorphoMaxMin::getMaxMinHalfEdgeWindows
std::size_t getMaxMinHalfEdgeWindows() const
Definition: filtermorpho.cpp:270
pappso::FilterMorphoMean
mean filter apply mean of y values inside the window : this results in a kind of smoothing
Definition: filtermorpho.h:210
pappso::FilterMorphoMean::getMeanHalfEdgeWindows
std::size_t getMeanHalfEdgeWindows() const
Definition: filtermorpho.cpp:432
pappso::FilterMorphoMinMax
transform the trace with the minimum of the maximum equivalent of the dilate filter for pictures
Definition: filtermorpho.h:118
pappso::FilterMorphoMinMax::getMinMaxHalfEdgeWindows
std::size_t getMinMaxHalfEdgeWindows() const
Definition: filtermorpho.cpp:236
pappso::FilterMorphoMinMax::filter
Trace & filter(Trace &data_points) const override
Definition: filtermorpho.cpp:227
pappso::FilterMorphoWindowBase::filter
virtual Trace & filter(Trace &data_points) const override
Definition: filtermorpho.cpp:61
pappso::PappsoException::qwhat
virtual const QString & qwhat() const
Definition: pappsoexception.h:68
pappso::TraceDetectionSinkInterface
Definition: tracedetectioninterface.h:38
pappso::TraceDetectionSinkInterface::setTracePeak
virtual void setTracePeak(TracePeak &xic_peak)=0
pappso::TraceDetectionZivy::setFilterMorphoMinMax
void setFilterMorphoMinMax(const FilterMorphoMinMax &m_minMax)
Definition: tracedetectionzivy.cpp:55
pappso::TraceDetectionZivy::setDetectionThresholdOnMaxmin
void setDetectionThresholdOnMaxmin(double detectionThresholdOnMaxMin)
Definition: tracedetectionzivy.cpp:72
pappso::TraceDetectionZivy::getMinMaxHalfEdgeWindows
unsigned int getMinMaxHalfEdgeWindows() const
Definition: tracedetectionzivy.cpp:89
pappso::TraceDetectionZivy::m_maxMin
FilterMorphoMaxMin m_maxMin
Definition: tracedetectionzivy.h:41
pappso::TraceDetectionZivy::getSmoothingHalfEdgeWindows
unsigned int getSmoothingHalfEdgeWindows() const
Definition: tracedetectionzivy.cpp:78
pappso::TraceDetectionZivy::getDetectionThresholdOnMinmax
pappso_double getDetectionThresholdOnMinmax() const
Definition: tracedetectionzivy.cpp:94
pappso::TraceDetectionZivy::getDetectionThresholdOnMaxmin
pappso_double getDetectionThresholdOnMaxmin() const
Definition: tracedetectionzivy.cpp:99
pappso::TraceDetectionZivy::setFilterMorphoMaxMin
void setFilterMorphoMaxMin(const FilterMorphoMaxMin &maxMin)
Definition: tracedetectionzivy.cpp:60
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:32
pappso::TraceDetectionZivy::m_minMax
FilterMorphoMinMax m_minMax
Definition: tracedetectionzivy.h:40
pappso::TraceDetectionZivy::~TraceDetectionZivy
virtual ~TraceDetectionZivy()
Definition: tracedetectionzivy.cpp:45
pappso::TraceDetectionZivy::m_detectionThresholdOnMaxMin
pappso_double m_detectionThresholdOnMaxMin
Definition: tracedetectionzivy.h:43
pappso::TraceDetectionZivy::setFilterMorphoMean
void setFilterMorphoMean(const FilterMorphoMean &smooth)
Definition: tracedetectionzivy.cpp:50
pappso::TraceDetectionZivy::m_detectionThresholdOnMinMax
pappso_double m_detectionThresholdOnMinMax
Definition: tracedetectionzivy.h:42
pappso::TraceDetectionZivy::m_smooth
FilterMorphoMean m_smooth
Definition: tracedetectionzivy.h:39
pappso::TraceDetectionZivy::getMaxMinHalfEdgeWindows
unsigned int getMaxMinHalfEdgeWindows() const
Definition: tracedetectionzivy.cpp:83
pappso::TraceDetectionZivy::detect
void detect(const Trace &xic, TraceDetectionSinkInterface &sink) const override
Definition: tracedetectionzivy.cpp:106
pappso::TraceDetectionZivy::setDetectionThresholdOnMinmax
void setDetectionThresholdOnMinmax(double detectionThresholdOnMinMax)
Definition: tracedetectionzivy.cpp:66
pappso::TracePeak
Definition: tracepeak.h:40
pappso::Trace
A simple container of DataPoint instances.
Definition: trace.h:148
pappso
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition: aa.cpp:39
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:32
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:182
pappso::pappso_double
double pappso_double
A type definition for doubles.
Definition: types.h:48
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:164
tracedetectionzivy.h
tracepeak.h