#[non_exhaustive]pub struct SpectrumRecord {Show 23 fields
pub index: usize,
pub scan_number: u32,
pub native_id: String,
pub ms_level: u32,
pub polarity: Option<Polarity>,
pub scan_mode: Option<ScanMode>,
pub analyzer: Option<Analyzer>,
pub acquisition_event_id: Option<u32>,
pub filter: Option<String>,
pub retention_time_sec: f64,
pub total_ion_current: Option<f64>,
pub base_peak_mz: Option<f64>,
pub base_peak_intensity: Option<f64>,
pub low_mz: Option<f64>,
pub high_mz: Option<f64>,
pub ion_injection_time_ms: Option<f64>,
pub inv_mobility: Option<f64>,
pub faims_cv: Option<f64>,
pub precursor: Option<PrecursorInfo>,
pub mz: Vec<f64>,
pub intensity: Vec<f32>,
pub inv_mobility_per_peak: Option<Vec<f32>>,
pub extra: BTreeMap<String, String>,
}Expand description
One fully-decoded spectrum.
Retention time is stored in seconds (the mzML preferred unit). Vendors that natively store minutes (e.g. Thermo) convert at the boundary.
mz is f64 and intensity is f32 because that is what the PSI-MS CV
64-bit float / 32-bit float defaults are and what every downstream
search engine expects. Vendors that decode lower-precision arrays should
widen to these types.
§Example
A reader in another crate builds a record with SpectrumRecord::new
and the with_* setters:
use openmassspec_core::{
Activation, Analyzer, Polarity, PrecursorInfo, ScanMode, SpectrumRecord,
};
let precursor = PrecursorInfo::default()
.with_target_mz(445.12)
.with_selected_mz(445.1201)
.with_isolation_width(1.6)
.with_charge(2)
.with_collision_energy(30.0)
.with_ce_is_nce(true)
.with_activation(Activation::HCD)
.with_precursor_native_id("controllerType=0 controllerNumber=1 scan=41".to_string());
let rec = SpectrumRecord::new(41, 42, "controllerType=0 controllerNumber=1 scan=42")
.with_ms_level(2)
.with_polarity(Polarity::Positive)
.with_scan_mode(ScanMode::Centroid)
.with_analyzer(Analyzer::FTMS)
.with_retention_time_sec(12.5 * 60.0)
.with_faims_cv(None) // `Option<T>` values are accepted too
.with_precursor(precursor)
.with_peaks(vec![150.1, 250.2], vec![10.0, 20.0])
.with_extra("myreader.segment", "2");
assert_eq!(rec.ms_level, 2);
assert_eq!(rec.precursor.as_ref().unwrap().charge, Some(2));
// Public fields stay readable and assignable.
let mut rec = rec;
rec.filter = Some("FTMS + c NSI d Full ms2 445.12@hcd30.00".into());Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.index: usizeZero-based position in the source file. The mzML writer does not
copy it to index=; it numbers written spectra 0, 1, 2, … so
skipped records leave no gaps.
scan_number: u32One-based, source-stable scan number. For Bruker bundles this is a running counter assigned by the iterator (since PASEF frames produce many spectra per frame).
native_id: StringVerbatim mzML native ID for this spectrum. Vendors populate this with
the appropriate controllerType=..., frame=... scan=..., or
function=... process=... scan=... literal.
ms_level: u32MS level (1 for MS1, 2 for MS2, …).
polarity: Option<Polarity>Scan polarity.
scan_mode: Option<ScanMode>Centroid or profile.
analyzer: Option<Analyzer>Mass analyzer that recorded this spectrum.
acquisition_event_id: Option<u32>Numeric acquisition-event or grouping identifier decoded from the source file, when available.
filter: Option<String>Thermo-style scan filter (or vendor-equivalent). Optional; populated by parsers that have a meaningful filter string.
retention_time_sec: f64Retention time in seconds.
total_ion_current: Option<f64>Total ion current. If None, the mzML writer computes it from
intensity.
base_peak_mz: Option<f64>Base-peak m/z. If None, the mzML writer computes it from mz /
intensity.
base_peak_intensity: Option<f64>Base-peak intensity. If None, the mzML writer computes it from
intensity.
low_mz: Option<f64>Lowest observed m/z. If None, the writer uses mz.first().
high_mz: Option<f64>Highest observed m/z. If None, the writer uses mz.last().
ion_injection_time_ms: Option<f64>Ion injection (accumulation) time in milliseconds.
inv_mobility: Option<f64>Mean inverse reduced ion mobility (1/K0) for the spectrum, when applicable (Bruker timsTOF, Waters TWIMS).
faims_cv: Option<f64>FAIMS compensation voltage in volts, when the instrument has a FAIMS
Pro interface and reports it per-scan (Thermo Orbitrap Fusion/Lumos/
Eclipse/Ascend). None when not applicable or not decoded.
precursor: Option<PrecursorInfo>Precursor information for MS2+ spectra.
mz: Vec<f64>m/z values, ascending.
intensity: Vec<f32>Intensities, parallel to mz.
inv_mobility_per_peak: Option<Vec<f32>>Per-peak inverse reduced ion mobility, parallel to mz / intensity,
when an IMS-resolved parser opts to preserve it. Length must equal
mz.len() when present.
extra: BTreeMap<String, String>Namespaced reader-specific values. Keys use <reader>.<field>.
Implementations§
Source§impl SpectrumRecord
impl SpectrumRecord
Sourcepub fn new(index: usize, scan_number: u32, native_id: impl Into<String>) -> Self
pub fn new(index: usize, scan_number: u32, native_id: impl Into<String>) -> Self
A record with the identifying fields set, ms_level 1, retention
time 0, no peaks, and every optional field None. Fill in the rest
with the with_* setters or by assigning the public fields.
Sourcepub fn with_peaks(self, mz: Vec<f64>, intensity: Vec<f32>) -> Self
pub fn with_peaks(self, mz: Vec<f64>, intensity: Vec<f32>) -> Self
Set the mz and intensity arrays together.
Sourcepub fn with_extra(
self,
key: impl Into<String>,
value: impl Into<String>,
) -> Self
pub fn with_extra( self, key: impl Into<String>, value: impl Into<String>, ) -> Self
Insert one extra entry. Keys use <reader>.<field>.
Sourcepub fn effective_tic(&self) -> f64
pub fn effective_tic(&self) -> f64
Total ion current, computed from intensity when not pre-populated.
Sourcepub fn effective_base_peak(&self) -> Option<(f64, f64)>
pub fn effective_base_peak(&self) -> Option<(f64, f64)>
Base-peak (mz, intensity), computed from the arrays when not
pre-populated. Returns None when the spectrum has no peaks.
Sourcepub fn effective_mz_range(&self) -> Option<(f64, f64)>
pub fn effective_mz_range(&self) -> Option<(f64, f64)>
(low_mz, high_mz), falling back to the first/last entries in mz
when not pre-populated. Returns None for empty spectra.
Source§impl SpectrumRecord
impl SpectrumRecord
Sourcepub fn with_index(self, value: usize) -> Self
pub fn with_index(self, value: usize) -> Self
Set index.
Sourcepub fn with_scan_number(self, value: u32) -> Self
pub fn with_scan_number(self, value: u32) -> Self
Set scan_number.
Sourcepub fn with_native_id(self, value: impl Into<String>) -> Self
pub fn with_native_id(self, value: impl Into<String>) -> Self
Set native_id.
Sourcepub fn with_ms_level(self, value: u32) -> Self
pub fn with_ms_level(self, value: u32) -> Self
Set ms_level.
Sourcepub fn with_polarity(self, value: impl Into<Option<Polarity>>) -> Self
pub fn with_polarity(self, value: impl Into<Option<Polarity>>) -> Self
Set polarity. Accepts a value or an Option.
Sourcepub fn with_scan_mode(self, value: impl Into<Option<ScanMode>>) -> Self
pub fn with_scan_mode(self, value: impl Into<Option<ScanMode>>) -> Self
Set scan_mode. Accepts a value or an Option.
Sourcepub fn with_analyzer(self, value: impl Into<Option<Analyzer>>) -> Self
pub fn with_analyzer(self, value: impl Into<Option<Analyzer>>) -> Self
Set analyzer. Accepts a value or an Option.
Sourcepub fn with_acquisition_event_id(self, value: impl Into<Option<u32>>) -> Self
pub fn with_acquisition_event_id(self, value: impl Into<Option<u32>>) -> Self
Set acquisition_event_id. Accepts a value or an Option.
Sourcepub fn with_filter(self, value: impl Into<Option<String>>) -> Self
pub fn with_filter(self, value: impl Into<Option<String>>) -> Self
Set filter. Accepts a value or an Option.
Sourcepub fn with_retention_time_sec(self, value: f64) -> Self
pub fn with_retention_time_sec(self, value: f64) -> Self
Set retention_time_sec.
Sourcepub fn with_total_ion_current(self, value: impl Into<Option<f64>>) -> Self
pub fn with_total_ion_current(self, value: impl Into<Option<f64>>) -> Self
Set total_ion_current. Accepts a value or an Option.
Sourcepub fn with_base_peak_mz(self, value: impl Into<Option<f64>>) -> Self
pub fn with_base_peak_mz(self, value: impl Into<Option<f64>>) -> Self
Set base_peak_mz. Accepts a value or an Option.
Sourcepub fn with_base_peak_intensity(self, value: impl Into<Option<f64>>) -> Self
pub fn with_base_peak_intensity(self, value: impl Into<Option<f64>>) -> Self
Set base_peak_intensity. Accepts a value or an Option.
Sourcepub fn with_low_mz(self, value: impl Into<Option<f64>>) -> Self
pub fn with_low_mz(self, value: impl Into<Option<f64>>) -> Self
Set low_mz. Accepts a value or an Option.
Sourcepub fn with_high_mz(self, value: impl Into<Option<f64>>) -> Self
pub fn with_high_mz(self, value: impl Into<Option<f64>>) -> Self
Set high_mz. Accepts a value or an Option.
Sourcepub fn with_ion_injection_time_ms(self, value: impl Into<Option<f64>>) -> Self
pub fn with_ion_injection_time_ms(self, value: impl Into<Option<f64>>) -> Self
Set ion_injection_time_ms. Accepts a value or an Option.
Sourcepub fn with_inv_mobility(self, value: impl Into<Option<f64>>) -> Self
pub fn with_inv_mobility(self, value: impl Into<Option<f64>>) -> Self
Set inv_mobility. Accepts a value or an Option.
Sourcepub fn with_faims_cv(self, value: impl Into<Option<f64>>) -> Self
pub fn with_faims_cv(self, value: impl Into<Option<f64>>) -> Self
Set faims_cv. Accepts a value or an Option.
Sourcepub fn with_precursor(self, value: impl Into<Option<PrecursorInfo>>) -> Self
pub fn with_precursor(self, value: impl Into<Option<PrecursorInfo>>) -> Self
Set precursor. Accepts a value or an Option.
Sourcepub fn with_intensity(self, value: Vec<f32>) -> Self
pub fn with_intensity(self, value: Vec<f32>) -> Self
Set intensity.
Sourcepub fn with_inv_mobility_per_peak(
self,
value: impl Into<Option<Vec<f32>>>,
) -> Self
pub fn with_inv_mobility_per_peak( self, value: impl Into<Option<Vec<f32>>>, ) -> Self
Set inv_mobility_per_peak. Accepts a value or an Option.
Sourcepub fn with_extra_map(self, value: BTreeMap<String, String>) -> Self
pub fn with_extra_map(self, value: BTreeMap<String, String>) -> Self
Set extra.