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 }
DefaultParamHandler.h
OpenMS::TargetedSpectraExtractor::use_gauss_
bool use_gauss_
Definition: TargetedSpectraExtractor.h:479
OpenMS::TransitionTSVFile::validateTargetedExperiment
void validateTargetedExperiment(const OpenMS::TargetedExperiment &targeted_exp)
Validate a TargetedExperiment (check that all ids are unique)
OpenMS::TargetedSpectraExtractor::tic_weight_
double tic_weight_
Definition: TargetedSpectraExtractor.h:462
OpenMS::TransitionTSVFile
This class supports reading and writing of OpenSWATH transition lists.
Definition: TransitionTSVFile.h:142
OpenMS::TOPPBase
Base class for TOPP applications.
Definition: TOPPBase.h:150
OpenMS::TransitionPQPFile
This class supports reading and writing of PQP files.
Definition: TransitionPQPFile.h:57
TargetedExperiment.h
OpenMS::Param::copy
Param copy(const String &prefix, bool remove_prefix=false) const
Returns a new Param object containing all entries that start with prefix.
FileHandler.h
OpenMS::TargetedSpectraExtractor::peak_height_max_
double peak_height_max_
Definition: TargetedSpectraExtractor.h:454
FileTypes.h
OpenMS::TraMLFile::store
void store(const String &filename, const TargetedExperiment &id) const
Stores a map in a TraML file.
BinnedSpectralContrastAngle.h
OpenMS::TargetedSpectraExtractor::Match::Match
Match(MSSpectrum a, double b)
Definition: TargetedSpectraExtractor.h:83
TransitionTSVFile.h
OpenMS::TargetedSpectraExtractor::mz_unit_is_Da_
bool mz_unit_is_Da_
Definition: TargetedSpectraExtractor.h:424
OpenMS::TargetedSpectraExtractor::fwhm_weight_
double fwhm_weight_
Definition: TargetedSpectraExtractor.h:463
OpenMS::BinnedSpectrum
This is a binned representation of a PeakSpectrum.
Definition: BinnedSpectrum.h:75
OpenMS::FileHandler::getTypeByFileName
static FileTypes::Type getTypeByFileName(const String &filename)
Determines the file type from a file name.
OpenMS::TargetedSpectraExtractor::Match
Definition: TargetedSpectraExtractor.h:80
OpenMS::FileTypes::MRM
@ MRM
SpectraST MRM List.
Definition: FileTypes.h:102
OpenMS::String
A more convenient string class.
Definition: String.h:57
OpenMS::MSExperiment
In-Memory representation of a mass spectrometry experiment.
Definition: MSExperiment.h:77
OpenMS::TargetedSpectraExtractor::Match::score
double score
Definition: TargetedSpectraExtractor.h:85
OpenMS::Size
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
LOG_INFO
#define LOG_INFO
Macro if a information, e.g. a status should be reported.
Definition: LogStream.h:454
OpenMS::TraMLFile::load
void load(const String &filename, TargetedExperiment &id)
Loads a map from a TraML file.
OpenMS::FileTypes::TSV
@ TSV
msInspect file (.tsv)
Definition: FileTypes.h:87
OpenMS::TransitionTSVFile::convertTargetedExperimentToTSV
void convertTargetedExperimentToTSV(const char *filename, OpenMS::TargetedExperiment &targeted_exp)
Write out a targeted experiment (TraML structure) into a tsv file.
OpenMS::TargetedSpectraExtractor::min_match_score_
double min_match_score_
Minimum score for a match to be considered valid in `matchSpectrum()`.
Definition: TargetedSpectraExtractor.h:488
BinnedSpectrum.h
OpenMS::FileTypes::UNKNOWN
@ UNKNOWN
Unknown file extension.
Definition: FileTypes.h:60
OpenMS::TargetedSpectraExtractor
This class filters, annotates, picks, and scores spectra (e.g., taken from a DDA experiment) based on...
Definition: TargetedSpectraExtractor.h:69
ListUtils.h
OpenMS::DefaultParamHandler
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:91
OpenMS::TargetedSpectraExtractor::BinnedSpectrumComparator::init
void init(const std::vector< MSSpectrum > &library, const std::map< String, DataValue > &options)
Definition: TargetedSpectraExtractor.h:132
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
OpenMS::TraMLFile
File adapter for HUPO PSI TraML files.
Definition: TraMLFile.h:63
OpenMS::TargetedSpectraExtractor::Comparator::library_
std::vector< MSSpectrum > library_
Definition: TargetedSpectraExtractor.h:108
Exception.h
OpenMS::TargetedSpectraExtractor::Comparator
Definition: TargetedSpectraExtractor.h:88
ProgressLogger.h
OpenMS::TargetedSpectraExtractor::Comparator::getLibrary
const std::vector< MSSpectrum > & getLibrary() const
Definition: TargetedSpectraExtractor.h:102
OpenMS::FileHandler
Facilitates file handling by file type recognition.
Definition: FileHandler.h:62
FeatureMap.h
OpenMS::FileTypes::Type
Type
Actual file types enum.
Definition: FileTypes.h:58
OpenMS::FileHandler::getType
static FileTypes::Type getType(const String &filename)
Tries to determine the file type (by name or content)
OpenMS::TargetedSpectraExtractor::mz_tolerance_
double mz_tolerance_
Definition: TargetedSpectraExtractor.h:442
OpenMS::DefaultParamHandler::setParameters
void setParameters(const Param &param)
Sets the parameters.
OpenMS::TargetedSpectraExtractor::BinnedSpectrumComparator::bs_library_
std::vector< BinnedSpectrum > bs_library_
Definition: TargetedSpectraExtractor.h:156
OpenMS::DefaultParamHandler::getDefaults
const Param & getDefaults() const
Non-mutable access to the default parameters.
OpenMS::TargetedSpectraExtractor::BinnedSpectrumComparator
Definition: TargetedSpectraExtractor.h:111
OpenMS::TransitionPQPFile::convertPQPToTargetedExperiment
void convertPQPToTargetedExperiment(const char *filename, OpenMS::TargetedExperiment &targeted_exp, bool legacy_traml_id=false)
Read in a PQP file and construct a targeted experiment (TraML structure)
OpenMS::TransitionTSVFile::convertTSVToTargetedExperiment
void convertTSVToTargetedExperiment(const char *filename, FileTypes::Type filetype, OpenMS::TargetedExperiment &targeted_exp)
Read in a tsv/mrm file and construct a targeted experiment (TraML structure)
main
int main(int argc, const char **argv)
Definition: INIFileEditor.cpp:73
MSExperiment.h
OpenMS::FeatureMap
A container for features.
Definition: FeatureMap.h:93
OpenMS::FileTypes::PQP
@ PQP
OpenSWATH Peptide Query Parameter (PQP) SQLite DB.
Definition: FileTypes.h:104
OpenMS::TargetedSpectraExtractor::rt_window_
double rt_window_
Definition: TargetedSpectraExtractor.h:433
OpenMS::FileTypes::nameToType
static Type nameToType(const String &name)
Converts a file type name into a Type.
OpenMS::TransitionPQPFile::convertTargetedExperimentToPQP
void convertTargetedExperimentToPQP(const char *filename, OpenMS::TargetedExperiment &targeted_exp)
Write out a targeted experiment (TraML structure) into a PQP file.
OpenMS::FileTypes::TRAML
@ TRAML
TraML (HUPO PSI format) for transitions (.traML)
Definition: FileTypes.h:81
OpenMS::TargetedSpectraExtractor::top_matches_to_report_
Size top_matches_to_report_
Definition: TargetedSpectraExtractor.h:485
OpenMS::Param
Management and storage of parameters / INI files.
Definition: Param.h:74
OpenMS::TargetedSpectraExtractor::peak_height_min_
double peak_height_min_
Definition: TargetedSpectraExtractor.h:448
OpenMS::TargetedSpectraExtractor::snr_weight_
double snr_weight_
Definition: TargetedSpectraExtractor.h:464
OpenMS::TargetedSpectraExtractor::Match::spectrum
MSSpectrum spectrum
Definition: TargetedSpectraExtractor.h:84
OpenMS::TargetedSpectraExtractor::fwhm_threshold_
double fwhm_threshold_
Definition: TargetedSpectraExtractor.h:460
OpenMS::TargetedExperiment
A description of a targeted experiment containing precursor and production ions.
Definition: TargetedExperiment.h:64
TransitionPQPFile.h
OpenMS::BinnedSpectralContrastAngle
Compare functor scoring the spectral contrast angle for similarity measurement.
Definition: BinnedSpectralContrastAngle.h:57
OpenMS::MSSpectrum
The representation of a 1D spectrum.
Definition: MSSpectrum.h:66
TraMLFile.h
OpenMS::TargetedSpectraExtractor::BinnedSpectrumComparator::generateScores
void generateScores(const MSSpectrum &spec, std::vector< std::pair< Size, double >> &scores, double min_score) const
Definition: TargetedSpectraExtractor.h:114
OpenMS::TargetedSpectraExtractor::min_select_score_
double min_select_score_
Definition: TargetedSpectraExtractor.h:472
OpenMS::TargetedSpectraExtractor::BinnedSpectrumComparator::cmp_bs_
BinnedSpectralContrastAngle cmp_bs_
Definition: TargetedSpectraExtractor.h:155
OpenMS::ProgressLogger::setLogType
void setLogType(LogType type) const
Sets the progress log that should be used. The default type is NONE!
TOPPBase.h
OpenMS::FileTypes::typeToName
static String typeToName(Type type)
Returns the name/extension of the type.