OpenMS  2.4.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-2018.
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  virtual ~TargetedSpectraExtractor() = default;
75 
80  struct Match
81  {
82  Match() = default;
83  Match(MSSpectrum a, double b) : spectrum(a), score(b) {}
85  double score;
86  };
87 
88  class Comparator
89  {
90  public:
91  virtual void generateScores(
92  const MSSpectrum& spec,
93  std::vector<std::pair<Size,double>>& scores,
94  double min_score
95  ) const = 0;
96 
97  virtual void init(
98  const std::vector<MSSpectrum>& library,
99  const std::map<String,DataValue>& options
100  ) = 0;
101 
102  const std::vector<MSSpectrum>& getLibrary() const
103  {
104  return library_;
105  }
106 
107  protected:
108  std::vector<MSSpectrum> library_;
109  };
110 
112  {
113  public:
115  const MSSpectrum& spec,
116  std::vector<std::pair<Size,double>>& scores,
117  double min_score
118  ) const
119  {
120  scores.clear();
121  const BinnedSpectrum in_bs(spec, bin_size_, false, peak_spread_, bin_offset_);
122  for (Size i = 0; i < bs_library_.size(); ++i)
123  {
124  const double cmp_score = cmp_bs_(in_bs, bs_library_[i]);
125  if (cmp_score >= min_score)
126  {
127  scores.emplace_back(i, cmp_score);
128  }
129  }
130  }
131 
132  void init(const std::vector<MSSpectrum>& library, const std::map<String,DataValue>& options)
133  {
134  if (options.count("bin_size"))
135  {
136  bin_size_ = options.at("bin_size");
137  }
138  if (options.count("peak_spread"))
139  {
140  peak_spread_ = options.at("peak_spread");
141  }
142  if (options.count("bin_offset"))
143  {
144  bin_offset_ = options.at("bin_offset");
145  }
146  library_ = library;
147  bs_library_.clear();
148  for (const MSSpectrum& s : library_)
149  {
150  bs_library_.emplace_back(s, bin_size_, false, peak_spread_, bin_offset_);
151  }
152  LOG_INFO << "The library contains " << bs_library_.size() << " spectra." << std::endl;
153  }
154  private:
156  std::vector<BinnedSpectrum> bs_library_;
157  double bin_size_ = 1.0;
158  double peak_spread_ = 0.0;
159  double bin_offset_ = 0.4;
160  };
161 
162  void getDefaultParameters(Param& params) const;
163 
180  void annotateSpectra(
181  const std::vector<MSSpectrum>& spectra,
182  const TargetedExperiment& targeted_exp,
183  std::vector<MSSpectrum>& annotated_spectra,
184  FeatureMap& features,
185  const bool compute_features = true
186  ) const;
187 
202  void annotateSpectra(
203  const std::vector<MSSpectrum>& spectra,
204  const TargetedExperiment& targeted_exp,
205  std::vector<MSSpectrum>& annotated_spectra
206  ) const;
207 
225  void pickSpectrum(const MSSpectrum& spectrum, MSSpectrum& picked_spectrum) const;
226 
245  void scoreSpectra(
246  const std::vector<MSSpectrum>& annotated_spectra,
247  const std::vector<MSSpectrum>& picked_spectra,
248  FeatureMap& features,
249  std::vector<MSSpectrum>& scored_spectra,
250  const bool compute_features = true
251  ) const;
252 
266  void scoreSpectra(
267  const std::vector<MSSpectrum>& annotated_spectra,
268  const std::vector<MSSpectrum>& picked_spectra,
269  std::vector<MSSpectrum>& scored_spectra
270  ) const;
271 
284  void selectSpectra(
285  const std::vector<MSSpectrum>& scored_spectra,
286  const FeatureMap& features,
287  std::vector<MSSpectrum>& selected_spectra,
288  FeatureMap& selected_features,
289  const bool compute_features = true
290  ) const;
291 
299  void selectSpectra(
300  const std::vector<MSSpectrum>& scored_spectra,
301  std::vector<MSSpectrum>& selected_spectra
302  ) const;
303 
320  void extractSpectra(
321  const MSExperiment& experiment,
322  const TargetedExperiment& targeted_exp,
323  std::vector<MSSpectrum>& extracted_spectra,
324  FeatureMap& extracted_features,
325  const bool compute_features = true
326  ) const;
327 
341  void extractSpectra(
342  const MSExperiment& experiment,
343  const TargetedExperiment& targeted_exp,
344  std::vector<MSSpectrum>& extracted_spectra
345  ) const;
346 
355  void matchSpectrum(
356  const MSSpectrum& input_spectrum,
357  const Comparator& cmp,
358  std::vector<Match>& matches
359  );
360 
383  void targetedMatching(
384  const std::vector<MSSpectrum>& spectra,
385  const Comparator& cmp,
386  FeatureMap& features
387  );
388 
410  void untargetedMatching(
411  const std::vector<MSSpectrum>& spectra,
412  const Comparator& cmp,
413  FeatureMap& features
414  );
415 
416 protected:
418  void updateMembers_();
419 
420 private:
425 
433  double rt_window_;
434 
443 
449 
455 
461 
462  double tic_weight_;
463  double fwhm_weight_;
464  double snr_weight_;
473 
480 
486 
489  };
490 }
void generateScores(const MSSpectrum &spec, std::vector< std::pair< Size, double >> &scores, double min_score) const
Definition: TargetedSpectraExtractor.h:114
std::vector< BinnedSpectrum > bs_library_
Definition: TargetedSpectraExtractor.h:156
void init(const std::vector< MSSpectrum > &library, const std::map< String, DataValue > &options)
Definition: TargetedSpectraExtractor.h:132
#define LOG_INFO
Macro if a information, e.g. a status should be reported.
Definition: LogStream.h:454
Definition: TargetedSpectraExtractor.h:111
A container for features.
Definition: FeatureMap.h:93
double peak_height_min_
Definition: TargetedSpectraExtractor.h:448
double mz_tolerance_
Definition: TargetedSpectraExtractor.h:442
BinnedSpectralContrastAngle cmp_bs_
Definition: TargetedSpectraExtractor.h:155
This class filters, annotates, picks, and scores spectra (e.g., taken from a DDA experiment) based on...
Definition: TargetedSpectraExtractor.h:69
Size top_matches_to_report_
Definition: TargetedSpectraExtractor.h:485
double score
Definition: TargetedSpectraExtractor.h:85
double fwhm_threshold_
Definition: TargetedSpectraExtractor.h:460
double snr_weight_
Definition: TargetedSpectraExtractor.h:464
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
double rt_window_
Definition: TargetedSpectraExtractor.h:433
double min_select_score_
Definition: TargetedSpectraExtractor.h:472
The representation of a 1D spectrum.
Definition: MSSpectrum.h:66
double tic_weight_
Definition: TargetedSpectraExtractor.h:462
bool mz_unit_is_Da_
Definition: TargetedSpectraExtractor.h:424
const std::vector< MSSpectrum > & getLibrary() const
Definition: TargetedSpectraExtractor.h:102
Definition: TargetedSpectraExtractor.h:88
This is a binned representation of a PeakSpectrum.
Definition: BinnedSpectrum.h:75
Compare functor scoring the spectral contrast angle for similarity measurement.
Definition: BinnedSpectralContrastAngle.h:57
Management and storage of parameters / INI files.
Definition: Param.h:74
bool use_gauss_
Definition: TargetedSpectraExtractor.h:479
In-Memory representation of a mass spectrometry experiment.
Definition: MSExperiment.h:77
Definition: TargetedSpectraExtractor.h:80
double peak_height_max_
Definition: TargetedSpectraExtractor.h:454
double fwhm_weight_
Definition: TargetedSpectraExtractor.h:463
MSSpectrum spectrum
Definition: TargetedSpectraExtractor.h:84
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
A description of a targeted experiment containing precursor and production ions.
Definition: TargetedExperiment.h:64
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:91
std::vector< MSSpectrum > library_
Definition: TargetedSpectraExtractor.h:108
Match(MSSpectrum a, double b)
Definition: TargetedSpectraExtractor.h:83
double min_match_score_
Minimum score for a match to be considered valid in `matchSpectrum()`.
Definition: TargetedSpectraExtractor.h:488