Skip to content

Commit

Permalink
fix: prevent crash when query cds is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-aksamentov committed Jun 13, 2024
1 parent 149f294 commit 6c34eb5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
18 changes: 12 additions & 6 deletions packages/nextclade/src/analyze/find_private_aa_mutations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,22 @@ pub fn find_private_aa_mutations(
.get(&cds.name)
.map(|node_mut_map| (cds, node, node_mut_map))
})
.map(|(cds, node, node_mut_map)| {
.filter_map(|(cds, node, node_mut_map)| {
let ref_peptide = ref_translation.get_cds(&cds.name).ok();
let qry_peptide = qry_translation.get_cds(&cds.name).ok();
if let (Some(ref_peptide), Some(qry_peptide)) = (ref_peptide, qry_peptide) {
Some((cds, node, node_mut_map, ref_peptide, qry_peptide))
} else {
None
}
})
.map(|(cds, node, node_mut_map, ref_peptide, qry_peptide)| {
let aln = NucAlignmentWithOverlay::new(aln, &node.tmp.mutations);

let ref_peptide = ref_translation.get_cds(&cds.name)?;
let qry_peptide = qry_translation.get_cds(&cds.name)?;

let empty = btreemap! {};
let node_aa_muts = node.tmp.aa_mutations.get(&cds.name).unwrap_or(&empty);
let ref_tr = AaAlignment::new(cds, ref_peptide, qry_peptide); // alignment ref -> qry
let node_tr = AaAlignmentView::new(&ref_tr, node_aa_muts); // alignment node -> qry
let ref_tr = AaAlignment::new(cds, ref_peptide, qry_peptide); // alignment: ref -> qry
let node_tr = AaAlignmentView::new(&ref_tr, node_aa_muts); // alignment: node -> qry

let empty = vec![];
let aa_unsequenced_ranges = aa_unsequenced_ranges.get(&cds.name).unwrap_or(&empty);
Expand Down
6 changes: 4 additions & 2 deletions packages/nextclade/src/translate/translate_genes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ impl Translation {
.iter()
.find_map(|(_, gene)| gene.cdses.get(cds_name))
.ok_or_else(|| {
make_internal_report!("When looking up a CDS translation: CDS '{cds_name}' is expected, but not found")
make_internal_report!(
"Translation::get_cds(): When looking up a CDS translation: CDS '{cds_name}' is expected, but not found"
)
})
}

Expand Down Expand Up @@ -115,7 +117,7 @@ impl GeneTranslation {
let cds_name = cds_name.as_ref();
self.cdses.get(cds_name).ok_or_else(|| {
make_internal_report!(
"When looking up a CDS translation: CDS '{cds_name}' in gene '{}' is expected, but not found",
"GeneTranslation::get_cds(): When looking up a CDS translation: CDS '{cds_name}' in gene '{}' is expected, but not found",
self.gene.name
)
})
Expand Down

0 comments on commit 6c34eb5

Please sign in to comment.