1 # -*-Perl-*- Test Harness script for Bioperl
10 test_begin(-tests => 51);
12 use_ok('Bio::Tools::CodonTable');
15 # create a table object by giving an ID
16 my $DEBUG = test_debug();
17 my $myCodonTable = Bio::Tools::CodonTable -> new ( -id => 16);
18 ok defined $myCodonTable;
19 isa_ok $myCodonTable, 'Bio::Tools::CodonTable';
21 # defaults to ID 1 "Standard"
22 $myCodonTable = Bio::Tools::CodonTable->new();
23 is $myCodonTable->id(), 1;
26 $myCodonTable->id(10);
27 is $myCodonTable->id, 10;
28 is $myCodonTable->name(), 'Euplotid Nuclear';
30 # enumerate tables as object method
31 my $table = $myCodonTable->tables();
32 cmp_ok (keys %{$table}, '>=', 17); # currently 17 known tables
33 is $table->{11}, q{"Bacterial"};
35 # enumerate tables as class method
36 $table = Bio::Tools::CodonTable->tables;
37 cmp_ok (values %{$table}, '>=', 17); # currently 17 known tables
38 is $table->{23}, 'Thraustochytrium Mitochondrial';
44 $myCodonTable->translate();
48 is $myCodonTable->translate(''), '';
50 my @ii = qw(ACT acu ATN gt ytr sar);
51 my @res = qw(T T X V L Z );
54 if ($res[$i] ne $myCodonTable->translate($ii[$i]) ) {
56 print $ii[$i], ": |", $res[$i], "| ne |", $myCodonTable->translate($ii[$i]), "|\n" if( $DEBUG);
61 is $myCodonTable->translate('ag'), '';
62 is $myCodonTable->translate('jj'), '';
63 is $myCodonTable->translate('jjg'), 'X';
64 is $myCodonTable->translate('gt'), 'V';
65 is $myCodonTable->translate('g'), '';
67 # a more comprehensive test on ambiguous codes
69 atgaaraayacmacracwackacyacsacvachacdacbacxagragyatmatwatyathcarcayc
70 cmccrccwcckccyccsccvcchccdccbccxcgmcgrcgwcgkcgycgscgvcghcgdcgbcgxctmctrct
71 wctkctyctsctvcthctdctbctxgargaygcmgcrgcwgckgcygcsgcvgchgcdgcbgcxggmggrggw
72 ggkggyggsggvgghggdggbggxgtmgtrgtwgtkgtygtsgtvgthgtdgtbgtxtartaytcmtcrtcwt
73 cktcytcstcvtchtcdtcbtcxtgyttrttytramgamggmgrracratrayytaytgytrsaasagsartaa;
76 @ii = grep { length == 3 } split /(.{3})/, $seq;
77 print join (' ', @ii), "\n" if( $DEBUG);
79 MKNTTTTTTTTTTTRSIIIIQHPPPPPPPPPPPRRRRRRRRRRRLLLLLLLLLLLEDAAAAAAAAAAAGGG
80 GGGGGGGGVVVVVVVVVVV*YSSSSSSSSSSSCLF*RRRBBBLLLZZZ*
84 @res = split //, $prot;
85 print join (' ', @res), "\n" if( $DEBUG );
88 if ($res[$i] ne $myCodonTable->translate($ii[$i]) ) {
90 print $ii[$i], ": |", $res[$i], "| ne |",
91 $myCodonTable->translate($ii[$i]), "| @ $i\n" if( $DEBUG);
97 # reverse translate amino acids
99 is $myCodonTable->revtranslate('U'), 0;
100 is $myCodonTable->revtranslate('O'), 0;
101 is $myCodonTable->revtranslate('J'), 9;
102 is $myCodonTable->revtranslate('I'), 3;
104 @ii = qw(A l ACN Thr sER ter Glx);
106 [qw(gct gcc gca gcg)],
107 [qw(ggc gga ggg act acc aca acg)],
108 [qw(tct tcc tca tcg agt agc)],
109 [qw(act acc aca acg)],
110 [qw(tct tcc tca tcg agt agc)],
112 [qw(gaa gag caa cag)]
117 for my $i (0..$#ii) {
118 my @codonres = $myCodonTable->revtranslate($ii[$i]);
119 for my $j (0..$#codonres) {
120 if ($codonres[$j] ne $res[$i][$j]) {
122 print $ii[$i], ': ', $codonres[$j], " ne ",
123 $res[$i][$j], "\n" if( $DEBUG);
132 $myCodonTable->id(1);
134 ok $myCodonTable->is_start_codon('ATG');
135 is $myCodonTable->is_start_codon('GGH'), 0;
136 ok $myCodonTable->is_start_codon('HTG');
137 is $myCodonTable->is_start_codon('CCC'), 0;
139 ok $myCodonTable->is_ter_codon('UAG');
140 ok $myCodonTable->is_ter_codon('TaG');
141 ok $myCodonTable->is_ter_codon('TaR');
142 ok $myCodonTable->is_ter_codon('tRa');
143 is $myCodonTable->is_ter_codon('ttA'), 0;
145 ok $myCodonTable->is_unknown_codon('jAG');
146 ok $myCodonTable->is_unknown_codon('jg');
147 is $myCodonTable->is_unknown_codon('UAG'), 0;
149 is $myCodonTable->translate_strict('ATG'), 'M';
154 # adding a custom codon table
160 'FFLLSSSSYY**CC*WLLLL**PPHHQQR*RRIIIMT*TT*NKKSSRRV*VVAA*ADDEE*GGG'
163 ok my $custct = $myCodonTable->add_table(@custom_table);
165 is $myCodonTable->translate('atgaaraayacmacracwacka'), 'MKNTTTT';
166 ok $myCodonTable->id($custct);
167 is $myCodonTable->translate('atgaaraayacmacracwacka'), 'MKXXTTT';
169 # test doing this via Bio::PrimarySeq object
172 ok $seq = Bio::PrimarySeq->new(-seq=>'atgaaraayacmacracwacka', -alphabet=>'dna');
173 is $seq->translate()->seq, 'MKNTTTT';
174 is $seq->translate(undef, undef, undef, undef, undef, undef, $myCodonTable)->seq, 'MKXXTTT';
176 # test gapped translated
178 ok $seq = Bio::PrimarySeq->new(-seq => 'atg---aar------aay',
180 is $seq->translate->seq, 'M-K--N';
182 ok $seq = Bio::PrimarySeq->new(-seq=>'ASDFGHKL');
183 is $myCodonTable->reverse_translate_all($seq), 'GCBWSNGAYTTYGGVCAYAARYTN';
184 ok $seq = Bio::PrimarySeq->new(-seq=>'ASXFHKL');
185 is $myCodonTable->reverse_translate_all($seq), 'GCBWSNNNNTTYCAYAARYTN';