117 defaults_.setValue(
"signal_to_noise_", 1.0,
"Signal to noise value, each peak is required to be above this value (turn off by setting it to 0.0)");
118 defaults_.setValue(
"peak_width", 0.0,
"Expected peak width half width in Dalton - peaks will be extended until this half width is reached (even if the intensitity is increasing). In conjunction with check_width_internally it will also be used to remove peaks whose spacing is larger than this value.");
121 defaults_.setValue(
"spacing_difference", 1.5,
"Difference between peaks in multiples of the minimal difference to continue. The higher this value is set, the further apart peaks are allowed to be to still extend a peak. E.g. if the value is set to 1.5 and in a current peak the minimal spacing between peaks is 10 mDa, then only peaks at most 15 mDa apart will be added to the peak.", ListUtils::create<String>(
"advanced"));
122 defaults_.setValue(
"sn_bin_count_", 30,
"Bin count for the Signal to Noise estimation.", ListUtils::create<String>(
"advanced"));
123 defaults_.setValue(
"nr_iterations_", 5,
"Nr of iterations to perform (how many times the peaks are re-centered).", ListUtils::create<String>(
"advanced"));
124 defaults_.setMinInt(
"nr_iterations_", 1);
125 defaults_.setValue(
"sn_win_len_", 20.0,
"Window length for the Signal to Noise estimation.", ListUtils::create<String>(
"advanced"));
127 defaults_.setValue(
"check_width_internally",
"false",
"Delete peaks where the spacing is larger than the peak width (should be set to true to avoid artefacts)", ListUtils::create<String>(
"advanced"));
128 defaults_.setValidStrings(
"check_width_internally", ListUtils::create<String>(
"true,false"));
130 defaults_.setValue(
"ms1_only",
"false",
"Only do MS1");
131 defaults_.setValidStrings(
"ms1_only", ListUtils::create<String>(
"true,false"));
132 defaults_.setValue(
"clear_meta_data",
"false",
"Delete meta data about peak width");
133 defaults_.setValidStrings(
"clear_meta_data", ListUtils::create<String>(
"true,false"));
141 signal_to_noise_ = (
double)param_.getValue(
"signal_to_noise_");
142 peak_width_ = (
double)param_.getValue(
"peak_width");
143 spacing_difference_ = (
double)param_.getValue(
"spacing_difference");
144 sn_bin_count_ = (
double)param_.getValue(
"sn_bin_count_");
145 nr_iterations_ = (
double)param_.getValue(
"nr_iterations_");
146 sn_win_len_ = (
double)param_.getValue(
"sn_win_len_");
148 check_width_internally_ = param_.getValue(
"check_width_internally").toBool();
168 std::vector<PeakCandidate>& PeakCandidates,
171 for (
Size peak_it = 0; peak_it < PeakCandidates.size(); peak_it++)
173 int i = PeakCandidates[peak_it].index;
174 double central_peak_mz = input[i].getMZ(), central_peak_int = input[i].getIntensity();
175 double left_neighbor_mz = input[i - 1].getMZ(), left_neighbor_int = input[i - 1].getIntensity();
176 double right_neighbor_mz = input[i + 1].getMZ(), right_neighbor_int = input[i + 1].getIntensity();
179 double left_to_central = std::fabs(central_peak_mz - left_neighbor_mz);
180 double central_to_right = std::fabs(right_neighbor_mz - central_peak_mz);
181 double min_spacing = (left_to_central < central_to_right) ? left_to_central : central_to_right;
182 double est_peak_width = peak_width_;
184 if (check_width_internally_ && (left_to_central > est_peak_width || central_to_right > est_peak_width))
187 PeakCandidates[peak_it].integrated_intensity = -1;
188 PeakCandidates[peak_it].leftWidth = -1;
189 PeakCandidates[peak_it].rightWidth = -1;
190 PeakCandidates[peak_it].mz = -1;
194 std::map<double, double> peak_raw_data;
196 peak_raw_data[central_peak_mz] = central_peak_int;
197 peak_raw_data[left_neighbor_mz] = left_neighbor_int;
198 peak_raw_data[right_neighbor_mz] = right_neighbor_int;
204 while ((i -
k + 1) > 0
205 && std::fabs(input[i -
k].getMZ() - peak_raw_data.begin()->first) < spacing_difference_ * min_spacing
206 && (input[i -
k].getIntensity() < peak_raw_data.begin()->second
207 || std::fabs(input[i -
k].getMZ() - central_peak_mz) < est_peak_width)
210 if (signal_to_noise_ > 0.0)
217 peak_raw_data[input[i -
k].getMZ()] = input[i -
k].getIntensity();
220 double leftborder = input[i -
k + 1].getMZ();
224 while ((i +
k) < input.size()
225 && std::fabs(input[i +
k].getMZ() - peak_raw_data.rbegin()->first) < spacing_difference_ * min_spacing
226 && (input[i +
k].getIntensity() < peak_raw_data.rbegin()->second
227 || std::fabs(input[i +
k].getMZ() - central_peak_mz) < est_peak_width)
230 if (signal_to_noise_ > 0.0)
238 peak_raw_data[input[i +
k].getMZ()] = input[i +
k].getIntensity();
244 double rightborder = input[i +
k - 1].getMZ();
246 double weighted_mz = 0;
247 double integrated_intensity = 0;
248 for (std::map<double, double>::const_iterator map_it = peak_raw_data.begin(); map_it != peak_raw_data.end(); ++map_it)
250 weighted_mz += map_it->first * map_it->second;
251 integrated_intensity += map_it->second;
253 weighted_mz /= integrated_intensity;
256 PeakCandidates[peak_it].integrated_intensity = integrated_intensity;
257 PeakCandidates[peak_it].leftWidth = leftborder;
258 PeakCandidates[peak_it].rightWidth = rightborder;
259 PeakCandidates[peak_it].mz = weighted_mz;
262 double min_diff = std::fabs(weighted_mz - input[i].getMZ());
266 for (
int m = 1; i - m > 0 && leftborder < input[i - m].getMZ(); m++)
268 if (std::fabs(weighted_mz - input[i - m].getMZ()) < min_diff)
270 min_diff = std::fabs(weighted_mz - input[i - m].getMZ());
275 for (
int m = 1; i - m > 0 && rightborder > input[i + m].getMZ(); m++)
277 if (std::fabs(weighted_mz - input[i + m].getMZ()) < min_diff)
279 min_diff = std::fabs(weighted_mz - input[i + m].getMZ());
283 PeakCandidates[peak_it].index = min_i;
302 if (input.size() < 3)
return;
306 output.SpectrumSettings::operator=(input);
307 output.MetaInfoInterface::operator=(input);
314 std::vector<PeakCandidate> PeakCandidates;
320 pepi_param.
setValue(
"signal_to_noise", signal_to_noise_);
321 pepi_param.
setValue(
"spacing_difference", spacing_difference_);
323 pp.
pick(input, picked_spectrum);
326 std::vector<PeakCandidate> newPeakCandidates_;
329 for (
Size k = 0;
k < input.size() && j < picked_spectrum.size();
k++)
331 if (input[
k].getMZ() > picked_spectrum[j].getMZ())
334 PeakCandidate pc = { static_cast<int>(
k), picked_spectrum[j].getIntensity(), -1, -1, -1, -1};
335 newPeakCandidates_.push_back(pc);
340 PeakCandidates = newPeakCandidates_;
345 if (signal_to_noise_ > 0.0)
347 Param snt_parameters = snt.getParameters();
348 snt_parameters.
setValue(
"win_len", sn_win_len_);
349 snt_parameters.
setValue(
"bin_count", sn_bin_count_);
350 snt.setParameters(snt_parameters);
355 for (
int i = 0; i < nr_iterations_; i++)
357 pickRecenterPeaks_(input, PeakCandidates, snt);
368 for (
Size peak_it = 0; peak_it < PeakCandidates.size(); peak_it++)
370 if (PeakCandidates[peak_it].leftWidth < 0)
continue;
373 for (
Size m = peak_it + 1; m < PeakCandidates.size(); m++)
375 if (PeakCandidates[m].mz >= PeakCandidates[peak_it].leftWidth && PeakCandidates[m].mz <= PeakCandidates[peak_it].rightWidth)
377 OPENMS_LOG_DEBUG <<
"Remove peak " << m <<
" : " << PeakCandidates[m].mz <<
" " <<
378 PeakCandidates[m].peak_apex_intensity <<
" (too close to " << PeakCandidates[peak_it].mz <<
379 " " << PeakCandidates[peak_it].peak_apex_intensity <<
")" << std::endl;
380 PeakCandidates[m].leftWidth = PeakCandidates[m].rightWidth = -1;
385 peak.
setMZ(PeakCandidates[peak_it].mz);
386 peak.
setIntensity(PeakCandidates[peak_it].integrated_intensity);
387 output.push_back(peak);
390 output.
getFloatDataArrays()[0].push_back(PeakCandidates[peak_it].integrated_intensity);
395 OPENMS_LOG_DEBUG <<
"Found seeds: " << PeakCandidates.size() <<
" / Found peaks: " << output.size() << std::endl;
405 static_cast<ExperimentalSettings&>(output) = input;
410 bool ms1_only = param_.getValue(
"ms1_only").toBool();
411 bool clear_meta_data = param_.getValue(
"clear_meta_data").toBool();
414 startProgress(0, input.
size(),
"picking peaks");
415 for (
Size scan_idx = 0; scan_idx != input.
size(); ++scan_idx)
417 if (ms1_only && (input[scan_idx].getMSLevel() != 1))
419 output[scan_idx] = input[scan_idx];
423 pick(input[scan_idx], output[scan_idx]);
424 if (clear_meta_data) {output[scan_idx].getFloatDataArrays().
clear();}
426 setProgress(progress++);