OpenMS
SpectrumMetaDataLookup.h
Go to the documentation of this file.
1 // Copyright (c) 2002-2023, The OpenMS Team -- EKU Tuebingen, ETH Zurich, and FU Berlin
2 // SPDX-License-Identifier: BSD-3-Clause
3 //
4 // --------------------------------------------------------------------------
5 // $Maintainer: Hendrik Weisser $
6 // $Authors: Hendrik Weisser $
7 // --------------------------------------------------------------------------
8 
9 #pragma once
10 
12 
17 
18 #include <limits> // for "quiet_NaN"
19 
20 namespace OpenMS
21 {
22 
116  class OPENMS_DLLAPI SpectrumMetaDataLookup: public SpectrumLookup
117  {
118  public:
119 
121  typedef unsigned char MetaDataFlags;
122 
125  static const MetaDataFlags MDF_RT = 1;
126  static const MetaDataFlags MDF_PRECURSORRT = 2;
127  static const MetaDataFlags MDF_PRECURSORMZ = 4;
128  static const MetaDataFlags MDF_PRECURSORCHARGE = 8;
129  static const MetaDataFlags MDF_MSLEVEL = 16;
130  static const MetaDataFlags MDF_SCANNUMBER = 32;
131  static const MetaDataFlags MDF_NATIVEID = 64;
132  static const MetaDataFlags MDF_ALL = 127;
133 
134 
137  {
138  double rt;
139  double precursor_rt;
140  double precursor_mz;
145 
148  rt(std::numeric_limits<double>::quiet_NaN()),
149  precursor_rt(std::numeric_limits<double>::quiet_NaN()),
150  precursor_mz(std::numeric_limits<double>::quiet_NaN()),
151  precursor_charge(0), ms_level(0), scan_number(-1), native_id("")
152  {
153  }
154 
156  SpectrumMetaData(const SpectrumMetaData &) = default;
160  ~SpectrumMetaData() = default;
161 
166  };
167 
170  {}
171 
174 
185  template <typename SpectrumContainer>
186  void readSpectra(const SpectrumContainer& spectra,
187  const String& scan_regexp = default_scan_regexp,
188  bool get_precursor_rt = false)
189  {
190  // If class SpectrumContainer is e.g. OnDiscMSExperiment, reading each
191  // spectrum is expensive. Thus, to avoid iterating over all spectra twice,
192  // we do not call "SpectrumLookup::readSpectra" here:
193  n_spectra_ = spectra.size();
194  metadata_.reserve(n_spectra_);
195  setScanRegExp_(scan_regexp);
196  // mapping: MS level -> RT of previous spectrum of that level
197  std::map<Size, double> precursor_rts;
198  for (Size i = 0; i < n_spectra_; ++i)
199  {
200  const MSSpectrum& spectrum = spectra[i];
201  SpectrumMetaData meta;
202  getSpectrumMetaData(spectrum, meta, scan_regexp_, precursor_rts);
203  if (get_precursor_rt) precursor_rts[meta.ms_level] = meta.rt;
204  addEntry_(i, meta.rt, meta.scan_number, meta.native_id);
205  metadata_.push_back(meta);
206  }
207  }
208 
209 
215  void setSpectraDataRef(const String& spectra_data)
216  {
217  this->spectra_data_ref = spectra_data;
218  }
219 
220 
227  void getSpectrumMetaData(Size index, SpectrumMetaData& meta) const;
228 
239  static void getSpectrumMetaData(
240  const MSSpectrum& spectrum, SpectrumMetaData& meta,
241  const boost::regex& scan_regexp = boost::regex(),
242  const std::map<Size, double>& precursor_rts = (std::map<Size, double>()));
243 
255  void getSpectrumMetaData(const String& spectrum_ref, SpectrumMetaData& meta,
256  MetaDataFlags flags = MDF_ALL) const;
257 
269  static bool addMissingRTsToPeptideIDs(std::vector<PeptideIdentification>& peptides, const String &filename,
270  bool stop_on_error = false);
271 
286  static bool addMissingSpectrumReferences(std::vector<PeptideIdentification>& peptides,
287  const String& filename,
288  bool stop_on_error = false,
289  bool override_spectra_data = false,
290  bool override_spectra_references = false,
291  std::vector<ProteinIdentification> proteins = std::vector<ProteinIdentification>());
292 
293  protected:
294 
295  std::vector<SpectrumMetaData> metadata_;
297 
298  private:
299 
302 
305 
306  };
307 
308 } //namespace OpenMS
309 
The representation of a 1D spectrum.
Definition: MSSpectrum.h:44
Helper class for looking up spectra based on different attributes.
Definition: SpectrumLookup.h:42
Helper class for looking up spectrum meta data.
Definition: SpectrumMetaDataLookup.h:117
SpectrumMetaDataLookup()
Constructor.
Definition: SpectrumMetaDataLookup.h:169
void getSpectrumMetaData(Size index, SpectrumMetaData &meta) const
Look up meta data of a spectrum.
SpectrumMetaDataLookup & operator=(const SpectrumMetaDataLookup &)
Assignment operator (not implemented)
void readSpectra(const SpectrumContainer &spectra, const String &scan_regexp=default_scan_regexp, bool get_precursor_rt=false)
Read spectra and store their meta data.
Definition: SpectrumMetaDataLookup.h:186
static bool addMissingSpectrumReferences(std::vector< PeptideIdentification > &peptides, const String &filename, bool stop_on_error=false, bool override_spectra_data=false, bool override_spectra_references=false, std::vector< ProteinIdentification > proteins=std::vector< ProteinIdentification >())
Add missing "spectrum_reference"s to peptide identifications based on raw data.
~SpectrumMetaDataLookup() override
Destructor.
Definition: SpectrumMetaDataLookup.h:173
std::vector< SpectrumMetaData > metadata_
Meta data for spectra.
Definition: SpectrumMetaDataLookup.h:295
static void getSpectrumMetaData(const MSSpectrum &spectrum, SpectrumMetaData &meta, const boost::regex &scan_regexp=boost::regex(), const std::map< Size, double > &precursor_rts=(std::map< Size, double >()))
Extract meta data from a spectrum.
unsigned char MetaDataFlags
Bit mask for which meta data to extract from a spectrum.
Definition: SpectrumMetaDataLookup.h:121
static bool addMissingRTsToPeptideIDs(std::vector< PeptideIdentification > &peptides, const String &filename, bool stop_on_error=false)
Add missing retention time values to peptide identifications based on raw data.
void setSpectraDataRef(const String &spectra_data)
set spectra_data from read SpectrumContainer origin (i.e. filename)
Definition: SpectrumMetaDataLookup.h:215
void getSpectrumMetaData(const String &spectrum_ref, SpectrumMetaData &meta, MetaDataFlags flags=MDF_ALL) const
Extract meta data via a spectrum reference.
SpectrumMetaDataLookup(const SpectrumMetaDataLookup &)
Copy constructor (not implemented)
String spectra_data_ref
Definition: SpectrumMetaDataLookup.h:296
A more convenient string class.
Definition: String.h:34
int Int
Signed integer type.
Definition: Types.h:76
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:101
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:22
Meta data of a spectrum.
Definition: SpectrumMetaDataLookup.h:137
Int scan_number
Scan number.
Definition: SpectrumMetaDataLookup.h:143
double precursor_rt
Precursor retention time.
Definition: SpectrumMetaDataLookup.h:139
SpectrumMetaData(const SpectrumMetaData &)=default
Copy constructor.
Int precursor_charge
Precursor charge.
Definition: SpectrumMetaDataLookup.h:141
SpectrumMetaData & operator=(const SpectrumMetaData &)=default
Assignment operator.
String native_id
Native ID.
Definition: SpectrumMetaDataLookup.h:144
SpectrumMetaData(SpectrumMetaData &&)=default
Move constructor.
SpectrumMetaData()
Constructor.
Definition: SpectrumMetaDataLookup.h:147
Size ms_level
MS level.
Definition: SpectrumMetaDataLookup.h:142
SpectrumMetaData & operator=(SpectrumMetaData &&) &=default
Move assignment operator.
double rt
Retention time.
Definition: SpectrumMetaDataLookup.h:138
double precursor_mz
Precursor mass-to-charge ratio.
Definition: SpectrumMetaDataLookup.h:140