From 4fccdb826fea15539b59630b2f9d742271aac3c4 Mon Sep 17 00:00:00 2001 From: Manuel Holtgrewe Date: Thu, 6 Apr 2023 12:48:45 +0200 Subject: [PATCH] fix: out of bounds issue on 5'-to-3' shifting beyond CDS (#94) --- src/mapper/altseq.rs | 11 +++++++++++ src/normalizer.rs | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/mapper/altseq.rs b/src/mapper/altseq.rs index e2f8670..b8f5135 100644 --- a/src/mapper/altseq.rs +++ b/src/mapper/altseq.rs @@ -777,6 +777,17 @@ impl AltSeqToHgvsp { is_frameshift, } = &record; + // Handle the case of the variant being after the end of the protein sequence. This can + // happen when the variant is 5'-to-3' shifted beyond the stop codon. In this case, we + // can simply return `ProtLocEdit::NoChange` which will display as `p.=`. + if *start as usize > self.ref_seq().len() { + return Ok(HgvsVariant::ProtVariant { + accession: Accession::new(protein_accession), + gene_symbol: None, + loc_edit: ProtLocEdit::NoChange, + }); + } + // defaults let mut is_dup = false; // assume no dup let mut fsext_len = UncertainLengthChange::default(); // fs or ext length diff --git a/src/normalizer.rs b/src/normalizer.rs index 5a23a07..4825dcb 100644 --- a/src/normalizer.rs +++ b/src/normalizer.rs @@ -413,7 +413,7 @@ impl<'a> Normalizer<'a> { if stop < ref_seq.len().try_into()? || start == orig_start { break; } - // If stop at the end of the window, try to extend teh shuffling to the right. + // If stop at the end of the window, try to extend the shuffling to the right. base += start - orig_start; stop -= start - orig_start; start = orig_start;