Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
72d0e86
Merge branch 'test/dda-path-goldens' into feat/params-declared-once
ypriverol Nov 22, 2026
1e11b3d
params: one table holds what clap cannot (config key, unit, range, un…
ypriverol Nov 22, 2026
1d70992
params: a plain-number unit; output_pin is required only without --re…
ypriverol Nov 22, 2026
26ac51c
params: record where each search setting came from (default, config, …
ypriverol Nov 22, 2026
cdd7276
params: recorded values are config values (lists by argument shape, b…
ypriverol Nov 22, 2026
ce6e6b8
params: every command-line value records as a config value, checked f…
ypriverol Nov 22, 2026
8dba5fa
params: allow the not-yet-read declaration fields in test builds too,…
ypriverol Nov 22, 2026
e0487d5
params: valid examples for the mod lists and the isotope-error range
ypriverol Nov 22, 2026
dccc50f
params: wrap a doc line
ypriverol Nov 22, 2026
ec608ee
params: a valid crosslinker example for --xl
ypriverol Nov 22, 2026
aab6e56
params: config.example.yaml and the DOCS.md flag reference are genera…
ypriverol Nov 22, 2026
e101a44
params: generated configs leave defaults unset, so copying or replayi…
ypriverol Nov 22, 2026
2bc1417
params: full example header, full short help in the flag tables, safe…
ypriverol Nov 22, 2026
e195f26
params: compile fixes
ypriverol Nov 22, 2026
c031e05
params: regenerate config.example.yaml and the DOCS.md flag reference…
ypriverol Nov 22, 2026
eb24685
search: --print-config writes the resolved settings as a config that …
ypriverol Nov 22, 2026
d4d8887
cli: module doc for the moved value parsers
ypriverol Nov 22, 2026
8832243
print-config: keep the short help curated; precise test for the omitt…
ypriverol Nov 22, 2026
2c86861
params: regenerate the DOCS.md flag reference (--print-config)
ypriverol Nov 22, 2026
80aa3ea
params: --print-config holds every setting it can and names the rest
ypriverol Nov 22, 2026
138bfc8
params: tests for the replay of every value, config plus SDRF replay,…
ypriverol Nov 22, 2026
f18a836
docs: command-line-only flags and paths in a printed config
ypriverol Nov 22, 2026
e1c42e4
params: regenerate config.example.yaml and the DOCS.md flag reference
ypriverol Nov 22, 2026
d7044c7
Merge remote-tracking branch 'origin/feat/guardrails-g0' into feat/pa…
ypriverol Nov 22, 2026
f904a97
params: regenerate the DOCS.md flag reference after the merge of main…
ypriverol Nov 22, 2026
162dc02
Merge remote-tracking branch 'origin/main' into feat/params-declared-…
ypriverol Nov 23, 2026
619e0b6
params: generated-file checks ignore CRLF (Windows checkouts); DOCS l…
ypriverol Nov 23, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
289 changes: 214 additions & 75 deletions DOCS.md

Large diffs are not rendered by default.

232 changes: 119 additions & 113 deletions config.example.yaml

Large diffs are not rendered by default.

63 changes: 59 additions & 4 deletions crates/andes/src/bin/andes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ use clap::{Parser, Subcommand};
mod acquisition;
#[path = "andes/cli.rs"]
mod cli;
#[path = "andes/cli_parse.rs"]
mod cli_parse;
#[path = "../cohort.rs"]
mod cohort;
#[path = "andes/cohort_cmd.rs"]
mod cohort_cmd;
#[path = "../config.rs"]
mod config;
#[path = "../config_mods.rs"]
mod config_mods;
#[path = "andes/database_cmd.rs"]
mod database_cmd;
#[path = "andes/dia.rs"]
Expand Down Expand Up @@ -58,6 +62,12 @@ mod quant_run;
mod sdrf;
#[path = "andes/optimize.rs"]
mod optimize;
#[path = "../param_sources.rs"]
mod param_sources;
#[path = "../params.rs"]
mod params;
#[path = "../params_render.rs"]
mod params_render;
#[path = "andes/search.rs"]
mod search;
#[path = "andes/spectra.rs"]
Expand Down Expand Up @@ -256,20 +266,19 @@ fn main() -> ExitCode {
Some(Command::Cohort(cmd)) => cohort_cmd::run(cmd),
None => {
let mut cfg_missed_cleavages = false;
let mut cfg_keys = sdrf::ConfigKeys::default();
let mut sources = param_sources::from_command_line(&matches);
if let Some(cfg_path) = top.search.config.clone() {
if let Err(e) = config::RunConfig::load(&cfg_path).and_then(|c| {
cfg_missed_cleavages = c.search.max_missed_cleavages.is_some();
cfg_keys = sdrf::ConfigKeys::of(&c);
config::apply(c, &mut top.search, &matches)
config::apply(c, &mut top.search, &matches, &mut sources)
}) {
log::error!("{e}");
return ExitCode::from(2);
}
}
if let Some(sdrf_path) = top.search.sdrf.clone() {
match sdrf::read(&sdrf_path)
.and_then(|s| sdrf::apply(&s, &mut top.search, &matches, cfg_keys))
.and_then(|s| sdrf::apply(&s, &mut top.search, &matches, &mut sources))
{
Ok(lines) => lines.iter().for_each(|l| match l.strip_prefix("WARN: ") {
Some(w) => log::warn!(target: "sdrf", "{w}"),
Expand All @@ -285,6 +294,9 @@ fn main() -> ExitCode {
log::error!("{e}");
return ExitCode::from(2);
}
if let Some(dest) = top.search.print_config.as_deref() {
return print_config(dest, &sources);
}
let _ = EXPLICIT_MISSED_CLEAVAGES.set(missed_cleavages_explicit(
matches.value_source("max_missed_cleavages"),
cfg_missed_cleavages,
Expand Down Expand Up @@ -326,6 +338,37 @@ fn main() -> ExitCode {
}
}

fn print_config(dest: &std::path::Path, sources: &param_sources::ParamSources) -> ExitCode {
let text = match params_render::effective_config(sources) {
Ok(text) => text,
Err(e) => {
log::error!("{e}");
return ExitCode::from(2);
}
};
let cli_only = params_render::command_line_only(sources);
if !cli_only.is_empty() {
log::warn!(
"--print-config: {} has no config key; the printed config lists it as a comment, \
pass it again on the command line to reproduce the run",
cli_only.join(" ")
);
}
let written = if dest == std::path::Path::new("-") {
use std::io::Write;
std::io::stdout().write_all(text.as_bytes())
} else {
std::fs::write(dest, &text)
};
match written {
Ok(()) => ExitCode::SUCCESS,
Err(e) => {
log::error!("cannot write the config to {}: {e}", dest.display());
ExitCode::from(1)
}
}
}

fn run_rescore(args: cli::RescoreArgs) -> Result<(), Box<dyn std::error::Error>> {
cli::ensure_scratch_dir(&args.temp_dir)?;
let limit = memlimit::rescore_memory(args.rescore_memory_gb, args.temp_dir);
Expand Down Expand Up @@ -387,3 +430,15 @@ mod missed_cleavages_explicit_tests {
assert!(!missed_cleavages_explicit(None, false));
}
}

#[cfg(test)]
#[path = "../tests/params_table.rs"]
mod params_table;

#[cfg(test)]
#[path = "../tests/params_sources.rs"]
mod params_sources;

#[cfg(test)]
#[path = "../tests/params_render.rs"]
mod params_render_tests;
184 changes: 11 additions & 173 deletions crates/andes/src/bin/andes/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ use model::Tolerance;
use model_train::geometry::GeometryConfig;
use search::decoy::DecoyStrategy;
use search::PrecursorCalMode;
pub(crate) use crate::cli_parse::{
parse_charge_range, parse_isotope_error_range, parse_non_negative, parse_non_negative_f32,
parse_open_search_delta, parse_positive_tol, parse_precursor_tol, parse_unit_fraction,
parse_xl,
};

pub(crate) const H_IO: &str = "Input and output";
pub(crate) const H_SEARCH: &str = "Search";
Expand Down Expand Up @@ -301,22 +306,6 @@ impl XlSet {
}
}

pub(crate) fn parse_xl_one(s: &str) -> Result<xl::crosslinker::Crosslinker, String> {
xl::spec::XlDecl::parse(s)
.and_then(|d| d.resolve(model::unimod::bundled()))
.map_err(|e| e.to_string())
}

pub(crate) fn parse_xl(s: &str) -> Result<XlSet, String> {
let linkers = s
.split(';')
.map(str::trim)
.filter(|x| !x.is_empty())
.map(parse_xl_one)
.collect::<Result<Vec<_>, _>>()?;
XlSet::new("--xl", linkers)
}

/// The protein database options shared by the search, `andes inference` and
/// `andes quant finalize`: how the database is digested and expanded, and how
/// a decoy is recognised. Inference and finalize take the search's values.
Expand Down Expand Up @@ -441,6 +430,12 @@ pub(crate) struct SearchArgs {
#[arg(long, value_name = "FILE", help_heading = H_IO)]
pub(crate) config: Option<PathBuf>,

/// Write the resolved settings as a config file that reproduces the run, then exit
///
/// FILE, or `-` for stdout. Nothing is searched. Replay with --config FILE.
#[arg(long, value_name = "FILE", help_heading = H_IO, hide_short_help = true)]
pub(crate) print_config: Option<PathBuf>,

/// SDRF-Proteomics file: data files, protease, modifications, tolerance and labels
///
/// Reads `comment[data file]` (looked up next to the SDRF), the cleavage agents, the
Expand Down Expand Up @@ -2103,163 +2098,6 @@ pub(crate) fn parse_plex(s: &str) -> Result<quant::Plex, String> {
quant::Plex::parse(s)
}

pub(crate) fn dash_sep_index(s: &str) -> Option<usize> {
let b = s.as_bytes();
(1..b.len()).find(|&i| b[i] == b'-' && b[i - 1].is_ascii_digit())
}

pub(crate) fn parse_int_range<T>(s: &str, label: &str) -> Result<(T, T), String>
where
T: std::str::FromStr + PartialOrd + std::fmt::Display + Copy,
{
let trimmed = s.trim();
let (lo_s, hi_s) = if let Some((a, b)) = trimmed.split_once("..") {
(a.trim(), b.trim())
} else if let Some(idx) = dash_sep_index(trimmed) {
(trimmed[..idx].trim(), trimmed[idx + 1..].trim())
} else {
return Err(format!(
"invalid {label} `{s}`: expected MIN..MAX (or MIN-MAX)"
));
};
let lo: T = lo_s
.parse()
.map_err(|_| format!("invalid {label} `{s}`: bad MIN `{lo_s}`"))?;
let hi: T = hi_s
.parse()
.map_err(|_| format!("invalid {label} `{s}`: bad MAX `{hi_s}`"))?;
if lo > hi {
return Err(format!("invalid {label} `{s}`: MIN {lo} > MAX {hi}"));
}
Ok((lo, hi))
}

pub(crate) const MAX_SUPPORTED_CHARGE: u8 = 50;

pub(crate) fn parse_charge_range(s: &str) -> Result<(u8, u8), String> {
let (lo, hi) = parse_int_range::<u8>(s, "charge")?;
if lo < 1 {
return Err(format!(
"invalid charge `{s}`: minimum charge must be >= 1 (got {lo})"
));
}
if hi > MAX_SUPPORTED_CHARGE {
return Err(format!(
"invalid charge `{s}`: maximum charge {hi} exceeds supported bound {MAX_SUPPORTED_CHARGE}"
));
}
Ok((lo, hi))
}

pub(crate) fn parse_isotope_error_range(s: &str) -> Result<(i8, i8), String> {
parse_int_range::<i8>(s, "isotope-error")
}

pub(crate) fn parse_precursor_tol(s: &str) -> Result<Tolerance, String> {
let t = s.trim();
let lower = t.to_ascii_lowercase();
let (num_str, is_ppm) = if let Some(n) = lower.strip_suffix("ppm") {
(n, true)
} else if let Some(n) = lower.strip_suffix("da") {
(n, false)
} else {
return Err(format!(
"invalid --precursor-tol `{s}`: expected VALUE+unit, e.g. 20ppm or 0.02da"
));
};
let v: f64 = num_str
.trim()
.parse()
.map_err(|_| format!("invalid --precursor-tol `{s}`: bad number `{num_str}`"))?;
if !v.is_finite() || v <= 0.0 {
return Err(format!(
"invalid --precursor-tol `{s}`: value must be finite and > 0 (got {v})"
));
}
Ok(if is_ppm {
Tolerance::Ppm(v)
} else {
Tolerance::Da(v)
})
}

pub(crate) fn parse_open_search_delta(s: &str) -> Result<(f64, f64), String> {
let t = s.trim();
let (min_s, max_s) = t.split_once("..").ok_or_else(|| {
format!("invalid --open-search-delta `{s}`: expected MIN..MAX in Da, e.g. -100..300")
})?;
let parse = |v: &str| -> Result<f64, String> {
v.trim()
.parse::<f64>()
.map_err(|_| format!("invalid --open-search-delta `{s}`: bad number `{}`", v.trim()))
};
let (lo, hi) = (parse(min_s)?, parse(max_s)?);
if !lo.is_finite() || !hi.is_finite() || lo >= hi {
return Err(format!(
"invalid --open-search-delta `{s}`: need finite MIN < MAX (got {lo}..{hi})"
));
}
if lo > 0.0 || hi < 0.0 {
return Err(format!(
"invalid --open-search-delta `{s}`: the window must contain 0 (got {lo}..{hi})"
));
}
if hi - lo > 2000.0 {
return Err(format!(
"invalid --open-search-delta `{s}`: width {} Da exceeds the 2000 Da limit",
hi - lo
));
}
Ok((lo, hi))
}

pub(crate) fn parse_unit_fraction(s: &str) -> Result<f64, String> {
let v: f64 = s
.trim()
.parse()
.map_err(|_| format!("invalid value `{s}`: expected a number in [0, 1]"))?;
if !v.is_finite() || !(0.0..=1.0).contains(&v) {
return Err(format!(
"invalid value `{s}`: must be finite and within [0, 1] (got {v})"
));
}
Ok(v)
}

pub(crate) fn parse_non_negative(s: &str) -> Result<f64, String> {
let v: f64 = s
.trim()
.parse()
.map_err(|_| format!("invalid value `{s}`: expected a number >= 0"))?;
if !v.is_finite() || v < 0.0 {
return Err(format!(
"invalid value `{s}`: must be finite and >= 0 (got {v})"
));
}
Ok(v)
}

pub(crate) fn parse_non_negative_f32(s: &str) -> Result<f32, String> {
let v = parse_non_negative(s)?;
if v > f32::MAX as f64 {
return Err(format!("invalid value `{s}`: out of range"));
}
Ok(v as f32)
}

pub(crate) fn parse_positive_tol(s: &str) -> Result<f64, String> {
let v: f64 = s
.trim()
.parse()
.map_err(|_| format!("invalid tolerance `{s}`: expected a positive number"))?;
if !v.is_finite() || v <= 0.0 {
return Err(format!(
"invalid tolerance `{s}`: must be finite and > 0 (got {v})"
));
}
Ok(v)
}

pub(crate) fn dir_or_output_dir(flag: Option<&Path>, output: &Path) -> PathBuf {
match flag {
Some(dir) => dir.to_path_buf(),
Expand Down
Loading
Loading