OpenMS
Loading...
Searching...
No Matches
ThermoRawFileMetadata.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: Timo Sachsenberg $
6// $Authors: Timo Sachsenberg $
7// --------------------------------------------------------------------------
8#pragma once
9
10#include <OpenMS/OpenMSConfig.h>
11
12#include <cstddef>
13#include <map>
14#include <optional>
15#include <string>
16#include <string_view>
17#include <vector>
18
19namespace OpenMS::Internal
20{
22struct OPENMS_DLLAPI ThermoTrailerEntry
23{
24 std::string label;
25 std::string value;
26};
27
29struct OPENMS_DLLAPI ThermoReaction
30{
31 std::optional<double> precursor_mass;
32 std::optional<double> isolation_width;
33 std::optional<double> isolation_offset;
34 std::string activation;
35 std::optional<double> collision_energy;
36 bool collision_energy_valid = false;
37};
38
40struct OPENMS_DLLAPI ThermoScan
41{
42 int scan_number = 0;
43 int ms_level = 0;
44 std::string filter;
45 std::string native_id;
46 std::vector<ThermoTrailerEntry> trailer;
47 std::vector<ThermoReaction> reactions;
48};
49
59class OPENMS_DLLAPI ThermoTrailerIndex
60{
61public:
63 using Key = std::size_t;
64
66 Key add(const std::string& label);
67
69 const std::string* find(const ThermoScan& scan, Key key);
70
72 const std::string& value(const ThermoScan& scan, Key key);
73
74private:
75 static constexpr std::size_t npos_ = static_cast<std::size_t>(-1);
76 std::vector<std::string> labels_;
77 std::vector<std::size_t> positions_;
78};
79
81struct OPENMS_DLLAPI ThermoPrecursor
82{
83 double target_mz = 0.0;
84 double selected_mz = 0.0;
85 std::optional<int> charge;
86 std::optional<double> width;
87 double lower_offset = 0.0;
88 double upper_offset = 0.0;
89 int parent_scan = 0;
90 bool estimate_intensity = true;
91 std::string spectrum_ref;
93 std::optional<ThermoReaction> supplemental;
94};
95
100class OPENMS_DLLAPI ThermoRawFileMetadata
101{
102public:
104
106 static std::string trailer(const ThermoScan& scan, const std::string& label);
107
114 static std::optional<double> number(std::string_view value);
115
123 static std::string filterKey(const std::string& filter);
124
133 static double selectedIon(double target, std::optional<double> mono, double width);
134
145 std::vector<ThermoPrecursor> precursors(const ThermoScan& scan);
146
147private:
149 struct State
150 {
151 int level = 1;
152 int parent = 0;
153 std::size_t reactions = 0;
154 std::string native_id;
155 std::vector<ThermoPrecursor> own;
156 };
157 std::map<int, State> scans_;
158 std::map<std::string, int> filters_;
160 ThermoTrailerIndex::Key master_key_, charge_key_, mono_key_, sps_masses_key_;
161 std::vector<ThermoTrailerIndex::Key> width_keys_;
162
164 static bool supplemental_(const ThermoReaction& first, const ThermoReaction& second);
166 static std::size_t lastReaction_(const std::vector<ThermoReaction>& reactions);
168 int parentFromFilter_(const std::string& key) const;
170 std::vector<double> spsMasses_(const ThermoScan& scan);
172 static bool isLegacySpsLabel_(const std::string& label);
174 static bool isModernSpsLabel_(const std::string& label);
175};
176} // namespace OpenMS::Internal
Resolve the precursor hierarchy from bridge metadata without fetching peaks. Keeps isolation targets ...
Definition ThermoRawFileMetadata.h:101
std::vector< ThermoPrecursor > precursors(const ThermoScan &scan)
Precursor descriptors of one scan; scans must be passed in acquisition order.
ThermoTrailerIndex::Key charge_key_
Definition ThermoRawFileMetadata.h:160
ThermoTrailerIndex trailer_
per-file positions of the trailer labels read below
Definition ThermoRawFileMetadata.h:159
std::map< int, State > scans_
seen scans by scan number
Definition ThermoRawFileMetadata.h:157
int parentFromFilter_(const std::string &key) const
Most recent scan whose filter key is the parent of key (0 if none).
static std::size_t lastReaction_(const std::vector< ThermoReaction > &reactions)
Index of the reaction that isolated this scan's precursor when no parent is known.
static std::string filterKey(const std::string &filter)
Filter key of an MSn filter string: the text between "ms<N> " and the following " [".
static bool supplemental_(const ThermoReaction &first, const ThermoReaction &second)
True if second is the supplemental (HCD / CID) step of an ETD / ECD reaction first on the same target...
std::vector< ThermoTrailerIndex::Key > width_keys_
"MS<level> Isolation Width:" by level
Definition ThermoRawFileMetadata.h:161
std::map< std::string, int > filters_
most recent scan per filter key ("" for MS1)
Definition ThermoRawFileMetadata.h:158
static std::string trailer(const ThermoScan &scan, const std::string &label)
Value of the trailer-extra entry with exactly this label, or "" if absent.
std::string native_id
spectrum reference for descendants
Definition ThermoRawFileMetadata.h:154
static bool isModernSpsLabel_(const std::string &label)
True if label is "SPS Masses:" or "SPS Masses Continued:".
static double selectedIon(double target, std::optional< double > mono, double width)
Selected ion m/z of a precursor (ThermoRawFileParser rule).
std::vector< ThermoPrecursor > own
this scan's own precursor descriptors
Definition ThermoRawFileMetadata.h:155
static bool isLegacySpsLabel_(const std::string &label)
True if label is a legacy "SPS Mass <N>:" label.
static std::optional< double > number(std::string_view value)
Parse a trailer value as a number (locale-independent).
std::vector< double > spsMasses_(const ThermoScan &scan)
SPS target masses from the legacy ("SPS Mass N:") or modern ("SPS Masses:") trailer labels.
What is retained per seen scan to resolve later scans' parents.
Definition ThermoRawFileMetadata.h:150
Per-file trailer label lookup.
Definition ThermoRawFileMetadata.h:60
std::vector< std::size_t > positions_
last position of each label (npos_ if not seen yet)
Definition ThermoRawFileMetadata.h:77
std::size_t Key
Key of a registered label for find() / value().
Definition ThermoRawFileMetadata.h:63
const std::string & value(const ThermoScan &scan, Key key)
Value of the registered label in scan, or "" if absent.
const std::string * find(const ThermoScan &scan, Key key)
Value of the registered label in scan, or nullptr if the scan has no such entry.
Key add(const std::string &label)
Register label (exact match, including the trailing colon) and return its key.
std::vector< std::string > labels_
registered labels by key
Definition ThermoRawFileMetadata.h:76
OpenMS looks in the< code > OPENMS_THERMO_MANAGED_DIR</code > environment variable first
Definition common-cmake-parameters.doxygen:197
Initialization procedures.
Definition BayesianProteinInferenceAlgorithm.h:26
std::optional< double > width
isolation width; unset if unknown or negative
Definition ThermoRawFileMetadata.h:86
std::optional< double > isolation_width
isolation window width (Th)
Definition ThermoRawFileMetadata.h:32
std::string label
e.g. "Monoisotopic M/Z:"
Definition ThermoRawFileMetadata.h:24
std::optional< double > precursor_mass
isolation target m/z
Definition ThermoRawFileMetadata.h:31
std::string spectrum_ref
native ID of the parent scan ("" if unknown)
Definition ThermoRawFileMetadata.h:91
std::string value
as reported by the instrument, numbers included
Definition ThermoRawFileMetadata.h:25
std::string filter
scan filter string, e.g. "FTMS + c NSI Full ms2 500.00@hcd30.00 [100-1000]"
Definition ThermoRawFileMetadata.h:44
std::optional< int > charge
unset if unknown or not positive
Definition ThermoRawFileMetadata.h:85
std::vector< ThermoTrailerEntry > trailer
trailer-extra entries in file order
Definition ThermoRawFileMetadata.h:46
std::optional< double > isolation_offset
isolation window offset from the target (Th)
Definition ThermoRawFileMetadata.h:33
std::string native_id
e.g. "controllerType=0 controllerNumber=1 scan=12"
Definition ThermoRawFileMetadata.h:45
std::vector< ThermoReaction > reactions
reactions in acquisition order (MS2 first)
Definition ThermoRawFileMetadata.h:47
std::optional< double > collision_energy
vendor value; meaningful only if collision_energy_valid
Definition ThermoRawFileMetadata.h:35
ThermoReaction activation
primary reaction
Definition ThermoRawFileMetadata.h:92
std::optional< ThermoReaction > supplemental
supplemental activation (e.g. the HCD step of EThcD)
Definition ThermoRawFileMetadata.h:93
std::string activation
vendor activation type name, e.g. "HigherEnergyCollisionalDissociation"
Definition ThermoRawFileMetadata.h:34
One precursor of an MSn scan as reconstructed by ThermoRawFileMetadata::precursors().
Definition ThermoRawFileMetadata.h:82
One reaction (isolation plus activation step) of a Thermo MSn scan event.
Definition ThermoRawFileMetadata.h:30
The per-scan metadata needed to reconstruct the precursor hierarchy.
Definition ThermoRawFileMetadata.h:41
One "trailer extra" label/value pair of a Thermo scan.
Definition ThermoRawFileMetadata.h:23