35 #ifndef OPENMS_ANALYSIS_OPENSWATH_CHROMATOGRAMEXTRACTOR_H
36 #define OPENMS_ANALYSIS_OPENSWATH_CHROMATOGRAMEXTRACTOR_H
78 template <
typename ExperimentT>
86 Size input_size = input.size();
93 if (filter ==
"tophat")
97 else if (filter ==
"bartlett")
104 "Filter either needs to be tophat or bartlett");
108 PeptideRTMap_.clear();
112 if (pep.
rts.empty() || pep.
rts[0].getCVTerms()[
"MS:1000896"].empty())
116 if (rt_extraction_window >= 0)
119 "Error: Peptide " + pep.
id +
" does not have normalized retention times (term 1000896) which are necessary to perform an RT-limited extraction");
123 PeptideRTMap_[pep.
id] = pep.
rts[0].getCVTerms()[
"MS:1000896"][0].getValue().toString().toDouble();
131 std::vector<typename ExperimentT::ChromatogramType> chromatograms;
132 prepareSpectra_(settings, chromatograms, transition_exp);
135 startProgress(0, input_size,
"Extracting chromatograms");
136 for (
Size scan_idx = 0; scan_idx < input_size; ++scan_idx)
138 setProgress(scan_idx);
140 if (input[scan_idx].size() == 0)
146 double integrated_intensity = 0;
152 for (
Size k = 0;
k < chromatograms.size(); ++
k)
155 double current_rt = input[scan_idx].getRT();
156 if (outsideExtractionWindow_(transition_exp.
getTransitions()[
k], current_rt, trafo, rt_extraction_window))
164 if (used_filter == 1)
166 extract_value_tophat(input[scan_idx], mz, peak_idx, integrated_intensity, extract_window, ppm);
168 else if (used_filter == 2)
170 extract_value_bartlett(input[scan_idx], mz, peak_idx, integrated_intensity, extract_window, ppm);
174 p.setIntensity(integrated_intensity);
175 chromatograms[
k].push_back(p);
181 output.setChromatograms(chromatograms);
186 template <
typename SpectrumT>
187 void extract_value_tophat(
const SpectrumT& input,
const double& mz,
Size& peak_idx,
double& integrated_intensity,
const double& extract_window,
const bool ppm)
189 integrated_intensity = 0;
190 if (input.size() == 0)
199 left = mz - mz * extract_window / 2.0 * 1.0e-6;
200 right = mz + mz * extract_window / 2.0 * 1.0e-6;
204 left = mz - extract_window / 2.0;
205 right = mz + extract_window / 2.0;
211 while (peak_idx < input.size() && input[peak_idx].getMZ() < mz)
216 integrated_intensity = 0;
221 if (peak_idx >= input.size())
223 walker = input.size() - 1;
227 if (input[walker].getMZ() > left && input[walker].getMZ() < right)
229 integrated_intensity += input[walker].getIntensity();
238 while (walker > 0 && input[walker].getMZ() > left && input[walker].getMZ() < right)
240 integrated_intensity += input[walker].getIntensity(); walker--;
243 if (walker < input.size() )
247 while (walker<input.size() && input[walker].getMZ()> left && input[walker].getMZ() < right)
249 integrated_intensity += input[walker].getIntensity(); walker++;
253 template <
typename SpectrumT>
254 void extract_value_bartlett(
const SpectrumT& input,
const double& mz,
Size& peak_idx,
double& integrated_intensity,
const double& extract_window,
const bool ppm)
256 integrated_intensity = 0;
257 if (input.size() == 0)
263 double left, right, half_window_size, weight;
266 half_window_size = mz * extract_window / 2.0 * 1.0e-6;
267 left = mz - mz * extract_window / 2.0 * 1.0e-6;
268 right = mz + mz * extract_window / 2.0 * 1.0e-6;
272 half_window_size = extract_window / 2.0;
273 left = mz - extract_window / 2.0;
274 right = mz + extract_window / 2.0;
280 while (peak_idx < input.size() && input[peak_idx].getMZ() < mz)
289 if (peak_idx >= input.size())
291 walker = input.size() - 1;
295 if (input[walker].getMZ() > left && input[walker].getMZ() < right)
297 weight = 1 - fabs(input[walker].getMZ() - mz) / half_window_size;
298 integrated_intensity += input[walker].getIntensity() * weight;
307 while (walker > 0 && input[walker].getMZ() > left && input[walker].getMZ() < right)
309 weight = 1 - fabs(input[walker].getMZ() - mz) / half_window_size;
310 integrated_intensity += input[walker].getIntensity() * weight; walker--;
313 if (walker < input.size() )
317 while (walker<input.size() && input[walker].getMZ()> left && input[walker].getMZ() < right)
319 weight = 1 - fabs(input[walker].getMZ() - mz) / half_window_size;
320 integrated_intensity += input[walker].getIntensity() * weight; walker++;
324 void extract_value_tophat(
const std::vector<double>::const_iterator& mz_start, std::vector<double>::const_iterator& mz_it,
325 const std::vector<double>::const_iterator& mz_end, std::vector<double>::const_iterator& int_it,
326 const double& mz,
double& integrated_intensity,
double& extract_window,
bool ppm)
328 integrated_intensity = 0;
329 if (mz_start == mz_end)
338 left = mz - mz * extract_window / 2.0 * 1.0e-6;
339 right = mz + mz * extract_window / 2.0 * 1.0e-6;
343 left = mz - extract_window / 2.0;
344 right = mz + extract_window / 2.0;
347 std::vector<double>::const_iterator mz_walker;
348 std::vector<double>::const_iterator int_walker;
351 while (mz_it != mz_end && (*mz_it) < mz)
363 mz_walker--; int_walker--;
367 if ((*mz_walker) > left && (*mz_walker) < right)
369 integrated_intensity += (*int_walker);
375 if (mz_it != mz_start)
380 while (mz_walker != mz_start && (*mz_walker) > left && (*mz_walker) < right)
382 integrated_intensity += (*int_walker); mz_walker--; int_walker--;
391 while (mz_walker != mz_end && (*mz_walker) > left && (*mz_walker) < right)
393 integrated_intensity += (*int_walker); mz_walker++; int_walker++;
400 template <
class SpectrumSettingsT,
class ChromatogramT>
416 if (settings.getPrecursors().size() > 0)
424 for (
Size pep_idx = 0; pep_idx < transition_exp.
getPeptides().size(); pep_idx++)
427 if (pep->
id == pepref)
434 chrom.setPrecursor(prec);
439 chrom.setProduct(prod);
442 chrom.setInstrumentSettings(settings.getInstrumentSettings());
443 chrom.setAcquisitionInfo(settings.getAcquisitionInfo());
444 chrom.setSourceFile(settings.getSourceFile());
446 for (
Size i = 0; i < settings.getDataProcessing().size(); ++i)
450 chrom.getDataProcessing().push_back(dp);
456 chromatograms.push_back(chrom);
464 if (rt_extraction_window < 0)
474 double expected_rt = PeptideRTMap_[transition.
getPeptideRef()];
475 double de_normalized_experimental_rt = trafo.
apply(expected_rt);
476 if (current_rt < de_normalized_experimental_rt - rt_extraction_window || current_rt > de_normalized_experimental_rt + rt_extraction_window)
Descripton of the applied preprocessing steps.
Definition: DataProcessing.h:51
void setIsolationWindowUpperOffset(DoubleReal bound)
sets the upper offset from the target m/z
A more convenient string class.
Definition: String.h:56
Precursor meta information.
Definition: Precursor.h:56
Product meta information.
Definition: Product.h:49
Peak2D PeakType
Definition: MassTrace.h:49
void setIsolationWindowLowerOffset(DoubleReal bound)
sets the lower offset from the target m/z
void setMZ(DoubleReal mz)
sets the target m/z
Representation of 1D spectrum settings.
Definition: SpectrumSettings.h:64
void setMZ(CoordinateType mz)
Mutable access to m/z.
Definition: Peak1D.h:114
void sortTransitionsByProductMZ()
Lexicographically sorts the transitions by their product m/z.
std::vector< RetentionTime > rts
Definition: TargetedExperimentHelper.h:333
const String & getPeptideRef() const
A method or algorithm argument contains illegal values.
Definition: Exception.h:634
String id
Definition: TargetedExperimentHelper.h:334
const std::vector< ReactionMonitoringTransition > & getTransitions() const
returns the transition list
DoubleReal getPrecursorMZ() const
Definition: ChromatogramSettings.h:74
String sequence
Definition: TargetedExperimentHelper.h:337
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:144
Base class for all classes that want to report their progess.
Definition: ProgressLogger.h:56
This class stores an prediction of an SRM/MRM transition.
Definition: TargetedExperiment.h:53
const String & getNativeID() const
DoubleReal getProductMZ() const
const std::vector< Peptide > & getPeptides() const
Definition: TargetedExperimentHelper.h:211
This class stores a SRM/MRM transition.
Definition: ReactionMonitoringTransition.h:53