Helper class for looking up spectra based on different attributes.
More...
#include <OpenMS/METADATA/SpectrumLookup.h>
|
| 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.
|
| |
| static Int | extractScanNumber (const String &native_id, const String &native_id_type_accession) |
| | Extract the scan number from the native ID using a CV accession.
|
| |
| static std::string | getRegExFromNativeID (const String &native_id) |
| | Determine the RegEx string to extract scan/index number from native IDs. Can be used for extractScanNumber.
|
| |
| static bool | isNativeID (const String &id) |
| | Simple prefix check if a spectrum identifier id is a nativeID from a vendor file.
|
| |
|
| std::vector< boost::regex > | reference_formats |
| | Possible formats of spectrum references, defined as regular expressions.
|
| |
| double | rt_tolerance |
| | Tolerance for look-up by retention time.
|
| |
|
| void | addEntry_ (Size index, double rt, Int scan_number, const String &native_id) |
| | Add a look-up entry for a spectrum.
|
| |
| Size | findByRegExpMatch_ (const String &spectrum_ref, const String ®exp, const boost::smatch &match) const |
| | Look up spectrum by regular expression match.
|
| |
| void | setScanRegExp_ (const String &scan_regexp) |
| | Set the regular expression for extracting scan numbers from spectrum native IDs.
|
| |
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").
- Spectrum reference formats
- Formats for spectrum references are defined by regular expressions, that must contain certain fields (named groups, i.e. "(?<GROUP>...)") referring to usable information. The following named groups are recognized and can be used to look up spectra:
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
- For example, if the format of a spectrum reference is "scan=123", where 123 is the scan number, the expression "scan=(?<SCAN>\\d+)" can be used to extract that number, allowing look-up of the corresponding spectrum.
- Reference formats are registered via addReferenceFormat(). Several possible formats can be added and will be tried in order by the function findByReference().
- Native ID Parsing
- For standalone parsing of spectrum native IDs (without spectrum lookup), use SpectrumNativeIDParser directly:
{
}
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 using a regular expression.
static bool isNativeID(const String &id)
Check if a spectrum identifier is a native ID from a vendor file.
static std::string getRegExFromNativeID(const String &native_id)
Determine the regular expression to extract scan/index numbers from native IDs.
A more convenient string class.
Definition String.h:34
int Int
Signed integer type.
Definition Types.h:72
- See also
- SpectrumMetaDataLookup, SpectrumNativeIDParser
◆ SpectrumLookup() [1/2]
◆ ~SpectrumLookup()
◆ SpectrumLookup() [2/2]
Copy constructor (not implemented)
◆ addEntry_()
| void addEntry_ |
( |
Size |
index, |
|
|
double |
rt, |
|
|
Int |
scan_number, |
|
|
const String & |
native_id |
|
) |
| |
|
protected |
Add a look-up entry for a spectrum.
- Parameters
-
| [in] | index | Spectrum index (position in the vector) |
| [in] | rt | Retention time |
| [in] | scan_number | Scan number |
| [in] | native_id | Native ID |
◆ addReferenceFormat()
| void addReferenceFormat |
( |
const String & |
regexp | ) |
|
Register a possible format for a spectrum reference.
- Parameters
-
| [in] | regexp | Regular expression defining the format |
- Exceptions
-
The regular expression defining the reference format must contain one or more of the recognized named groups defined in SpectrumLookup::regexp_names_.
◆ empty()
Check if any spectra were set.
◆ extractScanNumber() [1/2]
| static Int extractScanNumber |
( |
const String & |
native_id, |
|
|
const boost::regex & |
scan_regexp, |
|
|
bool |
no_error = false |
|
) |
| |
|
static |
◆ extractScanNumber() [2/2]
| static Int extractScanNumber |
( |
const String & |
native_id, |
|
|
const String & |
native_id_type_accession |
|
) |
| |
|
static |
◆ findByIndex()
| Size findByIndex |
( |
Size |
index, |
|
|
bool |
count_from_one = false |
|
) |
| const |
Look up spectrum by index (position in the vector of spectra).
- Parameters
-
| [in] | index | Index to look up |
| [in] | count_from_one | Do indexes start counting at one (default: zero)? |
- Exceptions
-
- Returns
- Index of the spectrum that matched
◆ findByNativeID()
| Size findByNativeID |
( |
const String & |
native_id | ) |
const |
Look up spectrum by native ID.
- Parameters
-
| [in] | native_id | Native ID to look up |
- Exceptions
-
- Returns
- Index of the spectrum that matched
◆ findByReference()
| Size findByReference |
( |
const String & |
spectrum_ref | ) |
const |
Look up spectrum by reference.
- Parameters
-
| [in] | spectrum_ref | Spectrum reference to parse |
- Exceptions
-
- Returns
- Index of the spectrum that 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.
◆ findByRegExpMatch_()
| Size findByRegExpMatch_ |
( |
const String & |
spectrum_ref, |
|
|
const String & |
regexp, |
|
|
const boost::smatch & |
match |
|
) |
| const |
|
protected |
Look up spectrum by regular expression match.
- Parameters
-
| [in] | spectrum_ref | Spectrum reference that was parsed |
| [in] | regexp | Regular expression used for parsing |
| [in] | match | Regular expression match |
- Exceptions
-
- Returns
- Index of the spectrum that matched
◆ findByRT()
| Size findByRT |
( |
double |
rt | ) |
const |
Look up spectrum by retention time (RT).
- Parameters
-
| [in] | rt | Retention time to look up |
- Exceptions
-
- Returns
- Index of the spectrum that matched
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).
◆ findByScanNumber()
| Size findByScanNumber |
( |
Size |
scan_number | ) |
const |
Look up spectrum by scan number (extracted from the native ID).
- Parameters
-
| [in] | scan_number | Scan number to look up |
- Exceptions
-
- Returns
- Index of the spectrum that matched
◆ getRegExFromNativeID()
| static std::string getRegExFromNativeID |
( |
const String & |
native_id | ) |
|
|
static |
◆ isNativeID()
| static bool isNativeID |
( |
const String & |
id | ) |
|
|
static |
◆ operator=()
Assignment operator (not implemented).
◆ readSpectra()
template<typename SpectrumContainer >
Read and index spectra for later look-up.
- Template Parameters
-
| SpectrumContainer | Spectrum container class, must support size and operator[] |
- Parameters
-
| [in] | spectra | Container of spectra |
| [in] | scan_regexp | Regular expression for matching scan numbers in spectrum native IDs (must contain the named group "?<SCAN>") |
- Exceptions
-
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.
◆ setScanRegExp_()
| void setScanRegExp_ |
( |
const String & |
scan_regexp | ) |
|
|
protected |
Set the regular expression for extracting scan numbers from spectrum native IDs.
- Parameters
-
| [in] | scan_regexp | Regular expression to use (must contain the named group "?<SCAN>") |
◆ default_scan_regexp
| const String& default_scan_regexp |
|
static |
Default regular expression for extracting scan numbers from spectrum native IDs.
◆ ids_
Mapping: native ID -> spectrum index.
◆ n_spectra_
◆ reference_formats
| std::vector<boost::regex> reference_formats |
Possible formats of spectrum references, defined as regular expressions.
◆ regexp_name_list_
| std::vector<String> regexp_name_list_ |
|
protected |
Named groups in vector format.
◆ regexp_names_
Named groups recognized in regular expression.
◆ rt_tolerance
Tolerance for look-up by retention time.
◆ rts_
| std::map<double, Size> rts_ |
|
protected |
Mapping: RT -> spectrum index.
◆ scan_regexp_
| boost::regex scan_regexp_ |
|
protected |
Regular expression to extract scan numbers.
◆ scans_
Mapping: scan number -> spectrum index.