15#include <boost/regex.hpp>
91 template <
typename SpectrumContainer>
93 const std::string& scan_regexp = default_scan_regexp)
98 n_spectra_ = spectra.size();
99 setScanRegExp_(scan_regexp);
100 for (
Size i = 0; i < n_spectra_; ++i)
103 const std::string& native_id = spectrum.
getNativeID();
105 if (!scan_regexp.empty())
107 scan_no = extractScanNumber(native_id, scan_regexp_,
true);
110 OPENMS_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;
113 addEntry_(i, spectrum.
getRT(), scan_no, native_id);
204 const boost::regex& scan_regexp,
205 bool no_error =
false);
219 const std::string& native_id_type_accession);
257 std::map<std::string, Size>
ids_;
269 const std::string& native_id);
283 const boost::smatch& match)
const;
#define OPENMS_LOG_WARN
Macro for warnings.
Definition LogStream.h:583
The representation of a 1D spectrum.
Definition MSSpectrum.h:44
Helper class for looking up spectra based on different attributes.
Definition SpectrumLookup.h:57
virtual ~SpectrumLookup()
Destructor.
std::map< Size, Size > scans_
Mapping: scan number -> spectrum index.
Definition SpectrumLookup.h:258
std::vector< std::string > regexp_name_list_
Named groups in vector format.
Definition SpectrumLookup.h:254
void setScanRegExp_(const std::string &scan_regexp)
Set the regular expression for extracting scan numbers from spectrum native IDs.
void readSpectra(const SpectrumContainer &spectra, const std::string &scan_regexp=default_scan_regexp)
Read and index spectra for later look-up.
Definition SpectrumLookup.h:92
static const std::string & default_scan_regexp
Default regular expression for extracting scan numbers from spectrum native IDs.
Definition SpectrumLookup.h:61
static Int extractScanNumber(const std::string &native_id, const std::string &native_id_type_accession)
Extract the scan number from the native ID using a CV accession.
Size findByIndex(Size index, bool count_from_one=false) const
Look up spectrum by index (position in the vector of spectra).
std::map< double, Size > rts_
Mapping: RT -> spectrum index.
Definition SpectrumLookup.h:256
static std::string getRegExFromNativeID(const std::string &native_id)
Determine the RegEx string to extract scan/index number from native IDs. Can be used for extractScanN...
Size n_spectra_
Number of spectra.
Definition SpectrumLookup.h:250
bool empty() const
Check if any spectra were set.
boost::regex scan_regexp_
Regular expression to extract scan numbers.
Definition SpectrumLookup.h:252
SpectrumLookup & operator=(const SpectrumLookup &)
Assignment operator (not implemented).
Size findByRT(double rt) const
Look up spectrum by retention time (RT).
Size findByRegExpMatch_(const std::string &spectrum_ref, const std::string ®exp, const boost::smatch &match) const
Look up spectrum by regular expression match.
SpectrumLookup(const SpectrumLookup &)
Copy constructor (not implemented)
Size findByScanNumber(Size scan_number) const
Look up spectrum by scan number (extracted from the native ID).
static bool isNativeID(const std::string &id)
Simple prefix check if a spectrum identifier id is a nativeID from a vendor file.
static Int extractScanNumber(const std::string &native_id, const boost::regex &scan_regexp, bool no_error=false)
Extract the scan number from the native ID of a spectrum.
Size findByNativeID(const std::string &native_id) const
Look up spectrum by native ID.
Size findByReference(const std::string &spectrum_ref) const
Look up spectrum by reference.
std::vector< boost::regex > reference_formats
Possible formats of spectrum references, defined as regular expressions.
Definition SpectrumLookup.h:64
SpectrumLookup()
Constructor.
double rt_tolerance
Tolerance for look-up by retention time.
Definition SpectrumLookup.h:67
void addReferenceFormat(const std::string ®exp)
Register a possible format for a spectrum reference.
std::map< std::string, Size > ids_
Mapping: native ID -> spectrum index.
Definition SpectrumLookup.h:257
void addEntry_(Size index, double rt, Int scan_number, const std::string &native_id)
Add a look-up entry for a spectrum.
static const std::string & regexp_names_
Named groups recognized in regular expression.
Definition SpectrumLookup.h:248
const std::string & getNativeID() const
returns the native identifier for the spectrum, used by the acquisition software.
int Int
Signed integer type.
Definition Types.h:72
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition Types.h:97
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19