From 31a5c13017b3ce153d2f58a4b3d0889093b085f4 Mon Sep 17 00:00:00 2001 From: acesnik Date: Tue, 30 Apr 2024 15:07:02 -0700 Subject: [PATCH 1/3] add file expansion and file existance checks --- Cargo.lock | 7 +++++++ crates/sage-cli/Cargo.toml | 1 + crates/sage-cli/src/input.rs | 40 ++++++++++++++++++++++++++++++++++-- 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a08e23f2..c2d2c638 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1205,6 +1205,12 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" +[[package]] +name = "glob" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" + [[package]] name = "h2" version = "0.3.24" @@ -2260,6 +2266,7 @@ dependencies = [ "csv", "env_logger", "fnv", + "glob", "itoa", "log", "num_cpus", diff --git a/crates/sage-cli/Cargo.toml b/crates/sage-cli/Cargo.toml index 1ee88d0d..368debfd 100644 --- a/crates/sage-cli/Cargo.toml +++ b/crates/sage-cli/Cargo.toml @@ -23,6 +23,7 @@ csv = "1" clap = { version="4.0", features = ["cargo", "unicode"] } env_logger = "0.8.4" fnv = "1.0" +glob = "0.3.1" log = "0.4.0" itoa = "1.0" num_cpus = "1.13" diff --git a/crates/sage-cli/src/input.rs b/crates/sage-cli/src/input.rs index 45761033..f0f21ddd 100644 --- a/crates/sage-cli/src/input.rs +++ b/crates/sage-cli/src/input.rs @@ -8,6 +8,7 @@ use sage_core::{ tmt::Isobaric, }; use serde::{Deserialize, Serialize}; +use glob::glob; #[derive(Serialize)] /// Actual search parameters - may include overrides or default values not set by user @@ -176,7 +177,28 @@ impl Input { input.database.fasta = Some(fasta.into()); } if let Some(mzml_paths) = matches.get_many::("mzml_paths") { - input.mzml_paths = Some(mzml_paths.into_iter().map(|p| p.into()).collect()); + let mut paths = Vec::new(); + for path_pattern in mzml_paths { + match glob(path_pattern) { + Ok(glob_paths) => { + for entry in glob_paths { + match entry { + Ok(path) => { + // Convert PathBuf to String, handle potential conversion error + if let Some(path_str) = path.to_str() { + paths.push(path_str.to_string()); + } else { + eprintln!("Error converting path to string: {:?}", path); + } + }, + Err(e) => eprintln!("Error processing path: {}", e), + } + } + }, + Err(e) => eprintln!("Glob pattern error: {}", e), + } + } + input.mzml_paths = Some(paths); } if let Some(write_pin) = matches.get_one::("write-pin").copied() { @@ -187,7 +209,7 @@ impl Input { input.annotate_matches = Some(annotate_matches); } - // avoid to later panic if these parameters are not set (but doesn't check if files exist) + // avoid to later panic if these parameters are not set ensure!( input.database.fasta.is_some(), @@ -202,6 +224,20 @@ impl Input { > 0, "`mzml_paths` must be set. For more information try '--help'" ); + if let Some(fasta) = &input.database.fasta { + ensure!( + std::path::Path::new(&fasta).exists(), + "Specified FASTA file does not exist" + ); + } + if let Some(paths) = &input.mzml_paths { + for path in paths { + ensure!( + std::path::Path::new(path).exists(), + "One or more specified mzML files do not exist." + ); + } + } Ok(input) } From ea401b282e23f40ec6af0b43c47350754ce7d933 Mon Sep 17 00:00:00 2001 From: acesnik Date: Tue, 30 Apr 2024 15:17:15 -0700 Subject: [PATCH 2/3] remove file existence check --- crates/sage-cli/src/input.rs | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/crates/sage-cli/src/input.rs b/crates/sage-cli/src/input.rs index f0f21ddd..133f539f 100644 --- a/crates/sage-cli/src/input.rs +++ b/crates/sage-cli/src/input.rs @@ -209,7 +209,7 @@ impl Input { input.annotate_matches = Some(annotate_matches); } - // avoid to later panic if these parameters are not set + // avoid to later panic if these parameters are not set (but doesn't check if files exist) ensure!( input.database.fasta.is_some(), @@ -224,20 +224,6 @@ impl Input { > 0, "`mzml_paths` must be set. For more information try '--help'" ); - if let Some(fasta) = &input.database.fasta { - ensure!( - std::path::Path::new(&fasta).exists(), - "Specified FASTA file does not exist" - ); - } - if let Some(paths) = &input.mzml_paths { - for path in paths { - ensure!( - std::path::Path::new(path).exists(), - "One or more specified mzML files do not exist." - ); - } - } Ok(input) } From ff83877e75feed0106d2be5202d5739f9fdacbe1 Mon Sep 17 00:00:00 2001 From: acesnik Date: Fri, 3 May 2024 13:00:42 -0700 Subject: [PATCH 3/3] error logging --- crates/sage-cli/src/input.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/sage-cli/src/input.rs b/crates/sage-cli/src/input.rs index 133f539f..2d337da6 100644 --- a/crates/sage-cli/src/input.rs +++ b/crates/sage-cli/src/input.rs @@ -188,14 +188,14 @@ impl Input { if let Some(path_str) = path.to_str() { paths.push(path_str.to_string()); } else { - eprintln!("Error converting path to string: {:?}", path); + log::error!("Error converting path to string: {:?}", path); } }, - Err(e) => eprintln!("Error processing path: {}", e), + Err(e) => log::error!("Error processing path: {}", e), } } }, - Err(e) => eprintln!("Glob pattern error: {}", e), + Err(e) => log::error!("Glob pattern error: {}", e), } } input.mzml_paths = Some(paths);