diff --git a/Cargo.lock b/Cargo.lock index a08e23f..1ab5882 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2376,18 +2376,18 @@ checksum = "a3f0bf26fd526d2a95683cd0f87bf103b8539e2ca1ef48ce002d67aad59aa0b4" [[package]] name = "serde" -version = "1.0.197" +version = "1.0.198" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" +checksum = "9846a40c979031340571da2545a4e5b7c4163bdae79b301d5f86d03979451fcc" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.197" +version = "1.0.198" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" +checksum = "e88edab869b01783ba905e7d0153f9fc1a6505a96e4ad3018011eedb838566d9" dependencies = [ "proc-macro2", "quote", @@ -2396,9 +2396,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.114" +version = "1.0.116" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5f09b1bd632ef549eaa9f60a1f8de742bdbc698e6cee2095fc84dde5f549ae0" +checksum = "3e17db7126d17feb94eb3fad46bf1a96b034e8aacbc2e775fe81505f8b0b2813" dependencies = [ "itoa", "ryu", @@ -2636,9 +2636,9 @@ dependencies = [ [[package]] name = "timsrust" -version = "0.2.4" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9301709a549fabb2d79f564c528b0af5ca0002bdf0055341cfcc07950a44290b" +checksum = "1da6a544bbe53188e4d2955f45edb5317437cf84cc05a24158b929a663e7f69c" dependencies = [ "bytemuck", "byteorder", diff --git a/crates/sage-cli/src/main.rs b/crates/sage-cli/src/main.rs index d87fee6..d64bbdc 100644 --- a/crates/sage-cli/src/main.rs +++ b/crates/sage-cli/src/main.rs @@ -203,7 +203,7 @@ impl Runner { min_deisotope_mz.unwrap_or(0.0), ); - let bruker_extensions = [".d", ".tdf", ".tdf_bin"]; + let bruker_extensions = [".d", ".tdf", ".tdf_bin", "ms2", "raw"]; let spectra = chunk .par_iter() .enumerate() @@ -213,10 +213,16 @@ impl Runner { let path_lower = path.to_lowercase(); let res = if path_lower.ends_with(".mgf.gz") || path_lower.ends_with(".mgf") { sage_cloudpath::util::read_mgf(path, file_id) - } else if bruker_extensions - .iter() - .any(|ext| path_lower.ends_with(ext)) - { + } else if bruker_extensions.iter().any(|ext| { + if path_lower.ends_with(std::path::MAIN_SEPARATOR) { + path_lower + .strip_suffix(std::path::MAIN_SEPARATOR) + .unwrap() + .ends_with(ext) + } else { + path_lower.ends_with(ext) + } + }) { sage_cloudpath::util::read_tdf(path, file_id) } else { sage_cloudpath::util::read_mzml(path, file_id, sn) diff --git a/crates/sage-cloudpath/Cargo.toml b/crates/sage-cloudpath/Cargo.toml index 0e55748..d69c9ea 100644 --- a/crates/sage-cloudpath/Cargo.toml +++ b/crates/sage-cloudpath/Cargo.toml @@ -23,7 +23,7 @@ log = "0.4.0" once_cell = "1.0" tokio = { version = "1.0", features = ["fs", "io-util", "rt", "macros"] } quick-xml = { version = "0.31.0", features = ["async-tokio"] } -timsrust = "0.2.4" +timsrust = "0.3.0" rayon = "1.5" reqwest = { version = "0.11", features = ["json", "rustls-tls"], default-features = false } regex = "1.6" diff --git a/crates/sage-cloudpath/src/tdf.rs b/crates/sage-cloudpath/src/tdf.rs index e0e7cc7..be81f62 100644 --- a/crates/sage-cloudpath/src/tdf.rs +++ b/crates/sage-cloudpath/src/tdf.rs @@ -1,5 +1,8 @@ use rayon::prelude::*; -use sage_core::spectrum::{Precursor, RawSpectrum, Representation}; +use sage_core::{ + mass::Tolerance, + spectrum::{Precursor, RawSpectrum, Representation}, +}; pub struct TdfReader; @@ -9,21 +12,28 @@ impl TdfReader { path_name: impl AsRef, file_id: usize, ) -> Result, timsrust::Error> { - let dda_spectra: Vec = - timsrust::FileReader::new(path_name.as_ref())?.read_all_spectra(); - let spectra: Vec = (0..dda_spectra.len()) + let spectrum_reader = timsrust::io::readers::SpectrumReader::new(path_name.as_ref()); + let spectra: Vec = (0..spectrum_reader.len()) .into_par_iter() .map(|index| { - let dda_spectrum = &dda_spectra[index]; + let dda_spectrum = spectrum_reader.get(index); let mut precursor: Precursor = Precursor::default(); - let dda_precursor: timsrust::Precursor = - dda_spectrum.precursor.unwrap_as_precursor(); + let dda_precursor: timsrust::ms_data::Precursor = dda_spectrum.precursor; precursor.mz = dda_precursor.mz as f32; - precursor.charge = Option::from(dda_precursor.charge as u8); - // precursor.ion_mobility = Option::from(dda_precursor.im as f32); - precursor.intensity = Option::from(dda_precursor.intensity as f32); + precursor.charge = match dda_precursor.charge { + Some(x) => Some(x as u8), + None => None, + }; + precursor.intensity = match dda_precursor.intensity { + Some(x) => Some(x as f32), + None => None, + }; precursor.spectrum_ref = Option::from(dda_precursor.frame_index.to_string()); precursor.inverse_ion_mobility = Option::from(dda_precursor.im as f32); + precursor.isolation_window = Option::from(Tolerance::Da( + -dda_spectrum.isolation_width as f32 / 2.0, + dda_spectrum.isolation_width as f32 / 2.0, + )); let spectrum: RawSpectrum = RawSpectrum { file_id, precursors: vec![precursor],