1 # -*-Perl-*- Test Harness script for Bioperl
10 test_begin(-tests => 61);
12 use_ok('Bio::Tools::CodonTable');
13 use_ok('Bio::CodonUsage::IO');
16 # create a table object by giving an ID
17 my $DEBUG = test_debug();
18 my $myCodonTable = Bio::Tools::CodonTable -> new ( -id => 16);
19 ok defined $myCodonTable;
20 isa_ok $myCodonTable, 'Bio::Tools::CodonTable';
22 # defaults to ID 1 "Standard"
23 $myCodonTable = Bio::Tools::CodonTable->new();
24 is $myCodonTable->id(), 1;
27 $myCodonTable->id(10);
28 is $myCodonTable->id, 10;
29 is $myCodonTable->name(), 'Euplotid Nuclear';
31 # enumerate tables as object method
32 my $table = $myCodonTable->tables();
33 cmp_ok (keys %{$table}, '>=', 17); # currently 17 known tables
34 is $table->{11}, q{"Bacterial"};
36 # enumerate tables as class method
37 $table = Bio::Tools::CodonTable->tables;
38 cmp_ok (values %{$table}, '>=', 17); # currently 17 known tables
39 is $table->{23}, 'Thraustochytrium Mitochondrial';
45 $myCodonTable->translate();
49 # Automatically completing translation of incomplete codons is no longer default
50 # behavior b/c of inconsistent behavior compared with Bio::PrimarySeq::translate
51 # and unexpected side effects (e.g. what if the last few bases isn't supposed to
52 # be translated). To re-establish this, pass a second argument to the method.
54 is $myCodonTable->translate(''), '';
56 my @ii = qw(ACT acu ATN gt ytr sar);
57 my @res = qw(T T X V L Z );
60 if ($res[$i] ne $myCodonTable->translate($ii[$i], 1) ) {
62 print $ii[$i], ": |", $res[$i], "| ne |",
63 $myCodonTable->translate($ii[$i], 1), "|\n" if( $DEBUG);
68 is $myCodonTable->translate('ag'), '';
69 is $myCodonTable->translate('ag',1), '';
71 is $myCodonTable->translate('jj'), '';
72 is $myCodonTable->translate('jj',1), '';
74 is $myCodonTable->translate('jjg'), 'X';
75 is $myCodonTable->translate('jjg',1), 'X';
77 is $myCodonTable->translate('gt'), '';
78 is $myCodonTable->translate('gt',1), 'V';
80 is $myCodonTable->translate('g'), '';
81 is $myCodonTable->translate('g',1), '';
83 # a more comprehensive test on ambiguous codes
85 atgaaraayacmacracwackacyacsacvachacdacbacxagragyatmatwatyathcarcayc
86 cmccrccwcckccyccsccvcchccdccbccxcgmcgrcgwcgkcgycgscgvcghcgdcgbcgxctmctrct
87 wctkctyctsctvcthctdctbctxgargaygcmgcrgcwgckgcygcsgcvgchgcdgcbgcxggmggrggw
88 ggkggyggsggvgghggdggbggxgtmgtrgtwgtkgtygtsgtvgthgtdgtbgtxtartaytcmtcrtcwt
89 cktcytcstcvtchtcdtcbtcxtgyttrttytramgamggmgrracratrayytaytgytrsaasagsartaa;
92 @ii = grep { length == 3 } split /(.{3})/, $seq;
93 print join (' ', @ii), "\n" if( $DEBUG);
95 MKNTTTTTTTTTTTRSIIIIQHPPPPPPPPPPPRRRRRRRRRRRLLLLLLLLLLLEDAAAAAAAAAAAGGG
96 GGGGGGGGVVVVVVVVVVV*YSSSSSSSSSSSCLF*RRRBBBLLLZZZ*
100 @res = split //, $prot;
101 print join (' ', @res), "\n" if( $DEBUG );
103 for my $i (0..$#ii) {
104 if ($res[$i] ne $myCodonTable->translate($ii[$i]) ) {
106 print $ii[$i], ": |", $res[$i], "| ne |",
107 $myCodonTable->translate($ii[$i]), "| @ $i\n" if( $DEBUG);
113 # reverse translate amino acids
115 is $myCodonTable->revtranslate('U'), 0;
116 is $myCodonTable->revtranslate('O'), 0;
117 is $myCodonTable->revtranslate('J'), 9;
118 is $myCodonTable->revtranslate('I'), 3;
120 @ii = qw(A l ACN Thr sER ter Glx);
122 [qw(gct gcc gca gcg)],
123 [qw(ggc gga ggg act acc aca acg)],
124 [qw(tct tcc tca tcg agt agc)],
125 [qw(act acc aca acg)],
126 [qw(tct tcc tca tcg agt agc)],
128 [qw(gaa gag caa cag)]
133 for my $i (0..$#ii) {
134 my @codonres = $myCodonTable->revtranslate($ii[$i]);
135 for my $j (0..$#codonres) {
136 if ($codonres[$j] ne $res[$i][$j]) {
138 print $ii[$i], ': ', $codonres[$j], " ne ",
139 $res[$i][$j], "\n" if( $DEBUG);
148 $myCodonTable->id(1);
150 ok $myCodonTable->is_start_codon('ATG');
151 is $myCodonTable->is_start_codon('GGH'), 0;
152 ok $myCodonTable->is_start_codon('HTG');
153 is $myCodonTable->is_start_codon('CCC'), 0;
155 ok $myCodonTable->is_ter_codon('UAG');
156 ok $myCodonTable->is_ter_codon('TaG');
157 ok $myCodonTable->is_ter_codon('TaR');
158 ok $myCodonTable->is_ter_codon('tRa');
159 is $myCodonTable->is_ter_codon('ttA'), 0;
161 ok $myCodonTable->is_unknown_codon('jAG');
162 ok $myCodonTable->is_unknown_codon('jg');
163 is $myCodonTable->is_unknown_codon('UAG'), 0;
165 is $myCodonTable->translate_strict('ATG'), 'M';
170 # adding a custom codon table
176 'FFLLSSSSYY**CC*WLLLL**PPHHQQR*RRIIIMT*TT*NKKSSRRV*VVAA*ADDEE*GGG'
179 ok my $custct = $myCodonTable->add_table(@custom_table);
181 is $myCodonTable->translate('atgaaraayacmacracwacka'), 'MKNTTTT';
182 ok $myCodonTable->id($custct);
183 is $myCodonTable->translate('atgaaraayacmacracwacka'), 'MKXXTTT';
185 # test doing this via Bio::PrimarySeq object
188 ok $seq = Bio::PrimarySeq->new(-seq=>'atgaaraayacmacracwacka', -alphabet=>'dna');
189 is $seq->translate()->seq, 'MKNTTTT';
190 is $seq->translate(undef, undef, undef, undef, undef, undef, $myCodonTable)->seq, 'MKXXTTT';
192 # test gapped translated
194 ok $seq = Bio::PrimarySeq->new(-seq => 'atg---aar------aay',
196 is $seq->translate->seq, 'M-K--N';
198 ok $seq = Bio::PrimarySeq->new(-seq =>'ASDFGHKL');
199 is $myCodonTable->reverse_translate_all($seq), 'GCBWSNGAYTTYGGVCAYAARYTN';
200 ok $seq = Bio::PrimarySeq->new(-seq => 'ASXFHKL');
201 is $myCodonTable->reverse_translate_all($seq), 'GCBWSNNNNTTYCAYAARYTN';
204 # test reverse_translate_best(), requires a Bio::CodonUsage::Table object
207 ok $seq = Bio::PrimarySeq->new(-seq =>'ACDEFGHIKLMNPQRSTVWY');
208 ok my $io = Bio::CodonUsage::IO->new(-file => test_input_file('MmCT'));
209 ok my $cut = $io->next_data();
210 is $myCodonTable->reverse_translate_best($seq,$cut), 'GCCTGCGACGAGTTCGGCCACATCAAGCTGATGAACCCCCAGCGCTCCACCGTGTGGTAC';