From be2f56d0bdd5e3a38d4435ef9ca5597d1b11205d Mon Sep 17 00:00:00 2001 From: theGreatHerrLebert Date: Thu, 25 Jul 2024 13:50:45 +0200 Subject: [PATCH] adding hyper score to cmd arguments --- crates/sage-cli/src/input.rs | 21 +++++++++++++++++++++ crates/sage-cli/src/main.rs | 4 ++-- crates/sage/src/scoring.rs | 18 +----------------- tests/config.json | 3 ++- 4 files changed, 26 insertions(+), 20 deletions(-) diff --git a/crates/sage-cli/src/input.rs b/crates/sage-cli/src/input.rs index 50624357..2ddb43bc 100644 --- a/crates/sage-cli/src/input.rs +++ b/crates/sage-cli/src/input.rs @@ -1,6 +1,7 @@ use anyhow::{ensure, Context}; use clap::ArgMatches; use sage_cloudpath::{tdf::BrukerSpectrumProcessor, CloudPath}; +use sage_core::scoring::ScoreType; use sage_core::{ database::{Builder, Parameters}, lfq::LfqSettings, @@ -41,6 +42,9 @@ pub struct Search { #[serde(skip_serializing)] pub annotate_matches: bool, + + #[serde(skip_serializing)] + pub score_type: ScoreType, } #[derive(Deserialize)] @@ -68,6 +72,7 @@ pub struct Input { annotate_matches: Option, write_pin: Option, + score_type: Option, } #[derive(Serialize, Deserialize, Debug)] @@ -287,6 +292,21 @@ impl Input { None => CloudPath::Local(std::env::current_dir()?), }; + let score_type = match self.score_type { + Some(s) => { + // check if s in ["sage_hyperscore", "openms_hyperscore"] + match s.to_lowercase().as_str() { + "sage_hyperscore" => ScoreType::SageHyperScore, + "openms_hyperscore" => ScoreType::OpenMSHyperScore, + _ => { + log::warn!("Invalid score type: {}. Supported values are: 'sage_hyperscore', 'openms_hyperscore', defaulting to sage_hyperscore", s); + ScoreType::SageHyperScore + } + } + } + None => ScoreType::SageHyperScore, + }; + Ok(Search { version: clap::crate_version!().into(), database, @@ -311,6 +331,7 @@ impl Input { output_paths: Vec::new(), write_pin: self.write_pin.unwrap_or(false), bruker_spectrum_processor: self.bruker_spectrum_processor.unwrap_or_default(), + score_type, }) } } diff --git a/crates/sage-cli/src/main.rs b/crates/sage-cli/src/main.rs index d4bfef08..9b9f2b51 100644 --- a/crates/sage-cli/src/main.rs +++ b/crates/sage-cli/src/main.rs @@ -6,7 +6,7 @@ use rayon::prelude::*; use sage_cloudpath::CloudPath; use sage_core::database::IndexedDatabase; use sage_core::mass::Tolerance; -use sage_core::scoring::{Feature, Scorer, ScoreType}; +use sage_core::scoring::{Feature, Scorer}; use sage_core::spectrum::{ProcessedSpectrum, SpectrumProcessor}; use sage_core::tmt::TmtQuant; use std::time::Instant; @@ -272,7 +272,7 @@ impl Runner { report_psms: self.parameters.report_psms, wide_window: self.parameters.wide_window, annotate_matches: self.parameters.annotate_matches, - score_type: ScoreType::SageHyperScore, + score_type: self.parameters.score_type, }; //Collect all results into a single container diff --git a/crates/sage/src/scoring.rs b/crates/sage/src/scoring.rs index e30e1d72..13a698c3 100644 --- a/crates/sage/src/scoring.rs +++ b/crates/sage/src/scoring.rs @@ -8,28 +8,12 @@ use serde::Serialize; use std::ops::AddAssign; use std::sync::atomic::{AtomicUsize, Ordering}; -#[derive(Copy, Clone, Debug, Serialize)] +#[derive(Copy, Clone, Debug)] pub enum ScoreType { SageHyperScore, OpenMSHyperScore, } -impl ScoreType { - pub fn from_str(s: &str) -> Self { - match s { - "sage_hyperscore" => ScoreType::SageHyperScore, - "openms_hyperscore" => ScoreType::OpenMSHyperScore, - _ => panic!("unknown score type."), - } - } - pub fn to_str(&self) -> &str { - match self { - ScoreType::SageHyperScore => "SageHyperscore", - ScoreType::OpenMSHyperScore => "OpenMSHyperscore", - } - } -} - /// Structure to hold temporary scores #[derive(Copy, Clone, Default, Debug)] struct Score { diff --git a/tests/config.json b/tests/config.json index e935013c..939575f1 100644 --- a/tests/config.json +++ b/tests/config.json @@ -37,5 +37,6 @@ ], "mzml_paths": [ "tests/LQSRPAAPPAPGPGQLTLR.mzML" - ] + ], + "score_type": "sage_hyperscore" } \ No newline at end of file