From 37f1c67e3491e1f76afce60a8d9f3ba422d6c7b8 Mon Sep 17 00:00:00 2001 From: Manuel Holtgrewe Date: Thu, 6 Apr 2023 10:41:58 +0200 Subject: [PATCH] fix: out of bounds issue for protein sequence creation --- src/mapper/altseq.rs | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/src/mapper/altseq.rs b/src/mapper/altseq.rs index 5caf89e..e2f8670 100644 --- a/src/mapper/altseq.rs +++ b/src/mapper/altseq.rs @@ -963,26 +963,16 @@ impl AltSeqToHgvsp { alternative = reference.clone(); } else { // is non-dup insertion - let start = start - 1; - let end = start + 1; + let start = *start as usize - 1; + let end = start as usize + 1; aa_start = Some(ProtPos { - aa: self - .ref_seq() - .chars() - .nth(start as usize - 1) - .ok_or(anyhow::anyhow!("start position out of range in reference"))? - .to_string(), - number: start, + aa: self.ref_seq()[(start - 1)..start].to_owned(), + number: start as i32, }); aa_end = Some(ProtPos { - aa: self - .ref_seq() - .chars() - .nth(end as usize - 1) - .ok_or(anyhow::anyhow!("end position out of range in reference"))? - .to_string(), - number: end, + aa: self.ref_seq()[(end - 1)..end].to_owned(), + number: end as i32, }); reference = "".to_string(); alternative = insertion.clone();