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
97 class OPENMS_DLLAPI Comparator
98 {
99 public:
100 virtual ~Comparator() = default;
108 virtual void generateScores(
109 const MSSpectrum& spec,
110 std::vector<std::pair<Size,double>>& scores,
111 double min_score
112 ) const = 0;
113
120 virtual void init(
121 const std::vector<MSSpectrum>& library,
122 const std::map<std::string,DataValue>& options
123 ) = 0;
124
126 const std::vector<MSSpectrum>& getLibrary() const
127 {
128 return library_;
129 }
130
131 protected:
132 std::vector<MSSpectrum> library_;
133 };
134
143 class OPENMS_DLLAPI BinnedSpectrumComparator : public Comparator
144 {
145 public:
146 ~BinnedSpectrumComparator() override = default;
160 const MSSpectrum& spec,
161 std::vector<std::pair<Size,double>>& scores,
162 double min_score
163 ) const override
164 {
165 scores.clear();
166 const BinnedSpectrum in_bs(spec, bin_size_, false, peak_spread_, bin_offset_);
167 for (Size i = 0; i < bs_library_.size(); ++i)
168 {
169 const double cmp_score = cmp_bs_(in_bs, bs_library_[i]);
170 if (cmp_score >= min_score)
171 {
172 scores.emplace_back(i, cmp_score);
173 }
174 }
175 }
176
189 void init(const std::vector<MSSpectrum>& library, const std::map<std::string,DataValue>& options) override;
190
191 private:
193 std::vector<BinnedSpectrum> bs_library_;
194 double bin_size_ = 0.02; // Default for nominal mass: 1.0;
195 UInt peak_spread_ = 0;
196 double bin_offset_ = 0.0; // Default for nominal mass resolution: 0.4;
197 };
198
199 void getDefaultParameters(Param& params) const;
200
218 const std::vector<MSSpectrum>& spectra,
219 const TargetedExperiment& targeted_exp,
220 std::vector<MSSpectrum>& annotated_spectra,
221 FeatureMap& features,
222 bool compute_features = true
223 ) const;
224
240 const std::vector<MSSpectrum>& spectra,
241 const TargetedExperiment& targeted_exp,
242 std::vector<MSSpectrum>& annotated_spectra
243 ) const;
244
258 const std::vector<MSSpectrum>& spectra,
259 const FeatureMap& ms1_features,
260 FeatureMap& ms2_features,
261 std::vector<MSSpectrum>& annotated_spectra) const;
262
271 OpenMS::FeatureMap& feat_map,
272 OpenMS::FeatureMap& feat_map_output,
273 bool add_unidentified_features = false) const;
274
292 void pickSpectrum(const MSSpectrum& spectrum, MSSpectrum& picked_spectrum) const;
293
313 const std::vector<MSSpectrum>& annotated_spectra,
314 const std::vector<MSSpectrum>& picked_spectra,
315 FeatureMap& features,
316 std::vector<MSSpectrum>& scored_spectra,
317 bool compute_features = true
318 ) const;
319
334 const std::vector<MSSpectrum>& annotated_spectra,
335 const std::vector<MSSpectrum>& picked_spectra,
336 std::vector<MSSpectrum>& scored_spectra
337 ) const;
338
352 const std::vector<MSSpectrum>& scored_spectra,
353 const FeatureMap& features,
354 std::vector<MSSpectrum>& selected_spectra,
355 FeatureMap& selected_features,
356 bool compute_features = true
357 ) const;
358
367 const std::vector<MSSpectrum>& scored_spectra,
368 std::vector<MSSpectrum>& selected_spectra
369 ) const;
370
388 const MSExperiment& experiment,
389 const TargetedExperiment& targeted_exp,
390 std::vector<MSSpectrum>& extracted_spectra,
391 FeatureMap& extracted_features,
392 bool compute_features = true
393 ) const;
394
409 const MSExperiment& experiment,
410 const TargetedExperiment& targeted_exp,
411 std::vector<MSSpectrum>& extracted_spectra
412 ) const;
413
429 const MSExperiment& experiment,
430 const FeatureMap& ms1_features,
431 std::vector<MSSpectrum>& extracted_spectra
432 ) const;
433
450 const MSExperiment& experiment,
451 const FeatureMap& ms1_features,
452 std::vector<MSSpectrum>& extracted_spectra,
453 FeatureMap& extracted_features
454 ) const;
455
465 const MSSpectrum& input_spectrum,
466 const Comparator& cmp,
467 std::vector<Match>& matches
468 ) const;
469
493 const std::vector<MSSpectrum>& spectra,
494 const Comparator& cmp,
495 FeatureMap& features
496 );
497
520 const std::vector<MSSpectrum>& spectra,
521 const Comparator& cmp,
522 FeatureMap& features
523 );
524
532 void constructTransitionsList(const OpenMS::FeatureMap& ms1_features, const OpenMS::FeatureMap& ms2_features, TargetedExperiment& t_exp) const;
533
540 void storeSpectraMSP(const std::string& filename, MSExperiment& experiment) const;
541
548 void mergeFeatures(const OpenMS::FeatureMap& fmap_input, OpenMS::FeatureMap& fmap_output) const;
549
550protected:
552 void updateMembers_() override;
553
555 void deisotopeMS2Spectra_(MSExperiment& experiment) const;
556
558 void removeMS2SpectraPeaks_(MSExperiment& experiment) const;
559
561 void organizeMapWithSameIdentifier(const OpenMS::FeatureMap& fmap_input, std::map<std::string, std::vector<OpenMS::Feature>>& fmapmap) const;
562
563 private:
581 const MSExperiment& experiment,
582 const FeatureMap& ms1_features,
583 std::vector<MSSpectrum>& extracted_spectra,
584 FeatureMap& extracted_features,
585 const bool compute_features
586 ) const;
587
588 private:
593
602
611
617
623
629
630 double tic_weight_;
632 double snr_weight_;
641
648
654
657
660
662
672
674 };
675}
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:78
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 description of a targeted experiment containing precursor and production ions.
Definition TargetedExperiment.h:40
Comparator implementation that scores query spectra against the library using BinnedSpectralContrastA...
Definition TargetedSpectraExtractor.h:144
std::vector< BinnedSpectrum > bs_library_
Definition TargetedSpectraExtractor.h:193
BinnedSpectralContrastAngle cmp_bs_
Definition TargetedSpectraExtractor.h:192
void generateScores(const MSSpectrum &spec, std::vector< std::pair< Size, double > > &scores, double min_score) const override
Bin spec with the configured bin parameters and score it against every entry of the cached library; k...
Definition TargetedSpectraExtractor.h:159
void init(const std::vector< MSSpectrum > &library, const std::map< std::string, DataValue > &options) override
Cache library, pre-binning each spectrum with the current parameters, and apply any options overrides...
Abstract base interface for spectral-library scoring strategies consumed by matchSpectrum.
Definition TargetedSpectraExtractor.h:98
const std::vector< MSSpectrum > & getLibrary() const
Return the reference library passed to the most recent init call.
Definition TargetedSpectraExtractor.h:126
std::vector< MSSpectrum > library_
Definition TargetedSpectraExtractor.h:132
virtual void generateScores(const MSSpectrum &spec, std::vector< std::pair< Size, double > > &scores, double min_score) const =0
Score spec against every entry of the cached library; keep only matches >= min_score.
virtual void init(const std::vector< MSSpectrum > &library, const std::map< std::string, DataValue > &options)=0
Load the reference library and (re)configure the comparator.
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:668
double snr_weight_
Definition TargetedSpectraExtractor.h:632
double rt_window_
Definition TargetedSpectraExtractor.h:601
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:630
bool deisotoping_use_deisotoper_
Definition TargetedSpectraExtractor.h:663
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:622
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:592
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:653
double relative_allowable_product_mass_
Definition TargetedSpectraExtractor.h:661
double peak_height_min_
Definition TargetedSpectraExtractor.h:616
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:628
bool deisotoping_annotate_charge_
Definition TargetedSpectraExtractor.h:671
double deisotoping_fragment_tolerance_
Definition TargetedSpectraExtractor.h:664
bool use_gauss_
Definition TargetedSpectraExtractor.h:647
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:659
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:666
bool deisotoping_keep_only_deisotoped_
Definition TargetedSpectraExtractor.h:670
double mz_tolerance_
Definition TargetedSpectraExtractor.h:610
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:673
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:667
void organizeMapWithSameIdentifier(const OpenMS::FeatureMap &fmap_input, std::map< std::string, std::vector< OpenMS::Feature > > &fmapmap) const
organize into a map by combining features and subordinates with the same identifier
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:656
double fwhm_weight_
Definition TargetedSpectraExtractor.h:631
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:658
int deisotoping_max_isopeaks_
Definition TargetedSpectraExtractor.h:669
void storeSpectraMSP(const std::string &filename, MSExperiment &experiment) const
store spectra in MSP format
double min_select_score_
Definition TargetedSpectraExtractor.h:640
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:665
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