Skip to content

Commit

Permalink
fix: cases of empty sequence (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
holtgrewe authored Mar 27, 2023
1 parent 54231b9 commit 0a6a109
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
12 changes: 10 additions & 2 deletions src/mapper/altseq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,11 @@ impl AltSeqToHgvsp {
aa_end = aa_start.clone();

reference = "".to_owned();
alternative = insertion.chars().next().unwrap().to_string();
alternative = insertion
.chars()
.next()
.map(|c| c.to_string())
.unwrap_or_default();
is_ext = true;
} else if *is_frameshift {
// frameshift
Expand All @@ -793,7 +797,11 @@ impl AltSeqToHgvsp {
aa_end = aa_start.clone();

reference = "".to_owned();
alternative = insertion.chars().next().unwrap().to_string();
alternative = insertion
.chars()
.next()
.map(|c| c.to_string())
.unwrap_or_default();

fsext_len = insertion
.find('*')
Expand Down
10 changes: 6 additions & 4 deletions src/sequences.rs
Original file line number Diff line number Diff line change
Expand Up @@ -541,12 +541,14 @@ pub fn aa_to_aa3(seq: &str) -> Result<String, anyhow::Error> {
#[allow(dead_code)]
pub fn aa1_to_aa3(seq: &str) -> Result<String, anyhow::Error> {
let mut result = String::new();
if seq.is_empty() {
return Ok(result);
}

for i in 0..seq.len() {
let aa3 = AA1_TO_AA3_LUT.get(&seq[i..(i + 1)]).ok_or(anyhow::anyhow!(
"Invalid 1-letter amino acid: {}",
&seq[i..(i + 1)]
))?;
let aa3 = AA1_TO_AA3_LUT
.get(&seq[i..(i + 1)])
.ok_or_else(|| anyhow::anyhow!("Invalid 1-letter amino acid: {}", &seq[i..(i + 1)]))?;
result.push_str(aa3);
}

Expand Down

0 comments on commit 0a6a109

Please sign in to comment.