15
Bio::Tools::CodonTable - Bioperl codon table object
15
Bio::Tools::CodonTable - Codon table object
19
19
# This is a read-only class for all known codon tables. The IDs are
20
20
# the ones used by nucleotide sequence databases. All common IUPAC
21
# ambiguity codes for DNA, RNA and animo acids are recognized.
21
# ambiguity codes for DNA, RNA and amino acids are recognized.
24
23
use Bio::Tools::CodonTable;
26
25
# defaults to ID 1 "Standard"
57
56
my $seqobj = Bio::PrimarySeq->new(-seq => 'FHGERHEL');
58
57
my $iupac_str = $myCodonTable->reverse_translate_all($seqobj);
61
60
print "Is a start\n" if $myCodonTable->is_start_codon('ATG');
62
print "Is a termianator\n" if $myCodonTable->is_ter_codon('tar');
61
print "Is a terminator\n" if $myCodonTable->is_ter_codon('tar');
63
62
print "Is a unknown\n" if $myCodonTable->is_unknown_codon('JTG');
118
117
B Asx Aspartic acid or Asparagine
119
118
Z Glx Glutamine or Glutamic acid
120
J Xle Isoleucine or Valine (mass spec ambiguity)
119
J Xle Isoleucine or Valine (mass spec ambiguity)
121
120
X Xaa Any or unknown amino acid
172
171
# Let the code begin...
174
173
package Bio::Tools::CodonTable;
175
use vars qw(@NAMES @TABLES @STARTS $TRCOL $CODONS %IUPAC_DNA $CODONGAP $GAP
176
%IUPAC_AA %THREELETTERSYMBOLS $VALID_PROTEIN $TERMINATOR);
174
use vars qw(@NAMES @TABLES @STARTS $TRCOL $CODONS %IUPAC_DNA $CODONGAP $GAP
175
%IUPAC_AA %THREELETTERSYMBOLS $VALID_PROTEIN $TERMINATOR);
179
178
# Object preamble - inherits from Bio::Root::Root
300
299
Usage : $obj->id(3); $id_integer = $obj->id();
303
Sets or returns the id of the translation table. IDs are
300
Function: Sets or returns the id of the translation table. IDs are
304
301
integers from 1 to 15, excluding 7 and 8 which have been
305
302
removed as redundant. If an invalid ID is given the method
306
303
returns 0, false.
310
305
Returns : value of id, a scalar, 0 if not a valid
311
306
Args : newvalue (optional)
539
534
sub revtranslate {
540
my ($self, $value, $coding) = @_;
541
my ($id) = $self->{'id'};
535
my ($self, $value, $coding) = @_;
536
my ($id) = $self->{'id'};
545
if (length($value) == 3 ) {
547
$value = ucfirst $value;
548
$value = $THREELETTERSYMBOLS{$value};
550
if ( defined $value and $value =~ /$VALID_PROTEIN/
551
and length($value) == 1 ) {
553
@aas = @{$IUPAC_AA{$value}};
554
foreach my $aa (@aas) {
556
$aa = '\*' if $aa eq '*';
557
while ($TABLES[$id-1] =~ m/$aa/g) {
558
$p = pos $TABLES[$id-1];
559
push (@codons, $TRCOL->{--$p});
540
if (length($value) == 3 ) {
542
$value = ucfirst $value;
543
$value = $THREELETTERSYMBOLS{$value};
545
if ( defined $value and $value =~ /$VALID_PROTEIN/
546
and length($value) == 1 ) {
548
@aas = @{$IUPAC_AA{$value}};
549
foreach my $aa (@aas) {
551
$aa = '\*' if $aa eq '*';
552
while ($TABLES[$id-1] =~ m/$aa/g) {
553
$p = pos $TABLES[$id-1];
554
push (@codons, $TRCOL->{--$p});
564
if ($coding and uc ($coding) eq 'RNA') {
565
for my $i (0..$#codons) {
566
$codons[$i] =~ tr/t/u/;
559
if ($coding and uc ($coding) eq 'RNA') {
560
for my $i (0..$#codons) {
561
$codons[$i] =~ tr/t/u/;
572
568
=head2 reverse_translate_all
574
570
Title : reverse_translate_all
583
579
Args : a Bio::PrimarySeqI compatible object (mandatory)
584
580
a Bio::CodonUsage::Table object and a threshold if only
585
581
codons with a relative frequency above the threshold are
591
585
sub reverse_translate_all {
593
587
my ($self, $obj, $cut, $threshold) = @_;
597
591
if (!$obj || !$obj->isa('Bio::PrimarySeqI')){
598
592
$self->throw(" I need a Bio::PrimarySeqI object, not a [".
634
=head2 reverse_translate_best
636
Title : reverse_translate_best
637
Usage : my $str = $cttable->reverse_translate_best($seq_object,$cutable);
638
Function: Reverse translates a protein sequence into plain nucleotide
639
sequence (GATC), uses the most common codon for each amino acid
641
Args : A Bio::PrimarySeqI compatible object and a Bio::CodonUsage::Table object
645
sub reverse_translate_best {
647
my ($self, $obj, $cut) = @_;
649
if (!$obj || !$obj->isa('Bio::PrimarySeqI')){
650
$self->throw(" I need a Bio::PrimarySeqI object, not a [".
653
if ($obj->alphabet ne 'protein') {
654
$self->throw("Cannot reverse translate, need an amino acid sequence .".
655
"This sequence is of type [" . $obj->alphabet ."]");
657
if ( !$cut | !$cut->isa('Bio::CodonUsage::Table')) {
658
$self->throw("I need a Bio::CodonUsage::Table object, not a [".
663
my @seq = split '', $obj->seq;
665
my $cod_ref = $cut->most_common_codons();
667
for my $aa ( @seq ) {
672
if ( defined $cod_ref->{$aa} ) {
673
$str .= $cod_ref->{$aa};
675
$self->throw("Input sequence contains invalid character: $aa");
640
681
=head2 is_start_codon
642
683
Title : is_start_codon