From 0d132a3e6c912b4135be82db5b34069dd7050e98 Mon Sep 17 00:00:00 2001 From: Vitaliy Mysak Date: Fri, 15 Sep 2023 19:16:33 -0700 Subject: [PATCH] Catch invalid codon errors --- intact/intact.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/intact/intact.py b/intact/intact.py index 68ae0b4..e295f96 100644 --- a/intact/intact.py +++ b/intact/intact.py @@ -28,6 +28,7 @@ NONHIV_ERROR = "NonHIV" INTERNALINVERSION_ERROR = "InternalInversion" ALIGNMENT_FAILED = "AlignmentFailed" # Happens when mafft process fails +INVALID_CODON = "InvalidCodon" # Happens when there is an invalid codon in ORF FRAMESHIFTINORF_ERROR = "FrameshiftInOrf" MSDMUTATED_ERROR = "MajorSpliceDonorSiteMutated" @@ -508,11 +509,16 @@ def has_reading_frames( reference_aligned_mapping = coords.map_nonaligned_to_aligned_positions(reference, alignment[0].seq) query_aligned_mapping = coords.map_nonaligned_to_aligned_positions(sequence, alignment[1].seq) + errors = [] + matches = [] + try: query_aminoacids_table = [translate(sequence.seq, i) for i in range(3)] except Bio.Data.CodonTable.TranslationError as e: log.error(e) - return [], [] + err = IntactnessError(INVALID_CODON, e.args[0]) + errors.append(err) + return matches, errors def find_closest(aminoacids, start, direction, target): distance = 0 @@ -581,8 +587,6 @@ def get_indel_impact(alignment): impacted += counter if counter > 30 else 0 return impacted - errors = [] - matches = [] for e in expected: best_match = find_real_correspondence(e) matches.append(best_match)