OpenMS  2.8.0
SpectrumMetaDataLookup.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: Hendrik Weisser $
32 // $Authors: Hendrik Weisser $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
38 
43 
44 #include <limits> // for "quiet_NaN"
45 
46 namespace OpenMS
47 {
48 
142  class OPENMS_DLLAPI SpectrumMetaDataLookup: public SpectrumLookup
143  {
144  public:
145 
147  typedef unsigned char MetaDataFlags;
148 
151  static const MetaDataFlags MDF_RT = 1;
152  static const MetaDataFlags MDF_PRECURSORRT = 2;
153  static const MetaDataFlags MDF_PRECURSORMZ = 4;
154  static const MetaDataFlags MDF_PRECURSORCHARGE = 8;
155  static const MetaDataFlags MDF_MSLEVEL = 16;
156  static const MetaDataFlags MDF_SCANNUMBER = 32;
157  static const MetaDataFlags MDF_NATIVEID = 64;
158  static const MetaDataFlags MDF_ALL = 127;
159 
160 
163  {
164  double rt;
165  double precursor_rt;
166  double precursor_mz;
171 
174  rt(std::numeric_limits<double>::quiet_NaN()),
175  precursor_rt(std::numeric_limits<double>::quiet_NaN()),
176  precursor_mz(std::numeric_limits<double>::quiet_NaN()),
177  precursor_charge(0), ms_level(0), scan_number(-1), native_id("")
178  {
179  }
180 
182  SpectrumMetaData(const SpectrumMetaData &) = default;
186  ~SpectrumMetaData() = default;
187 
192  };
193 
196  {}
197 
200 
211  template <typename SpectrumContainer>
212  void readSpectra(const SpectrumContainer& spectra,
213  const String& scan_regexp = default_scan_regexp,
214  bool get_precursor_rt = false)
215  {
216  // If class SpectrumContainer is e.g. OnDiscMSExperiment, reading each
217  // spectrum is expensive. Thus, to avoid iterating over all spectra twice,
218  // we do not call "SpectrumLookup::readSpectra" here:
219  n_spectra_ = spectra.size();
220  metadata_.reserve(n_spectra_);
221  setScanRegExp_(scan_regexp);
222  // mapping: MS level -> RT of previous spectrum of that level
223  std::map<Size, double> precursor_rts;
224  for (Size i = 0; i < n_spectra_; ++i)
225  {
226  const MSSpectrum& spectrum = spectra[i];
227  SpectrumMetaData meta;
228  getSpectrumMetaData(spectrum, meta, scan_regexp_, precursor_rts);
229  if (get_precursor_rt) precursor_rts[meta.ms_level] = meta.rt;
230  addEntry_(i, meta.rt, meta.scan_number, meta.native_id);
231  metadata_.push_back(meta);
232  }
233  }
234 
235 
241  void setSpectraDataRef(const String& spectra_data)
242  {
243  this->spectra_data_ref = spectra_data;
244  }
245 
246 
253  void getSpectrumMetaData(Size index, SpectrumMetaData& meta) const;
254 
265  static void getSpectrumMetaData(
266  const MSSpectrum& spectrum, SpectrumMetaData& meta,
267  const boost::regex& scan_regexp = boost::regex(),
268  const std::map<Size, double>& precursor_rts = (std::map<Size, double>()));
269 
281  void getSpectrumMetaData(const String& spectrum_ref, SpectrumMetaData& meta,
282  MetaDataFlags flags = MDF_ALL) const;
283 
295  static bool addMissingRTsToPeptideIDs(std::vector<PeptideIdentification>& peptides, const String &filename,
296  bool stop_on_error = false);
297 
312  static bool addMissingSpectrumReferences(std::vector<PeptideIdentification>& peptides,
313  const String& filename,
314  bool stop_on_error = false,
315  bool override_spectra_data = false,
316  bool override_spectra_references = false,
317  std::vector<ProteinIdentification> proteins = std::vector<ProteinIdentification>());
318 
319  protected:
320 
321  std::vector<SpectrumMetaData> metadata_;
323 
324  private:
325 
328 
331 
332  };
333 
334 } //namespace OpenMS
335 
The representation of a 1D spectrum.
Definition: MSSpectrum.h:70
Helper class for looking up spectra based on different attributes.
Definition: SpectrumLookup.h:68
Helper class for looking up spectrum meta data.
Definition: SpectrumMetaDataLookup.h:143
SpectrumMetaDataLookup()
Constructor.
Definition: SpectrumMetaDataLookup.h:195
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:212
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:199
std::vector< SpectrumMetaData > metadata_
Meta data for spectra.
Definition: SpectrumMetaDataLookup.h:321
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:147
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:241
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:322
A more convenient string class.
Definition: String.h:60
int Int
Signed integer type.
Definition: Types.h:102
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
Meta data of a spectrum.
Definition: SpectrumMetaDataLookup.h:163
Int scan_number
Scan number.
Definition: SpectrumMetaDataLookup.h:169
double precursor_rt
Precursor retention time.
Definition: SpectrumMetaDataLookup.h:165
SpectrumMetaData(const SpectrumMetaData &)=default
Copy constructor.
Int precursor_charge
Precursor charge.
Definition: SpectrumMetaDataLookup.h:167
SpectrumMetaData & operator=(const SpectrumMetaData &)=default
Assignment operator.
String native_id
Native ID.
Definition: SpectrumMetaDataLookup.h:170
SpectrumMetaData(SpectrumMetaData &&)=default
Move constructor.
SpectrumMetaData()
Constructor.
Definition: SpectrumMetaDataLookup.h:173
Size ms_level
MS level.
Definition: SpectrumMetaDataLookup.h:168
SpectrumMetaData & operator=(SpectrumMetaData &&) &=default
Move assignment operator.
double rt
Retention time.
Definition: SpectrumMetaDataLookup.h:164
double precursor_mz
Precursor mass-to-charge ratio.
Definition: SpectrumMetaDataLookup.h:166