| OpenMS 2.5.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-2020.
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
37 #include <OpenMS/METADATA/SpectrumLookup.h>
38
39 #include <OpenMS/FORMAT/FileHandler.h>
40 #include <OpenMS/KERNEL/MSSpectrum.h>
41 #include <OpenMS/METADATA/ProteinIdentification.h>
42 #include <OpenMS/KERNEL/MSExperiment.h>
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
162 struct SpectrumMetaData
163 {
164 double rt;
165 double precursor_rt;
166 double precursor_mz;
167 Int precursor_charge;
168 Size ms_level;
169 Int scan_number;
170 String native_id;
171
173 SpectrumMetaData():
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;
184 SpectrumMetaData(SpectrumMetaData&&) = default;
186 ~SpectrumMetaData() = default;
187
189 SpectrumMetaData & operator=(const SpectrumMetaData &) = default;
191 SpectrumMetaData& operator=(SpectrumMetaData&&) & = default;
192 };
193
195 SpectrumMetaDataLookup(): SpectrumLookup()
196 {}
197
199 ~SpectrumMetaDataLookup() override {}
200
212 template <typename SpectrumContainer>
213 void readSpectra(const SpectrumContainer& spectra,
214 const String& scan_regexp = default_scan_regexp,
215 bool get_precursor_rt = false)
216 {
217 // If class SpectrumContainer is e.g. OnDiscMSExperiment, reading each
218 // spectrum is expensive. Thus, to avoid iterating over all spectra twice,
219 // we do not call "SpectrumLookup::readSpectra" here:
220 n_spectra_ = spectra.size();
221 metadata_.reserve(n_spectra_);
222 setScanRegExp_(scan_regexp);
223 // mapping: MS level -> RT of previous spectrum of that level
224 std::map<Size, double> precursor_rts;
225 for (Size i = 0; i < n_spectra_; ++i)
226 {
227 const MSSpectrum& spectrum = spectra[i];
228 SpectrumMetaData meta;
229 getSpectrumMetaData(spectrum, meta, scan_regexp_, precursor_rts);
230 if (get_precursor_rt) precursor_rts[meta.ms_level] = meta.rt;
231 addEntry_(i, meta.rt, meta.scan_number, meta.native_id);
232 metadata_.push_back(meta);
233 }
234 }
235
236
242 void setSpectraDataRef(const String& spectra_data)
243 {
244 this->spectra_data_ref = spectra_data;
245 }
246
247
254 void getSpectrumMetaData(Size index, SpectrumMetaData& meta) const;
255
266 static void getSpectrumMetaData(
267 const MSSpectrum& spectrum, SpectrumMetaData& meta,
268 const boost::regex& scan_regexp = boost::regex(),
269 const std::map<Size, double>& precursor_rts = (std::map<Size, double>()));
270
282 void getSpectrumMetaData(const String& spectrum_ref, SpectrumMetaData& meta,
283 MetaDataFlags flags = MDF_ALL) const;
284
296 static bool addMissingRTsToPeptideIDs(std::vector<PeptideIdentification>& peptides, const String &filename,
297 bool stop_on_error = false);
298
313 static bool addMissingSpectrumReferences(std::vector<PeptideIdentification>& peptides,
314 const String& filename,
315 bool stop_on_error = false,
316 bool override_spectra_data = false,
317 bool override_spectra_references = false,
318 std::vector<ProteinIdentification> proteins = std::vector<ProteinIdentification>());
319
320 protected:
321
322 std::vector<SpectrumMetaData> metadata_;
323 String spectra_data_ref;
324
325 private:
326
328 SpectrumMetaDataLookup(const SpectrumMetaDataLookup&);
329
331 SpectrumMetaDataLookup& operator=(const SpectrumMetaDataLookup&);
332
333 };
334
335 } //namespace OpenMS
336
OpenMS::SpectrumMetaDataLookup::SpectrumMetaDataLookup
SpectrumMetaDataLookup()
Constructor.
Definition: SpectrumMetaDataLookup.h:195
OpenMS::SpectrumMetaDataLookup::SpectrumMetaData::SpectrumMetaData
SpectrumMetaData()
Constructor.
Definition: SpectrumMetaDataLookup.h:173
ProteinIdentification.h
OpenMS::String
A more convenient string class.
Definition: String.h:58
OpenMS::SpectrumMetaDataLookup::SpectrumMetaData::scan_number
Int scan_number
Scan number.
Definition: SpectrumMetaDataLookup.h:169
OpenMS::SpectrumMetaDataLookup::spectra_data_ref
String spectra_data_ref
Definition: SpectrumMetaDataLookup.h:323
OpenMS::SpectrumMetaDataLookup::SpectrumMetaData::rt
double rt
Retention time.
Definition: SpectrumMetaDataLookup.h:164
OpenMS::SpectrumLookup
Helper class for looking up spectra based on different attributes.
Definition: SpectrumLookup.h:67
std
STL namespace.
OpenMS::SpectrumMetaDataLookup::SpectrumMetaData::ms_level
Size ms_level
MS level.
Definition: SpectrumMetaDataLookup.h:168
SpectrumLookup.h
OpenMS::SpectrumMetaDataLookup::SpectrumMetaData::precursor_rt
double precursor_rt
Precursor retention time.
Definition: SpectrumMetaDataLookup.h:165
OpenMS::SpectrumMetaDataLookup::SpectrumMetaData
Meta data of a spectrum.
Definition: SpectrumMetaDataLookup.h:162
OpenMS::MSSpectrum
The representation of a 1D spectrum.
Definition: MSSpectrum.h:67
OpenMS::SpectrumMetaDataLookup::setSpectraDataRef
void setSpectraDataRef(const String &spectra_data)
set spectra_data from read SpectrumContainer origin (i.e. filename)
Definition: SpectrumMetaDataLookup.h:242
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
OpenMS::SpectrumMetaDataLookup
Helper class for looking up spectrum meta data.
Definition: SpectrumMetaDataLookup.h:142
MSExperiment.h
OpenMS::SpectrumMetaDataLookup::readSpectra
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:213
FileHandler.h
MSSpectrum.h
OpenMS::SpectrumMetaDataLookup::metadata_
std::vector< SpectrumMetaData > metadata_
Meta data for spectra.
Definition: SpectrumMetaDataLookup.h:322
double
OpenMS::SpectrumMetaDataLookup::MetaDataFlags
unsigned char MetaDataFlags
Bit mask for which meta data to extract from a spectrum.
Definition: SpectrumMetaDataLookup.h:147
OpenMS::SpectrumMetaDataLookup::SpectrumMetaData::precursor_charge
Int precursor_charge
Precursor charge.
Definition: SpectrumMetaDataLookup.h:167
int
OpenMS::SpectrumMetaDataLookup::SpectrumMetaData::precursor_mz
double precursor_mz
Precursor mass-to-charge ratio.
Definition: SpectrumMetaDataLookup.h:166
OpenMS::SpectrumMetaDataLookup::SpectrumMetaData::native_id
String native_id
Native ID.
Definition: SpectrumMetaDataLookup.h:170
OpenMS::Size
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
OpenMS::SpectrumMetaDataLookup::~SpectrumMetaDataLookup
~SpectrumMetaDataLookup() override
Destructor.
Definition: SpectrumMetaDataLookup.h:199