OpenMS  3.0.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-2022.
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 
162  void annotateSpectra(
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 
184  void annotateSpectra(
185  const std::vector<MSSpectrum>& spectra,
186  const TargetedExperiment& targeted_exp,
187  std::vector<MSSpectrum>& annotated_spectra
188  ) const;
189 
202  void annotateSpectra(
203  const std::vector<MSSpectrum>& spectra,
204  const FeatureMap& ms1_features,
205  FeatureMap& ms2_features,
206  std::vector<MSSpectrum>& annotated_spectra) const;
207 
215  void searchSpectrum(
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 
257  void scoreSpectra(
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 
278  void scoreSpectra(
279  const std::vector<MSSpectrum>& annotated_spectra,
280  const std::vector<MSSpectrum>& picked_spectra,
281  std::vector<MSSpectrum>& scored_spectra
282  ) const;
283 
296  void selectSpectra(
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 
311  void selectSpectra(
312  const std::vector<MSSpectrum>& scored_spectra,
313  std::vector<MSSpectrum>& selected_spectra
314  ) const;
315 
332  void extractSpectra(
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 
353  void extractSpectra(
354  const MSExperiment& experiment,
355  const TargetedExperiment& targeted_exp,
356  std::vector<MSSpectrum>& extracted_spectra
357  ) const;
358 
373  void extractSpectra(
374  const MSExperiment& experiment,
375  const FeatureMap& ms1_features,
376  std::vector<MSSpectrum>& extracted_spectra
377  ) const;
378 
394  void extractSpectra(
395  const MSExperiment& experiment,
396  const FeatureMap& ms1_features,
397  std::vector<MSSpectrum>& extracted_spectra,
398  FeatureMap& extracted_features
399  ) const;
400 
409  void matchSpectrum(
410  const MSSpectrum& input_spectrum,
411  const Comparator& cmp,
412  std::vector<Match>& matches
413  ) const;
414 
437  void targetedMatching(
438  const std::vector<MSSpectrum>& spectra,
439  const Comparator& cmp,
440  FeatureMap& features
441  );
442 
464  void untargetedMatching(
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 
495 protected:
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:
525  void extractSpectra(
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 
546  double rt_window_;
547 
556 
562 
568 
574 
575  double tic_weight_;
576  double fwhm_weight_;
577  double snr_weight_;
586 
593 
599 
602 
605 
607 
617 
619  };
620 }
DefaultParamHandler.h
OpenMS::TargetedSpectraExtractor::use_gauss_
bool use_gauss_
Definition: TargetedSpectraExtractor.h:592
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:575
OpenMS::TargetedSpectraExtractor::deisotoping_min_charge_
int deisotoping_min_charge_
Definition: TargetedSpectraExtractor.h:611
OpenMS::TransitionTSVFile
This class supports reading and writing of OpenSWATH transition lists.
Definition: TransitionTSVFile.h:144
OpenMS::TOPPBase
Base class for TOPP applications.
Definition: TOPPBase.h:147
OpenMS::TransitionPQPFile
This class supports reading and writing of PQP files.
Definition: TransitionPQPFile.h:215
TargetedExperiment.h
FileHandler.h
OpenMS::TargetedSpectraExtractor::peak_height_max_
double peak_height_max_
Definition: TargetedSpectraExtractor.h:567
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:537
OpenMS::TargetedSpectraExtractor::fwhm_weight_
double fwhm_weight_
Definition: TargetedSpectraExtractor.h:576
OpenMS::TargetedSpectraExtractor::deisotoping_max_isopeaks_
int deisotoping_max_isopeaks_
Definition: TargetedSpectraExtractor.h:614
OpenMS::BinnedSpectrum
This is a binned representation of a PeakSpectrum.
Definition: BinnedSpectrum.h:80
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
SpectraST MRM List.
Definition: FileTypes.h:100
OpenMS::TargetedSpectraExtractor::max_fragment_mz_
double max_fragment_mz_
Definition: TargetedSpectraExtractor.h:604
OpenMS::String
A more convenient string class.
Definition: String.h:58
OpenMS::TargetedSpectraExtractor::BinnedSpectrumComparator::generateScores
void generateScores(const MSSpectrum &spec, std::vector< std::pair< Size, double >> &scores, double min_score) const override
Definition: TargetedSpectraExtractor.h:116
OpenMS::MSExperiment
In-Memory representation of a mass spectrometry run.
Definition: MSExperiment.h:70
OpenMS::Size
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
OpenMS::TraMLFile::load
void load(const String &filename, TargetedExperiment &id)
Loads a map from a TraML file.
OpenMS::FileTypes::TSV
any TSV file, for example msInspect file or OpenSWATH transition file (see TransitionTSVFile)
Definition: FileTypes.h:86
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:601
BinnedSpectrum.h
OpenMS::FileTypes::UNKNOWN
Unknown file extension.
Definition: FileTypes.h:58
OpenMS::TargetedSpectraExtractor::deisotoping_keep_only_deisotoped_
bool deisotoping_keep_only_deisotoped_
Definition: TargetedSpectraExtractor.h:615
OpenMS::TargetedSpectraExtractor::deisotoping_fragment_unit_
std::string deisotoping_fragment_unit_
Definition: TargetedSpectraExtractor.h:610
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:92
OpenMS::TargetedSpectraExtractor::relative_allowable_product_mass_
double relative_allowable_product_mass_
Definition: TargetedSpectraExtractor.h:606
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
OpenMS::TraMLFile
File adapter for HUPO PSI TraML files.
Definition: TraMLFile.h:63
OpenMS::TargetedSpectraExtractor::Comparator::library_
std::vector< MSSpectrum > library_
Definition: TargetedSpectraExtractor.h:109
Exception.h
OpenMS::TargetedSpectraExtractor::deisotoping_min_isopeaks_
int deisotoping_min_isopeaks_
Definition: TargetedSpectraExtractor.h:613
OpenMS::TargetedSpectraExtractor::Comparator
Definition: TargetedSpectraExtractor.h:88
ProgressLogger.h
OpenMS::TargetedSpectraExtractor::Comparator::getLibrary
const std::vector< MSSpectrum > & getLibrary() const
Definition: TargetedSpectraExtractor.h:103
OpenMS::FileHandler
Facilitates file handling by file type recognition.
Definition: FileHandler.h:66
OpenMS::TargetedSpectraExtractor::max_precursor_mass_threashold_
double max_precursor_mass_threashold_
Definition: TargetedSpectraExtractor.h:618
FeatureMap.h
OpenMS::TargetedSpectraExtractor::deisotoping_max_charge_
int deisotoping_max_charge_
Definition: TargetedSpectraExtractor.h:612
OpenMS::FileTypes::Type
Type
Actual file types enum.
Definition: FileTypes.h:56
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:555
OpenMS::DefaultParamHandler::setParameters
void setParameters(const Param &param)
Sets the parameters.
OpenMS::TargetedSpectraExtractor::BinnedSpectrumComparator::bs_library_
std::vector< BinnedSpectrum > bs_library_
Definition: TargetedSpectraExtractor.h:138
OpenMS::DefaultParamHandler::getDefaults
const Param & getDefaults() const
Non-mutable access to the default parameters.
OpenMS::TargetedSpectraExtractor::BinnedSpectrumComparator
Definition: TargetedSpectraExtractor.h:112
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::StringList
std::vector< String > StringList
Vector of String.
Definition: ListUtils.h:70
OpenMS::UInt
unsigned int UInt
Unsigned integer type.
Definition: Types.h:94
OpenMS::TargetedSpectraExtractor::min_fragment_mz_
double min_fragment_mz_
Definition: TargetedSpectraExtractor.h:603
OpenMS::TargetedSpectraExtractor::deisotoping_use_deisotoper_
bool deisotoping_use_deisotoper_
Definition: TargetedSpectraExtractor.h:608
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:71
OpenMS::TargetedSpectraExtractor::deisotoping_fragment_tolerance_
double deisotoping_fragment_tolerance_
Definition: TargetedSpectraExtractor.h:609
MSExperiment.h
OpenMS::FeatureMap
A container for features.
Definition: FeatureMap.h:98
OpenMS::FileTypes::PQP
OpenSWATH Peptide Query Parameter (PQP) SQLite DB, see TransitionPQPFile.
Definition: FileTypes.h:102
OpenMS::Param::copy
Param copy(const std::string &prefix, bool remove_prefix=false) const
Returns a new Param object containing all entries that start with prefix.
OpenMS::TargetedSpectraExtractor::deisotoping_annotate_charge_
bool deisotoping_annotate_charge_
Definition: TargetedSpectraExtractor.h:616
OpenMS::TargetedSpectraExtractor::rt_window_
double rt_window_
Definition: TargetedSpectraExtractor.h:546
OpenMS::FileTypes::nameToType
static Type nameToType(const String &name)
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 (HUPO PSI format) for transitions (.traML)
Definition: FileTypes.h:80
OpenMS::TargetedSpectraExtractor::top_matches_to_report_
Size top_matches_to_report_
Definition: TargetedSpectraExtractor.h:598
OpenMS::Param
Management and storage of parameters / INI files.
Definition: Param.h:69
OpenMS::TargetedSpectraExtractor::peak_height_min_
double peak_height_min_
Definition: TargetedSpectraExtractor.h:561
OpenMS::TargetedSpectraExtractor::snr_weight_
double snr_weight_
Definition: TargetedSpectraExtractor.h:577
OpenMS::TargetedSpectraExtractor::Match::spectrum
MSSpectrum spectrum
Definition: TargetedSpectraExtractor.h:84
OpenMS::TargetedSpectraExtractor::fwhm_threshold_
double fwhm_threshold_
Definition: TargetedSpectraExtractor.h:573
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::min_select_score_
double min_select_score_
Definition: TargetedSpectraExtractor.h:585
OpenMS::TargetedSpectraExtractor::BinnedSpectrumComparator::cmp_bs_
BinnedSpectralContrastAngle cmp_bs_
Definition: TargetedSpectraExtractor.h:137
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.