Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,12 @@ namespace OpenMS
if (std::fabs(prev->getMZ() - RT) < std::fabs(iter->getMZ() - RT) )
{
// prev is closer to the apex
return sn_.getSignalToNoise(*prev);
return sn_.getSignalToNoise((Size) distance(chromatogram_.begin(),prev));
}
else
{
// iter is closer to the apex
return sn_.getSignalToNoise(*iter);
return sn_.getSignalToNoise((Size) distance(chromatogram_.begin(),iter));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,15 @@ namespace OpenMS
/// Constructor
inline SignalToNoiseEstimator() :
DefaultParamHandler("SignalToNoiseEstimator"),
ProgressLogger(),
first_(),
last_(),
is_result_valid_(false)
ProgressLogger()
{
}

/// Copy constructor
inline SignalToNoiseEstimator(const SignalToNoiseEstimator & source) :
DefaultParamHandler(source),
ProgressLogger(source),
stn_estimates_(source.stn_estimates_),
first_(source.first_),
last_(source.last_),
is_result_valid_(source.is_result_valid_)
stn_estimates_(source.stn_estimates_)
{}

/// Assignment operator
Expand All @@ -95,56 +89,26 @@ namespace OpenMS
DefaultParamHandler::operator=(source);
ProgressLogger::operator=(source);
stn_estimates_ = source.stn_estimates_;
first_ = source.first_;
last_ = source.last_;
return *this;
}

/// Destructor
~SignalToNoiseEstimator() override
{}


/// Set the start and endpoint of the raw data interval, for which signal to noise ratios will be estimated immediately
virtual void init(const PeakIterator & it_begin, const PeakIterator & it_end)
{
first_ = it_begin;
last_ = it_end;
computeSTN_(first_, last_);
is_result_valid_ = true;
}

/// Set the start and endpoint of the raw data interval, for which signal to noise ratios will be estimated immediately
virtual void init(const Container & c)
{
init(c.begin(), c.end());
}

/// Return to signal/noise estimate for data point @p data_point
/// @note the first query to this function will take longer, as
/// all SignalToNoise values are calculated
/// @note you will get a warning to stderr if more than 20% of the
/// noise estimates used sparse windows
virtual double getSignalToNoise(const PeakIterator & data_point)
virtual void init(const Container& c)
{
if (!is_result_valid_)
{
// recompute ...
init(first_, last_);
}

return stn_estimates_[*data_point];
computeSTN_(c);
}

virtual double getSignalToNoise(const PeakType & data_point)
///Return to signal/noise estimate for date point @p index
///@note you will get a warning to stderr if more than 20% of the
/// noise estimates used sparse windows
virtual double getSignalToNoise(const Size index)
{
if (!is_result_valid_)
{
// recompute ...
init(first_, last_);
}

return stn_estimates_[data_point];
OPENMS_POSTCONDITION(index < stn_estimates_.size(),"SignalToNoiseEstimator estimates beyond container size was requested.");
return stn_estimates_[index];
}

protected:
Expand All @@ -154,7 +118,7 @@ namespace OpenMS
*
* @exception Throws Exception::InvalidValue
*/
virtual void computeSTN_(const PeakIterator & scan_first_, const PeakIterator & scan_last_) = 0;
virtual void computeSTN_(const Container& c) = 0;



Expand Down Expand Up @@ -204,14 +168,7 @@ namespace OpenMS
//MEMBERS:

/// stores the noise estimate for each peak
std::map<PeakType, double, typename PeakType::PositionLess> stn_estimates_;

/// points to the first raw data point in the interval
PeakIterator first_;
/// points to the right position next to the last raw data point in the interval
PeakIterator last_;
/// flag: set to true if SignalToNoise estimates are calculated and none of the params were changed. otherwise false.
mutable bool is_result_valid_;
std::vector<double> stn_estimates_;
};

} // namespace OpenMS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include <OpenMS/CONCEPT/Exception.h>
#include <OpenMS/DATASTRUCTURES/ListUtils.h>
#include <vector>
#include <algorithm> //for std::max_element

namespace OpenMS
{
Expand Down Expand Up @@ -76,9 +77,6 @@ namespace OpenMS
enum IntensityThresholdCalculation {MANUAL = -1, AUTOMAXBYSTDEV = 0, AUTOMAXBYPERCENT = 1};

using SignalToNoiseEstimator<Container>::stn_estimates_;
using SignalToNoiseEstimator<Container>::first_;
using SignalToNoiseEstimator<Container>::last_;
using SignalToNoiseEstimator<Container>::is_result_valid_;
using SignalToNoiseEstimator<Container>::defaults_;
using SignalToNoiseEstimator<Container>::param_;

Expand Down Expand Up @@ -164,17 +162,22 @@ namespace OpenMS


/** calculate StN values for all datapoints given, by using a sliding window approach
@param scan_first_ first element in the scan
@param scan_last_ last element in the scan (disregarded)
@param c raw data
@exception Throws Exception::InvalidValue
*/
void computeSTN_(const PeakIterator & scan_first_, const PeakIterator & scan_last_) override
void computeSTN_(const Container& c) override
{
//first element in the scan
PeakIterator scan_first_ = c.begin();
//last element in the scan
PeakIterator scan_last_ = c.end();

// reset counter for sparse windows
double sparse_window_percent = 0;

// reset the results
stn_estimates_.clear();
stn_estimates_.resize(c.size());

// maximal range of histogram needs to be calculated first
if (auto_mode_ == AUTOMAXBYSTDEV)
Expand All @@ -200,28 +203,21 @@ namespace OpenMS
std::vector<int> histogram_auto(100, 0);

// find maximum of current scan
int size = 0;
typename PeakType::IntensityType maxInt = 0;
PeakIterator run = scan_first_;
while (run != scan_last_)
{
maxInt = std::max(maxInt, (*run).getIntensity());
++size;
++run;
}
auto maxIt = std::max_element(c.begin(), c.end() ,[](const PeakType& a, const PeakType& b){ return a.getIntensity() > b.getIntensity();});
typename PeakType::IntensityType maxInt = maxIt->getIntensity();

double bin_size = maxInt / 100;

// fill histogram
run = scan_first_;
PeakIterator run = scan_first_;
while (run != scan_last_)
{
++histogram_auto[(int) (((*run).getIntensity() - 1) / bin_size)];
++run;
}

// add up element counts in histogram until ?th percentile is reached
int elements_below_percentile = (int) (auto_max_percentile_ * size / 100);
int elements_below_percentile = (int) (auto_max_percentile_ * c.size() / 100);
int elements_seen = 0;
int i = -1;
run = scan_first_;
Expand Down Expand Up @@ -283,15 +279,8 @@ namespace OpenMS

double noise; // noise value of a datapoint

// determine how many elements we need to estimate (for progress estimation)
int windows_overall = 0;
PeakIterator run = scan_first_;
while (run != scan_last_)
{
++windows_overall;
++run;
}
SignalToNoiseEstimator<Container>::startProgress(0, windows_overall, "noise estimation of data");
///start progress estimation
SignalToNoiseEstimator<Container>::startProgress(0, c.size(), "noise estimation of data");

// MAIN LOOP
while (window_pos_center != scan_last_)
Expand Down Expand Up @@ -370,7 +359,7 @@ namespace OpenMS
}

// store result
stn_estimates_[*window_pos_center] = (*window_pos_center).getIntensity() / noise;
stn_estimates_[window_count] = (*window_pos_center).getIntensity() / noise;



Expand Down Expand Up @@ -412,7 +401,7 @@ namespace OpenMS
stdev_ = (double)param_.getValue("stdev_mp");
min_required_elements_ = param_.getValue("min_required_elements");
noise_for_empty_window_ = (double)param_.getValue("noise_for_empty_window");
is_result_valid_ = false;
stn_estimates_.clear();
}

/// maximal intensity considered during binning (values above get discarded)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include <OpenMS/CONCEPT/Exception.h>
#include <OpenMS/DATASTRUCTURES/ListUtils.h>
#include <vector>
#include <algorithm> //for std::max_element

namespace OpenMS
{
Expand Down Expand Up @@ -87,9 +88,6 @@ namespace OpenMS
enum IntensityThresholdCalculation {MANUAL = -1, AUTOMAXBYSTDEV = 0, AUTOMAXBYPERCENT = 1};

using SignalToNoiseEstimator<Container>::stn_estimates_;
using SignalToNoiseEstimator<Container>::first_;
using SignalToNoiseEstimator<Container>::last_;
using SignalToNoiseEstimator<Container>::is_result_valid_;
using SignalToNoiseEstimator<Container>::defaults_;
using SignalToNoiseEstimator<Container>::param_;

Expand Down Expand Up @@ -184,19 +182,24 @@ namespace OpenMS

/** Calculate signal-to-noise values for all data points given, by using a sliding window approach

@param scan_first_ first element in the scan
@param scan_last_ last element in the scan (disregarded)
@param c raw data
@exception Throws Exception::InvalidValue
*/
void computeSTN_(const PeakIterator & scan_first_, const PeakIterator & scan_last_) override
void computeSTN_(const Container& c) override
{
//first element in the scan
PeakIterator scan_first_ = c.begin();
//last element in the scan
PeakIterator scan_last_ = c.end();

// reset counter for sparse windows
sparse_window_percent_ = 0;
// reset counter for histogram overflow
histogram_oob_percent_ = 0;

// reset the results
stn_estimates_.clear();
stn_estimates_.resize(c.size());

// maximal range of histogram needs to be calculated first
if (auto_mode_ == AUTOMAXBYSTDEV)
Expand All @@ -222,28 +225,21 @@ namespace OpenMS
std::vector<int> histogram_auto(100, 0);

// find maximum of current scan
int size = 0;
typename PeakType::IntensityType maxInt = 0;
PeakIterator run = scan_first_;
while (run != scan_last_)
{
maxInt = std::max(maxInt, (*run).getIntensity());
++size;
++run;
}
auto maxIt = std::max_element(c.begin(), c.end() ,[](const PeakType& a, const PeakType& b){ return a.getIntensity() > b.getIntensity();});
typename PeakType::IntensityType maxInt = maxIt->getIntensity();

double bin_size = maxInt / 100;

// fill histogram
run = scan_first_;
PeakIterator run = scan_first_;
while (run != scan_last_)
{
++histogram_auto[(int) (((*run).getIntensity() - 1) / bin_size)];
++run;
}

// add up element counts in histogram until ?th percentile is reached
int elements_below_percentile = (int) (auto_max_percentile_ * size / 100);
int elements_below_percentile = (int) (auto_max_percentile_ * c.size() / 100);
int elements_seen = 0;
int i = -1;
run = scan_first_;
Expand Down Expand Up @@ -310,15 +306,8 @@ namespace OpenMS

double noise; // noise value of a datapoint

// determine how many elements we need to estimate (for progress estimation)
int windows_overall = 0;
PeakIterator run = scan_first_;
while (run != scan_last_)
{
++windows_overall;
++run;
}
SignalToNoiseEstimator<Container>::startProgress(0, windows_overall, "noise estimation of data");
///start progress estimation
SignalToNoiseEstimator<Container>::startProgress(0, c.size(), "noise estimation of data");

// MAIN LOOP
while (window_pos_center != scan_last_)
Expand Down Expand Up @@ -369,7 +358,7 @@ namespace OpenMS
}

// store result
stn_estimates_[*window_pos_center] = (*window_pos_center).getIntensity() / noise;
stn_estimates_[window_count] = (*window_pos_center).getIntensity() / noise;


// advance the window center by one datapoint
Expand Down Expand Up @@ -418,7 +407,7 @@ namespace OpenMS
min_required_elements_ = param_.getValue("min_required_elements");
noise_for_empty_window_ = (double)param_.getValue("noise_for_empty_window");
write_log_messages_ = (bool)param_.getValue("write_log_messages").toBool();
is_result_valid_ = false;
stn_estimates_.clear();
}

/// maximal intensity considered during binning (values above get discarded)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ namespace OpenMS
{
if (signal_to_noise_ > 0.0)
{
if (snt.getSignalToNoise(input[i - k]) < signal_to_noise_)
if (snt.getSignalToNoise(i - k) < signal_to_noise_)
{
break;
}
Expand All @@ -229,7 +229,7 @@ namespace OpenMS
{
if (signal_to_noise_ > 0.0)
{
if (snt.getSignalToNoise(input[i + k]) < signal_to_noise_)
if (snt.getSignalToNoise(i + k) < signal_to_noise_)
{
break;
}
Expand Down
4 changes: 2 additions & 2 deletions src/openms/source/ANALYSIS/OPENSWATH/PeakPickerMRM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ namespace OpenMS
//&& std::fabs(chromatogram[min_i-k].getMZ() - peak_raw_data.begin()->first) < spacing_difference*min_spacing
&& (chromatogram[min_i - k].getIntensity() < chromatogram[min_i - k + 1].getIntensity()
|| (peak_width_ > 0.0 && std::fabs(chromatogram[min_i - k].getRT() - central_peak_rt) < peak_width_))
&& (signal_to_noise_ <= 0.0 || snt_.getSignalToNoise(chromatogram[min_i - k]) >= signal_to_noise_))
&& (signal_to_noise_ <= 0.0 || snt_.getSignalToNoise(min_i - k) >= signal_to_noise_))
{
++k;
}
Expand All @@ -210,7 +210,7 @@ namespace OpenMS
//&& std::fabs(chromatogram[min_i+k].getMZ() - peak_raw_data.rbegin()->first) < spacing_difference*min_spacing
&& (chromatogram[min_i + k].getIntensity() < chromatogram[min_i + k - 1].getIntensity()
|| (peak_width_ > 0.0 && std::fabs(chromatogram[min_i + k].getRT() - central_peak_rt) < peak_width_))
&& (signal_to_noise_ <= 0.0 || snt_.getSignalToNoise(chromatogram[min_i + k]) >= signal_to_noise_) )
&& (signal_to_noise_ <= 0.0 || snt_.getSignalToNoise(min_i + k) >= signal_to_noise_) )
{
++k;
}
Expand Down
Loading