OpenMS  2.4.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-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: 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 {
141  class OPENMS_DLLAPI SpectrumMetaDataLookup: public SpectrumLookup
142  {
143  public:
144 
146  typedef unsigned char MetaDataFlags;
147 
150  static const MetaDataFlags MDF_RT = 1;
151  static const MetaDataFlags MDF_PRECURSORRT = 2;
152  static const MetaDataFlags MDF_PRECURSORMZ = 4;
153  static const MetaDataFlags MDF_PRECURSORCHARGE = 8;
154  static const MetaDataFlags MDF_MSLEVEL = 16;
155  static const MetaDataFlags MDF_SCANNUMBER = 32;
156  static const MetaDataFlags MDF_NATIVEID = 64;
157  static const MetaDataFlags MDF_ALL = 127;
158 
159 
162  {
163  double rt;
164  double precursor_rt;
165  double precursor_mz;
170 
173  rt(std::numeric_limits<double>::quiet_NaN()),
174  precursor_rt(std::numeric_limits<double>::quiet_NaN()),
175  precursor_mz(std::numeric_limits<double>::quiet_NaN()),
176  precursor_charge(0), ms_level(0), scan_number(-1), native_id("")
177  {
178  }
179  };
180 
183  {}
184 
187 
199  template <typename SpectrumContainer>
200  void readSpectra(const SpectrumContainer& spectra,
201  const String& scan_regexp = default_scan_regexp,
202  bool get_precursor_rt = false)
203  {
204  // If class SpectrumContainer is e.g. OnDiscMSExperiment, reading each
205  // spectrum is expensive. Thus, to avoid iterating over all spectra twice,
206  // we do not call "SpectrumLookup::readSpectra" here:
207  n_spectra_ = spectra.size();
208  metadata_.reserve(n_spectra_);
209  setScanRegExp_(scan_regexp);
210  // mapping: MS level -> RT of previous spectrum of that level
211  std::map<Size, double> precursor_rts;
212  for (Size i = 0; i < n_spectra_; ++i)
213  {
214  const MSSpectrum& spectrum = spectra[i];
215  SpectrumMetaData meta;
216  getSpectrumMetaData(spectrum, meta, scan_regexp_, precursor_rts);
217  if (get_precursor_rt) precursor_rts[meta.ms_level] = meta.rt;
218  addEntry_(i, meta.rt, meta.scan_number, meta.native_id);
219  metadata_.push_back(meta);
220  }
221  }
222 
223 
229  void setSpectraDataRef(const String& spectra_data)
230  {
231  this->spectra_data_ref = spectra_data;
232  }
233 
234 
241  void getSpectrumMetaData(Size index, SpectrumMetaData& meta) const;
242 
253  static void getSpectrumMetaData(
254  const MSSpectrum& spectrum, SpectrumMetaData& meta,
255  const boost::regex& scan_regexp = boost::regex(),
256  const std::map<Size, double>& precursor_rts = (std::map<Size, double>()));
257 
269  void getSpectrumMetaData(const String& spectrum_ref, SpectrumMetaData& meta,
270  MetaDataFlags flags = MDF_ALL) const;
271 
283  static bool addMissingRTsToPeptideIDs(std::vector<PeptideIdentification>& peptides, const String &filename,
284  bool stop_on_error = false);
285 
299  static bool addMissingSpectrumReferences(std::vector<PeptideIdentification>& peptides, const String& filename,
300  bool stop_on_error = false, bool override_spectra_data = false, std::vector<ProteinIdentification> proteins = std::vector<ProteinIdentification>());
301 
302  protected:
303 
304  std::vector<SpectrumMetaData> metadata_;
306 
307  private:
308 
311 
314 
315  };
316 
317 } //namespace OpenMS
318 
Helper class for looking up spectra based on different attributes.
Definition: SpectrumLookup.h:67
A more convenient string class.
Definition: String.h:57
unsigned char MetaDataFlags
Bit mask for which meta data to extract from a spectrum.
Definition: SpectrumMetaDataLookup.h:146
String native_id
Native ID.
Definition: SpectrumMetaDataLookup.h:169
Helper class for looking up spectrum meta data.
Definition: SpectrumMetaDataLookup.h:141
STL namespace.
std::vector< SpectrumMetaData > metadata_
Meta data for spectra.
Definition: SpectrumMetaDataLookup.h:304
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
The representation of a 1D spectrum.
Definition: MSSpectrum.h:66
String spectra_data_ref
Definition: SpectrumMetaDataLookup.h:305
void setSpectraDataRef(const String &spectra_data)
set spectra_data from read SpectrumContainer origin (i.e. filename)
Definition: SpectrumMetaDataLookup.h:229
double precursor_mz
Precursor mass-to-charge ratio.
Definition: SpectrumMetaDataLookup.h:165
double rt
Retention time.
Definition: SpectrumMetaDataLookup.h:163
~SpectrumMetaDataLookup() override
Destructor.
Definition: SpectrumMetaDataLookup.h:186
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:200
SpectrumMetaData()
Constructor.
Definition: SpectrumMetaDataLookup.h:172
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
double precursor_rt
Precursor retention time.
Definition: SpectrumMetaDataLookup.h:164
Int scan_number
Scan number.
Definition: SpectrumMetaDataLookup.h:168
Size ms_level
MS level.
Definition: SpectrumMetaDataLookup.h:167
Int precursor_charge
Precursor charge.
Definition: SpectrumMetaDataLookup.h:166
SpectrumMetaDataLookup()
Constructor.
Definition: SpectrumMetaDataLookup.h:182
Meta data of a spectrum.
Definition: SpectrumMetaDataLookup.h:161
int Int
Signed integer type.
Definition: Types.h:102