From d58e46b60a357aeed584e3609df0ea4eb9d6d5da Mon Sep 17 00:00:00 2001 From: Sander Willems Date: Tue, 3 Sep 2024 17:03:44 +0200 Subject: [PATCH] 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")]