OpenMS
Loading...
Searching...
No Matches
ThermoRawScanReader.h
Go to the documentation of this file.
1// Copyright (c) 2002-present, OpenMS Inc. -- EKU Tuebingen, ETH Zurich, and FU Berlin
2// SPDX-License-Identifier: BSD-3-Clause
3//
4// --------------------------------------------------------------------------
5// $Maintainer: Julianus Pfeuffer $
6// $Authors: Julianus Pfeuffer $
7// --------------------------------------------------------------------------
8
9#pragma once
10
13
14#include <algorithm>
15#include <cmath>
16#include <limits>
17#include <functional>
18#include <memory>
19#include <string>
20#include <vector>
21
22namespace OpenMS
23{
24 class DataProcessing;
25 class ExperimentalSettings;
26 class MSChromatogram;
27 class MSSpectrum;
28
29namespace Internal
30{
52 class OPENMS_DLLAPI ThermoRawScanReader
53 {
54 public:
55 using Options = ThermoRawFile::Options;
56
58 struct ScanInfo
59 {
60 int scan = 0;
61 int ms_level = 0;
62 double rt = 0.0;
63 double tic = 0.0;
64 double precursor_mz = 0.0;
65 };
66
73 {
75 std::vector<ThermoPrecursor> precursors;
76 std::string configuration_id;
77 std::string native_id;
78 };
79
88 class OPENMS_DLLAPI Accessor
89 {
90 public:
92 Accessor(const Accessor&) = delete;
93 Accessor& operator=(const Accessor&) = delete;
94
105 void convert(const ScanRecord& record, MSSpectrum& spectrum, bool peaks);
106
108 void readPeaks(int scan, MSSpectrum& spectrum);
109
111 std::unique_ptr<Accessor> clone() const;
112
113 private:
115 struct Impl;
116 explicit Accessor(std::unique_ptr<Impl> impl);
117 std::unique_ptr<Impl> impl_;
118 };
119
121 using ParentLookup = std::function<const MSSpectrum*(int scan)>;
122
137 ThermoRawScanReader(const std::string& path, const Options& options);
141
143 bool hasMSData() const;
145 int firstScan() const;
147 int lastScan() const;
148
150 void fillSettings(ExperimentalSettings& settings) const;
151
159 const ScanInfo& header(int scan, bool with_peaks = false);
160
171 void readAhead(int last_scan, int peaks_from);
172
187 void scanHeaders(int first, int last, bool precursors, const std::function<bool(const ScanInfo&)>& visit);
188
197 void convert(MSSpectrum& spectrum, ExperimentalSettings& settings, const ParentLookup& parent, bool peaks);
198
207
210
217 std::unique_ptr<Accessor> accessor() const;
218
220 std::shared_ptr<DataProcessing> dataProcessing() const;
221
224
226 void readDetectors(std::vector<MSChromatogram>& chromatograms, std::vector<MSSpectrum>& spectra);
227
228 private:
229 struct Impl;
230 std::unique_ptr<Impl> impl_;
231 };
234 {
235 const ThermoRawFile::Options& options;
236
237 bool level(int level) const
238 {
239 return options.ms_levels.empty() || std::find(options.ms_levels.begin(), options.ms_levels.end(), level) != options.ms_levels.end();
240 }
241 bool rt(double rt) const { return rt >= options.rt_min && rt < options.rt_max; }
242 bool precursorFiltered() const
243 {
244 return options.precursor_mz_min > -std::numeric_limits<double>::infinity() || options.precursor_mz_max < std::numeric_limits<double>::infinity();
245 }
247 bool headerFiltered() const
248 {
249 return ! options.ms_levels.empty() || precursorFiltered() || options.rt_min > -std::numeric_limits<double>::infinity()
250 || options.rt_max < std::numeric_limits<double>::infinity();
251 }
253 int lastScan(int last) const { return options.last_scan > 0 ? std::min(last, options.last_scan) : last; }
255 bool beyondRT(const ThermoRawScanReader::ScanInfo& info) const { return info.rt >= options.rt_max; }
257 {
258 if (info.scan < options.first_scan || ! rt(info.rt) || ! level(info.ms_level)) { return false; }
259 return info.ms_level <= 1 || std::isnan(info.precursor_mz)
260 || (info.precursor_mz >= options.precursor_mz_min && info.precursor_mz < options.precursor_mz_max);
261 }
262 };
263
264} // namespace Internal
265} // namespace OpenMS
Description of the experimental settings.
Definition ExperimentalSettings.h:37
Converts scans independently of each other (random access).
Definition ThermoRawScanReader.h:89
void convert(const ScanRecord &record, MSSpectrum &spectrum, bool peaks)
Convert the scan of record, as ThermoRawScanReader::convert() would.
void readPeaks(int scan, MSSpectrum &spectrum)
Only the peaks (and the charge array if requested by the options) of scan; spectrum is reset.
std::unique_ptr< Accessor > clone() const
A new accessor on the same file; safe to call concurrently from several threads.
std::unique_ptr< Impl > impl_
Definition ThermoRawScanReader.h:117
Accessor(std::unique_ptr< Impl > impl)
Accessor & operator=(const Accessor &)=delete
Scan-by-scan conversion of a Thermo RAW file into OpenMS spectra (private).
Definition ThermoRawScanReader.h:53
std::shared_ptr< DataProcessing > dataProcessing() const
Data processing attached to every converted spectrum and chromatogram.
void convert(MSSpectrum &spectrum, ExperimentalSettings &settings, const ParentLookup &parent, bool peaks)
Convert the scan of the last header() call.
int scan
scan number
Definition ThermoRawScanReader.h:60
ThermoRawFile::Options Options
Definition ThermoRawScanReader.h:55
void readDetectors(std::vector< MSChromatogram > &chromatograms, std::vector< MSSpectrum > &spectra)
Detector (UV/PDA/analog) chromatograms and PDA spectra (Options::all_detectors); may be called at any...
int ms_level
MS level (0 for unknown or non-MS controllers)
Definition ThermoRawScanReader.h:61
void scanHeaders(int first, int last, bool precursors, const std::function< bool(const ScanInfo &)> &visit)
Visit the headers of scans first to last ahead of header(), without peaks.
std::vector< ThermoPrecursor > precursors
resolved in acquisition order
Definition ThermoRawScanReader.h:75
std::unique_ptr< Impl > impl_
Definition ThermoRawScanReader.h:230
bool hasMSData() const
True if the file contains a mass spectrometer controller.
void fillSettings(ExperimentalSettings &settings) const
Write run-level settings into settings (instrument configurations are added by convert() and addInstr...
std::string native_id
Definition ThermoRawScanReader.h:77
const ScanInfo & header(int scan, bool with_peaks=false)
Read the header of scan; must be called for every scan in increasing order.
int firstScan() const
First MS scan number (only valid if hasMSData()).
MSChromatogram ticChromatogram() const
TIC chromatogram as reported by the vendor library (reads every scan header).
ThermoRawScanReader(const std::string &path, const Options &options)
Open path.
ScanInfo info
Definition ThermoRawScanReader.h:74
ThermoRawScanReader(const ThermoRawScanReader &)=delete
std::unique_ptr< Accessor > accessor() const
Random access converter for scans whose records were taken.
void addInstrumentConfigurations(ExperimentalSettings &settings)
Add the instrument configurations of all scans read by header() so far to settings.
std::string configuration_id
instrument configuration id
Definition ThermoRawScanReader.h:76
int lastScan() const
Last MS scan number (only valid if hasMSData()).
double rt
retention time in seconds
Definition ThermoRawScanReader.h:62
ThermoRawScanReader & operator=(const ThermoRawScanReader &)=delete
std::function< const MSSpectrum *(int scan)> ParentLookup
Returns the converted (peak-sorted) spectrum of a scan or nullptr if it is not available.
Definition ThermoRawScanReader.h:121
void readAhead(int last_scan, int peaks_from)
Read the following scans up to last_scan on worker threads ahead of header().
double precursor_mz
m/z of the first precursor (NaN if there is none)
Definition ThermoRawScanReader.h:64
ScanRecord record() const
Record of the scan whose header was read last (by header()).
Scan header values needed to select scans before converting them.
Definition ThermoRawScanReader.h:59
Everything of a scan that depends on the scans before it (see header()).
Definition ThermoRawScanReader.h:73
The representation of a chromatogram.
Definition MSChromatogram.h:34
The representation of a 1D spectrum.
Definition MSSpectrum.h:45
OpenMS looks in the< code > OPENMS_THERMO_MANAGED_DIR</code > environment variable first
Definition common-cmake-parameters.doxygen:179
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
Scan selection by ThermoRawFile::Options, shared by load(), transform() and OnDiscThermoRawExperiment...
Definition ThermoRawScanReader.h:234
bool beyondRT(const ThermoRawScanReader::ScanInfo &info) const
True if no scan from info on can be selected (checked after reading its header).
Definition ThermoRawScanReader.h:255
bool rt(double rt) const
Definition ThermoRawScanReader.h:241
bool precursorFiltered() const
Definition ThermoRawScanReader.h:242
bool selected(const ThermoRawScanReader::ScanInfo &info) const
Definition ThermoRawScanReader.h:256
bool headerFiltered() const
True if scans are selected by values of their header.
Definition ThermoRawScanReader.h:247
int lastScan(int last) const
Last scan to read: scans of one controller are in acquisition order, so no later scan can be selected...
Definition ThermoRawScanReader.h:253
bool level(int level) const
Definition ThermoRawScanReader.h:237
const ThermoRawFile::Options & options
Definition ThermoRawScanReader.h:235