Skip to main content

openmassspec_core/
enums.rs

1//! Shared enums used across the open mass-spec parsers.
2//!
3//! The enums are **vendor neutral**: anything vendor-specific (e.g. firmware
4//! byte codes, scan-filter symbols) stays in the vendor crate.
5//!
6//! Every enum is `#[non_exhaustive]`, so new variants can be added in a minor
7//! release. Code outside this crate that matches on one needs a wildcard arm.
8
9/// Detector / mass analyzer family.
10///
11/// The variants follow Thermo's preamble encoding (the most detailed source
12/// available across vendors); other vendors map their detector class onto the
13/// closest equivalent.
14#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
15#[non_exhaustive]
16pub enum Analyzer {
17    /// Ion trap.
18    ITMS,
19    /// Triple quadrupole.
20    TQMS,
21    /// Single quadrupole.
22    SQMS,
23    /// Time-of-flight.
24    TOFMS,
25    /// Fourier-transform (Orbitrap, FT-ICR).
26    FTMS,
27    /// Magnetic sector.
28    Sector,
29}
30
31/// Scan polarity.
32#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
33#[non_exhaustive]
34pub enum Polarity {
35    /// Negative ion mode.
36    Negative,
37    /// Positive ion mode.
38    Positive,
39}
40
41/// Whether a spectrum holds centroided peak picks or the raw profile signal.
42#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
43#[non_exhaustive]
44pub enum ScanMode {
45    /// Centroided peak list.
46    Centroid,
47    /// Continuum (profile) signal.
48    Profile,
49}
50
51/// MSn order (MS1, MS2, ...).
52#[derive(Debug, Clone, Copy, PartialEq, Eq)]
53#[non_exhaustive]
54pub enum MsPower {
55    /// MS order not recorded.
56    Undefined,
57    /// MS1.
58    Ms1,
59    /// MS2.
60    Ms2,
61    /// MS3.
62    Ms3,
63    /// MS4.
64    Ms4,
65    /// MS5.
66    Ms5,
67    /// MS6.
68    Ms6,
69    /// MS7.
70    Ms7,
71    /// MS8.
72    Ms8,
73}
74
75/// Activation method used for MSn fragmentation.
76#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
77#[non_exhaustive]
78pub enum Activation {
79    /// Higher-energy collisional dissociation (Q Exactive style).
80    HCD,
81    /// Multi-photon induced dissociation.
82    MPID,
83    /// Electron transfer dissociation.
84    ETD,
85    /// Collision-induced dissociation. On FTMS analyzers this is
86    /// conventionally rendered as beam-type CID (HCD-equivalent) in mzML.
87    CID,
88    /// Electron-capture dissociation.
89    ECD,
90    /// Infrared multiphoton dissociation.
91    IRMPD,
92    /// Proton-transfer / activated-ion variant.
93    PD,
94    /// Pulsed q dissociation.
95    PQD,
96    /// Ultraviolet photodissociation.
97    UVPD,
98    /// Surface-induced dissociation.
99    SID,
100    /// ETD with supplemental HCD.
101    EThcD,
102}
103
104/// Compression codec applied to a `<binaryDataArray>`'s `<binary>` payload
105/// by the mzML writer.
106///
107/// Selects both the bytes actually written (compressed or not) and the
108/// matching PSI-MS cvParam. `Zlib` is the default; select another codec with
109/// [`WriteOptions::with_compression`](crate::WriteOptions::with_compression).
110#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
111#[non_exhaustive]
112pub enum Compression {
113    /// No compression: `MS:1000576` ("no compression").
114    NoCompression,
115    /// DEFLATE/zlib compression: `MS:1000574` ("zlib compression").
116    #[default]
117    Zlib,
118}
119
120/// Unit + meaning of a per-peak ion mobility array.
121///
122/// Selects the CV term and unit emitted by the mzML writer when a
123/// [`crate::SpectrumRecord::inv_mobility_per_peak`] array is present.
124#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
125#[non_exhaustive]
126pub enum MobilityArrayKind {
127    /// Bruker TIMS convention: per-peak 1/K0 in volt-second per square
128    /// centimeter. Emitted as MS:1003008 "raw inverse reduced ion mobility
129    /// array" with unit MS:1002814.
130    InverseReducedVsPerCm2,
131    /// Waters traveling-wave IMS convention: per-peak drift time in
132    /// milliseconds. Emitted as MS:1003007 "raw ion mobility array" with
133    /// unit UO:0000028 "millisecond".
134    DriftTimeMilliseconds,
135}
136
137impl MsPower {
138    /// Numeric MS level (1 for MS1, 2 for MS2, ...). Returns 1 for `Undefined`,
139    /// matching the convention used in mzML output.
140    pub fn ms_level(self) -> u32 {
141        match self {
142            Self::Undefined | Self::Ms1 => 1,
143            Self::Ms2 => 2,
144            Self::Ms3 => 3,
145            Self::Ms4 => 4,
146            Self::Ms5 => 5,
147            Self::Ms6 => 6,
148            Self::Ms7 => 7,
149            Self::Ms8 => 8,
150        }
151    }
152}
153
154impl Polarity {
155    /// Stable lowercase label (`"positive"`, `"negative"`), used as the
156    /// `polarity` value in `openmassspec-arrow` batches.
157    pub fn as_str(self) -> &'static str {
158        match self {
159            Self::Positive => "positive",
160            Self::Negative => "negative",
161        }
162    }
163}
164
165impl ScanMode {
166    /// Stable lowercase label (`"centroid"`, `"profile"`), used as the
167    /// `scan_mode` value in `openmassspec-arrow` batches.
168    pub fn as_str(self) -> &'static str {
169        match self {
170            Self::Centroid => "centroid",
171            Self::Profile => "profile",
172        }
173    }
174}
175
176impl Analyzer {
177    /// Stable lowercase label (`"itms"`, `"tqms"`, `"sqms"`, `"tof"`,
178    /// `"ftms"`, `"sector"`), used as the `analyzer` value in
179    /// `openmassspec-arrow` batches.
180    pub fn as_str(self) -> &'static str {
181        match self {
182            Self::ITMS => "itms",
183            Self::TQMS => "tqms",
184            Self::SQMS => "sqms",
185            Self::TOFMS => "tof",
186            Self::FTMS => "ftms",
187            Self::Sector => "sector",
188        }
189    }
190}
191
192impl Activation {
193    /// Stable lowercase label (`"hcd"`, `"cid"`, `"ethcd"`, ...), used as the
194    /// `precursor_activation` value in `openmassspec-arrow` batches.
195    pub fn as_str(self) -> &'static str {
196        match self {
197            Self::CID => "cid",
198            Self::HCD => "hcd",
199            Self::ETD => "etd",
200            Self::ECD => "ecd",
201            Self::UVPD => "uvpd",
202            Self::PQD => "pqd",
203            Self::PD => "pd",
204            Self::SID => "sid",
205            Self::EThcD => "ethcd",
206            Self::IRMPD => "irmpd",
207            Self::MPID => "mpid",
208        }
209    }
210}
211
212impl MobilityArrayKind {
213    /// Stable label (`"inverse_reduced_k0"`, `"drift_time_ms"`), used as the
214    /// `mobility_array_kind` value in `openmassspec-arrow` batches.
215    pub fn as_str(self) -> &'static str {
216        match self {
217            Self::InverseReducedVsPerCm2 => "inverse_reduced_k0",
218            Self::DriftTimeMilliseconds => "drift_time_ms",
219        }
220    }
221}