Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
SpectrumLookup.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_SPECTRUMLOOKUP_H
36 #define OPENMS_METADATA_SPECTRUMLOOKUP_H
37 
40 
41 #include <boost/regex.hpp>
42 
43 namespace OpenMS
44 {
68  class OPENMS_DLLAPI SpectrumLookup
69  {
70  public:
71 
73  static const String& default_scan_regexp;
74 
76  std::vector<boost::regex> reference_formats;
77 
79  double rt_tolerance;
80 
83 
85  virtual ~SpectrumLookup();
86 
88  bool empty() const;
89 
103  template <typename SpectrumContainer>
104  void readSpectra(const SpectrumContainer& spectra,
105  const String& scan_regexp = default_scan_regexp)
106  {
107  rts_.clear();
108  ids_.clear();
109  scans_.clear();
110  n_spectra_ = spectra.size();
111  setScanRegExp_(scan_regexp);
112  for (Size i = 0; i < n_spectra_; ++i)
113  {
114  const MSSpectrum& spectrum = spectra[i];
115  String native_id = spectrum.getNativeID();
116  Int scan_no = -1;
117  if (!scan_regexp.empty())
118  {
119  scan_no = extractScanNumber(native_id, scan_regexp_, true);
120  if (scan_no < 0)
121  {
122  LOG_WARN << "Warning: Could not extract scan number from spectrum native ID '" + native_id + "' using regular expression '" + scan_regexp + "'. Look-up by scan number may not work properly." << std::endl;
123  }
124  }
125  addEntry_(i, spectrum.getRT(), scan_no, native_id);
126  }
127  }
128 
140  Size findByRT(double rt) const;
141 
151  Size findByNativeID(const String& native_id) const;
152 
163  Size findByIndex(Size index, bool count_from_one = false) const;
164 
174  Size findByScanNumber(Size scan_number) const;
175 
188  Size findByReference(const String& spectrum_ref) const;
189 
199  void addReferenceFormat(const String& regexp);
200 
212  static Int extractScanNumber(const String& native_id,
213  const boost::regex& scan_regexp,
214  bool no_error = false);
215 
216  protected:
217 
219  static const String& regexp_names_;
220 
222 
223  boost::regex scan_regexp_;
224 
225  std::vector<String> regexp_name_list_;
226 
227  std::map<double, Size> rts_;
228  std::map<String, Size> ids_;
229  std::map<Size, Size> scans_;
230 
239  void addEntry_(Size index, double rt, Int scan_number,
240  const String& native_id);
241 
253  Size findByRegExpMatch_(const String& spectrum_ref, const String& regexp,
254  const boost::smatch& match) const;
255 
261  void setScanRegExp_(const String& scan_regexp);
262 
263  private:
264 
267 
269  SpectrumLookup& operator=(const SpectrumLookup&);
270 
271  };
272 
273 } //namespace OpenMS
274 
275 #endif // OPENMS_METADATA_SPECTRUMLOOKUP_H
static const String & regexp_names_
Named groups recognized in regular expression.
Definition: SpectrumLookup.h:219
Helper class for looking up spectra based on different attributes.
Definition: SpectrumLookup.h:68
A more convenient string class.
Definition: String.h:57
static const String & default_scan_regexp
Default regular expression for extracting scan numbers from spectrum native IDs.
Definition: SpectrumLookup.h:73
void readSpectra(const SpectrumContainer &spectra, const String &scan_regexp=default_scan_regexp)
Read and index spectra for later look-up.
Definition: SpectrumLookup.h:104
std::vector< boost::regex > reference_formats
Possible formats of spectrum references, defined as regular expressions.
Definition: SpectrumLookup.h:76
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
boost::regex scan_regexp_
Regular expression to extract scan numbers.
Definition: SpectrumLookup.h:223
#define LOG_WARN
Macro if a warning, a piece of information which should be read by the user, should be logged...
Definition: LogStream.h:451
std::map< Size, Size > scans_
Mapping: scan number -> spectrum index.
Definition: SpectrumLookup.h:229
The representation of a 1D spectrum.
Definition: MSSpectrum.h:67
std::map< String, Size > ids_
Mapping: native ID -> spectrum index.
Definition: SpectrumLookup.h:228
std::vector< String > regexp_name_list_
Named groups in vector format.
Definition: SpectrumLookup.h:225
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:128
std::map< double, Size > rts_
Mapping: RT -> spectrum index.
Definition: SpectrumLookup.h:227
const String & getNativeID() const
returns the native identifier for the spectrum, used by the acquisition software. ...
Size n_spectra_
Number of spectra.
Definition: SpectrumLookup.h:221
double getRT() const
int Int
Signed integer type.
Definition: Types.h:103
double rt_tolerance
Tolerance for look-up by retention time.
Definition: SpectrumLookup.h:79

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