filterpass.cpp
Go to the documentation of this file.
/**
* \file pappsomspp/filers/filterpass.cpp
* \date 26/04/2019
* \author Olivier Langella
* \brief collection of filters concerned by Y selection
*/
/*******************************************************************************
* Copyright (c) 2019 Olivier Langella <Olivier.Langella@u-psud.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/>.
*
******************************************************************************/
#include "filterpass.h"
#include "../../trace/trace.h"
#include <algorithm>
#include <cmath>
#include "../../massspectrum/massspectrum.h"
#include "../../exception/exceptionoutofrange.h"
#include "../../exception/exceptionnotrecognized.h"
using namespace pappso;
FilterLowPass::FilterLowPass(double pass_y) : m_passY(pass_y)
{
}
FilterLowPass::FilterLowPass(const FilterLowPass &other)
: m_passY(other.m_passY)
{
}
FilterLowPass &
FilterLowPass::operator=(const FilterLowPass &other)
{
m_passY = other.m_passY;
return *this;
}
Trace &
FilterLowPass::filter(Trace &data_points) const
{
Trace new_data_points;
for(auto &&data_point : data_points)
{
if(data_point.y < m_passY)
{
new_data_points.push_back(data_point);
}
}
data_points = std::move(new_data_points);
return data_points;
}
FilterHighPass::FilterHighPass(double pass_y) : m_passY(pass_y)
{
}
FilterHighPass::FilterHighPass(const FilterHighPass &other)
: m_passY(other.m_passY)
{
}
FilterHighPass &
FilterHighPass::operator=(const FilterHighPass &other)
{
m_passY = other.m_passY;
return *this;
}
Trace &
FilterHighPass::filter(Trace &data_points) const
{
Trace new_data_points;
for(auto &&data_point : data_points)
{
if(data_point.y > m_passY)
{
new_data_points.push_back(data_point);
}
}
data_points = std::move(new_data_points);
return data_points;
}
FilterHighPassPercentage::FilterHighPassPercentage(double ratio_pass_y)
: m_ratioPassY(ratio_pass_y)
{
}
FilterHighPassPercentage::FilterHighPassPercentage(
const FilterHighPassPercentage &other)
: m_ratioPassY(other.m_ratioPassY)
{
}
FilterHighPassPercentage &
FilterHighPassPercentage::operator=(const FilterHighPassPercentage &other)
{
m_ratioPassY = other.m_ratioPassY;
return *this;
}
Trace &
FilterHighPassPercentage::filter(Trace &data_points) const
{
auto it_max = maxYDataPoint(data_points.begin(), data_points.end());
if(it_max == data_points.end())
return data_points;
double pass = (it_max->y * m_ratioPassY);
Trace new_data_points;
for(auto &&data_point : data_points)
{
if(data_point.y > pass)
{
new_data_points.push_back(data_point);
}
}
data_points = std::move(new_data_points);
return data_points;
}
FilterGreatestY::FilterGreatestY(std::size_t number_of_points)
: m_numberOfPoints(number_of_points)
{
}
FilterGreatestY::FilterGreatestY(const FilterGreatestY &other)
: m_numberOfPoints(other.m_numberOfPoints)
{
}
FilterGreatestY &
FilterGreatestY::operator=(const FilterGreatestY &other)
{
m_numberOfPoints = other.m_numberOfPoints;
return *this;
}
Trace &
FilterGreatestY::filter(Trace &data_points) const
{
// Reverse-sort the data points (in y decreasing order) so that we get the
// greatest to the front of the vector and we'll then copy the first n data
// points to the returned vector. See that return (b < a) ?
if(m_numberOfPoints >= data_points.size())
return data_points;
std::sort(data_points.begin(),
data_points.end(),
[](const DataPoint &a, const DataPoint &b) { return (b.y < a.y); });
data_points.erase(data_points.begin() + m_numberOfPoints, data_points.end());
// And now sort the Trace conventionally, that is in x increasing order.
std::sort(data_points.begin(),
data_points.end(),
[](const DataPoint &a, const DataPoint &b) { return (a.x < b.x); });
return data_points;
}
std::size_t
FilterGreatestY::getNumberOfPoints() const
{
return m_numberOfPoints;
}
FilterGreatestYperWindow::FilterGreatestYperWindow(
double window_range, std::size_t number_of_points_per_window)
: m_xWindowRange(window_range), m_numberOfPoints(number_of_points_per_window)
{
qDebug();
if(m_xWindowRange < 0.5)
{
throw pappso::ExceptionOutOfRange(
QObject::tr("window_range must be greater than 0.5"));
}
qDebug();
}
FilterGreatestYperWindow::FilterGreatestYperWindow(
const FilterGreatestYperWindow &other)
: m_xWindowRange(other.m_xWindowRange),
m_numberOfPoints(other.m_numberOfPoints)
{
qDebug();
}
FilterGreatestYperWindow &
FilterGreatestYperWindow::operator=(const FilterGreatestYperWindow &other)
{
qDebug();
m_numberOfPoints = other.m_numberOfPoints;
m_xWindowRange = other.m_xWindowRange;
return *this;
}
Trace &
FilterGreatestYperWindow::filter(Trace &data_points) const
{
std::vector<DataPoint> new_trace(data_points);
data_points.clear();
int window_number = 0;
int old_window_number = -1;
std::size_t number_of_peaks_in_window = 0;
auto itbegin = data_points.begin();
std::vector<DataPoint>::iterator it_min;
// std::sort(data_points.begin(),
// data_points.end(),
// [](const DataPoint &a, const DataPoint &b) { return (a.y > b.y);
// });
qDebug() << " m_xWindowRange=" << m_xWindowRange
<< " m_numberOfPoints=" << m_numberOfPoints;
for(const pappso::DataPoint &data_point : new_trace)
{
qDebug() << " data_point.x=" << data_point.x
<< " data_point.y=" << data_point.y;
window_number = trunc(data_point.x / m_xWindowRange);
qDebug() << window_number;
if(window_number != old_window_number)
{
old_window_number = window_number;
number_of_peaks_in_window = 0;
itbegin = data_points.end();
}
if(number_of_peaks_in_window < m_numberOfPoints)
{
qDebug();
data_points.push_back(data_point);
number_of_peaks_in_window++;
if(number_of_peaks_in_window == 1)
{
itbegin = data_points.begin() + (data_points.size() - 1);
}
}
else
{
qDebug();
it_min = minYDataPoint(itbegin, data_points.end());
if(it_min != data_points.end())
{
qDebug();
if(it_min->y < data_point.y)
{
qDebug();
*it_min = data_point;
// it_min->x = data_point.x;
// it_min->y = data_point.y;
}
}
}
}
qDebug();
// new_trace.sortX();
// qDebug() << new_trace.size();
// data_points.clear();
// data_points = new_trace;
// data_points = std::move(new_trace);
// qDebug() << data_points.size();
data_points.sortX();
qDebug();
return data_points;
}
std::size_t
FilterGreatestYperWindow::getNumberOfPoints() const
{
return m_numberOfPoints;
}
FilterFloorY::FilterFloorY()
{
}
FilterFloorY::FilterFloorY([[maybe_unused]] const FilterFloorY &other)
{
}
FilterFloorY &
FilterFloorY::operator=([[maybe_unused]] const FilterFloorY &other)
{
return *this;
}
Trace &
FilterFloorY::filter(Trace &data_points) const
{
for(auto &&dataPoint : data_points)
{
dataPoint.y = std::floor(dataPoint.y);
}
return data_points;
}
FilterRoundY::FilterRoundY()
{
}
FilterRoundY::FilterRoundY([[maybe_unused]] const FilterRoundY &other)
{
}
FilterRoundY &
FilterRoundY::operator=([[maybe_unused]] const FilterRoundY &other)
{
return *this;
}
Trace &
FilterRoundY::filter(Trace &data_points) const
{
for(auto &&dataPoint : data_points)
{
dataPoint.y = std::round(dataPoint.y);
}
return data_points;
}
FilterRescaleY::FilterRescaleY(double dynamic) : m_dynamic(dynamic)
{
}
FilterRescaleY::FilterRescaleY(const FilterRescaleY &other)
: m_dynamic(other.m_dynamic)
{
}
Trace &
FilterRescaleY::filter(Trace &data_points) const
{
if(m_dynamic == 0)
return data_points;
auto it_max = maxYDataPoint(data_points.begin(), data_points.end());
if(it_max == data_points.end())
return data_points;
double maximum = it_max->y;
for(auto &&dataPoint : data_points)
{
dataPoint.y = (dataPoint.y / maximum) * m_dynamic;
}
return data_points;
}
FilterRescaleY &
FilterRescaleY::operator=(const FilterRescaleY &other)
{
m_dynamic = other.m_dynamic;
return *this;
}
double
FilterRescaleY::getDynamicRange() const
{
return m_dynamic;
}
MassSpectrumFilterGreatestItensities::MassSpectrumFilterGreatestItensities(
std::size_t number_of_points)
: m_filterGreatestY(number_of_points)
{
}
MassSpectrumFilterGreatestItensities::MassSpectrumFilterGreatestItensities(
const MassSpectrumFilterGreatestItensities &other)
: m_filterGreatestY(other.m_filterGreatestY)
{
}
MassSpectrumFilterGreatestItensities &
MassSpectrumFilterGreatestItensities::operator=(
const MassSpectrumFilterGreatestItensities &other)
{
m_filterGreatestY = other.m_filterGreatestY;
return *this;
}
MassSpectrum &
MassSpectrumFilterGreatestItensities::filter(MassSpectrum &spectrum) const
{
m_filterGreatestY.filter(spectrum);
return spectrum;
}
FilterScaleFactorY::FilterScaleFactorY(double dynamic) : m_factor(dynamic)
{
}
FilterScaleFactorY::FilterScaleFactorY(const FilterScaleFactorY &other)
: m_factor(other.m_factor)
{
}
FilterScaleFactorY &
FilterScaleFactorY::operator=(const FilterScaleFactorY &other)
{
m_factor = other.m_factor;
return *this;
}
Trace &
FilterScaleFactorY::filter(Trace &data_points) const
{
if(m_factor == 1)
return data_points;
for(auto &&dataPoint : data_points)
{
dataPoint.y = dataPoint.y * m_factor;
}
return data_points;
}
double
FilterScaleFactorY::getScaleFactorY() const
{
return m_factor;
}
FilterRemoveY::FilterRemoveY(double valueToRemove)
: m_valueToRemove(valueToRemove)
{
}
FilterRemoveY::FilterRemoveY(const FilterRemoveY &other)
: m_valueToRemove(other.m_valueToRemove)
{
}
FilterRemoveY &
FilterRemoveY::operator=(const FilterRemoveY &other)
{
m_valueToRemove = other.m_valueToRemove;
return *this;
}
double
FilterRemoveY::getValue() const
{
return m_valueToRemove;
}
Trace &
FilterRemoveY::filter(Trace &data_points) const
{
for(auto &&dataPoint : data_points)
{
if(dataPoint.y < m_valueToRemove)
dataPoint.y = 0;
else
dataPoint.y = dataPoint.y - m_valueToRemove;
}
return data_points;
}
FilterQuantileBasedRemoveY::FilterQuantileBasedRemoveY(double quantile)
: m_quantile(quantile)
{
}
FilterQuantileBasedRemoveY::FilterQuantileBasedRemoveY(
const FilterQuantileBasedRemoveY &other)
: m_quantile(other.m_quantile)
{
}
FilterQuantileBasedRemoveY &
FilterQuantileBasedRemoveY::operator=(const FilterQuantileBasedRemoveY &other)
{
m_quantile = other.m_quantile;
return *this;
}
double
FilterQuantileBasedRemoveY::getQuantileThreshold() const
{
return m_quantile;
}
Trace &
pappso::FilterQuantileBasedRemoveY::filter(pappso::Trace &data_points) const
{
if(data_points.size() == 0)
return data_points;
double value_to_temove =
quantileYTrace(data_points.begin(), data_points.end(), m_quantile);
for(auto &&dataPoint : data_points)
{
if(dataPoint.y < value_to_temove)
dataPoint.y = 0;
else
dataPoint.y = dataPoint.y - value_to_temove;
}
return data_points;
}
pappso::FilterQuantileBasedRemoveY::FilterQuantileBasedRemoveY(
const QString &strBuildParams)
{
buildFilterFromString(strBuildParams);
}
void
pappso::FilterQuantileBasedRemoveY::buildFilterFromString(
const QString &strBuildParams)
{
//"passQuantileBasedRemoveY|0.6"
qDebug();
if(strBuildParams.startsWith("passQuantileBasedRemoveY|"))
{
QStringList params =
strBuildParams.split("|").back().split(";", Qt::SkipEmptyParts);
QString value = params.at(0);
m_quantile = value.toDouble();
}
else
{
throw pappso::ExceptionNotRecognized(
QString(
"building passQuantileBasedRemoveY from string %1 is not possible")
.arg(strBuildParams));
}
qDebug();
}
QString
pappso::FilterQuantileBasedRemoveY::name() const
{
return "passQuantileBasedRemoveY";
}
QString
pappso::FilterQuantileBasedRemoveY::toString() const
{
QString strCode = QString("%1|%2").arg(name()).arg(m_quantile);
return strCode;
}
pappso::ExceptionNotRecognized
excetion to use when an item type is not recognized
Definition: exceptionnotrecognized.h:42
pappso::ExceptionOutOfRange
Definition: exceptionoutofrange.h:32
pappso::FilterFloorY
apply std::floor (round to lowest integer) to all Y values
Definition: filterpass.h:166
pappso::FilterFloorY::operator=
FilterFloorY & operator=(const FilterFloorY &other)
Definition: filterpass.cpp:320
pappso::FilterFloorY::filter
Trace & filter(Trace &data_points) const override
Definition: filterpass.cpp:327
pappso::FilterFloorY::FilterFloorY
FilterFloorY()
Definition: filterpass.cpp:312
pappso::FilterGreatestY
keep N datapoints form the greatest intensities to the lowest
Definition: filterpass.h:96
pappso::FilterGreatestY::filter
Trace & filter(Trace &data_points) const override
Definition: filterpass.cpp:166
pappso::FilterGreatestY::FilterGreatestY
FilterGreatestY(std::size_t number_of_points=0)
constructor with the number of datapoints to keep
Definition: filterpass.cpp:144
pappso::FilterGreatestY::operator=
FilterGreatestY & operator=(const FilterGreatestY &other)
Definition: filterpass.cpp:157
pappso::FilterGreatestY::getNumberOfPoints
std::size_t getNumberOfPoints() const
Definition: filterpass.cpp:191
pappso::FilterGreatestY::m_numberOfPoints
std::size_t m_numberOfPoints
Definition: filterpass.h:114
pappso::FilterGreatestYperWindow
keep N datapoints form the greatest intensities to the lowest within a mass range in dalton
Definition: filterpass.h:122
pappso::FilterGreatestYperWindow::filter
Trace & filter(Trace &data_points) const override
Definition: filterpass.cpp:233
pappso::FilterGreatestYperWindow::m_numberOfPoints
std::size_t m_numberOfPoints
Definition: filterpass.h:143
pappso::FilterGreatestYperWindow::FilterGreatestYperWindow
FilterGreatestYperWindow(double window_range, std::size_t number_of_points_per_window)
constructor with the number of datapoints to keep
Definition: filterpass.cpp:197
pappso::FilterGreatestYperWindow::operator=
FilterGreatestYperWindow & operator=(const FilterGreatestYperWindow &other)
Definition: filterpass.cpp:222
pappso::FilterGreatestYperWindow::m_xWindowRange
double m_xWindowRange
Definition: filterpass.h:142
pappso::FilterGreatestYperWindow::getNumberOfPoints
std::size_t getNumberOfPoints() const
Definition: filterpass.cpp:306
pappso::FilterHighPassPercentage
remove datapoints below a given intensity percentage (ratio) of the maximum intensity
Definition: filterpass.h:76
pappso::FilterHighPassPercentage::FilterHighPassPercentage
FilterHighPassPercentage(double y_ratio)
Definition: filterpass.cpp:104
pappso::FilterHighPassPercentage::filter
Trace & filter(Trace &data_points) const override
Definition: filterpass.cpp:125
pappso::FilterHighPassPercentage::m_ratioPassY
double m_ratioPassY
Definition: filterpass.h:89
pappso::FilterHighPassPercentage::operator=
FilterHighPassPercentage & operator=(const FilterHighPassPercentage &other)
Definition: filterpass.cpp:116
pappso::FilterHighPass
remove datapoints below a given Y value (intensity)
Definition: filterpass.h:58
pappso::FilterHighPass::filter
Trace & filter(Trace &data_points) const override
Definition: filterpass.cpp:89
pappso::FilterHighPass::m_passY
double m_passY
Definition: filterpass.h:60
pappso::FilterHighPass::operator=
FilterHighPass & operator=(const FilterHighPass &other)
Definition: filterpass.cpp:80
pappso::FilterHighPass::FilterHighPass
FilterHighPass(double pass_y)
Definition: filterpass.cpp:71
pappso::FilterLowPass
remove datapoints higher than a given Y value (intensity)
Definition: filterpass.h:41
pappso::FilterLowPass::FilterLowPass
FilterLowPass(double pass_y)
Definition: filterpass.cpp:39
pappso::FilterLowPass::filter
Trace & filter(Trace &data_points) const override
Definition: filterpass.cpp:57
pappso::FilterLowPass::operator=
FilterLowPass & operator=(const FilterLowPass &other)
Definition: filterpass.cpp:48
pappso::FilterLowPass::m_passY
double m_passY
Definition: filterpass.h:43
pappso::FilterQuantileBasedRemoveY
removes a value found by quantile to all Y values
Definition: filterpass.h:258
pappso::FilterQuantileBasedRemoveY::getQuantileThreshold
double getQuantileThreshold() const
Definition: filterpass.cpp:520
pappso::FilterQuantileBasedRemoveY::operator=
FilterQuantileBasedRemoveY & operator=(const FilterQuantileBasedRemoveY &other)
Definition: filterpass.cpp:513
pappso::FilterQuantileBasedRemoveY::FilterQuantileBasedRemoveY
FilterQuantileBasedRemoveY(double quantile_threshold)
Definition: filterpass.cpp:501
pappso::FilterQuantileBasedRemoveY::buildFilterFromString
void buildFilterFromString(const QString &strBuildParams) override
build this filter using a string
Definition: filterpass.cpp:551
pappso::FilterQuantileBasedRemoveY::filter
Trace & filter(Trace &data_points) const override
Definition: filterpass.cpp:526
pappso::FilterQuantileBasedRemoveY::toString
QString toString() const override
Definition: filterpass.cpp:583
pappso::FilterQuantileBasedRemoveY::name
virtual QString name() const override
Definition: filterpass.cpp:576
pappso::FilterQuantileBasedRemoveY::m_quantile
double m_quantile
Definition: filterpass.h:285
pappso::FilterRemoveY
removes a value to all Y values
Definition: filterpass.h:235
pappso::FilterRemoveY::FilterRemoveY
FilterRemoveY(double valueToRemove)
Definition: filterpass.cpp:464
pappso::FilterRemoveY::getValue
double getValue() const
Definition: filterpass.cpp:482
pappso::FilterRemoveY::filter
Trace & filter(Trace &data_points) const override
Definition: filterpass.cpp:488
pappso::FilterRemoveY::operator=
FilterRemoveY & operator=(const FilterRemoveY &other)
Definition: filterpass.cpp:475
pappso::FilterRemoveY::m_valueToRemove
double m_valueToRemove
Definition: filterpass.h:237
pappso::FilterRescaleY
rescales Y values into a dynamic range if the dynamic range is set to 0, this filter is ignored
Definition: filterpass.h:196
pappso::FilterRescaleY::filter
Trace & filter(Trace &data_points) const override
Definition: filterpass.cpp:369
pappso::FilterRescaleY::FilterRescaleY
FilterRescaleY(double dynamic)
Definition: filterpass.cpp:361
pappso::FilterRescaleY::getDynamicRange
double getDynamicRange() const
Definition: filterpass.cpp:394
pappso::FilterRescaleY::m_dynamic
double m_dynamic
Definition: filterpass.h:198
pappso::FilterRescaleY::operator=
FilterRescaleY & operator=(const FilterRescaleY &other)
Definition: filterpass.cpp:385
pappso::FilterRoundY
apply std::round (round to nearest integer) to all Y values
Definition: filterpass.h:181
pappso::FilterRoundY::filter
Trace & filter(Trace &data_points) const override
Definition: filterpass.cpp:351
pappso::FilterRoundY::operator=
FilterRoundY & operator=(const FilterRoundY &other)
Definition: filterpass.cpp:345
pappso::FilterRoundY::FilterRoundY
FilterRoundY()
Definition: filterpass.cpp:337
pappso::FilterScaleFactorY
rescales Y values given a tranformation factor
Definition: filterpass.h:215
pappso::FilterScaleFactorY::operator=
FilterScaleFactorY & operator=(const FilterScaleFactorY &other)
Definition: filterpass.cpp:439
pappso::FilterScaleFactorY::FilterScaleFactorY
FilterScaleFactorY(double m_factor)
Definition: filterpass.cpp:430
pappso::FilterScaleFactorY::m_factor
double m_factor
Definition: filterpass.h:217
pappso::FilterScaleFactorY::filter
Trace & filter(Trace &data_points) const override
Definition: filterpass.cpp:448
pappso::FilterScaleFactorY::getScaleFactorY
double getScaleFactorY() const
Definition: filterpass.cpp:459
pappso::MassSpectrumFilterGreatestItensities
Definition: filterpass.h:148
pappso::MassSpectrumFilterGreatestItensities::MassSpectrumFilterGreatestItensities
MassSpectrumFilterGreatestItensities(std::size_t number_of_points=0)
Definition: filterpass.cpp:400
pappso::MassSpectrumFilterGreatestItensities::m_filterGreatestY
FilterGreatestY m_filterGreatestY
Definition: filterpass.h:150
pappso::MassSpectrumFilterGreatestItensities::filter
MassSpectrum & filter(MassSpectrum &spectrum) const override
Definition: filterpass.cpp:423
pappso::MassSpectrumFilterGreatestItensities::operator=
MassSpectrumFilterGreatestItensities & operator=(const MassSpectrumFilterGreatestItensities &other)
Definition: filterpass.cpp:413
pappso::MassSpectrum
Class to represent a mass spectrum.
Definition: massspectrum.h:71
pappso::Trace
A simple container of DataPoint instances.
Definition: trace.h:148
pappso::Trace::sortX
void sortX()
Definition: trace.cpp:905
filterpass.h
pappso
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition: aa.cpp:39
pappso::maxYDataPoint
std::vector< DataPoint >::const_iterator maxYDataPoint(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end)
Definition: trace.cpp:139
pappso::PeptideIonNter::a
@ a
pappso::PeptideIonNter::b
@ b
pappso::minYDataPoint
std::vector< DataPoint >::const_iterator minYDataPoint(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end)
Definition: trace.cpp:117
pappso::quantileYTrace
double quantileYTrace(std::vector< DataPoint >::const_iterator begin, std::vector< DataPoint >::const_iterator end, double quantile)
calculate the quantile of y value of a trace
Definition: trace.cpp:224
pappso::DataPoint
Definition: datapoint.h:21