79 template <
typename Container = MSSpectrum>
105 this->
setName(
"SignalToNoiseEstimatorMedian");
107 defaults_.
setValue(
"max_intensity", -1,
"maximal intensity considered for histogram construction. By default, it will be calculated automatically (see auto_mode)." \
108 " Only provide this parameter if you know what you are doing (and change 'auto_mode' to '-1')!" \
109 " All intensities EQUAL/ABOVE 'max_intensity' will be added to the LAST histogram bin." \
110 " If you choose 'max_intensity' too small, the noise estimate might be too small as well. " \
111 " If chosen too big, the bins become quite large (which you could counter by increasing 'bin_count', which increases runtime)." \
112 " In general, the Median-S/N estimator is more robust to a manual max_intensity than the MeanIterative-S/N.", ListUtils::create<String>(
"advanced"));
115 defaults_.
setValue(
"auto_max_stdev_factor", 3.0,
"parameter for 'max_intensity' estimation (if 'auto_mode' == 0): mean + 'auto_max_stdev_factor' * stdev", ListUtils::create<String>(
"advanced"));
119 defaults_.
setValue(
"auto_max_percentile", 95,
"parameter for 'max_intensity' estimation (if 'auto_mode' == 1): auto_max_percentile th percentile", ListUtils::create<String>(
"advanced"));
123 defaults_.
setValue(
"auto_mode", 0,
"method to use to determine maximal intensity: -1 --> use 'max_intensity'; 0 --> 'auto_max_stdev_factor' method (default); 1 --> 'auto_max_percentile' method", ListUtils::create<String>(
"advanced"));
133 defaults_.
setValue(
"min_required_elements", 10,
"minimum number of elements required in a window (otherwise it is considered sparse)");
136 defaults_.
setValue(
"noise_for_empty_window", std::pow(10.0, 20),
"noise value used for sparse windows", ListUtils::create<String>(
"advanced"));
138 defaults_.
setValue(
"write_log_messages",
"true",
"Write out log messages in case of sparse windows or median in rightmost histogram bin");
157 if (&source ==
this)
return *
this;
217 OPENMS_PRETTY_FUNCTION,
218 "auto_mode is on AUTOMAXBYPERCENT! auto_max_percentile is not in [0,100]. Use setAutoMaxPercentile(<value>) to change it!",
222 std::vector<int> histogram_auto(100, 0);
228 while (run != scan_last_)
230 maxInt = std::max(maxInt, (*run).getIntensity());
235 double bin_size = maxInt / 100;
239 while (run != scan_last_)
241 ++histogram_auto[(int) (((*run).getIntensity() - 1) / bin_size)];
247 int elements_seen = 0;
251 while (run != scan_last_ && elements_seen < elements_below_percentile)
254 elements_seen += histogram_auto[i];
267 OPENMS_PRETTY_FUNCTION,
268 "auto_mode is on MANUAL! max_intensity is <=0. Needs to be positive! Use setMaxIntensity(<value>) or enable auto_mode!",
275 std::cerr <<
"TODO SignalToNoiseEstimatorMedian: the max_intensity_ value should be positive! " <<
max_intensity_ << std::endl;
283 double window_half_size =
win_len_ / 2;
293 bin_value[bin] = (bin + 0.5) * bin_size;
301 int element_inc_count = 0;
304 int elements_in_window = 0;
306 int window_count = 0;
309 int element_in_window_half = 0;
314 int windows_overall = 0;
316 while (run != scan_last_)
324 while (window_pos_center != scan_last_)
328 while ((*window_pos_borderleft).getMZ() < (*window_pos_center).getMZ() - window_half_size)
330 to_bin = std::max(std::min<int>((
int)((*window_pos_borderleft).getIntensity() / bin_size), bin_count_minus_1), 0);
332 --elements_in_window;
333 ++window_pos_borderleft;
337 while ((window_pos_borderright != scan_last_)
338 && ((*window_pos_borderright).getMZ() <= (*window_pos_center).getMZ() + window_half_size))
341 to_bin = std::max(std::min<int>((
int)((*window_pos_borderright).getIntensity() / bin_size), bin_count_minus_1), 0);
343 ++elements_in_window;
344 ++window_pos_borderright;
356 element_inc_count = 0;
357 element_in_window_half = (elements_in_window + 1) / 2;
358 while (median_bin < bin_count_minus_1 && element_inc_count < element_in_window_half)
361 element_inc_count += histogram[median_bin];
368 noise = std::max(1.0, bin_value[median_bin]);
372 stn_estimates_[*window_pos_center] = (*window_pos_center).getIntensity() / noise;
391 LOG_WARN <<
"WARNING in SignalToNoiseEstimatorMedian: " 393 <<
"% of all windows were sparse. You should consider increasing 'win_len' or decreasing 'min_required_elements'" 400 LOG_WARN <<
"WARNING in SignalToNoiseEstimatorMedian: " 402 <<
"% of all Signal-to-Noise estimates are too high, because the median was found in the rightmost histogram-bin. " 403 <<
"You should consider increasing 'max_intensity' (and maybe 'bin_count' with it, to keep bin width reasonable)" int min_required_elements_
minimal number of elements a window needs to cover to be used
Definition: SignalToNoiseEstimatorMedian.h:437
void setMaxFloat(const String &key, double max)
Sets the maximum value for the floating point or floating point list parameter key.
double auto_max_percentile_
parameter for initial automatic estimation of "max_intensity_" percentile or a stdev ...
Definition: SignalToNoiseEstimatorMedian.h:429
#define LOG_WARN
Macro if a warning, a piece of information which should be read by the user, should be logged...
Definition: LogStream.h:452
const DataValue & getValue(const String &key) const
Returns a value of a parameter.
double noise_for_empty_window_
Definition: SignalToNoiseEstimatorMedian.h:440
bool write_log_messages_
Definition: SignalToNoiseEstimatorMedian.h:443
void setProgress(SignedSize value) const
Sets the current progress.
void setMinFloat(const String &key, double min)
Sets the minimum value for the floating point or floating point list parameter key.
int auto_mode_
determines which method shall be used for estimating "max_intensity_". valid are MANUAL=-1, AUTOMAXBYSTDEV=0 or AUTOMAXBYPERCENT=1
Definition: SignalToNoiseEstimatorMedian.h:431
protected struct to store parameters my, sigma for a Gaussian distribution
Definition: SignalToNoiseEstimator.h:166
Definition: SignalToNoiseEstimatorMedian.h:87
PeakIterator::value_type PeakType
Definition: SignalToNoiseEstimator.h:65
SignalToNoiseEstimatorMedian()
default constructor
Definition: SignalToNoiseEstimatorMedian.h:102
Param defaults_
Container for default parameters. This member should be filled in the constructor of derived classes!...
Definition: DefaultParamHandler.h:156
bool is_result_valid_
flag: set to true if SignalToNoise estimates are calculated and none of the params were changed...
Definition: SignalToNoiseEstimator.h:214
void setName(const String &name)
Mutable access to the name.
A more convenient string class.
Definition: String.h:58
void setValue(const String &key, const DataValue &value, const String &description="", const StringList &tags=StringList())
Sets a value.
Estimates the signal/noise (S/N) ratio of each data point in a scan by using the median (histogram ba...
Definition: SignalToNoiseEstimatorMedian.h:80
This class represents the abstract base class of a signal to noise estimator.
Definition: SignalToNoiseEstimator.h:56
SignalToNoiseEstimator< Container >::PeakType PeakType
Definition: SignalToNoiseEstimatorMedian.h:97
Param param_
Container for current parameters.
Definition: DefaultParamHandler.h:149
double histogram_oob_percent_
Definition: SignalToNoiseEstimatorMedian.h:448
int bin_count_
number of bins in the histogram
Definition: SignalToNoiseEstimatorMedian.h:435
SignalToNoiseEstimatorMedian & operator=(const SignalToNoiseEstimatorMedian &source)
Definition: SignalToNoiseEstimatorMedian.h:155
SignalToNoiseEstimator & operator=(const SignalToNoiseEstimator &source)
Assignment operator.
Definition: SignalToNoiseEstimator.h:91
Definition: SignalToNoiseEstimatorMedian.h:87
Container::const_iterator PeakIterator
Definition: SignalToNoiseEstimator.h:64
void updateMembers_() override
overridden function from DefaultParamHandler to keep members up to date, when a parameter is changed ...
Definition: SignalToNoiseEstimatorMedian.h:410
SignalToNoiseEstimator< Container >::PeakIterator PeakIterator
Definition: SignalToNoiseEstimatorMedian.h:96
bool toBool() const
Conversion to bool.
double auto_max_stdev_Factor_
parameter for initial automatic estimation of "max_intensity_": a stdev multiplier ...
Definition: SignalToNoiseEstimatorMedian.h:427
SignalToNoiseEstimator< Container >::GaussianEstimate GaussianEstimate
Definition: SignalToNoiseEstimatorMedian.h:99
double getHistogramRightmostPercent() const
Returns the percentage where the median was found in the rightmost bin.
Definition: SignalToNoiseEstimatorMedian.h:177
void setMinInt(const String &key, Int min)
Sets the minimum value for the integer or integer list parameter key.
void setValidStrings(const String &key, const std::vector< String > &strings)
Sets the valid strings for the parameter key.
void startProgress(SignedSize begin, SignedSize end, const String &label) const
Initializes the progress display.
double sparse_window_percent_
Definition: SignalToNoiseEstimatorMedian.h:446
~SignalToNoiseEstimatorMedian() override
Destructor.
Definition: SignalToNoiseEstimatorMedian.h:167
void computeSTN_(const PeakIterator &scan_first_, const PeakIterator &scan_last_) override
Definition: SignalToNoiseEstimatorMedian.h:191
SignalToNoiseEstimatorMedian(const SignalToNoiseEstimatorMedian &source)
Copy Constructor.
Definition: SignalToNoiseEstimatorMedian.h:145
std::map< PeakType, double, typename PeakType::PositionLess > stn_estimates_
stores the noise estimate for each peak
Definition: SignalToNoiseEstimator.h:207
double getSparseWindowPercent() const
Returns how many percent of the windows were sparse.
Definition: SignalToNoiseEstimatorMedian.h:171
Definition: SignalToNoiseEstimatorMedian.h:87
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
void setMaxInt(const String &key, Int max)
Sets the maximum value for the integer or integer list parameter key.
IntensityThresholdCalculation
method to use for estimating the maximal intensity that is used for histogram calculation ...
Definition: SignalToNoiseEstimatorMedian.h:87
GaussianEstimate estimate_(const PeakIterator &scan_first_, const PeakIterator &scan_last_) const
calculate mean & stdev of intensities of a spectrum
Definition: SignalToNoiseEstimator.h:174
double max_intensity_
maximal intensity considered during binning (values above get discarded)
Definition: SignalToNoiseEstimatorMedian.h:425
double win_len_
range of data points which belong to a window in Thomson
Definition: SignalToNoiseEstimatorMedian.h:433
Invalid value exception.
Definition: Exception.h:335
void defaultsToParam_()
Updates the parameters after the defaults have been set in the constructor.
void endProgress() const
Ends the progress display.