AlignDB-Codon
view release on metacpan or search on metacpan
lib/AlignDB/Codon.pm view on Meta::CPAN
elsif ( $cnt == 2 ) {
$return_pos = $sames[0];
}
return ( $cnt, $return_pos );
}
sub translate {
my $self = shift;
my $seq = shift;
my $frame = shift;
# check $frame
if ( defined $frame ) {
if ( List::MoreUtils::PP::none { $_ == $frame } ( 0 .. 2 ) ) {
confess Dump( { frame => $frame } ), "Wrong frame\n";
}
}
else {
$frame = 0;
}
if ( $frame != 0 ) {
$seq = substr( $seq, $frame ); # delete first $frame bases from $seq
}
my $offset = length($seq) - ( length($seq) % 3 );
substr( $seq, $offset, length($seq), '' ); # now $seq is 3n bp
my $peptide = "";
my $codon2aa = $self->codon2aa;
my $codon_size = 3;
for ( my $i = 0; $i < ( length($seq) - ( $codon_size - 1 ) ); $i += $codon_size ) {
my $triplet = substr( $seq, $i, $codon_size );
if ( exists $codon2aa->{$triplet} ) {
t/04.syn_nsy.t view on Meta::CPAN
= ( [ 0, 1 ], [ 1, 0 ], [ 0.5, 1.5 ], [ 0.5, 1.5 ], [ 0.75, 2.25 ], );
for my $i ( 0 .. $#compare ) {
my ( $exp1, $exp2 ) = @{ $expect[$i] };
my ( $syn, $nsy ) = $codon->comp_codons( @{ $compare[$i] } );
is( $syn, $exp1, "syn $i" );
is( $nsy, $exp2, "nsy $i" );
}
}
{ # compare normal codons with frames
my $codon = AlignDB::Codon->new( table_id => 1 );
my @compare = (
[qw{ TTT TTA 2 }], [qw{ TTT TTA 0 }], [qw{ TTT TTC 2 }], [qw{ TTT TTC 1 }],
[qw{ TTT GTA 0 }], [qw{ TTT GTA 1 }], [qw{ TTT GTA 2 }], [qw{ TTG AGA 0 }],
[qw{ TTG AGA 1 }], [qw{ TTG AGA 2 }],
);
my @expect = (
[ 0, 1 ],
my $codon = AlignDB::Codon->new( table_id => 1 );
my $dna = "CGACGTCTTCGTACGGGACTAGCTCGTGTCGGTCGC";
my $pep = "RRLRTGLARVGR";
is( $codon->translate($dna), $pep, "translate full" );
is( $codon->translate( substr( $dna, 0, length($dna) - 1 ) ),
substr( $pep, 0, length($pep) - 1 ), "translate minus one" );
eval { $codon->translate( $dna, -1 ); };
like( $@, qr{Wrong frame}i, "Wrong frame" );
done_testing();
( run in 0.801 second using v1.01-cache-2.11-cpan-df04353d9ac )