diff --git a/Changes b/Changes index 430d051..f7fabcc 100644 --- a/Changes +++ b/Changes @@ -1,8 +1,13 @@ Revision history for JCVI-Translator +0.5.3 Apr 13 2009 + - Fixed inconsistencies in the way the start codon is being stored in the + reverse translation table + - Added test for above condition + 0.5.2 Apr 13 2009 - Even more documentation in Utils - - codons/regex/find method in Utils can take "stop" for stop codons + - codons/regex/find method in Utils can take "stop" for stop codons 0.5.1 Apr 13 2009 - Better documentation in Utils diff --git a/lib/JCVI/Translator.pm b/lib/JCVI/Translator.pm index e8561c4..7831166 100644 --- a/lib/JCVI/Translator.pm +++ b/lib/JCVI/Translator.pm @@ -67,7 +67,7 @@ use strict; use warnings; use version; -our $VERSION = qv('0.5.2'); +our $VERSION = qv('0.5.3'); use base qw(Class::Accessor::Fast); __PACKAGE__->mk_accessors(qw(table base)); diff --git a/lib/JCVI/Translator/Table.pm b/lib/JCVI/Translator/Table.pm index 8509369..89594ae 100644 --- a/lib/JCVI/Translator/Table.pm +++ b/lib/JCVI/Translator/Table.pm @@ -391,8 +391,8 @@ sub add_translation { $table->store( $residue, $$codon_ref, $$rc_codon_ref ); # Store the reverse lookup - $residue = 'start' if ( $p{start} ); - $self->_reverse->push( 'start', $$codon_ref, $$rc_codon_ref ); + $residue = '+' if ( $p{start} ); + $self->_reverse->push( $residue, $$codon_ref, $$rc_codon_ref ); } =head2 bootstrap diff --git a/lib/JCVI/Translator/Utils.pm b/lib/JCVI/Translator/Utils.pm index 4487a84..9b3af7e 100644 --- a/lib/JCVI/Translator/Utils.pm +++ b/lib/JCVI/Translator/Utils.pm @@ -57,7 +57,7 @@ our $BOOLEAN_REGEX = qr/^[01]$/; our $INTEGER_REGEX = qr/^\d+$/; our $STRAND_REGEX = qr/^[+-]?1$/; our $SEARCH_STRAND_REGEX = qr/^[+-]?[01]$/; -our $RESIDUE_REGEX = qr/^(?:$aa_match|start|stop|lower|upper)$/; +our $RESIDUE_REGEX = qr/^(?:$aa_match|\+|start|stop|lower|upper)$/; our $STRICT_REGEX = qr/^[012]$/; sub _new { @@ -79,8 +79,9 @@ Returns a list of codons for a particular residue or start codon. In addition to the one-letter codes for amino acids, the following are valid inputs for the residue: - start: Start codons - stop: Stop codons (you may also use "*" which is the 1 letter code) + start: Start codons (you may also use "+" which is what the translator + uses as the 1-letter code for start codons) + stop: Stop codons (you may also use "*" which is the 1-letter code) lower: Start or stop codons, depending up on strand upper: Start or stop codons, depending up on strand @@ -124,17 +125,14 @@ sub codons { # Set the reverse comlement variable my $rc = $p{strand} == 1 ? 0 : 1; - # If residue is 'stop' change it to '*' - if ( $residue eq 'stop' ) { $residue = '*' } - - # Do nothing if residue is "start" (don't want to capitalize) - elsif ( $residue eq 'start' ) { } - - # Lower bound is "*" on the - strand, "start" on the + strand - elsif ( $residue eq 'lower' ) { $residue = $rc ? '*' : 'start' } + # Format start/stop to be '+' and '*' which is how translator stores them + if ( $residue eq 'stop' ) { $residue = '*' } + elsif ( $residue eq 'start' ) { $residue = '+' } - # Upper bound is "start" on the - strand, or "*" on the + strand - elsif ( $residue eq 'upper' ) { $residue = $rc ? 'start' : '*' } + # Lower bound is stop on the - strand, start on the + strand. Upper bound + # is the reverse + elsif ( $residue eq 'lower' ) { $residue = $rc ? '*' : '+' } + elsif ( $residue eq 'upper' ) { $residue = $rc ? '+' : '*' } # Capitalize all other residues else { $residue = uc $residue } @@ -157,7 +155,8 @@ Returns a regular expression matching codons for a particular amino acid residue. In addition to the one-letter codes for amino acids, the following are valid inputs for the residue: - start: Start codons + start: Start codons (you may also use "+" which is what the translator + uses as the 1-letter code for start codons) stop: Stop codons (you may also use "*" which is the 1 letter code) lower: Start or stop codons, depending up on strand upper: Start or stop codons, depending up on strand @@ -225,7 +224,8 @@ Find the indexes of a given residue in a sequence. In addition to the one-letter codes for amino acids, the following are valid inputs for the residue: - start: Start codons + start: Start codons (you may also use "+" which is what the translator + uses as the 1-letter code for start codons) stop: Stop codons (you may also use "*" which is the 1 letter code) lower: Start or stop codons, depending up on strand upper: Start or stop codons, depending up on strand diff --git a/t/21-codons.t b/t/21-codons.t index 1daa14c..0567791 100644 --- a/t/21-codons.t +++ b/t/21-codons.t @@ -23,18 +23,31 @@ ok( !$@, 'codons ran with strand = 1' ); eval { $utils->codons( 'F', { strand => -1 } ) }; ok( !$@, 'codons ran with strand = -1' ); - eval { $utils->codons( 'F', { strand => 2 } ) }; ok( $@, 'codons died with strand = 2' ); -my @expected = ( [qw(TTT TTC TTY)], [qw(AAA GAA RAA)] ); - -foreach my $strand ( 1, -1 ) { - my $codons = $utils->codons( 'F', { strand => $strand } ); - my $expected = shift @expected; - is( scalar(@$codons), scalar(@$expected), 'Expected number of codons' ); - - my $lc = List::Compare->new( $expected, $codons ); - - is( scalar( $lc->get_symdiff ), 0, '0 differences between lists' ); +my @entries = ( + [ 'F' => [ [qw(TTT TTC TTY)], [qw(AAA GAA RAA)] ] ], + [ + 'start' => [ + [qw(YTG WTG MTG HTG TTG CTG ATG)], + [qw(CAR CAW CAK CAD CAA CAG CAT)] + ] + ] +); + +foreach my $entry (@entries) { + my ( $residue, $expecteds ) = @$entry; + + foreach my $strand ( 1, -1 ) { + my $codons = $utils->codons( $residue, { strand => $strand } ); + my $expected = shift @$expecteds; + is( scalar(@$codons), scalar(@$expected), + "Got expected number of codons for $residue" ); + + my $lc = List::Compare->new( $expected, $codons ); + + is( scalar( $lc->get_symdiff ), 0, + '0 differences between codon lists' ); + } }