Skip to content

Commit

Permalink
adding hyper score to cmd arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
theGreatHerrLebert authored and lazear committed Oct 17, 2024
1 parent 04f5572 commit be2f56d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 20 deletions.
21 changes: 21 additions & 0 deletions crates/sage-cli/src/input.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -41,6 +42,9 @@ pub struct Search {

#[serde(skip_serializing)]
pub annotate_matches: bool,

#[serde(skip_serializing)]
pub score_type: ScoreType,
}

#[derive(Deserialize)]
Expand Down Expand Up @@ -68,6 +72,7 @@ pub struct Input {

annotate_matches: Option<bool>,
write_pin: Option<bool>,
score_type: Option<String>,
}

#[derive(Serialize, Deserialize, Debug)]
Expand Down Expand Up @@ -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,
Expand All @@ -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,
})
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/sage-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
18 changes: 1 addition & 17 deletions crates/sage/src/scoring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion tests/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@
],
"mzml_paths": [
"tests/LQSRPAAPPAPGPGQLTLR.mzML"
]
],
"score_type": "sage_hyperscore"
}

0 comments on commit be2f56d

Please sign in to comment.