OpenMS  2.8.0
TargetedSpectraExtractor.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // OpenMS -- Open-Source Mass Spectrometry
3 // --------------------------------------------------------------------------
4 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
5 // ETH Zurich, and Freie Universitaet Berlin 2002-2021.
6 //
7 // This software is released under a three-clause BSD license:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of any author or any participating institution
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
16 // For a full list of authors, refer to the file AUTHORS.
17 // --------------------------------------------------------------------------
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
22 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // --------------------------------------------------------------------------
31 // $Maintainer: Douglas McCloskey, Pasquale Domenico Colaianni $
32 // $Authors: Douglas McCloskey, Pasquale Domenico Colaianni $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
37 #include <OpenMS/config.h> // OPENMS_DLLAPI
44 
45 namespace OpenMS
46 {
69  class OPENMS_DLLAPI TargetedSpectraExtractor :
70  public DefaultParamHandler
71  {
72 public:
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_ = 1.0;
140  UInt peak_spread_ = 0;
141  double bin_offset_ = 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 
215  OpenMS::FeatureMap& feat_map,
216  OpenMS::FeatureMap& feat_map_output) const;
217 
235  void pickSpectrum(const MSSpectrum& spectrum, MSSpectrum& picked_spectrum) const;
236 
256  const std::vector<MSSpectrum>& annotated_spectra,
257  const std::vector<MSSpectrum>& picked_spectra,
258  FeatureMap& features,
259  std::vector<MSSpectrum>& scored_spectra,
260  bool compute_features = true
261  ) const;
262 
277  const std::vector<MSSpectrum>& annotated_spectra,
278  const std::vector<MSSpectrum>& picked_spectra,
279  std::vector<MSSpectrum>& scored_spectra
280  ) const;
281 
295  const std::vector<MSSpectrum>& scored_spectra,
296  const FeatureMap& features,
297  std::vector<MSSpectrum>& selected_spectra,
298  FeatureMap& selected_features,
299  bool compute_features = true
300  ) const;
301 
310  const std::vector<MSSpectrum>& scored_spectra,
311  std::vector<MSSpectrum>& selected_spectra
312  ) const;
313 
331  const MSExperiment& experiment,
332  const TargetedExperiment& targeted_exp,
333  std::vector<MSSpectrum>& extracted_spectra,
334  FeatureMap& extracted_features,
335  bool compute_features = true
336  ) const;
337 
352  const MSExperiment& experiment,
353  const TargetedExperiment& targeted_exp,
354  std::vector<MSSpectrum>& extracted_spectra
355  ) const;
356 
366  const MSSpectrum& input_spectrum,
367  const Comparator& cmp,
368  std::vector<Match>& matches
369  ) const;
370 
394  const std::vector<MSSpectrum>& spectra,
395  const Comparator& cmp,
396  FeatureMap& features
397  );
398 
421  const std::vector<MSSpectrum>& spectra,
422  const Comparator& cmp,
423  FeatureMap& features
424  );
425 
433  void storeSpectraTraML(const String& filename, const OpenMS::FeatureMap& ms1_features, const OpenMS::FeatureMap& ms2_features) const;
434 
441  void storeSpectraMSP(const String& filename, MSExperiment& experiment) const;
442 
449  void mergeFeatures(const OpenMS::FeatureMap& fmap_input, OpenMS::FeatureMap& fmap_output) const;
450 
451 protected:
453  void updateMembers_() override;
454 
456  void deisotopeMS2Spectra_(MSExperiment& experiment) const;
457 
459  void removeMS2SpectraPeaks_(MSExperiment& experiment) const;
460 
462  void organizeMapWithSameIdentifier(const OpenMS::FeatureMap& fmap_input, std::map<std::string, std::vector<OpenMS::Feature>>& fmapmap) const;
463 
464  private:
469 
477  double rt_window_;
478 
487 
493 
499 
505 
506  double tic_weight_;
507  double fwhm_weight_;
508  double snr_weight_;
517 
524 
530 
533 
536 
538 
548 
550  };
551 }
Compare functor scoring the spectral contrast angle for similarity measurement.
Definition: BinnedSpectralContrastAngle.h:59
This is a binned representation of a PeakSpectrum.
Definition: BinnedSpectrum.h:81
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:93
A container for features.
Definition: FeatureMap.h:106
In-Memory representation of a mass spectrometry run.
Definition: MSExperiment.h:73
The representation of a 1D spectrum.
Definition: MSSpectrum.h:70
Management and storage of parameters / INI files.
Definition: Param.h:70
A more convenient string class.
Definition: String.h:60
A description of a targeted experiment containing precursor and production ions.
Definition: TargetedExperiment.h:65
Definition: TargetedSpectraExtractor.h:113
std::vector< BinnedSpectrum > bs_library_
Definition: TargetedSpectraExtractor.h:138
void generateScores(const MSSpectrum &spec, std::vector< std::pair< Size, double >> &scores, double min_score) const override
Definition: TargetedSpectraExtractor.h:116
void init(const std::vector< MSSpectrum > &library, const std::map< String, DataValue > &options) override
BinnedSpectralContrastAngle cmp_bs_
Definition: TargetedSpectraExtractor.h:137
Definition: TargetedSpectraExtractor.h:89
std::vector< MSSpectrum > library_
Definition: TargetedSpectraExtractor.h:109
const std::vector< MSSpectrum > & getLibrary() const
Definition: TargetedSpectraExtractor.h:103
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:544
double snr_weight_
Definition: TargetedSpectraExtractor.h:508
double rt_window_
Definition: TargetedSpectraExtractor.h:477
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:506
bool deisotoping_use_deisotoper_
Definition: TargetedSpectraExtractor.h:539
double peak_height_max_
Definition: TargetedSpectraExtractor.h:498
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:468
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:529
double relative_allowable_product_mass_
Definition: TargetedSpectraExtractor.h:537
double peak_height_min_
Definition: TargetedSpectraExtractor.h:492
double fwhm_threshold_
Definition: TargetedSpectraExtractor.h:504
bool deisotoping_annotate_charge_
Definition: TargetedSpectraExtractor.h:547
double deisotoping_fragment_tolerance_
Definition: TargetedSpectraExtractor.h:540
bool use_gauss_
Definition: TargetedSpectraExtractor.h:523
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 in...
double max_fragment_mz_
Definition: TargetedSpectraExtractor.h:535
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:542
bool deisotoping_keep_only_deisotoped_
Definition: TargetedSpectraExtractor.h:546
double mz_tolerance_
Definition: TargetedSpectraExtractor.h:486
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.
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 storeSpectraTraML(const String &filename, const OpenMS::FeatureMap &ms1_features, const OpenMS::FeatureMap &ms2_features) const
store MS1 and the associated MS2 features
double max_precursor_mass_threashold_
Definition: TargetedSpectraExtractor.h:549
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:543
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:532
double fwhm_weight_
Definition: TargetedSpectraExtractor.h:507
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:534
int deisotoping_max_isopeaks_
Definition: TargetedSpectraExtractor.h:545
void storeSpectraMSP(const String &filename, MSExperiment &experiment) const
store spectra in MSP format
double min_select_score_
Definition: TargetedSpectraExtractor.h:516
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:541
void getDefaultParameters(Param &params) const
void searchSpectrum(OpenMS::FeatureMap &feat_map, OpenMS::FeatureMap &feat_map_output) const
Search accurate masses and add identification (peptide hits) as features/sub-features.
unsigned int UInt
Unsigned integer type.
Definition: Types.h:94
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
Definition: TargetedSpectraExtractor.h:81
Match(MSSpectrum a, double b)
Definition: TargetedSpectraExtractor.h:83
MSSpectrum spectrum
Definition: TargetedSpectraExtractor.h:84