Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
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-2016.
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 #ifndef OPENMS_METADATA_SPECTRUMMETADATALOOKUP_H
36 #define OPENMS_METADATA_SPECTRUMMETADATALOOKUP_H
37 
39 
42 
43 #include <limits> // for "quiet_NaN"
44 
45 namespace OpenMS
46 {
140  class OPENMS_DLLAPI SpectrumMetaDataLookup: public SpectrumLookup
141  {
142  public:
143 
145  typedef unsigned char MetaDataFlags;
146 
149  static const MetaDataFlags MDF_RT = 1;
150  static const MetaDataFlags MDF_PRECURSORRT = 2;
151  static const MetaDataFlags MDF_PRECURSORMZ = 4;
152  static const MetaDataFlags MDF_PRECURSORCHARGE = 8;
153  static const MetaDataFlags MDF_MSLEVEL = 16;
154  static const MetaDataFlags MDF_SCANNUMBER = 32;
155  static const MetaDataFlags MDF_NATIVEID = 64;
156  static const MetaDataFlags MDF_ALL = 127;
157 
160  {
161  double rt;
162  double precursor_rt;
163  double precursor_mz;
168 
171  rt(std::numeric_limits<double>::quiet_NaN()),
172  precursor_rt(std::numeric_limits<double>::quiet_NaN()),
173  precursor_mz(std::numeric_limits<double>::quiet_NaN()),
174  precursor_charge(0), ms_level(0), scan_number(-1), native_id("")
175  {
176  }
177  };
178 
181 
184 
196  template <typename SpectrumContainer>
197  void readSpectra(const SpectrumContainer& spectra,
198  const String& scan_regexp = default_scan_regexp,
199  bool get_precursor_rt = false)
200  {
201  // If class SpectrumContainer is e.g. OnDiscMSExperiment, reading each
202  // spectrum is expensive. Thus, to avoid iterating over all spectra twice,
203  // we do not call "SpectrumLookup::readSpectra" here:
204  n_spectra_ = spectra.size();
205  metadata_.reserve(n_spectra_);
206  setScanRegExp_(scan_regexp);
207  // mapping: MS level -> RT of previous spectrum of that level
208  std::map<Size, double> precursor_rts;
209  for (Size i = 0; i < n_spectra_; ++i)
210  {
211  const MSSpectrum<>& spectrum = spectra[i];
212  SpectrumMetaData meta;
213  getSpectrumMetaData(spectrum, meta, scan_regexp_, precursor_rts);
214  if (get_precursor_rt) precursor_rts[meta.ms_level] = meta.rt;
215  addEntry_(i, meta.rt, meta.scan_number, meta.native_id);
216  metadata_.push_back(meta);
217  }
218  }
219 
226  void getSpectrumMetaData(Size index, SpectrumMetaData& meta) const;
227 
238  static void getSpectrumMetaData(
239  const MSSpectrum<>& spectrum, SpectrumMetaData& meta,
240  const boost::regex& scan_regexp = boost::regex(),
241  const std::map<Size, double>& precursor_rts = (std::map<Size, double>()));
242 
254  void getSpectrumMetaData(const String& spectrum_ref, SpectrumMetaData& meta,
255  MetaDataFlags flags = MDF_ALL) const;
256 
270  static bool addMissingRTsToPeptideIDs(
271  std::vector<PeptideIdentification>& peptides, const String& filename,
272  bool stop_on_error = false);
273 
274  protected:
275 
276  std::vector<SpectrumMetaData> metadata_;
277 
278  private:
279 
282 
285 
286  };
287 
288 } //namespace OpenMS
289 
290 #endif // OPENMS_METADATA_SPECTRUMMETADATALOOKUP_H
Helper class for looking up spectra based on different attributes.
Definition: SpectrumLookup.h:68
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:145
String native_id
Native ID.
Definition: SpectrumMetaDataLookup.h:167
Helper class for looking up spectrum meta data.
Definition: SpectrumMetaDataLookup.h:140
STL namespace.
std::vector< SpectrumMetaData > metadata_
Meta data for spectra.
Definition: SpectrumMetaDataLookup.h:276
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
The representation of a 1D spectrum.
Definition: MSSpectrum.h:66
double precursor_mz
Precursor mass-to-charge ratio.
Definition: SpectrumMetaDataLookup.h:163
double rt
Retention time.
Definition: SpectrumMetaDataLookup.h:161
virtual ~SpectrumMetaDataLookup()
Destructor.
Definition: SpectrumMetaDataLookup.h:183
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:197
SpectrumMetaData()
Constructor.
Definition: SpectrumMetaDataLookup.h:170
double precursor_rt
Precursor retention time.
Definition: SpectrumMetaDataLookup.h:162
Int scan_number
Scan number.
Definition: SpectrumMetaDataLookup.h:166
Size ms_level
MS level.
Definition: SpectrumMetaDataLookup.h:165
Int precursor_charge
Precursor charge.
Definition: SpectrumMetaDataLookup.h:164
SpectrumMetaDataLookup()
Constructor.
Definition: SpectrumMetaDataLookup.h:180
Meta data of a spectrum.
Definition: SpectrumMetaDataLookup.h:159
int Int
Signed integer type.
Definition: Types.h:103

OpenMS / TOPP release 2.0.0 Documentation generated on Tue Jan 31 2017 06:39:53 using doxygen 1.8.8