35 #ifndef OPENMS_ANALYSIS_OPENSWATH_CHROMATOGRAMEXTRACTOR_H 36 #define OPENMS_ANALYSIS_OPENSWATH_CHROMATOGRAMEXTRACTOR_H 88 template <
typename ExperimentT>
96 Size input_size = input.size();
102 int used_filter = getFilterNr_(filter);
103 populatePeptideRTMap_(transition_exp, rt_extraction_window);
111 std::vector<typename ExperimentT::ChromatogramType> chromatograms;
112 prepareSpectra_(settings, chromatograms, transition_exp);
115 startProgress(0, input_size,
"Extracting chromatograms");
116 for (
Size scan_idx = 0; scan_idx < input_size; ++scan_idx)
118 setProgress(scan_idx);
120 if (input[scan_idx].size() == 0)
126 double integrated_intensity = 0;
132 for (
Size k = 0;
k < chromatograms.size(); ++
k)
135 double current_rt = input[scan_idx].getRT();
136 if (outsideExtractionWindow_(transition_exp.
getTransitions()[
k], current_rt, trafo, rt_extraction_window))
144 if (used_filter == 1)
146 extract_value_tophat(input[scan_idx], mz, peak_idx, integrated_intensity, mz_extraction_window, ppm);
148 else if (used_filter == 2)
150 extract_value_bartlett(input[scan_idx], mz, peak_idx, integrated_intensity, mz_extraction_window, ppm);
155 p.setIntensity(integrated_intensity);
156 chromatograms[
k].push_back(p);
162 output.setChromatograms(chromatograms);
172 std::vector< OpenSwath::ChromatogramPtr >& output,
173 std::vector<ExtractionCoordinates> extraction_coordinates,
174 double mz_extraction_window,
bool ppm,
String filter)
177 extraction_coordinates, mz_extraction_window, ppm, filter);
203 void prepare_coordinates(std::vector< OpenSwath::ChromatogramPtr > & output_chromatograms,
204 std::vector< ExtractionCoordinates > & coordinates,
206 const double rt_extraction_window,
207 const bool ms1)
const;
222 template <
typename TransitionExpT>
224 std::vector< ChromatogramExtractor::ExtractionCoordinates > & coordinates,
225 TransitionExpT& transition_exp_used,
227 std::vector<OpenMS::MSChromatogram > & output_chromatograms,
230 typedef std::map<String, const typename TransitionExpT::Transition* > TransitionMapType;
231 TransitionMapType trans_map;
232 for (
Size i = 0; i < transition_exp_used.getTransitions().size(); i++)
234 trans_map[transition_exp_used.getTransitions()[i].getNativeID()] = &transition_exp_used.getTransitions()[i];
237 for (
Size i = 0; i < chromatograms.size(); i++)
259 String r = extract_id_(transition_exp_used, coord.
id);
264 typename TransitionExpT::Transition transition = (*trans_map[coord.
id]);
266 prec.
setMZ(transition.getPrecursorMZ());
275 prod.
setMZ(transition.getProductMZ());
281 if (!transition.getPeptideRef().empty())
283 String r = extract_id_(transition_exp_used, transition.getPeptideRef());
288 String r = extract_id_(transition_exp_used, transition.getCompoundRef());
304 output_chromatograms.push_back(chrom);
309 template <
typename SpectrumT>
311 double& integrated_intensity,
const double& extract_window,
const bool ppm)
313 integrated_intensity = 0;
314 if (input.size() == 0)
323 left = mz - mz * extract_window / 2.0 * 1.0e-6;
324 right = mz + mz * extract_window / 2.0 * 1.0e-6;
328 left = mz - extract_window / 2.0;
329 right = mz + extract_window / 2.0;
335 while (peak_idx < input.size() && input[peak_idx].getMZ() < mz)
344 if (peak_idx >= input.size())
346 walker = input.size() - 1;
350 if (input[walker].getMZ() > left && input[walker].getMZ() < right)
352 integrated_intensity += input[walker].getIntensity();
363 if (walker == 0 && input[walker].getMZ() > left && input[walker].getMZ() < right)
365 integrated_intensity += input[walker].getIntensity();
368 while (walker > 0 && input[walker].getMZ() > left && input[walker].getMZ() < right)
370 integrated_intensity += input[walker].getIntensity(); walker--;
376 if (walker < input.size() )
380 while (walker < input.size() && input[walker].getMZ() > left && input[walker].getMZ() < right)
382 integrated_intensity += input[walker].getIntensity(); walker++;
387 template <
typename SpectrumT>
389 double& integrated_intensity,
const double& extract_window,
const bool ppm)
391 integrated_intensity = 0;
392 if (input.size() == 0)
398 double left, right, half_window_size, weight;
401 half_window_size = mz * extract_window / 2.0 * 1.0e-6;
402 left = mz - mz * extract_window / 2.0 * 1.0e-6;
403 right = mz + mz * extract_window / 2.0 * 1.0e-6;
407 half_window_size = extract_window / 2.0;
408 left = mz - extract_window / 2.0;
409 right = mz + extract_window / 2.0;
415 while (peak_idx < input.size() && input[peak_idx].getMZ() < mz)
424 if (peak_idx >= input.size())
426 walker = input.size() - 1;
430 if (input[walker].getMZ() > left && input[walker].getMZ() < right)
432 weight = 1 - fabs(input[walker].getMZ() - mz) / half_window_size;
433 integrated_intensity += input[walker].getIntensity() * weight;
444 if (walker == 0 && input[walker].getMZ() > left && input[walker].getMZ() < right)
446 integrated_intensity += input[walker].getIntensity();
449 while (walker > 0 && input[walker].getMZ() > left && input[walker].getMZ() < right)
451 weight = 1 - fabs(input[walker].getMZ() - mz) / half_window_size;
452 integrated_intensity += input[walker].getIntensity() * weight; walker--;
458 if (walker < input.size() )
462 while (walker<input.size() && input[walker].getMZ()> left && input[walker].getMZ() < right)
464 weight = 1 - fabs(input[walker].getMZ() - mz) / half_window_size;
465 integrated_intensity += input[walker].getIntensity() * weight; walker++;
478 template <
typename TransitionExpT>
479 static String extract_id_(TransitionExpT& transition_exp_used,
String id);
495 template <
class SpectrumSettingsT,
class ChromatogramT>
507 if (settings.getPrecursors().size() > 0)
515 for (
Size pep_idx = 0; pep_idx < transition_exp.
getPeptides().size(); pep_idx++)
518 if (pep->
id == pepref)
525 for (
Size comp_idx = 0; comp_idx < transition_exp.
getCompounds().size(); comp_idx++)
528 if (comp->
id == compref)
536 chrom.setPrecursor(prec);
541 chrom.setProduct(prod);
544 chrom.setInstrumentSettings(settings.getInstrumentSettings());
545 chrom.setAcquisitionInfo(settings.getAcquisitionInfo());
546 chrom.setSourceFile(settings.getSourceFile());
548 for (
Size j = 0; j < settings.getDataProcessing().size(); ++j)
550 settings.getDataProcessing()[j]->setMetaValue(
"performed_on_spectra",
"true");
551 chrom.getDataProcessing().push_back(settings.getDataProcessing()[j]);
557 chromatograms.push_back(chrom);
567 int getFilterNr_(
String filter);
596 if (transition_exp_used.hasPeptide(
id))
601 else if (transition_exp_used.hasCompound(
id))
613 #endif // OPENMS_ANALYSIS_OPENSWATH_CHROMATOGRAMEXTRACTOR_H
A more convenient string class.
Definition: String.h:57
Precursor meta information.
Definition: Precursor.h:58
Product meta information.
Definition: Product.h:49
boost::shared_ptr< ISpectrumAccess > SpectrumAccessPtr
Definition: openswathalgo/include/OpenMS/ANALYSIS/OPENSWATH/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:90
The representation of a chromatogram.
Definition: MSChromatogram.h:55
void setChromatogramType(ChromatogramType type)
sets the chromatogram type
void setProduct(const Product &product)
sets the products
Peak2D PeakType
Definition: MassTrace.h:48
const InstrumentSettings & getInstrumentSettings() const
returns a const reference to the instrument settings of the current spectrum
const String & getCompoundRef() const
Representation of 1D spectrum settings.
Definition: SpectrumSettings.h:64
void setMZ(double mz)
sets the target m/z
void setSourceFile(const SourceFile &source_file)
sets the source file
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
void setMZ(CoordinateType mz)
Mutable access to m/z.
Definition: Peak1D.h:120
Definition: ChromatogramSettings.h:72
const SourceFile & getSourceFile() const
returns a const reference to the source file
void sortTransitionsByProductMZ()
Lexicographically sorts the transitions by their product m/z.
void setInstrumentSettings(const InstrumentSettings &instrument_settings)
sets the instrument settings of the current spectrum
void setIsolationWindowLowerOffset(double bound)
sets the lower offset from the target m/z
const AcquisitionInfo & getAcquisitionInfo() const
returns a const reference to the acquisition info
String id
Definition: TargetedExperimentHelper.h:397
std::vector< DataProcessingPtr > & getDataProcessing()
returns a mutable reference to the description of the applied processing
const std::vector< ReactionMonitoringTransition > & getTransitions() const
returns the transition list
void setNativeID(const String &native_id)
sets the native identifier for the spectrum, used by the acquisition software.
boost::shared_ptr< Chromatogram > ChromatogramPtr
Definition: openswathalgo/include/OpenMS/ANALYSIS/OPENSWATH/OPENSWATHALGO/DATAACCESS/DataStructures.h:156
void setIsolationWindowUpperOffset(double bound)
sets the upper offset from the target m/z
void setAcquisitionInfo(const AcquisitionInfo &acquisition_info)
sets the acquisition info
double getProductMZ() const
Definition: TransitionExperiment.h:150
std::string sequence
Definition: TransitionExperiment.h:160
Definition: TargetedExperimentHelper.h:181
std::vector< DataProcessingPtr > & getDataProcessing()
returns a mutable reference to the description of the applied processing
double getPrecursorMZ() const
get the precursor mz (Q1 value)
Definition: ChromatogramSettings.h:74
const std::vector< Precursor > & getPrecursors() const
returns a const reference to the precursors
const String & getPeptideRef() const
String sequence
Definition: TargetedExperimentHelper.h:400
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:128
const std::vector< Compound > & getCompounds() const
Base class for all classes that want to report their progress.
Definition: ProgressLogger.h:55
A description of a targeted experiment containing precursor and production ions.
Definition: TargetedExperiment.h:62
String id
Definition: TargetedExperimentHelper.h:254
const std::vector< Peptide > & getPeptides() const
static void convertToOpenMSChromatogram(const OpenSwath::ChromatogramPtr cptr, OpenMS::MSChromatogram &chromatogram)
Convert a ChromatogramPtr to an OpenMS Chromatogram.
std::string compound_name
Definition: TransitionExperiment.h:168
const String & getNativeID() const
void setPrecursor(const Precursor &precursor)
sets the precursors
Definition: TransitionExperiment.h:195
Definition: TargetedExperimentHelper.h:266
This class stores a SRM/MRM transition.
Definition: ReactionMonitoringTransition.h:56