Loading...
Searching...
No Matches
localsignaltonoiseestimator.h
Go to the documentation of this file.
// Copyright 2026 Filippo Rusconi
// Largely inspired by code in OpenMS, by Chris Bielow
#pragma once
/////////////////////// stdlib includes
/////////////////////// Qt includes
#include <QList>
#include <QMap>
/////////////////////// pappsomspp includes
#include "pappsomspp/core/trace/trace.h"
/////////////////////// Local includes
#include "pappsomspp/export-import-config.h"
namespace pappso
{
using TraceIterator = std::vector<DataPoint>::const_iterator;
class PMSPP_LIB_DECL LocalSignalToNoiseEstimator
{
public:
// We will need that in the Parameters below.
enum IntensityThresholdCalculation
{
MANUAL_BY_VALUE = 0x0,
AUTO_MAX_BY_STDEV,
AUTO_MAX_BY_PERCENTILE
};
struct Parameters
{
// Maximal intensity considered during binning (values above get discarded)
// This ensures that absurdly-intense peaks are not used to compute the
// stats about the maximum intensity of the trace.
double maxIntensity = -1;
// parameter for initial automatic estimation of "max_intensity_": a stdev
// multiplier
double maxIntStdDevFactor = 3;
// parameter for initial automatic estimation of "max_intensity_" percentile
// or a stde
double maxIntPercentile = 95;
// Which method is used for estimating m_maxIntensity "max intensity of
// trace". valid are MANUAL, AUTOMABYSTDEV or AUTOMAXBYPERCENTILE
int maxIntMode = IntensityThresholdCalculation::AUTO_MAX_BY_STDEV;
// range of data points which belong to a window in Thomson
double windowSize = 200;
// number of bins in the histogram
int binCount = 30;
// minimal number of elements a window needs to cover to be used
int minRequiredElements = 10;
// used as noise value for windows which cover less than
// "min_required_elements_" use a very high value if you want to get a low
// S/N result
double noiseValueForEmptyWindow = std::pow(10.0, 20);
Parameters() {};
Parameters(double max_intensity,
double max_int_std_dev_factor,
double max_int_percentile,
int max_int_mode,
double window_size,
int bin_count,
int min_required_elements,
double noise_value_for_empty_window)
{
maxIntensity = max_intensity;
maxIntStdDevFactor = max_int_std_dev_factor;
maxIntPercentile = max_int_percentile;
maxIntMode = max_int_mode;
windowSize = window_size;
binCount = bin_count;
minRequiredElements = min_required_elements;
noiseValueForEmptyWindow = noise_value_for_empty_window;
}
Parameters(const Parameters &other)
{
maxIntensity = other.maxIntensity;
maxIntStdDevFactor = other.maxIntStdDevFactor;
maxIntPercentile = other.maxIntPercentile;
maxIntMode = other.maxIntMode;
windowSize = other.windowSize;
binCount = other.binCount;
minRequiredElements = other.minRequiredElements;
noiseValueForEmptyWindow = other.noiseValueForEmptyWindow;
}
};
explicit LocalSignalToNoiseEstimator(const Parameters &parameters);
virtual ~LocalSignalToNoiseEstimator();
struct GaussianEstimateParams
{
// mean of estimated Gaussian
double mean;
// variance of estimated Gaussian
double variance;
};
GaussianEstimateParams
estimateGaussian(const TraceIterator &iter_first_data_point,
const TraceIterator &iter_last_data_point) const;
void initialize(const Trace &trace);
void computeSignaToNoiseRatio(const Trace &trace);
double getSignalToNoiseRatio(qsizetype index) const;
protected:
Parameters m_parameters;
// counter for sparse windows
double m_sparseWindowPercentage;
// counter for histogram overflow
double m_histogramOverflowPercentage;
QList<double> m_signalToNoiseEstimates;
};
} // namespace pappso
pappso::LocalSignalToNoiseEstimator
Definition localsignaltonoiseestimator.h:26
pappso::LocalSignalToNoiseEstimator::initialize
void initialize(const Trace &trace)
Definition localsignaltonoiseestimator.cpp:65
pappso::LocalSignalToNoiseEstimator::m_histogramOverflowPercentage
double m_histogramOverflowPercentage
Definition localsignaltonoiseestimator.h:128
pappso::LocalSignalToNoiseEstimator::IntensityThresholdCalculation
IntensityThresholdCalculation
Definition localsignaltonoiseestimator.h:31
pappso::LocalSignalToNoiseEstimator::AUTO_MAX_BY_STDEV
@ AUTO_MAX_BY_STDEV
Definition localsignaltonoiseestimator.h:33
pappso::LocalSignalToNoiseEstimator::AUTO_MAX_BY_PERCENTILE
@ AUTO_MAX_BY_PERCENTILE
Definition localsignaltonoiseestimator.h:34
pappso::LocalSignalToNoiseEstimator::MANUAL_BY_VALUE
@ MANUAL_BY_VALUE
Definition localsignaltonoiseestimator.h:32
pappso::LocalSignalToNoiseEstimator::LocalSignalToNoiseEstimator
LocalSignalToNoiseEstimator(const Parameters &parameters)
Definition localsignaltonoiseestimator.cpp:21
pappso::LocalSignalToNoiseEstimator::m_signalToNoiseEstimates
QList< double > m_signalToNoiseEstimates
Definition localsignaltonoiseestimator.h:130
pappso::LocalSignalToNoiseEstimator::computeSignaToNoiseRatio
void computeSignaToNoiseRatio(const Trace &trace)
Definition localsignaltonoiseestimator.cpp:73
pappso::LocalSignalToNoiseEstimator::m_parameters
Parameters m_parameters
Definition localsignaltonoiseestimator.h:123
pappso::LocalSignalToNoiseEstimator::m_sparseWindowPercentage
double m_sparseWindowPercentage
Definition localsignaltonoiseestimator.h:126
pappso::LocalSignalToNoiseEstimator::estimateGaussian
GaussianEstimateParams estimateGaussian(const TraceIterator &iter_first_data_point, const TraceIterator &iter_last_data_point) const
Definition localsignaltonoiseestimator.cpp:32
pappso::LocalSignalToNoiseEstimator::getSignalToNoiseRatio
double getSignalToNoiseRatio(qsizetype index) const
Definition localsignaltonoiseestimator.cpp:351
pappso::Trace
A simple container of DataPoint instances.
Definition trace.h:152
export-import-config.h
PMSPP_LIB_DECL
#define PMSPP_LIB_DECL
Definition export-import-config.h:14
pappso
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39
pappso::TraceIterator
std::vector< DataPoint >::const_iterator TraceIterator
Definition localsignaltonoiseestimator.h:23
pappso::LocalSignalToNoiseEstimator::GaussianEstimateParams
Definition localsignaltonoiseestimator.h:107
pappso::LocalSignalToNoiseEstimator::GaussianEstimateParams::variance
double variance
Definition localsignaltonoiseestimator.h:111
pappso::LocalSignalToNoiseEstimator::GaussianEstimateParams::mean
double mean
Definition localsignaltonoiseestimator.h:109
pappso::LocalSignalToNoiseEstimator::Parameters
Definition localsignaltonoiseestimator.h:38
pappso::LocalSignalToNoiseEstimator::Parameters::maxIntensity
double maxIntensity
Definition localsignaltonoiseestimator.h:42
pappso::LocalSignalToNoiseEstimator::Parameters::noiseValueForEmptyWindow
double noiseValueForEmptyWindow
Definition localsignaltonoiseestimator.h:68
pappso::LocalSignalToNoiseEstimator::Parameters::maxIntStdDevFactor
double maxIntStdDevFactor
Definition localsignaltonoiseestimator.h:46
pappso::LocalSignalToNoiseEstimator::Parameters::minRequiredElements
int minRequiredElements
Definition localsignaltonoiseestimator.h:63
pappso::LocalSignalToNoiseEstimator::Parameters::maxIntPercentile
double maxIntPercentile
Definition localsignaltonoiseestimator.h:50
pappso::LocalSignalToNoiseEstimator::Parameters::windowSize
double windowSize
Definition localsignaltonoiseestimator.h:57
pappso::LocalSignalToNoiseEstimator::Parameters::Parameters
Parameters()
Definition localsignaltonoiseestimator.h:70
pappso::LocalSignalToNoiseEstimator::Parameters::Parameters
Parameters(const Parameters &other)
Definition localsignaltonoiseestimator.h:90
pappso::LocalSignalToNoiseEstimator::Parameters::maxIntMode
int maxIntMode
Definition localsignaltonoiseestimator.h:54
pappso::LocalSignalToNoiseEstimator::Parameters::binCount
int binCount
Definition localsignaltonoiseestimator.h:60
pappso::LocalSignalToNoiseEstimator::Parameters::Parameters
Parameters(double max_intensity, double max_int_std_dev_factor, double max_int_percentile, int max_int_mode, double window_size, int bin_count, int min_required_elements, double noise_value_for_empty_window)
Definition localsignaltonoiseestimator.h:71
trace.h