Skip to content

Commit

Permalink
Updated trunk to 0.5.6
Browse files Browse the repository at this point in the history
  • Loading branch information
kgalinsky committed Oct 28, 2009
1 parent b70f30e commit a44e62d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 21 deletions.
6 changes: 6 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -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

Expand Down
60 changes: 39 additions & 21 deletions lib/JCVI/Translator.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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,
{
Expand Down Expand Up @@ -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
}
}
);
Expand All @@ -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} );

Expand All @@ -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 );
Expand Down Expand Up @@ -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,
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit a44e62d

Please sign in to comment.