|  | OpenMS
    2.6.0
    | 
Helper class for looking up spectra based on different attributes. More...
#include <OpenMS/METADATA/SpectrumLookup.h>
| Public Member Functions | |
| SpectrumLookup () | |
| Constructor.  More... | |
| virtual | ~SpectrumLookup () | 
| Destructor.  More... | |
| bool | empty () const | 
| Check if any spectra were set.  More... | |
| template<typename SpectrumContainer > | |
| void | readSpectra (const SpectrumContainer &spectra, const String &scan_regexp=default_scan_regexp) | 
| Read and index spectra for later look-up.  More... | |
| Size | findByRT (double rt) const | 
| Look up spectrum by retention time (RT).  More... | |
| Size | findByNativeID (const String &native_id) const | 
| Look up spectrum by native ID.  More... | |
| Size | findByIndex (Size index, bool count_from_one=false) const | 
| Look up spectrum by index (position in the vector of spectra).  More... | |
| Size | findByScanNumber (Size scan_number) const | 
| Look up spectrum by scan number (extracted from the native ID).  More... | |
| Size | findByReference (const String &spectrum_ref) const | 
| Look up spectrum by reference.  More... | |
| void | addReferenceFormat (const String ®exp) | 
| Register a possible format for a spectrum reference.  More... | |
| Static Public Member Functions | |
| static Int | extractScanNumber (const String &native_id, const boost::regex &scan_regexp, bool no_error=false) | 
| Extract the scan number from the native ID of a spectrum.  More... | |
| static Int | extractScanNumber (const String &native_id, const String &native_id_type_accession) | 
| Public Attributes | |
| std::vector< boost::regex > | reference_formats | 
| Possible formats of spectrum references, defined as regular expressions.  More... | |
| double | rt_tolerance | 
| Tolerance for look-up by retention time.  More... | |
| Static Public Attributes | |
| static const String & | default_scan_regexp | 
| Default regular expression for extracting scan numbers from spectrum native IDs.  More... | |
| Protected Member Functions | |
| void | addEntry_ (Size index, double rt, Int scan_number, const String &native_id) | 
| Add a look-up entry for a spectrum.  More... | |
| Size | findByRegExpMatch_ (const String &spectrum_ref, const String ®exp, const boost::smatch &match) const | 
| Look up spectrum by regular expression match.  More... | |
| void | setScanRegExp_ (const String &scan_regexp) | 
| Set the regular expression for extracting scan numbers from spectrum native IDs.  More... | |
| Protected Attributes | |
| Size | n_spectra_ | 
| Number of spectra.  More... | |
| boost::regex | scan_regexp_ | 
| Regular expression to extract scan numbers.  More... | |
| std::vector< String > | regexp_name_list_ | 
| Named groups in vector format.  More... | |
| std::map< double, Size > | rts_ | 
| Mapping: RT -> spectrum index.  More... | |
| std::map< String, Size > | ids_ | 
| Mapping: native ID -> spectrum index.  More... | |
| std::map< Size, Size > | scans_ | 
| Mapping: scan number -> spectrum index.  More... | |
| Static Protected Attributes | |
| static const String & | regexp_names_ | 
| Named groups recognized in regular expression.  More... | |
| Private Member Functions | |
| SpectrumLookup (const SpectrumLookup &) | |
| Copy constructor (not implemented)  More... | |
| SpectrumLookup & | operator= (const SpectrumLookup &) | 
| Assignment operator (not implemented).  More... | |
Helper class for looking up spectra based on different attributes.
This class provides functions for looking up spectra that are stored in a vector (e.g. MSExperiment::getSpectra()) by index, retention time, native ID, scan number (extracted from the native ID), or by a reference string containing any of the previous information ("spectrum reference").
INDEX0: spectrum index, i.e. position in the vector of spectra, counting from zero INDEX1: spectrum index, i.e. position in the vector of spectra, counting from one ID: spectrum native ID SCAN: scan number (extracted from the native ID) RT: retention time| SpectrumLookup | ( | ) | 
Constructor.
| 
 | virtual | 
Destructor.
| 
 | private | 
Copy constructor (not implemented)
Add a look-up entry for a spectrum.
| index | Spectrum index (position in the vector) | 
| rt | Retention time | 
| scan_number | Scan number | 
| native_id | Native ID | 
| void addReferenceFormat | ( | const String & | regexp | ) | 
Register a possible format for a spectrum reference.
| regexp | Regular expression defining the format | 
| Exception::IllegalArgument | if regexpdoes not contain any of the recognized named groups | 
The regular expression defining the reference format must contain one or more of the recognized named groups defined in SpectrumLookup::regexp_names_.
| bool empty | ( | ) | const | 
Check if any spectra were set.
| 
 | static | 
Extract the scan number from the native ID of a spectrum.
| native_id | Spectrum native ID | 
| scan_regexp | Regular expression to use (must contain the named group "?<SCAN>") | 
| no_error | Suppress the exception on failure | 
| Exception::ParseError | if the scan number could not be extracted (unless no_erroris set) | 
| 
 | static | 
Look up spectrum by index (position in the vector of spectra).
| index | Index to look up | 
| count_from_one | Do indexes start counting at one (default: zero)? | 
| Exception::ElementNotFound | if no matching spectrum was found | 
Look up spectrum by native ID.
| native_id | Native ID to look up | 
| Exception::ElementNotFound | if no matching spectrum was found | 
Look up spectrum by reference.
| spectrum_ref | Spectrum reference to parse | 
| Exception::ElementNotFound | if no matching spectrum was found | 
| Exception::ParseError | if the reference could not be parsed (no reference format matched) | 
The regular expressions in SpectrumLookup::reference_formats are matched against the spectrum reference in order. The first one that matches is used to look up the spectrum.
| 
 | protected | 
Look up spectrum by regular expression match.
| spectrum_ref | Spectrum reference that was parsed | 
| regexp | Regular expression used for parsing | 
| match | Regular expression match | 
| Exception::ElementNotFound | if no matching spectrum was found | 
Look up spectrum by retention time (RT).
| rt | Retention time to look up | 
| Exception::ElementNotFound | if no matching spectrum was found | 
There is a tolerance for matching of RT values defined by SpectrumLookup::rt_tolerance. The spectrum with the closest match within that tolerance is returned (if any).
Look up spectrum by scan number (extracted from the native ID).
| scan_number | Scan number to look up | 
| Exception::ElementNotFound | if no matching spectrum was found | 
| 
 | private | 
Assignment operator (not implemented).
| 
 | inline | 
Read and index spectra for later look-up.
| SpectrumContainer | Spectrum container class, must support sizeandoperator[] | 
| spectra | Container of spectra | 
| scan_regexp | Regular expression for matching scan numbers in spectrum native IDs (must contain the named group "?<SCAN>") | 
| Exception::IllegalArgument | if scan_regexpdoes not contain "?<SCAN>" (and is not empty) | 
Spectra are indexed by retention time, native ID and scan number. In all cases it is expected that the value for each spectrum will be unique. Setting scan_regexp to the empty string ("") disables extraction of scan numbers; look-ups by scan number will fail in that case. 
References SpectrumSettings::getNativeID(), MSSpectrum::getRT(), and OPENMS_LOG_WARN.
| 
 | protected | 
Set the regular expression for extracting scan numbers from spectrum native IDs.
| scan_regexp | Regular expression to use (must contain the named group "?<SCAN>") | 
| 
 | static | 
Default regular expression for extracting scan numbers from spectrum native IDs.
| 
 | protected | 
Number of spectra.
| std::vector<boost::regex> reference_formats | 
Possible formats of spectrum references, defined as regular expressions.
| 
 | protected | 
Named groups in vector format.
| 
 | staticprotected | 
Named groups recognized in regular expression.
| double rt_tolerance | 
Tolerance for look-up by retention time.
| 
 | protected | 
Regular expression to extract scan numbers.
 1.8.16
 1.8.16