OpenMS
Loading...
Searching...
No Matches
TargetedSpectraExtractor.h
Go to the documentation of this file.
1// Copyright (c) 2002-present, OpenMS Inc. -- EKU Tuebingen, ETH Zurich, and FU Berlin
2// SPDX-License-Identifier: BSD-3-Clause
3//
4// --------------------------------------------------------------------------
5// $Maintainer: Douglas McCloskey, Pasquale Domenico Colaianni $
6// $Authors: Douglas McCloskey, Pasquale Domenico Colaianni $
7// --------------------------------------------------------------------------
8
9#pragma once
10
11#include <OpenMS/config.h> // OPENMS_DLLAPI
18
19namespace OpenMS
20{
69 class OPENMS_DLLAPI TargetedSpectraExtractor :
71 {
72public:
74 ~TargetedSpectraExtractor() override = default;
75
80 struct Match
81 {
82 Match() = default;
83 Match(MSSpectrum a, double b) : spectrum(std::move(a)), score(b) {}
85 double score = 0.0;
86 };
87
88 class OPENMS_DLLAPI Comparator
89 {
90 public:
91 virtual ~Comparator() = default;
92 virtual void generateScores(
93 const MSSpectrum& spec,
94 std::vector<std::pair<Size,double>>& scores,
95 double min_score
96 ) const = 0;
97
98 virtual void init(
99 const std::vector<MSSpectrum>& library,
100 const std::map<String,DataValue>& options
101 ) = 0;
102
103 const std::vector<MSSpectrum>& getLibrary() const
104 {
105 return library_;
106 }
107
108 protected:
109 std::vector<MSSpectrum> library_;
110 };
111
112 class OPENMS_DLLAPI BinnedSpectrumComparator : public Comparator
113 {
114 public:
115 ~BinnedSpectrumComparator() override = default;
117 const MSSpectrum& spec,
118 std::vector<std::pair<Size,double>>& scores,
119 double min_score
120 ) const override
121 {
122 scores.clear();
123 const BinnedSpectrum in_bs(spec, bin_size_, false, peak_spread_, bin_offset_);
124 for (Size i = 0; i < bs_library_.size(); ++i)
125 {
126 const double cmp_score = cmp_bs_(in_bs, bs_library_[i]);
127 if (cmp_score >= min_score)
128 {
129 scores.emplace_back(i, cmp_score);
130 }
131 }
132 }
133
134 void init(const std::vector<MSSpectrum>& library, const std::map<String,DataValue>& options) override;
135
136 private:
138 std::vector<BinnedSpectrum> bs_library_;
139 double bin_size_ = 0.02; // Default for nominal mass: 1.0;
140 UInt peak_spread_ = 0;
141 double bin_offset_ = 0.0; // Default for nominal mass resolution: 0.4;
142 };
143
144 void getDefaultParameters(Param& params) const;
145
163 const std::vector<MSSpectrum>& spectra,
164 const TargetedExperiment& targeted_exp,
165 std::vector<MSSpectrum>& annotated_spectra,
166 FeatureMap& features,
167 bool compute_features = true
168 ) const;
169
185 const std::vector<MSSpectrum>& spectra,
186 const TargetedExperiment& targeted_exp,
187 std::vector<MSSpectrum>& annotated_spectra
188 ) const;
189
203 const std::vector<MSSpectrum>& spectra,
204 const FeatureMap& ms1_features,
205 FeatureMap& ms2_features,
206 std::vector<MSSpectrum>& annotated_spectra) const;
207
216 OpenMS::FeatureMap& feat_map,
217 OpenMS::FeatureMap& feat_map_output,
218 bool add_unidentified_features = false) const;
219
237 void pickSpectrum(const MSSpectrum& spectrum, MSSpectrum& picked_spectrum) const;
238
258 const std::vector<MSSpectrum>& annotated_spectra,
259 const std::vector<MSSpectrum>& picked_spectra,
260 FeatureMap& features,
261 std::vector<MSSpectrum>& scored_spectra,
262 bool compute_features = true
263 ) const;
264
279 const std::vector<MSSpectrum>& annotated_spectra,
280 const std::vector<MSSpectrum>& picked_spectra,
281 std::vector<MSSpectrum>& scored_spectra
282 ) const;
283
297 const std::vector<MSSpectrum>& scored_spectra,
298 const FeatureMap& features,
299 std::vector<MSSpectrum>& selected_spectra,
300 FeatureMap& selected_features,
301 bool compute_features = true
302 ) const;
303
312 const std::vector<MSSpectrum>& scored_spectra,
313 std::vector<MSSpectrum>& selected_spectra
314 ) const;
315
333 const MSExperiment& experiment,
334 const TargetedExperiment& targeted_exp,
335 std::vector<MSSpectrum>& extracted_spectra,
336 FeatureMap& extracted_features,
337 bool compute_features = true
338 ) const;
339
354 const MSExperiment& experiment,
355 const TargetedExperiment& targeted_exp,
356 std::vector<MSSpectrum>& extracted_spectra
357 ) const;
358
374 const MSExperiment& experiment,
375 const FeatureMap& ms1_features,
376 std::vector<MSSpectrum>& extracted_spectra
377 ) const;
378
395 const MSExperiment& experiment,
396 const FeatureMap& ms1_features,
397 std::vector<MSSpectrum>& extracted_spectra,
398 FeatureMap& extracted_features
399 ) const;
400
410 const MSSpectrum& input_spectrum,
411 const Comparator& cmp,
412 std::vector<Match>& matches
413 ) const;
414
438 const std::vector<MSSpectrum>& spectra,
439 const Comparator& cmp,
440 FeatureMap& features
441 );
442
465 const std::vector<MSSpectrum>& spectra,
466 const Comparator& cmp,
467 FeatureMap& features
468 );
469
477 void constructTransitionsList(const OpenMS::FeatureMap& ms1_features, const OpenMS::FeatureMap& ms2_features, TargetedExperiment& t_exp) const;
478
485 void storeSpectraMSP(const String& filename, MSExperiment& experiment) const;
486
493 void mergeFeatures(const OpenMS::FeatureMap& fmap_input, OpenMS::FeatureMap& fmap_output) const;
494
495protected:
497 void updateMembers_() override;
498
500 void deisotopeMS2Spectra_(MSExperiment& experiment) const;
501
503 void removeMS2SpectraPeaks_(MSExperiment& experiment) const;
504
506 void organizeMapWithSameIdentifier(const OpenMS::FeatureMap& fmap_input, std::map<OpenMS::String, std::vector<OpenMS::Feature>>& fmapmap) const;
507
508 private:
526 const MSExperiment& experiment,
527 const FeatureMap& ms1_features,
528 std::vector<MSSpectrum>& extracted_spectra,
529 FeatureMap& extracted_features,
530 const bool compute_features
531 ) const;
532
533 private:
538
547
556
562
568
574
575 double tic_weight_;
577 double snr_weight_;
586
593
599
602
605
607
617
619 };
620}
Compare functor scoring the spectral contrast angle for similarity measurement.
Definition BinnedSpectralContrastAngle.h:33
This is a binned representation of a PeakSpectrum.
Definition BinnedSpectrum.h:55
A base class for all classes handling default parameters.
Definition DefaultParamHandler.h:66
A container for features.
Definition FeatureMap.h:82
In-Memory representation of a mass spectrometry run.
Definition MSExperiment.h:49
The representation of a 1D spectrum.
Definition MSSpectrum.h:44
Management and storage of parameters / INI files.
Definition Param.h:46
A more convenient string class.
Definition String.h:34
A description of a targeted experiment containing precursor and production ions.
Definition TargetedExperiment.h:39
Definition TargetedSpectraExtractor.h:113
std::vector< BinnedSpectrum > bs_library_
Definition TargetedSpectraExtractor.h:138
void init(const std::vector< MSSpectrum > &library, const std::map< String, DataValue > &options) override
BinnedSpectralContrastAngle cmp_bs_
Definition TargetedSpectraExtractor.h:137
void generateScores(const MSSpectrum &spec, std::vector< std::pair< Size, double > > &scores, double min_score) const override
Definition TargetedSpectraExtractor.h:116
Definition TargetedSpectraExtractor.h:89
const std::vector< MSSpectrum > & getLibrary() const
Definition TargetedSpectraExtractor.h:103
std::vector< MSSpectrum > library_
Definition TargetedSpectraExtractor.h:109
virtual void generateScores(const MSSpectrum &spec, std::vector< std::pair< Size, double > > &scores, double min_score) const =0
virtual void init(const std::vector< MSSpectrum > &library, const std::map< String, DataValue > &options)=0
This class filters, annotates, picks, and scores spectra (e.g., taken from a DDA experiment) based on...
Definition TargetedSpectraExtractor.h:71
void mergeFeatures(const OpenMS::FeatureMap &fmap_input, OpenMS::FeatureMap &fmap_output) const
organize into a map by combining features and subordinates with the same identifier
int deisotoping_min_isopeaks_
Definition TargetedSpectraExtractor.h:613
double snr_weight_
Definition TargetedSpectraExtractor.h:577
double rt_window_
Definition TargetedSpectraExtractor.h:546
void extractSpectra(const MSExperiment &experiment, const FeatureMap &ms1_features, std::vector< MSSpectrum > &extracted_spectra) const
Combines the functionalities given by all the other methods implemented in this class.
void removeMS2SpectraPeaks_(MSExperiment &experiment) const
Remove peaks form MS2 which are at a higher mz than the precursor + 10 ppm.
double tic_weight_
Definition TargetedSpectraExtractor.h:575
bool deisotoping_use_deisotoper_
Definition TargetedSpectraExtractor.h:608
void constructTransitionsList(const OpenMS::FeatureMap &ms1_features, const OpenMS::FeatureMap &ms2_features, TargetedExperiment &t_exp) const
compute transitions list from MS1 and the associated MS2 features
double peak_height_max_
Definition TargetedSpectraExtractor.h:567
void targetedMatching(const std::vector< MSSpectrum > &spectra, const Comparator &cmp, FeatureMap &features)
Compares a list of spectra against a spectral library and updates the related features.
bool mz_unit_is_Da_
Definition TargetedSpectraExtractor.h:537
void annotateSpectra(const std::vector< MSSpectrum > &spectra, const FeatureMap &ms1_features, FeatureMap &ms2_features, std::vector< MSSpectrum > &annotated_spectra) const
Annotates the MS2 spectra with the likely MS1 feature that it was derived from.
Size top_matches_to_report_
Definition TargetedSpectraExtractor.h:598
double relative_allowable_product_mass_
Definition TargetedSpectraExtractor.h:606
double peak_height_min_
Definition TargetedSpectraExtractor.h:561
void extractSpectra(const MSExperiment &experiment, const FeatureMap &ms1_features, std::vector< MSSpectrum > &extracted_spectra, FeatureMap &extracted_features, const bool compute_features) const
Combines the functionalities given by all the other methods implemented in this class.
double fwhm_threshold_
Definition TargetedSpectraExtractor.h:573
bool deisotoping_annotate_charge_
Definition TargetedSpectraExtractor.h:616
double deisotoping_fragment_tolerance_
Definition TargetedSpectraExtractor.h:609
bool use_gauss_
Definition TargetedSpectraExtractor.h:592
void extractSpectra(const MSExperiment &experiment, const TargetedExperiment &targeted_exp, std::vector< MSSpectrum > &extracted_spectra) const
Combines the functionalities given by all the other methods implemented in this class.
~TargetedSpectraExtractor() override=default
void untargetedMatching(const std::vector< MSSpectrum > &spectra, const Comparator &cmp, FeatureMap &features)
Compares a list of spectra against a spectral library and creates a FeatureMap with the relevant info...
double max_fragment_mz_
Definition TargetedSpectraExtractor.h:604
void scoreSpectra(const std::vector< MSSpectrum > &annotated_spectra, const std::vector< MSSpectrum > &picked_spectra, std::vector< MSSpectrum > &scored_spectra) const
Assigns a score to the spectra given an input and saves them in scored_spectra.
void matchSpectrum(const MSSpectrum &input_spectrum, const Comparator &cmp, std::vector< Match > &matches) const
Searches the spectral library for the top scoring candidates that match the input spectrum.
int deisotoping_min_charge_
Definition TargetedSpectraExtractor.h:611
bool deisotoping_keep_only_deisotoped_
Definition TargetedSpectraExtractor.h:615
double mz_tolerance_
Definition TargetedSpectraExtractor.h:555
void pickSpectrum(const MSSpectrum &spectrum, MSSpectrum &picked_spectrum) const
Picks a spectrum's peaks and saves them in picked_spectrum.
void scoreSpectra(const std::vector< MSSpectrum > &annotated_spectra, const std::vector< MSSpectrum > &picked_spectra, FeatureMap &features, std::vector< MSSpectrum > &scored_spectra, bool compute_features=true) const
Assigns a score to the spectra given an input and saves them in scored_spectra.
double max_precursor_mass_threashold_
Definition TargetedSpectraExtractor.h:618
void annotateSpectra(const std::vector< MSSpectrum > &spectra, const TargetedExperiment &targeted_exp, std::vector< MSSpectrum > &annotated_spectra) const
Filters and annotates those spectra that could potentially match the transitions of the target list.
int deisotoping_max_charge_
Definition TargetedSpectraExtractor.h:612
void extractSpectra(const MSExperiment &experiment, const FeatureMap &ms1_features, std::vector< MSSpectrum > &extracted_spectra, FeatureMap &extracted_features) const
Combines the functionalities given by all the other methods implemented in this class.
void selectSpectra(const std::vector< MSSpectrum > &scored_spectra, const FeatureMap &features, std::vector< MSSpectrum > &selected_spectra, FeatureMap &selected_features, bool compute_features=true) const
The method selects the highest scoring spectrum for each possible annotation (i.e....
double min_match_score_
Minimum score for a match to be considered valid in matchSpectrum().
Definition TargetedSpectraExtractor.h:601
double fwhm_weight_
Definition TargetedSpectraExtractor.h:576
void deisotopeMS2Spectra_(MSExperiment &experiment) const
Deisotope MS2 spectra.
void updateMembers_() override
Overridden function from DefaultParamHandler to keep members up to date, when a parameter is changed.
void selectSpectra(const std::vector< MSSpectrum > &scored_spectra, std::vector< MSSpectrum > &selected_spectra) const
The method selects the highest scoring spectrum for each possible annotation (i.e....
void annotateSpectra(const std::vector< MSSpectrum > &spectra, const TargetedExperiment &targeted_exp, std::vector< MSSpectrum > &annotated_spectra, FeatureMap &features, bool compute_features=true) const
Filters and annotates those spectra that could potentially match the transitions of the target list.
double min_fragment_mz_
Definition TargetedSpectraExtractor.h:603
int deisotoping_max_isopeaks_
Definition TargetedSpectraExtractor.h:614
void storeSpectraMSP(const String &filename, MSExperiment &experiment) const
store spectra in MSP format
void organizeMapWithSameIdentifier(const OpenMS::FeatureMap &fmap_input, std::map< OpenMS::String, std::vector< OpenMS::Feature > > &fmapmap) const
organize into a map by combining features and subordinates with the same identifier
double min_select_score_
Definition TargetedSpectraExtractor.h:585
void extractSpectra(const MSExperiment &experiment, const TargetedExperiment &targeted_exp, std::vector< MSSpectrum > &extracted_spectra, FeatureMap &extracted_features, bool compute_features=true) const
Combines the functionalities given by all the other methods implemented in this class.
std::string deisotoping_fragment_unit_
Definition TargetedSpectraExtractor.h:610
void getDefaultParameters(Param &params) const
void searchSpectrum(OpenMS::FeatureMap &feat_map, OpenMS::FeatureMap &feat_map_output, bool add_unidentified_features=false) const
Search accurate masses and add identification (peptide hits) as features/sub-features.
unsigned int UInt
Unsigned integer type.
Definition Types.h:64
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition Types.h:97
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
STL namespace.
Definition TargetedSpectraExtractor.h:81
Match(MSSpectrum a, double b)
Definition TargetedSpectraExtractor.h:83
MSSpectrum spectrum
Definition TargetedSpectraExtractor.h:84