From e451eaea57fce577191c3e334e2d2d3771344783 Mon Sep 17 00:00:00 2001 From: "chinmay@wsl" <> Date: Wed, 14 Oct 2026 14:29:37 +0530 Subject: [PATCH 1/2] refactor: Change dipeptide stability lookup key from String to tuple --- seqmetrics/src/metrics.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/seqmetrics/src/metrics.rs b/seqmetrics/src/metrics.rs index f3d2d93..c1f3dd7 100644 --- a/seqmetrics/src/metrics.rs +++ b/seqmetrics/src/metrics.rs @@ -378,7 +378,7 @@ use tokio::io::AsyncBufReadExt; use tokio::io::BufReader; #[allow(non_snake_case)] #[allow(dead_code)] -pub async fn load_instability(path: &str) -> Result, anyhow::Error> { +pub async fn load_instability(path: &str) -> Result, anyhow::Error> { let file = tokio::fs::File::open(path).await?; let reader = BufReader::new(file); let mut lines = reader.lines(); @@ -392,7 +392,8 @@ pub async fn load_instability(path: &str) -> Result, anyhow if parts.len() != 2 { continue; } - let key = parts[0].trim().to_string(); + let key_bytes = parts[0].trim().as_bytes(); + let key = (key_bytes[0] as char, key_bytes[1] as char); let val: f64 = parts[1] .trim() .replace('—', "-") // handle minus dash @@ -405,11 +406,11 @@ pub async fn load_instability(path: &str) -> Result, anyhow #[allow(non_snake_case)] #[allow(dead_code)] -pub async fn instability_index(seq: String, weights: &HashMap) -> f64 { +pub async fn instability_index(seq: String, weights: &HashMap<(char, char), f64>) -> f64 { let chars: Vec = seq.chars().collect(); let mut total = 0.0; for window in chars.windows(2) { - let pair = format!("{}{}", window[0], window[1]); + let pair = (window[0], window[1]); if let Some(val) = weights.get(&pair) { total += val; } From 11da82eff4cea04167083be895046b3e48c6a70a Mon Sep 17 00:00:00 2001 From: "chinmay@wsl" <> Date: Wed, 14 Oct 2026 15:13:19 +0530 Subject: [PATCH 2/2] refactor: Robust ascii character handling --- seqmetrics/src/metrics.rs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/seqmetrics/src/metrics.rs b/seqmetrics/src/metrics.rs index c1f3dd7..93386a8 100644 --- a/seqmetrics/src/metrics.rs +++ b/seqmetrics/src/metrics.rs @@ -383,17 +383,32 @@ pub async fn load_instability(path: &str) -> Result, let reader = BufReader::new(file); let mut lines = reader.lines(); let mut weights = HashMap::new(); + let mut line_num = 0; while let Some(line) = lines.next_line().await? { + line_num += 1; + let line = line.trim().to_string(); if line.is_empty() { continue; } + let parts: Vec<&str> = line.split(',').collect(); if parts.len() != 2 { - continue; + return Err(anyhow::anyhow!(format!( + "line {line_num}: Expected 2 parts, got {}", + parts.len() + ))); } - let key_bytes = parts[0].trim().as_bytes(); - let key = (key_bytes[0] as char, key_bytes[1] as char); + + let mut key_chars = parts[0].trim().chars(); + let (Some(a), Some(b), None) = (key_chars.next(), key_chars.next(), key_chars.next()) + else { + return Err(anyhow::anyhow!(format!( + "line: {line_num} Invalid key {:?}", + parts[0] + ))); + }; + let key = (a, b); let val: f64 = parts[1] .trim() .replace('—', "-") // handle minus dash