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-2017.
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 
44 
45 #include <limits> // for "quiet_NaN"
46 
47 namespace OpenMS
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  };
181 
184  {}
185 
188 
200  template <typename SpectrumContainer>
201  void readSpectra(const SpectrumContainer& spectra,
202  const String& scan_regexp = default_scan_regexp,
203  bool get_precursor_rt = false)
204  {
205  // If class SpectrumContainer is e.g. OnDiscMSExperiment, reading each
206  // spectrum is expensive. Thus, to avoid iterating over all spectra twice,
207  // we do not call "SpectrumLookup::readSpectra" here:
208  n_spectra_ = spectra.size();
209  metadata_.reserve(n_spectra_);
210  setScanRegExp_(scan_regexp);
211  // mapping: MS level -> RT of previous spectrum of that level
212  std::map<Size, double> precursor_rts;
213  for (Size i = 0; i < n_spectra_; ++i)
214  {
215  const MSSpectrum& spectrum = spectra[i];
216  SpectrumMetaData meta;
217  getSpectrumMetaData(spectrum, meta, scan_regexp_, precursor_rts);
218  if (get_precursor_rt) precursor_rts[meta.ms_level] = meta.rt;
219  addEntry_(i, meta.rt, meta.scan_number, meta.native_id);
220  metadata_.push_back(meta);
221  }
222  }
223 
224 
230  void setSpectraDataRef(const String& spectra_data)
231  {
232  this->spectra_data_ref = spectra_data;
233  }
234 
235 
242  void getSpectrumMetaData(Size index, SpectrumMetaData& meta) const;
243 
254  static void getSpectrumMetaData(
255  const MSSpectrum& spectrum, SpectrumMetaData& meta,
256  const boost::regex& scan_regexp = boost::regex(),
257  const std::map<Size, double>& precursor_rts = (std::map<Size, double>()));
258 
270  void getSpectrumMetaData(const String& spectrum_ref, SpectrumMetaData& meta,
271  MetaDataFlags flags = MDF_ALL) const;
272 
284  static bool addMissingRTsToPeptideIDs(std::vector<PeptideIdentification>& peptides, const String &filename,
285  bool stop_on_error = false);
286 
300  static bool addMissingSpectrumReferences(std::vector<PeptideIdentification>& peptides, const String& filename,
301  bool stop_on_error = false, bool override_spectra_data = false, std::vector<ProteinIdentification> proteins = std::vector<ProteinIdentification>());
302 
303  protected:
304 
305  std::vector<SpectrumMetaData> metadata_;
307 
308  private:
309 
312 
315 
316  };
317 
318 } //namespace OpenMS
319 
320 #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:147
String native_id
Native ID.
Definition: SpectrumMetaDataLookup.h:170
Helper class for looking up spectrum meta data.
Definition: SpectrumMetaDataLookup.h:142
STL namespace.
std::vector< SpectrumMetaData > metadata_
Meta data for spectra.
Definition: SpectrumMetaDataLookup.h:305
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
The representation of a 1D spectrum.
Definition: MSSpectrum.h:67
String spectra_data_ref
Definition: SpectrumMetaDataLookup.h:306
void setSpectraDataRef(const String &spectra_data)
set spectra_data from read SpectrumContainer origin (i.e. filename)
Definition: SpectrumMetaDataLookup.h:230
double precursor_mz
Precursor mass-to-charge ratio.
Definition: SpectrumMetaDataLookup.h:166
double rt
Retention time.
Definition: SpectrumMetaDataLookup.h:164
virtual ~SpectrumMetaDataLookup()
Destructor.
Definition: SpectrumMetaDataLookup.h:187
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:201
SpectrumMetaData()
Constructor.
Definition: SpectrumMetaDataLookup.h:173
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:128
double precursor_rt
Precursor retention time.
Definition: SpectrumMetaDataLookup.h:165
Int scan_number
Scan number.
Definition: SpectrumMetaDataLookup.h:169
Size ms_level
MS level.
Definition: SpectrumMetaDataLookup.h:168
Int precursor_charge
Precursor charge.
Definition: SpectrumMetaDataLookup.h:167
SpectrumMetaDataLookup()
Constructor.
Definition: SpectrumMetaDataLookup.h:183
Meta data of a spectrum.
Definition: SpectrumMetaDataLookup.h:162
int Int
Signed integer type.
Definition: Types.h:103

OpenMS / TOPP release 2.3.0 Documentation generated on Tue Jan 9 2018 18:22:04 using doxygen 1.8.13