Skip to main content

SpectrumRecord

Struct SpectrumRecord 

Source
#[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
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§index: usize

Zero-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: u32

One-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: String

Verbatim mzML native ID for this spectrum. Vendors populate this with the appropriate controllerType=..., frame=... scan=..., or function=... process=... scan=... literal.

§ms_level: u32

MS 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: f64

Retention 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

Source

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.

Source

pub fn with_peaks(self, mz: Vec<f64>, intensity: Vec<f32>) -> Self

Set the mz and intensity arrays together.

Source

pub fn with_extra( self, key: impl Into<String>, value: impl Into<String>, ) -> Self

Insert one extra entry. Keys use <reader>.<field>.

Source

pub fn effective_tic(&self) -> f64

Total ion current, computed from intensity when not pre-populated.

Source

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.

Source

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

Source

pub fn with_index(self, value: usize) -> Self

Set index.

Source

pub fn with_scan_number(self, value: u32) -> Self

Set scan_number.

Source

pub fn with_native_id(self, value: impl Into<String>) -> Self

Set native_id.

Source

pub fn with_ms_level(self, value: u32) -> Self

Set ms_level.

Source

pub fn with_polarity(self, value: impl Into<Option<Polarity>>) -> Self

Set polarity. Accepts a value or an Option.

Source

pub fn with_scan_mode(self, value: impl Into<Option<ScanMode>>) -> Self

Set scan_mode. Accepts a value or an Option.

Source

pub fn with_analyzer(self, value: impl Into<Option<Analyzer>>) -> Self

Set analyzer. Accepts a value or an Option.

Source

pub fn with_acquisition_event_id(self, value: impl Into<Option<u32>>) -> Self

Set acquisition_event_id. Accepts a value or an Option.

Source

pub fn with_filter(self, value: impl Into<Option<String>>) -> Self

Set filter. Accepts a value or an Option.

Source

pub fn with_retention_time_sec(self, value: f64) -> Self

Set retention_time_sec.

Source

pub fn with_total_ion_current(self, value: impl Into<Option<f64>>) -> Self

Set total_ion_current. Accepts a value or an Option.

Source

pub fn with_base_peak_mz(self, value: impl Into<Option<f64>>) -> Self

Set base_peak_mz. Accepts a value or an Option.

Source

pub fn with_base_peak_intensity(self, value: impl Into<Option<f64>>) -> Self

Set base_peak_intensity. Accepts a value or an Option.

Source

pub fn with_low_mz(self, value: impl Into<Option<f64>>) -> Self

Set low_mz. Accepts a value or an Option.

Source

pub fn with_high_mz(self, value: impl Into<Option<f64>>) -> Self

Set high_mz. Accepts a value or an Option.

Source

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.

Source

pub fn with_inv_mobility(self, value: impl Into<Option<f64>>) -> Self

Set inv_mobility. Accepts a value or an Option.

Source

pub fn with_faims_cv(self, value: impl Into<Option<f64>>) -> Self

Set faims_cv. Accepts a value or an Option.

Source

pub fn with_precursor(self, value: impl Into<Option<PrecursorInfo>>) -> Self

Set precursor. Accepts a value or an Option.

Source

pub fn with_mz(self, value: Vec<f64>) -> Self

Set mz.

Source

pub fn with_intensity(self, value: Vec<f32>) -> Self

Set intensity.

Source

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.

Source

pub fn with_extra_map(self, value: BTreeMap<String, String>) -> Self

Set extra.

Trait Implementations§

Source§

impl Clone for SpectrumRecord

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SpectrumRecord

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for SpectrumRecord

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for SpectrumRecord

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for SpectrumRecord

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for SpectrumRecord

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.