From cd9f511c571e8869987ff9cda3504dcca070bcbc Mon Sep 17 00:00:00 2001 From: Michael Lazear Date: Thu, 25 Jul 2024 14:23:41 -0700 Subject: [PATCH] feat: enforce variable modifications as a list of values --- crates/sage/src/database.rs | 2 +- crates/sage/src/modification.rs | 54 ++------------------------------- 2 files changed, 3 insertions(+), 53 deletions(-) diff --git a/crates/sage/src/database.rs b/crates/sage/src/database.rs index 567f72b..db8cd11 100644 --- a/crates/sage/src/database.rs +++ b/crates/sage/src/database.rs @@ -75,7 +75,7 @@ pub struct Builder { /// Static modifications to add to matching amino acids pub static_mods: Option>, /// Variable modifications to add to matching amino acids - pub variable_mods: Option>, + pub variable_mods: Option>>, /// Limit number of variable modifications on a peptide pub max_variable_mods: Option, /// Use this prefix for decoy proteins diff --git a/crates/sage/src/modification.rs b/crates/sage/src/modification.rs index de9baa7..5d025ea 100644 --- a/crates/sage/src/modification.rs +++ b/crates/sage/src/modification.rs @@ -127,14 +127,14 @@ pub fn validate_mods(input: Option>) -> HashMap>, + input: Option>>, ) -> HashMap> { let mut output = HashMap::new(); if let Some(input) = input { for (s, mass) in input { match ModificationSpecificity::from_str(&s) { Ok(m) => { - output.insert(m, mass.data); + output.insert(m, mass); } Err(InvalidModification::Empty) => { log::error!("Skipping invalid modification string: empty") @@ -154,56 +154,6 @@ pub fn validate_var_mods( output } -#[derive(Default)] -pub struct ValueOrVec { - data: Vec, -} - -impl<'de> Deserialize<'de> for ValueOrVec { - fn deserialize(deserializer: D) -> Result - where - D: serde::Deserializer<'de>, - { - deserializer.deserialize_any(ValueOrVec::default()) - } -} - -impl<'de> Visitor<'de> for ValueOrVec { - type Value = ValueOrVec; - - fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { - formatter.write_str("Expected floating point value, or list of floating point values") - } - - fn visit_seq(mut self, mut seq: A) -> Result - where - A: serde::de::SeqAccess<'de>, - { - while let Some(val) = seq.next_element::()? { - self.data.push(val); - } - Ok(self) - } - - fn visit_f64(mut self, v: f64) -> Result - where - E: serde::de::Error, - { - log::warn!("Variable modifications must be specified as a list of modifications: [{v}]. This will become a HARD ERROR by v0.15"); - self.data.push(v as f32); - Ok(self) - } - - fn visit_i64(mut self, v: i64) -> Result - where - E: serde::de::Error, - { - log::warn!("Variable modifications must be specified as a list of modifications: [{v}]. This will become a HARD ERROR by v0.15"); - self.data.push(v as f32); - Ok(self) - } -} - #[cfg(test)] mod test { use super::*;