diff --git a/Changes b/Changes index e61d1a6..7fffaa0 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,11 @@ Revision history for JCVI-Translator +0.5.6 May 7 2009 + - Fixed bug in Translator where sequence was being cleaned after default + upper bound was being set and bounds were tested to be within the sequence. + Cleaning can cause the sequence to be truncated, which then invalidates + these tests/settings. + 0.5.5 Apr 23 2009 - Fixed bug in Base where Xs weren't being put in when base isn't found diff --git a/lib/JCVI/Translator.pm b/lib/JCVI/Translator.pm index 6892552..0e89f22 100644 --- a/lib/JCVI/Translator.pm +++ b/lib/JCVI/Translator.pm @@ -66,7 +66,7 @@ package JCVI::Translator; use strict; use warnings; -use version; our $VERSION = qv('0.5.5'); +use version; our $VERSION = qv('0.5.6'); use base qw(Class::Accessor::Fast); __PACKAGE__->mk_accessors(qw(table base)); @@ -256,6 +256,13 @@ sub translate { { type => Params::Validate::HASHREF, default => {} } ); + # Check the sanitized value separately + my $sanitized = _is_sanitized(@p); + + # Clean the sequence and cache it + $seq_ref = cleanDNA($seq_ref) unless ($sanitized); + $self->base->set_seq($seq_ref); + my %p = validate( @p, { @@ -301,11 +308,6 @@ sub translate { default => $DEFAULT_PARTIAL, regex => qr/^[01]$/, type => Params::Validate::SCALAR - }, - sanitized => { - default => $DEFAULT_SANITIZED, - regex => qr/^[01]$/, - type => Params::Validate::SCALAR } } ); @@ -319,10 +321,6 @@ sub translate { # Return undef if the offset is bigger than the space between bounds return undef if ( $p{upper} <= $p{lower} + $p{offset} ); - # Clean the sequence and cache it - $seq_ref = cleanDNA($seq_ref) unless ( $p{sanitized} ); - $self->base->set_seq($seq_ref); - # Set the partial status $self->base->set_partial( $p{partial} ); @@ -335,6 +333,20 @@ sub translate { return \$peptide; } +sub _is_sanitized { + my ($p) = @_; + + my $sanitized = $DEFAULT_SANITIZED; + if ( exists $p->{sanitized} ) { + $sanitized = $p->{sanitized}; + croak qq{Invalid value for sanitized "$sanitized" (must be 0 or 1) } + unless ( $sanitized =~ m/^[01]$/ ); + delete $p->{sanitized}; + } + + return $sanitized; +} + =head2 translate6 my $pep_refs = $translator->translate6( $seq_ref ); @@ -387,6 +399,14 @@ sub translate6 { { type => Params::Validate::HASHREF, default => {} } ); + # Check the sanitized value separately + my $sanitized = _is_sanitized(@p); + + # Clean the sequence and cache it + $seq_ref = cleanDNA($seq_ref) unless ($sanitized); + $self->base->set_seq($seq_ref); + + my %p = validate( @p, { @@ -418,18 +438,10 @@ sub translate6 { default => $DEFAULT_PARTIAL, regex => qr/^[01]$/, type => Params::Validate::SCALAR - }, - sanitized => { - default => $DEFAULT_SANITIZED, - regex => qr/^[01]$/, - type => Params::Validate::SCALAR } } ); - $seq_ref = cleanDNA($seq_ref) unless ( $p{sanitized} ); - $self->base->set_seq($seq_ref); - $self->base->set_partial( $p{partial} ); my @peptides; @@ -494,6 +506,13 @@ sub translate_exons { { type => Params::Validate::HASHREF, default => {} } ); + # Check the sanitized value separately + my $sanitized = _is_sanitized(@p); + + # Clean the sequence and cache it + $seq_ref = cleanDNA($seq_ref) unless ($sanitized); + $self->base->set_seq($seq_ref); + # Validate optional arguments my %p = validate( @p, @@ -526,9 +545,6 @@ sub translate_exons { ( ( $a->[0] <=> $b->[0] ) || ( $a->[1] <=> $b->[1] ) ) * $p{strand} } @$exons; - $seq_ref = cleanDNA($seq_ref) unless ( $p{sanitized} ); - $self->base->set_seq($seq_ref); - $self->base->set_partial( $p{partial} ); my $prep = $self->base->prepare( $p{strand}, $self->table ); @@ -617,12 +633,14 @@ sub translate_codon { my %p = validate( @p, { + # Make sure strand is 1 or -1 strand => { default => 1, regex => qr/^[+-]?1$/, type => Params::Validate::SCALAR }, + # Make sure it is a boolean value start => { default => 0,