diff --git a/Cargo.toml b/Cargo.toml index 716e740..8449a1c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ thermo = ["mzdata/thermo"] [dependencies] mzdata = "0.39.0" -timsrust = "0.3.0" +timsrust = "0.4.1" [dependencies.pyo3] version = "0.23.3" diff --git a/src/parse_timsrust.rs b/src/parse_timsrust.rs index bf7fc69..5f12b5f 100644 --- a/src/parse_timsrust.rs +++ b/src/parse_timsrust.rs @@ -3,8 +3,8 @@ use std::collections::HashMap; use crate::ms2_spectrum::MS2Spectrum; use crate::precursor::Precursor; -impl From for Precursor { - fn from(precursor: timsrust::ms_data::Precursor) -> Self { +impl From for Precursor { + fn from(precursor: timsrust::Precursor) -> Self { Precursor { mz: precursor.mz, rt: precursor.rt, @@ -15,8 +15,8 @@ impl From for Precursor { } } -impl From for MS2Spectrum { - fn from(spectrum: timsrust::ms_data::Spectrum) -> Self { +impl From for MS2Spectrum { + fn from(spectrum: timsrust::Spectrum) -> Self { MS2Spectrum::new( spectrum.index.to_string(), spectrum.mz_values.iter().map(|mz| *mz as f32).collect(), @@ -25,7 +25,7 @@ impl From for MS2Spectrum { .iter() .map(|intensity| *intensity as f32) .collect(), - Some(Precursor::from(spectrum.precursor)), + spectrum.precursor.map(Precursor::from), ) } } @@ -34,35 +34,36 @@ impl From for MS2Spectrum { pub fn parse_precursor_info( spectrum_path: &str, ) -> Result, std::io::Error> { - let reader = timsrust::FileReader::new(spectrum_path) + let reader = timsrust::readers::SpectrumReader::new(spectrum_path) .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?; - Ok(reader - .read_all_spectra() + let spectra = reader + .get_all() .into_iter() - .filter(|spectrum| { - matches!( - spectrum.precursor, - timsrust::ms_data::Precursor { .. } - ) - }) - .map(|spectrum| { - ( - spectrum.index.to_string(), - Precursor::from(spectrum.precursor), - ) + .collect::, _>>() + .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?; + + let precursor_info = spectra + .into_iter() + .filter_map(|spectrum| match spectrum.precursor { + Some(precursor) => Some((spectrum.index.to_string(), Precursor::from(precursor))), + None => None, }) - .collect::>()) + .collect::>(); + + Ok(precursor_info) } /// Read MS2 spectra from spectrum files with timsrust pub fn read_ms2_spectra(spectrum_path: &str) -> Result, std::io::Error> { - let reader = timsrust::FileReader::new(spectrum_path) + let reader = timsrust::readers::SpectrumReader::new(spectrum_path) .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?; - Ok(reader - .read_all_spectra() + let spectra = reader + .get_all() .into_iter() - .map(MS2Spectrum::from) - .collect()) + .collect::, _>>() + .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?; + + Ok(spectra.into_iter().map(MS2Spectrum::from).collect()) }