Skip to content

Commit

Permalink
feature: formally use the expanded ion mobility ArrayTypes, can't s…
Browse files Browse the repository at this point in the history
…olve units
  • Loading branch information
mobiusklein committed Feb 17, 2025
1 parent fa6666a commit 21146d2
Show file tree
Hide file tree
Showing 6 changed files with 284 additions and 94 deletions.
61 changes: 37 additions & 24 deletions src/io/mzml/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,36 +151,41 @@ pub trait SpectrumBuilding<
}
}
1002477 => {
self.current_array_mut().name = ArrayType::MeanDriftTimeArray;
self.current_array_mut().unit = param.unit();
}
1002816 => {
self.current_array_mut().name = ArrayType::MeanIonMobilityArray;
self.current_array_mut().unit = Unit::Millisecond;
self.current_array_mut().unit = param.unit();
}
1003006 => {
self.current_array_mut().name = ArrayType::MeanIonMobilityArray;
self.current_array_mut().unit = Unit::VoltSecondPerSquareCentimeter;
self.current_array_mut().name = ArrayType::MeanInverseReducedIonMobilityArray;
self.current_array_mut().unit = param.unit();
}
1003007 => {
self.current_array_mut().name = ArrayType::IonMobilityArray;
self.current_array_mut().unit = Unit::Unknown;
self.current_array_mut().name = ArrayType::RawIonMobilityArray;
self.current_array_mut().unit = param.unit();
}
1003153 => {
self.current_array_mut().name = ArrayType::IonMobilityArray;
self.current_array_mut().unit = Unit::Unknown;
self.current_array_mut().name = ArrayType::RawDriftTimeArray;
self.current_array_mut().unit = param.unit();
}
1003156 => {
self.current_array_mut().name = ArrayType::IonMobilityArray;
self.current_array_mut().unit = Unit::Millisecond;
self.current_array_mut().name = ArrayType::DeconvolutedDriftTimeArray;
self.current_array_mut().unit = param.unit();
}
1003008 => {
self.current_array_mut().name = ArrayType::IonMobilityArray;
self.current_array_mut().unit = Unit::VoltSecondPerSquareCentimeter;
self.current_array_mut().name = ArrayType::RawInverseReducedIonMobilityArray;
self.current_array_mut().unit = param.unit();
}
1003154 => {
self.current_array_mut().name = ArrayType::DeconvolutedIonMobilityArray;
self.current_array_mut().unit = Unit::Millisecond;
self.current_array_mut().name = ArrayType::DeconvolutedDriftTimeArray;
self.current_array_mut().unit = param.unit();
}
1003155 => {
self.current_array_mut().name = ArrayType::DeconvolutedIonMobilityArray;
self.current_array_mut().unit = Unit::VoltSecondPerSquareCentimeter;
self.current_array_mut().name =
ArrayType::DeconvolutedInverseReducedIonMobilityArray;
self.current_array_mut().unit = param.unit();
}
_ => {
self.current_array_mut().add_param(param.into());
Expand Down Expand Up @@ -2744,34 +2749,42 @@ mod test {
builder._reset();
}
let pairs = [
(1002477, ArrayType::MeanIonMobilityArray, Unit::Millisecond),
(1002477, ArrayType::MeanDriftTimeArray, Unit::Millisecond),
(
1003006,
ArrayType::MeanIonMobilityArray,
ArrayType::MeanInverseReducedIonMobilityArray,
Unit::VoltSecondPerSquareCentimeter,
),
(1003007, ArrayType::IonMobilityArray, Unit::Unknown),
(1003153, ArrayType::IonMobilityArray, Unit::Unknown),
(1003156, ArrayType::IonMobilityArray, Unit::Millisecond),
(1003007, ArrayType::RawIonMobilityArray, Unit::Unknown),
(1003153, ArrayType::RawDriftTimeArray, Unit::Unknown),
(
1003156,
ArrayType::DeconvolutedDriftTimeArray,
Unit::Millisecond,
),
(
1003008,
ArrayType::IonMobilityArray,
ArrayType::RawInverseReducedIonMobilityArray,
Unit::VoltSecondPerSquareCentimeter,
),
(
1003154,
ArrayType::DeconvolutedIonMobilityArray,
ArrayType::DeconvolutedDriftTimeArray,
Unit::Millisecond,
),
(
1003155,
ArrayType::DeconvolutedIonMobilityArray,
ArrayType::DeconvolutedInverseReducedIonMobilityArray,
Unit::VoltSecondPerSquareCentimeter,
),
];

for (acc, term, unit) in pairs {
builder.fill_binary_data_array(ControlledVocabulary::MS.param(acc, term.to_string()));
builder.fill_binary_data_array(
ControlledVocabulary::MS
.param(acc, term.to_string())
.with_unit_t(&unit),
);
assert_eq!(builder.current_array.name, term);
assert_eq!(builder.current_array.unit, unit);
builder._reset();
Expand Down
50 changes: 34 additions & 16 deletions src/io/mzml/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ use mzpeaks::{CentroidPeak, DeconvolutedPeak};

use crate::io::traits::IonMobilityFrameWriter;
use crate::meta::{
ComponentType, DataProcessing, FileDescription, InstrumentConfiguration, MSDataFileMetadata, MassSpectrometryRun, Sample, Software
ComponentType, DataProcessing, FileDescription, InstrumentConfiguration, MSDataFileMetadata,
MassSpectrometryRun, Sample, Software,
};
use crate::params::{
AccessionIntCode, ControlledVocabulary, Param, ParamCow, ParamDescribed, ParamDescribedRead, ParamLike, ParamValue, Unit, ValueRef
AccessionIntCode, ControlledVocabulary, Param, ParamCow, ParamDescribed, ParamDescribedRead,
ParamLike, ParamValue, Unit, ValueRef,
};
use crate::spectrum::bindata::{
to_bytes, ArrayRetrievalError, ArrayType, BinaryArrayMap, BinaryCompressionType,
Expand Down Expand Up @@ -985,7 +987,7 @@ where

fn write_sample_list(&mut self) -> WriterResult {
if self.samples.is_empty() {
return Ok(())
return Ok(());
}
let mut outer = bstart!("sampleList");
let count = self.samples.len().to_string();
Expand Down Expand Up @@ -1499,8 +1501,11 @@ where
fn write_ms_level<
C1: CentroidLike + Default + BuildArrayMapFrom,
D1: DeconvolutedCentroidLike + Default + BuildArrayMapFrom,
S: SpectrumLike<C1, D1> + 'static
>(&mut self, spectrum: &S) -> WriterResult {
S: SpectrumLike<C1, D1> + 'static,
>(
&mut self,
spectrum: &S,
) -> WriterResult {
let ms_level = spectrum.ms_level();
match ms_level {
1 => self.handle.write_param(&MS1_SPECTRUM)?,
Expand All @@ -1519,8 +1524,11 @@ where
fn write_polarity<
C1: CentroidLike + Default + BuildArrayMapFrom,
D1: DeconvolutedCentroidLike + Default + BuildArrayMapFrom,
S: SpectrumLike<C1, D1> + 'static
>(&mut self, spectrum: &S) -> WriterResult {
S: SpectrumLike<C1, D1> + 'static,
>(
&mut self,
spectrum: &S,
) -> WriterResult {
match spectrum.polarity() {
ScanPolarity::Negative => self.handle.write_param(&NEGATIVE_SCAN),
ScanPolarity::Positive => self.handle.write_param(&POSITIVE_SCAN),
Expand All @@ -1537,8 +1545,11 @@ where
fn write_continuity<
C1: CentroidLike + Default + BuildArrayMapFrom,
D1: DeconvolutedCentroidLike + Default + BuildArrayMapFrom,
S: SpectrumLike<C1, D1> + 'static
>(&mut self, spectrum: &S) -> WriterResult {
S: SpectrumLike<C1, D1> + 'static,
>(
&mut self,
spectrum: &S,
) -> WriterResult {
match spectrum.signal_continuity() {
SignalContinuity::Profile => self.handle.write_param(&PROFILE_SPECTRUM),
SignalContinuity::Unknown => {
Expand All @@ -1555,7 +1566,7 @@ where
fn write_signal_properties<
C1: CentroidLike + Default + BuildArrayMapFrom,
D1: DeconvolutedCentroidLike + Default + BuildArrayMapFrom,
S: SpectrumLike<C1, D1> + 'static
S: SpectrumLike<C1, D1> + 'static,
>(
&mut self,
spectrum: &S,
Expand Down Expand Up @@ -1650,11 +1661,18 @@ where
self.handle.write_param(&array.name.as_param_const())?
}
ArrayType::TimeArray
| ArrayType::RawIonMobilityArray
| ArrayType::MeanIonMobilityArray
| ArrayType::DeconvolutedIonMobilityArray => self
| ArrayType::TemperatureArray
| ArrayType::FlowRateArray
| ArrayType::PressureArray
| ArrayType::WavelengthArray
| ArrayType::IonMobilityArray => self
.handle
.write_param(&array.name.as_param_with_unit_const(array.unit))?,
x if x.is_ion_mobility() => {
self
.handle
.write_param(&array.name.as_param_with_unit_const(array.unit))?
},
ArrayType::NonStandardDataArray { name } => {
let mut p =
self.ms_cv
Expand Down Expand Up @@ -1781,7 +1799,7 @@ where
pub fn spectrum_has_summaries<
C1: CentroidLike + Default + BuildArrayMapFrom,
D1: DeconvolutedCentroidLike + Default + BuildArrayMapFrom,
S: SpectrumLike<C1, D1> + 'static
S: SpectrumLike<C1, D1> + 'static,
>(
&self,
spectrum: &S,
Expand Down Expand Up @@ -1818,7 +1836,7 @@ where
pub fn write_spectrum_descriptors<
C1: CentroidLike + Default + BuildArrayMapFrom,
D1: DeconvolutedCentroidLike + Default + BuildArrayMapFrom,
S: SpectrumLike<C1, D1> + 'static
S: SpectrumLike<C1, D1> + 'static,
>(
&mut self,
spectrum: &S,
Expand Down Expand Up @@ -1852,7 +1870,7 @@ where
pub fn write_spectrum<
C1: CentroidLike + Default + BuildArrayMapFrom,
D1: DeconvolutedCentroidLike + Default + BuildArrayMapFrom,
S: SpectrumLike<C1, D1> + 'static
S: SpectrumLike<C1, D1> + 'static,
>(
&mut self,
spectrum: &S,
Expand Down
2 changes: 1 addition & 1 deletion src/io/mzmlb/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ impl Display for BufferName {
ArrayType::NonStandardDataArray { name } => Cow::Owned(name.replace(['/', ' '], "_")),
ArrayType::BaselineArray => Cow::Borrowed("baseline"),
ArrayType::ResolutionArray => Cow::Borrowed("resolution"),
_ => Cow::Owned(self.array_type.to_string())
_ => Cow::Owned(self.array_type.to_string().replace(['/', ' '], "_").to_lowercase())
};
let dtype = match self.dtype {
BinaryDataArrayType::Unknown => "unknown",
Expand Down
2 changes: 1 addition & 1 deletion src/io/tdf/arrays.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl<'a> FrameToArraysMapper<'a> {

BinaryArrayMap3D::from_ion_mobility_dimension_and_arrays(
im_dimension,
ArrayType::IonMobilityArray,
ArrayType::MeanInverseReducedIonMobilityArray,
Unit::VoltSecondPerSquareCentimeter,
arrays,
)
Expand Down
20 changes: 9 additions & 11 deletions src/io/tdf/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,12 @@ use std::{

use chrono::DateTime;

use crate::{
io::IntoIonMobilityFrameSource,
mzpeaks::{CentroidPeak, DeconvolutedPeak},
};

#[allow(unused)]
use crate::io::checksum_file;

use crate::{
curie,
io::{DetailLevel, IonMobilityFrameAccessError, OffsetIndex},
io::{DetailLevel, IonMobilityFrameAccessError, OffsetIndex, IntoIonMobilityFrameSource},
meta::{
Component, ComponentType, DataProcessing, DetectorTypeTerm,
DissociationMethodTerm::CollisionInducedDissociation, FileDescription,
Expand All @@ -26,6 +21,7 @@ use crate::{
mzpeaks::{
feature::{ChargedFeature, Feature},
IonMobility, Mass, MZ,
CentroidPeak, DeconvolutedPeak
},
params::{ControlledVocabulary, Unit, Value},
prelude::*,
Expand All @@ -47,12 +43,14 @@ use timsrust::{
};

pub use super::arrays::FrameToArraysMapper;
use super::constants::{InstrumentSource, MsMsType};
use super::sql::{
FromSQL, PasefPrecursor, RawTDFSQLReader, SQLDIAFrameMsMsWindow, SQLFrame, SQLPasefFrameMsMs,
SQLPrecursor, TDFMSnFacet,
use super::{
arrays::consolidate_peaks,
constants::{InstrumentSource, MsMsType},
sql::{
ChromatographyData, FromSQL, PasefPrecursor, RawTDFSQLReader, SQLDIAFrameMsMsWindow,
SQLFrame, SQLPasefFrameMsMs, SQLPrecursor, TDFMSnFacet,
},
};
use super::{arrays::consolidate_peaks, sql::ChromatographyData};

const PEAK_MERGE_TOLERANCE: Tolerance = Tolerance::Da(0.01);

Expand Down
Loading

0 comments on commit 21146d2

Please sign in to comment.