From 745d50d717f25096a17d19a2495b9c9a47d73c5a Mon Sep 17 00:00:00 2001 From: Sander Willems Date: Mon, 2 Sep 2024 10:16:00 +0200 Subject: [PATCH 1/4] CHORE: patch version update --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/io/readers/frame_reader.rs | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5119052..b91fce9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1121,7 +1121,7 @@ dependencies = [ [[package]] name = "timsrust" -version = "0.4.0" +version = "0.4.1" dependencies = [ "bytemuck", "criterion", diff --git a/Cargo.toml b/Cargo.toml index f69025d..dccb98f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "timsrust" -version = "0.4.0" +version = "0.4.1" edition = "2021" description = "A crate to read Bruker timsTOF data" license = "Apache-2.0" diff --git a/src/io/readers/frame_reader.rs b/src/io/readers/frame_reader.rs index 6460a83..ce956b7 100644 --- a/src/io/readers/frame_reader.rs +++ b/src/io/readers/frame_reader.rs @@ -112,6 +112,7 @@ impl FrameReader { } pub fn get(&self, index: usize) -> Result { + // NOTE: get does it by 0-offsetting the vec, not by Frame index!!! let mut frame = self.frames[index].clone(); let offset = self.offsets[index]; let blob = self.tdf_bin_reader.get(offset)?; From f54971a0eb62c4f825daff875cbf1bdf10be1077 Mon Sep 17 00:00:00 2001 From: Sander Willems Date: Mon, 2 Sep 2024 10:51:59 +0200 Subject: [PATCH 2/4] FEAT: Made spectrum readers Sendable --- src/io/readers/precursor_reader.rs | 2 +- src/io/readers/spectrum_reader.rs | 4 ++-- src/io/readers/spectrum_reader/tdf/raw_spectra.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/io/readers/precursor_reader.rs b/src/io/readers/precursor_reader.rs index 96c5027..04f0324 100644 --- a/src/io/readers/precursor_reader.rs +++ b/src/io/readers/precursor_reader.rs @@ -93,7 +93,7 @@ impl PrecursorReaderBuilder { } } -trait PrecursorReaderTrait: Sync { +trait PrecursorReaderTrait: Sync + Send { fn get(&self, index: usize) -> Option; fn len(&self) -> usize; } diff --git a/src/io/readers/spectrum_reader.rs b/src/io/readers/spectrum_reader.rs index 9607cb5..5a625f1 100644 --- a/src/io/readers/spectrum_reader.rs +++ b/src/io/readers/spectrum_reader.rs @@ -64,7 +64,7 @@ impl SpectrumReader { spectra } - pub fn calibrate(&mut self) { + fn calibrate(&mut self) { self.spectrum_reader.calibrate(); } } @@ -116,7 +116,7 @@ impl SpectrumReaderBuilder { } } -trait SpectrumReaderTrait: Sync { +trait SpectrumReaderTrait: Sync + Send { fn get(&self, index: usize) -> Result; fn get_path(&self) -> PathBuf; fn len(&self) -> usize; diff --git a/src/io/readers/spectrum_reader/tdf/raw_spectra.rs b/src/io/readers/spectrum_reader/tdf/raw_spectra.rs index 95b4a46..896c759 100644 --- a/src/io/readers/spectrum_reader/tdf/raw_spectra.rs +++ b/src/io/readers/spectrum_reader/tdf/raw_spectra.rs @@ -135,7 +135,7 @@ impl RawSpectrumReader { } } -pub trait RawSpectrumReaderTrait: Sync { +pub trait RawSpectrumReaderTrait: Sync + Send { fn get(&self, index: usize) -> Result; fn len(&self) -> usize; } From e8d24167100b3e559a4b01f90ffaa59eec0fefde Mon Sep 17 00:00:00 2001 From: Sander Willems Date: Tue, 3 Sep 2024 17:03:18 +0200 Subject: [PATCH 3/4] CHORE: added serialization feature --- Cargo.lock | 15 +++++++++------ Cargo.toml | 5 ++++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b91fce9..04cfc3b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1019,18 +1019,18 @@ checksum = "a3f0bf26fd526d2a95683cd0f87bf103b8539e2ca1ef48ce002d67aad59aa0b4" [[package]] name = "serde" -version = "1.0.204" +version = "1.0.209" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc76f558e0cbb2a839d37354c575f1dc3fdc6546b5be373ba43d95f231bf7c12" +checksum = "99fce0ffe7310761ca6bf9faf5115afbc19688edd00171d81b1bb1b116c63e09" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.204" +version = "1.0.209" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0cd7e117be63d3c3678776753929474f3b04a43a080c744d6b0ae2a8c28e222" +checksum = "a5831b979fd7b5439637af1752d535ff49f4860c0f341d1baeb6faf0f4242170" dependencies = [ "proc-macro2", "quote", @@ -1039,11 +1039,12 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.120" +version = "1.0.127" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e0d21c9a8cae1235ad58a00c11cb40d4b1e5c784f1ef2c537876ed6ffd8b7c5" +checksum = "8043c06d9f82bd7271361ed64f415fe5e12a77fdb52e573e7f06a516dea329ad" dependencies = [ "itoa", + "memchr", "ryu", "serde", ] @@ -1130,6 +1131,8 @@ dependencies = [ "parquet", "rayon", "rusqlite", + "serde", + "serde_json", "thiserror", "zstd 0.13.2", ] diff --git a/Cargo.toml b/Cargo.toml index dccb98f..2d50312 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,11 +22,14 @@ thiserror = "1.0.0" memmap2 = "0.9.3" rusqlite = { version = "0.31.0", features = ["bundled"], optional = true} parquet = { version = "42.0.0", optional = true } +serde = { version = "1.0.209", features = ["derive"], optional = true } +serde_json = { version = "1.0.127", optional = true } [features] tdf = ["rusqlite"] minitdf = ["parquet"] -default = ["tdf", "minitdf"] +default = ["tdf", "minitdf", "serialize"] +serialize = ["serde", "serde_json"] [dev-dependencies] criterion = { version = "0.5.1", features = ["html_reports"] } From d58e46b60a357aeed584e3609df0ea4eb9d6d5da Mon Sep 17 00:00:00 2001 From: Sander Willems Date: Tue, 3 Sep 2024 17:03:44 +0200 Subject: [PATCH 4/4] FEAT: add serialization to spectrum reader config --- src/domain_converters/scan_to_im.rs | 4 ++++ src/domain_converters/tof_to_mz.rs | 3 +++ src/io/readers/quad_settings_reader.rs | 4 ++++ src/io/readers/spectrum_reader.rs | 8 ++++++-- 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/domain_converters/scan_to_im.rs b/src/domain_converters/scan_to_im.rs index 2a9d8bd..62433c9 100644 --- a/src/domain_converters/scan_to_im.rs +++ b/src/domain_converters/scan_to_im.rs @@ -1,5 +1,9 @@ +#[cfg(feature = "serialize")] +use serde::{Deserialize, Serialize}; + /// A converter from Scan -> (inversed) ion mobility. #[derive(Debug, Default, Clone, Copy, PartialEq)] +#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))] pub struct Scan2ImConverter { scan_intercept: f64, scan_slope: f64, diff --git a/src/domain_converters/tof_to_mz.rs b/src/domain_converters/tof_to_mz.rs index c42078b..8360704 100644 --- a/src/domain_converters/tof_to_mz.rs +++ b/src/domain_converters/tof_to_mz.rs @@ -1,7 +1,10 @@ use linreg::linear_regression; +#[cfg(feature = "serialize")] +use serde::{Deserialize, Serialize}; /// A converter from TOF -> m/z. #[derive(Debug, Default, Clone, Copy, PartialEq)] +#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))] pub struct Tof2MzConverter { tof_intercept: f64, tof_slope: f64, diff --git a/src/io/readers/quad_settings_reader.rs b/src/io/readers/quad_settings_reader.rs index 147ab84..eb67dfc 100644 --- a/src/io/readers/quad_settings_reader.rs +++ b/src/io/readers/quad_settings_reader.rs @@ -1,3 +1,5 @@ +#[cfg(feature = "serialize")] +use serde::{Deserialize, Serialize}; use std::path::Path; use crate::{ @@ -151,6 +153,7 @@ type ScanSpanStep = (usize, usize); /// 100 and step 80 between their in the scan number. /// #[derive(Debug, Copy, Clone)] +#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))] pub enum QuadWindowExpansionStrategy { None, Even(usize), @@ -171,6 +174,7 @@ pub enum FrameWindowSplittingStrategy { } #[derive(Debug, Clone, Copy)] +#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))] pub enum FrameWindowSplittingConfiguration { Quadrupole(QuadWindowExpansionStrategy), Window(QuadWindowExpansionStrategy), diff --git a/src/io/readers/spectrum_reader.rs b/src/io/readers/spectrum_reader.rs index 5a625f1..7b125ab 100644 --- a/src/io/readers/spectrum_reader.rs +++ b/src/io/readers/spectrum_reader.rs @@ -8,6 +8,8 @@ use core::fmt; #[cfg(feature = "minitdf")] use minitdf::{MiniTDFSpectrumReader, MiniTDFSpectrumReaderError}; use rayon::iter::{IntoParallelIterator, ParallelIterator}; +#[cfg(feature = "serialize")] +use serde::{Deserialize, Serialize}; use std::path::{Path, PathBuf}; #[cfg(feature = "tdf")] use tdf::{TDFSpectrumReader, TDFSpectrumReaderError}; @@ -135,7 +137,8 @@ pub enum SpectrumReaderError { SpectrumReaderFileError(PathBuf), } -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Copy)] +#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))] pub struct SpectrumProcessingParams { pub smoothing_window: u32, pub centroiding_window: u32, @@ -154,7 +157,8 @@ impl Default for SpectrumProcessingParams { } } -#[derive(Debug, Default, Clone)] +#[derive(Debug, Default, Clone, Copy)] +#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))] pub struct SpectrumReaderConfig { pub spectrum_processing_params: SpectrumProcessingParams, #[cfg(feature = "tdf")]