From 7a28711dd75c0a42b95bb0ec28da6336f43c1d70 Mon Sep 17 00:00:00 2001 From: David Miguel Susano Pinto Date: Fri, 26 Apr 2024 15:05:07 +0100 Subject: [PATCH] Bio::Tools::CodonTable::is_start_codon: check in case of ambiguous codons (#266) In the case of ambiguous codons this method should only return true if all possible codons are start codons (same as is_ter_codon). This was the behaviour in BioPerl 1.2.3 but since at least BioPerl 1.6.924 it returns true if at least one codon is a start codon. This change fixes that regression and makes behaviour consistent with is_ter_codon. --- Changes | 7 +++++++ lib/Bio/Tools/CodonTable.pm | 28 +++++++++++++++++++--------- t/SeqTools/CodonTable.t | 6 +++++- 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/Changes b/Changes index f38c65e3b..3d62750ab 100644 --- a/Changes +++ b/Changes @@ -13,6 +13,13 @@ Summary of important user-visible changes for BioPerl being used. This update changes codon tables 3, 15, 24, 27-30, 32, and 33 [#389, #391]. + * Bio::Tools::CodonTable::is_start_codon now returns true when all + possible codons (in the case of ambiguous codons such as NTG) + are start codons. For some recent versions it was return true + if any of the codons was a start codon. This change is + consistent with the behaviour of is_ter_codon and returns to the + (very) old behaviour [#266]. + 1.7.8 2021-02-02 23:02:18-06:00 America/Chicago * Bio::SeqIO::interpro has been moved to a separate repository to deal with issues with XML::DOM::XPath bitrot [#347] diff --git a/lib/Bio/Tools/CodonTable.pm b/lib/Bio/Tools/CodonTable.pm index 23784ab8c..e9f2593ab 100644 --- a/lib/Bio/Tools/CodonTable.pm +++ b/lib/Bio/Tools/CodonTable.pm @@ -646,7 +646,9 @@ sub reverse_translate_best { Title : is_start_codon Usage : $obj->is_start_codon('ATG') Function: returns true (1) for all codons that can be used as a - translation start, false (0) for others. + translation start, false (0) for others. In the case of + ambiguous codons, e.g., 'NTG', only returns true if all + possible codons are true. Example : $myCodonTable->is_start_codon('ATG') Returns : boolean Args : codon @@ -662,7 +664,9 @@ sub is_start_codon{ Title : is_ter_codon Usage : $obj->is_ter_codon('GAA') Function: returns true (1) for all codons that can be used as a - translation tarminator, false (0) for others. + translation terminator, false (0) for others. In the case + of ambiguous codons, e.g., 'TAN', only returns true if all + possible codons are true. Example : $myCodonTable->is_ter_codon('ATG') Returns : boolean Args : codon @@ -699,12 +703,13 @@ sub is_ter_codon{ # desc: compares the passed value with a single entry in the given # codon table -# args: a value (typically a three-char string like 'atg'), -# a reference to the appropriate set of codon tables, -# a single-character value to check for at the position in the -# given codon table +# args: a value (typically a three-char string like 'atg'), a +# reference to the appropriate set of codon tables, a +# single-character value to check for at the position in the +# given codon table. # ret: boolean, true if the given codon table contains the $key at the -# position corresponding to $value +# position corresponding to $value. In the case of ambiguous +# codons, only returns true if all possibilities match $key. sub _codon_is { my ($self, $value, $table, $key ) = @_; @@ -714,11 +719,16 @@ sub _codon_is { $value =~ tr/u/t/; my $id = $self->{'id'}; + my $result = 0; for my $c ( $self->unambiguous_codons($value) ) { my $m = substr( $table->[$id], $CODONS->{$c}, 1 ); - if ($m eq $key) { return 1; } + if ($m eq $key) { + $result = 1; + } else { + return 0; + } } - return 0; + return $result; } =head2 is_unknown_codon diff --git a/t/SeqTools/CodonTable.t b/t/SeqTools/CodonTable.t index 9f2bc85a0..8f2e28609 100644 --- a/t/SeqTools/CodonTable.t +++ b/t/SeqTools/CodonTable.t @@ -6,7 +6,7 @@ use strict; BEGIN { use Bio::Root::Test; - test_begin(-tests => 91); + test_begin(-tests => 94); use_ok('Bio::Tools::CodonTable'); use_ok('Bio::CodonUsage::IO'); @@ -185,6 +185,10 @@ is $myCodonTable->is_ter_codon('NNN'), 0, 'is_ter_codon, ambiguous codons should is $myCodonTable->is_ter_codon('TAN'), 0, 'is_ter_codon, ambiguous codons should fail, TAN'; is $myCodonTable->is_ter_codon('CC'), 0, 'is_ter_codon, incomplete codons should fail, CC'; +is $myCodonTable->is_start_codon('NNN'), 0, 'is_start_codon, ambiguous codons should fail, NNN'; +is $myCodonTable->is_start_codon('NTG'), 0, 'is_start_codon, ambiguous codons should fail, NTG'; +is $myCodonTable->is_start_codon('N'), 0, 'is_start_codon, incomplete codons should fail, NN'; + ok $myCodonTable->is_unknown_codon('jAG'); ok $myCodonTable->is_unknown_codon('jg'); is $myCodonTable->is_unknown_codon('UAG'), 0; -- 2.11.4.GIT