Skip to content

Commit

Permalink
feature: added Thermo instrument methods to Thermo instrumentConfigur…
Browse files Browse the repository at this point in the history
…ation
  • Loading branch information
mobiusklein committed May 4, 2024
1 parent bca6269 commit 3cd0d1c
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 60 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ bytemuck = { version = "1.15.0", features = ["extern_crate_alloc"]}
base64-simd = "0.8.0"
thiserror = "1.0.50"

thermorawfilereader = { version = "0.2.3", default-features = false, optional = true }
thermorawfilereader = { version = "0.2.4", default-features = false, optional = true }
sha1 = "0.10.6"
base16ct = { version = "0.2.0", features = ["alloc"] }
chrono = "0.4.37"
Expand Down
105 changes: 50 additions & 55 deletions src/io/thermo/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use chrono::DateTime;
use crate::{
io::{utils::checksum_file, DetailLevel, OffsetIndex},
meta::{
Component, ComponentType, DataProcessing, DetectorTypeTerm, FileDescription, InstrumentConfiguration, IonizationTypeTerm, MassAnalyzerTerm, MassSpectrometryRun, Software, SourceFile
Component, ComponentType, DataProcessing, DetectorTypeTerm, FileDescription,
InstrumentConfiguration, IonizationTypeTerm, MassAnalyzerTerm, MassSpectrometryRun,
Software, SourceFile,
},
params::{ControlledVocabulary, Unit},
prelude::*,
Expand All @@ -19,13 +21,10 @@ use crate::{

use mzpeaks::{peak_set::PeakSetVec, prelude::*, CentroidPeak, DeconvolutedPeak, MZ};

use thermorawfilereader::schema::{
Polarity, SpectrumData, SpectrumMode,
};
use thermorawfilereader::schema::{Polarity, SpectrumData, SpectrumMode};
use thermorawfilereader::{
schema::{AcquisitionT, DissociationMethod, PrecursorT},
FileDescription as ThermoFileDescription, RawFileReader,
IonizationMode, MassAnalyzer
FileDescription as ThermoFileDescription, IonizationMode, MassAnalyzer, RawFileReader,
};

#[allow(unused)]
Expand Down Expand Up @@ -147,13 +146,7 @@ impl<C: CentroidLike + Default + From<CentroidPeak>, D: DeconvolutedCentroidLike
.const_param_ident("Thermo nativeID format", 1000768)
.into(),
);
sf.add_param(
ControlledVocabulary::MS.param_val(
1000569,
"SHA-1",
checksum_file(path)?
)
);
sf.add_param(ControlledVocabulary::MS.param_val(1000569, "SHA-1", checksum_file(path)?));

let levels: Vec<_> = description
.spectra_per_ms_level()
Expand Down Expand Up @@ -200,6 +193,21 @@ impl<C: CentroidLike + Default + From<CentroidPeak>, D: DeconvolutedCentroidLike
let mut configs = HashMap::new();
let mut components_to_instrument_id = HashMap::new();

let method_texts: Vec<Param> = (0..handle.instrument_method_count())
.into_iter()
.flat_map(|i| {
handle.instrument_method(i as u8)
})
.flat_map(|m| {
m.text().map(|s| {
Param::new_key_value(
"instrument method text",
s.to_string(),
)
})
})
.collect();

for (i, vconf) in descr.configurations().enumerate() {
let mut config = InstrumentConfiguration::default();

Expand Down Expand Up @@ -227,32 +235,23 @@ impl<C: CentroidLike + Default + From<CentroidPeak>, D: DeconvolutedCentroidLike
IonizationMode::CardNanoSprayIonization | IonizationMode::NanoSpray => {
IonizationTypeTerm::Nanoelectrospray
}
IonizationMode::ElectroSpray => {
IonizationTypeTerm::ElectrosprayIonization
}
IonizationMode::ElectroSpray => IonizationTypeTerm::ElectrosprayIonization,
IonizationMode::AtmosphericPressureChemicalIonization => {
IonizationTypeTerm::AtmosphericPressureChemicalIonization
}
IonizationMode::FastAtomBombardment => {
IonizationTypeTerm::FastAtomBombardmentIonization
}
IonizationMode::GlowDischarge => {
IonizationTypeTerm::GlowDischargeIonization
}
IonizationMode::ElectronImpact => {
IonizationTypeTerm::ElectronIonization
}
IonizationMode::GlowDischarge => IonizationTypeTerm::GlowDischargeIonization,
IonizationMode::ElectronImpact => IonizationTypeTerm::ElectronIonization,
IonizationMode::MatrixAssistedLaserDesorptionIonization => {
IonizationTypeTerm::MatrixAssistedLaserDesorptionIonization
}
IonizationMode::ChemicalIonization => {
IonizationTypeTerm::ChemicalIonization
}
_ => {
IonizationTypeTerm::IonizationType
}
IonizationMode::ChemicalIonization => IonizationTypeTerm::ChemicalIonization,
_ => IonizationTypeTerm::IonizationType,
}
.to_param().into(),
.to_param()
.into(),
);
config.components.push(ion_source);

Expand All @@ -262,29 +261,26 @@ impl<C: CentroidLike + Default + From<CentroidPeak>, D: DeconvolutedCentroidLike

analyzer.add_param(
match vconf.mass_analyzer {
MassAnalyzer::ITMS => {
MassAnalyzerTerm::RadialEjectionLinearIonTrap
}
MassAnalyzer::FTMS => {
MassAnalyzerTerm::Orbitrap
}
MassAnalyzer::ITMS => MassAnalyzerTerm::RadialEjectionLinearIonTrap,
MassAnalyzer::FTMS => MassAnalyzerTerm::Orbitrap,
MassAnalyzer::ASTMS => {
MassAnalyzerTerm::AsymmetricTrackLosslessTimeOfFlightAnalyzer
}
MassAnalyzer::TOFMS => {
MassAnalyzerTerm::TimeOfFlight
}
MassAnalyzer::TOFMS => MassAnalyzerTerm::TimeOfFlight,
// MassAnalyzer::TQMS => {}
// MassAnalyzer::SQMS => {}
MassAnalyzer::Sector => {
MassAnalyzerTerm::MagneticSector
}
MassAnalyzer::Sector => MassAnalyzerTerm::MagneticSector,
_ => MassAnalyzerTerm::MassAnalyzerType,
}
.to_param().into(),
.to_param()
.into(),
);
config.components.push(analyzer);

for p in method_texts.iter() {
config.add_param(p.clone())
}

let mut detector = Component::default();
detector.order = 2;
detector.component_type = ComponentType::Detector;
Expand All @@ -293,27 +289,24 @@ impl<C: CentroidLike + Default + From<CentroidPeak>, D: DeconvolutedCentroidLike
MassAnalyzer::ITMS | MassAnalyzer::ASTMS => {
DetectorTypeTerm::ElectronMultiplier
}
MassAnalyzer::FTMS => {
DetectorTypeTerm::InductiveDetector
}
MassAnalyzer::FTMS => DetectorTypeTerm::InductiveDetector,
_ => DetectorTypeTerm::DetectorType,
// MassAnalyzer::TOFMS => {}
// MassAnalyzer::TQMS => {}
// MassAnalyzer::SQMS => {}
// MassAnalyzer::Sector => {}
}
.to_param().into(),
.to_param()
.into(),
);
config.components.push(detector);

if let Some(serial) = descr.serial_number() {
config.add_param(
ControlledVocabulary::MS.param_val(
1000529,
"instrument serial number",
serial,
)
);
config.add_param(ControlledVocabulary::MS.param_val(
1000529,
"instrument serial number",
serial,
));
}
config.software_reference = sw.id.clone();
config.id = i as u32;
Expand Down Expand Up @@ -475,7 +468,10 @@ impl<C: CentroidLike + Default + From<CentroidPeak>, D: DeconvolutedCentroidLike
"preset scan configuration",
vevent.scan_event(),
));
let ic_key = (vevent.ionization_mode().0.into(), vevent.mass_analyzer().0.into());
let ic_key = (
vevent.ionization_mode().0.into(),
vevent.mass_analyzer().0.into(),
);
if let Some(conf_id) = self.components_to_instrument_id.get(&ic_key) {
event.instrument_configuration_id = *conf_id;
}
Expand Down Expand Up @@ -875,7 +871,6 @@ mod test {
assert_eq!(spec.signal_continuity(), SignalContinuity::Profile);
assert_eq!(spec.polarity(), ScanPolarity::Positive);


let event = spec.acquisition().first_scan().unwrap();
assert_eq!(1, event.instrument_configuration_id);

Expand Down
30 changes: 30 additions & 0 deletions src/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ pub trait ParamValue {

/// Get a reference to the stored value
fn as_ref(&self) -> ValueRef<'_>;

fn data_len(&self) -> usize;
}

#[doc(hidden)]
Expand Down Expand Up @@ -379,6 +381,16 @@ impl ParamValue for Value {
fn as_ref(&self) -> ValueRef<'_> {
self.into()
}

fn data_len(&self) -> usize {
match self {
Self::String(v) => v.len(),
Self::Buffer(v) => v.len(),
Self::Float(_) => 8,
Self::Int(_) => 8,
Self::Empty => 0,
}
}
}

impl PartialEq<String> for Value {
Expand Down Expand Up @@ -792,6 +804,16 @@ impl<'a> ParamValue for ValueRef<'a> {
fn as_ref(&self) -> ValueRef<'_> {
self.clone()
}

fn data_len(&self) -> usize {
match self {
Self::String(v) => v.len(),
Self::Buffer(v) => v.len(),
Self::Float(_) => 8,
Self::Int(_) => 8,
Self::Empty => 0,
}
}
}

impl<'a> From<&'a Value> for ValueRef<'a> {
Expand Down Expand Up @@ -1124,6 +1146,10 @@ impl<'a> ParamValue for ParamCow<'a> {
fn as_ref(&self) -> ValueRef<'_> {
<ValueRef<'a> as ParamValue>::as_ref(&self.value)
}

fn data_len(&self) -> usize {
<ValueRef<'a> as ParamValue>::data_len(&self.value)
}
}

impl ParamCow<'static> {
Expand Down Expand Up @@ -1280,6 +1306,10 @@ impl ParamValue for Param {
fn as_ref(&self) -> ValueRef<'_> {
<Value as ParamValue>::as_ref(&self.value)
}

fn data_len(&self) -> usize {
<Value as ParamValue>::data_len(&self.value)
}
}

impl Display for Param {
Expand Down

0 comments on commit 3cd0d1c

Please sign in to comment.