lib/Bio/CUA/CodonTable.pm

filter: Statementstmt 71.8% 125 / 174 Branchbran 55.6% 49 / 88 Conditioncond 27.2% 6 / 22 MC/DCmcdc 20.0% 2 / 10 Subroutinesub 65.2% 15 / 23 Podpod 100% 14 / 14 totaltotal 63.7% 211 / 331 SCAR 51.9
CC
51
Cov
63%
_build_table_by_file
42.0
_build_table_by_id
20.8
all_start_codons
20.0
CRAP 178.7
« lib/Bio/CUA/Summarizer.pm ↑ Summary script/build_cai_param.pl »
1 package Bio::CUA::CodonTable;
2  
3 =pod
4  
5 =head1 NAME
6  
7 Bio::CUA::CodonTable -- A package processing genetic codon table
8  
9 =head1 SYNOPSIS
10  
11 This package is provided to improve portability of
12 L<http://search.cpan.org/dist/Bio-CUA/>, in case that one may not
13 install L<BioPerl/http://www.bioperl.org/> which includes huge number
14 of modules.
15  
16 The package obtains genetic code tables from NCBI at
17 L<http://www.ncbi.nlm.nih.gov/Taxonomy/taxonomyhome.html/index.cgi?chapter=cgencodes>
18  
19 examples:
20  
21 # get the standard genetic code
22 my $table = Bio::CUA::CodonTable->new(-id => 1)
23  
24 # get table from an input file if know genetic codes can not
25 # satisfy the need.
26 my $table = Bio::CUA::CodonTable->new(-map_file =>
27 'codon_to_aa.tsv')
28 # in 'codon_to_aa.tsv', it looks like this
29 # GCU A
30 # AAU N
31 # CAU H
32 # ... ...
33  
34 =cut
35  
36 5 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 5 ▶use parent qw/Bio::CUA/;
Subroutine BEGIN: called CC=1 SCAR=0.0
40  
41 # global variables
42 5 my $pkg = __PACKAGE__;
43 5 my $STOPAA = '*';
44 5 my %validGCIds = map { $_ => 1 } (1..6,9..14,16,21..25); # in future this can be derived
45 # from data section at the end
46  
47 =head2 new
48  
49 Title : new
50 Usage : $obj = Bio::CUA::CodonTable->new(-map_file => 'file');
51 Function: creat an object for processing genetic codon tables
52 Returns : an object of L<Bio::CUA::CodonTable>
53 Args : a hash with following keys:
54  
55 =over 4
56  
57 =item -id
58  
59 genetic code id. The id follows NCBI's standard, here are
60 the list:
61 1. The Standard Code
62 2. The Vertebrate Mitochondrial Code
63 3. The Yeast Mitochondrial Code
64 4. The Mold, Protozoan, and Coelenterate Mitochondrial Code and
65 the Mycoplasma/Spiroplasma Code
66 5. The Invertebrate Mitochondrial Code
67 6. The Ciliate, Dasycladacean and Hexamita Nuclear Code
68 9. The Echinoderm and Flatworm Mitochondrial Code
69 10. The Euplotid Nuclear Code
70 11. The Bacterial, Archaeal and Plant Plastid Code
71 12. The Alternative Yeast Nuclear Code
72 13. The Ascidian Mitochondrial Code
73 14. The Alternative Flatworm Mitochondrial Code
74 16. Chlorophycean Mitochondrial Code
75 21. Trematode Mitochondrial Code
76 22. Scenedesmus obliquus Mitochondrial Code
77 23. Thraustochytrium Mitochondrial Code
78 24. Pterobranchia Mitochondrial Code
79 25. Candidate Division SR1 and Gracilibacteria Code
80 see
81 L<http://www.ncbi.nlm.nih.gov/Taxonomy/taxonomyhome.html/index.cgi?chapter=tgencodes#SG1>
82 for more details.
83  
84 =item -map_file
85  
86 -map_file = a file containing a mapping between codons to amino
87 acids, one codon per line followed by its amino acid, separated by
88 tab or space.
89  
90 =item -debug
91  
92 a switch to indicate whether to show more warnings which may
93 help to identify sources of errors if any. put 1 to switch
94 it on. The default is off.
95  
96 =back
97  
98 Note: argument -map_file has higher priority than -id, and the
99 default is -id => 1, i.e., the standard genetic code
100  
101 =cut
102  
103 sub new
104 {
105 4 ▶ my ($caller, @args) = @_;
Subroutine new: called CC=4 SCAR=17.3
Pod documented
106  
107 4 my $self = $caller->SUPER::new(@args);
108  
109 4 my $hash = $self->_array_to_hash(\@args);
110  
111 4 ▶ if($hash->{'map_file'})
Branch: 2 branches
BranchTrueFalseTotal
if ($hash->{'map_file'}) { } 0 4 4
elsif ($hash->{'id'}) { } 4 0 4
112 {
113 0 $self->_build_table_by_file($hash->{'map_file'});
114 }elsif($hash->{'id'})
115 {
116 4 $self->_build_table_by_id($hash->{'id'});
117 }else
118 {
119 0 ▶ $self->warn("No arguments -map_file or -id is provided in",
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 0 0 0
120 "$pkg, -id => 1 will be used") if($self->debug);
121 0 $self->_build_table_by_id(1);
122 }
123  
124 4 return $self;
125 }
126  
127 # get genetic code table by parsing a file
128 sub _build_table_by_file
129 {
130 0 ▶ my ($self, $file) = @_;
Subroutine _build_table_by_file: not called CC=6 SCAR=37.4
131  
132 0 my $codonToAA = $self->_parse_file($file,2);
133  
134 # check all the codons and amino acids
135 0 my %validCodons;
136 my %stopCodons;
137 0 ▶ while(my ($codon, $AA) = each %$codonToAA)
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$codonToAA) 0 0 0
138 {
139 0 $codon = _process_codon($codon);
140 0 ▶ ($self->warn("$codon is Not a valid codon") and next)
Branch: 1 branch
BranchTrueFalseTotal
unless $codon =~ /^[ATCG]{3}$/ 0 0 0
Condition0%0/5
$codon =~ /^[ATCG]{3}$/ || $self->warn("$codon is Not a valid codon") && (next)
l!l&&r!l&&!r
000
$self->warn("$codon is Not a valid codon") and next
!ll
00
MC/DC0%0/2
$codon =~ /^[ATCG]{3}$/ || $self->warn("$codon is Not a valid codon") && (next)
$codon =~ /^[ATCG]{3}$/ $self->warn("$codon is Not a valid codon")
Truth table0%0/3
A || B
A= $codon =~ /^[ATCG]{3}$/B= $self->warn("$codon is Not a valid codon")
ABresult
1X1
011
000
141 unless($codon =~ /^[ATCG]{3}$/);
142 0 $validCodons{$codon} = $AA;
143 0 ▶ $stopCodons{$codon}++ if($self->_is_stop_aa($AA));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_stop_aa($AA) 0 0 0
144 }
145  
146 0 $self->{'_codon_to_aa'} = \%validCodons;
147 0 $self->{'_stop_codons'} = \%stopCodons;
148 0 my $totalCodonNum = scalar(keys %validCodons);
149 0 $self->{'_num_codons'} = $totalCodonNum;
150 0 ▶ if($totalCodonNum < 64)
Branch: 1 branch
BranchTrueFalseTotal
if ($totalCodonNum < 64) 0 0 0
151 {
152 0 $self->warn("Only $totalCodonNum valid codons found in '$file'");
153 }
154  
155 0 return 1;
156 }
157  
158 # make codon table with given table ID
159 sub _build_table_by_id
160 {
161 4 ▶ my ($self, $id) = @_;
Subroutine _build_table_by_id: called CC=20 SCAR=30.4
162  
163 4 ▶ $self->throw("Id '$id' is not a valid genetic code table Id")
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_valid_gc_id($id) 0 4 4
164 unless($self->_is_valid_gc_id($id));
165  
166 #my $curFile = __FILE__;
167 #warn "I am in $curFile\n";
168  
169 4 my $fh = $self->_open_file(__FILE__);
170  
171 4 my $inDataSection = 0;
172 4 my $inGCSection = 0; # genetic codon section
173 4 my $data = '';
174 # cut the genetic codon section first
175 4 ▶ while(<$fh>)
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 3616 0 3616
176 {
177 3616 ▶ $inDataSection = 1 if(/^__END__/);
Branch: 1 branch
BranchTrueFalseTotal
if /^__END__/ 4 3612 3616
178 3616 ▶ next unless($inDataSection);
Branch: 1 branch
BranchTrueFalseTotal
unless $inDataSection 2548 1068 3616
179 1068 ▶ last if(/^<<GC/); # end of the section
Branch: 1 branch
BranchTrueFalseTotal
if /^<<GC/ 4 1064 1068
180 1064 ▶ $inGCSection = 1 if(/^>>GC/);
Branch: 1 branch
BranchTrueFalseTotal
if /^>>GC/ 4 1060 1064
181 1064 ▶ next if(/^>/ or /^--/); # comment lines
Branch: 1 branch
BranchTrueFalseTotal
if /^>/ or /^--/ 328 736 1064
Condition100%3/3
/^>/ or /^--/
l!l&&r!l&&!r
4324736
MC/DC100%2/2
/^>/ or /^--/
/^>/ /^--/
Truth table100%3/3
A or B
A= /^>/B= /^--/
ABresult
1X1
011
000
182 736 $data .= $_;
183 }
184 4 close $fh;
185  
186 # match each table and find that with the id = $id
187 4 my $table;
188 4 ▶ while($data =~ /\n *{ *\n *(name[^}]+)}/gcm)
Branch: 1 branch
BranchTrueFalseTotal
if ($data =~ /\n *{ *\n *(name[^}]+)}/cgm) 4 0 4
189 {
190 4 $table = $1;
191 4 ▶ next unless($table =~ /^ *id\s+$id\s*,/m);
Branch: 1 branch
BranchTrueFalseTotal
unless $table =~ /^ *id\s+$id\s*,/m 0 4 4
192 4 last; # found
193 }
194  
195 # now parse this table
196 4 my %codonToAA;
197 my %stopCodons;
198 4 my %startCodons;
199 4 my ($b1) = $table =~ /^ *-- +Base1 +(\w+)/mo;
200 4 my ($b2) = $table =~ /^ *-- +Base2 +(\w+)/mo;
201 4 my ($b3) = $table =~ /^ *-- +Base3 +(\w+)/mo;
202 4 my ($AAs) = $table =~ /^ *ncbieaa +"([^"]+)"/mo;
203 4 $AAs =~ s/\s+//g;
204 4 my ($starts) = $table =~ /^ *sncbieaa +"([^"]+)"/mo;
205 4 $starts =~ s/\s+//g;
206 4 my @names;
207 4 ▶ while($table =~ /^ *name +("[^"]+")/mgco)
Branch: 1 branch
BranchTrueFalseTotal
if ($table =~ /^ *name +("[^"]+")/cgmo) 8 4 12
208 {
209 8 my $name = $1;
210 8 $name =~ s/\n/ /g;
211 8 push @names, $name;
212 }
213  
214 4 ▶ $self->warn("The length of lines in genetic table $id is not 64")
Branch: 1 branch
BranchTrueFalseTotal
unless length $b1 == 64 0 4 4
215 unless(length($b1) == 64);
216 4 ▶ $self->throw("lines of bases and amino acids are not the same long",
Branch: 1 branch
BranchTrueFalseTotal
unless length $b1 == length $b2 and length $b1 == length $b3 and length $b1 == length $AAs and length $b1 == length $starts 0 4 4
Condition33%3/9
length $b1 == length $b2 and length $b1 == length $b3 and length $b1 == length $AAs and length $b1 == length $starts
!ll&&!rl&&r
004
length $b1 == length $b2 and length $b1 == length $b3 and length $b1 == length $AAs
!ll&&!rl&&r
004
length $b1 == length $b2 and length $b1 == length $b3
!ll&&!rl&&r
004
MC/DC0%0/4
length $b1 == length $b2 and length $b1 == length $b3 and length $b1 == length $AAs and length $b1 == length $starts
length $b1 == length $b2 length $b1 == length $b3 length $b1 == length $AAs length $b1 == length $starts
Truth table20%1/5
A and B and C and D
A= length $b1 == length $b2B= length $b1 == length $b3C= length $b1 == length $AAsD= length $b1 == length $starts
ABCDresult
0XXX0
10XX0
110X0
11100
11111
217 "in genetic table $id")
218 unless( length($b1) == length($b2) and
219 length($b1) == length($b3) and
220 length($b1) == length($AAs) and
221 length($b1) == length($starts));
222  
223 4 $self->set_tag('name', join(' or ', @names));
224 4 $self->set_tag('id', $id);
225 4 ▶ for(my $i = 0; $i < length($b1); $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < length $b1) 256 4 260
226 {
227 256 my $nt1 = substr($b1, $i, 1);
228 256 my $nt2 = substr($b2, $i, 1);
229 256 my $nt3 = substr($b3, $i, 1);
230 256 my $AA = substr($AAs, $i, 1);
231 256 my $start = substr($starts, $i, 1);
232 256 my $codon = uc($nt1.$nt2.$nt3);
233 256 $codonToAA{$codon} = $AA;
234 256 ▶ $stopCodons{$codon}++ if($self->_is_stop_aa($AA));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_stop_aa($AA) 12 244 256
235 256 ▶ $startCodons{$codon}++ unless($start eq '-');
Branch: 1 branch
BranchTrueFalseTotal
unless $start eq "-" 12 244 256
236 }
237  
238 4 $self->{'_codon_to_aa'} = \%codonToAA;
239 4 $self->{'_stop_codons'} = \%stopCodons;
240 4 $self->{'_start_codons'} = \%startCodons;
241 4 $self->{'_num_codons'} = scalar(keys %codonToAA);
242  
243 4 return 1;
244 }
245  
246 =head2 name
247  
248 Title : name
249 Usage : $name = $self->name();
250 Function: the name of genetic code table in use
251 Returns : a string for the name
252 Args : None
253  
254 =cut
255  
256 sub name
257 {
258 0 ▶ $_[0]->get_tag('name');
Subroutine name: not called CC=1 SCAR=6.9
Pod documented
259 }
260  
261 =head2 id
262  
263 Title : id
264 Usage : $id = $self->id();
265 Function: the id of genetic code table in use
266 Returns : a integer for the id
267 Args : None
268  
269 =cut
270  
271 sub id
272 {
273 0 ▶ $_[0]->get_tag('id');
Subroutine id: not called CC=1 SCAR=6.9
Pod documented
274 }
275  
276 =head2 total_num_of_codons
277  
278 Title : total_num_of_codons
279 Usage : $num = $self->total_num_of_codons;
280 Function: get total codons of the genetic code table in use
281 Returns : an integer
282 Args : None
283  
284 =cut
285  
286 sub total_num_of_codons
287 {
288 0 ▶ $_[0]->{'_num_codons'};
Subroutine total_num_of_codons: not called CC=1 SCAR=6.9
Pod documented
289 }
290  
291 sub _is_valid_gc_id
292 {
293 4 ▶ my ($self, $id) = @_;
Subroutine _is_valid_gc_id: called CC=2 SCAR=8.1
294
295 4 ▶ return 1 if($validGCIds{$id});
Branch: 1 branch
BranchTrueFalseTotal
if $validGCIds{$id} 4 0 4
296 0 return 0;
297 }
298  
299 # check whether this AA is a stop symbol
300 sub _is_stop_aa
301 {
302 768 ▶ my ($self, $AA) = @_;
Subroutine _is_stop_aa: called CC=2 SCAR=6.9
303  
304 768 ▶ return 1 if($AA eq $STOPAA);
Branch: 1 branch
BranchTrueFalseTotal
if $AA eq $STOPAA 36 732 768
305 732 return 0;
306 }
307  
308 =head2 is_valid_codon
309  
310 Title : is_valid_codon
311 Usage : $test = $self->is_valid_codon('ACG');
312 Function: test whether a given character string is a valid codon in
313 current codon table
314 Returns : 1 if true, otherwise 0
315 Args : a codon sequence
316  
317 =cut
318 # check whether this is a valid codon
319 sub is_valid_codon
320 {
321 0 ▶ my ($self,$codon,$allowAmb) = @_;
Subroutine is_valid_codon: not called CC=3 SCAR=24.8
Pod documented
322  
323 0 $codon = _process_codon($codon);
324 0 ▶ return 0 unless($codon =~ /^[ATCGU]{3}$/); # no ambiguous at present
Branch: 1 branch
BranchTrueFalseTotal
unless $codon =~ /^[ATCGU]{3}$/ 0 0 0
325 # also check whether it is in codon table
326 0 my $codons = $self->{'_codon_to_aa'};
327 0 ▶ return 0 unless(exists $codons->{$codon});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $codons->{$codon} 0 0 0
328 0 return 1;
329 }
330  
331 =head2 all_sense_codons
332  
333 Title : all_sense_codons
334 Usage : @codons = $self->all_sense_codons;
335 Function: get all the sense codons in this genetic code table
336 Returns : an array of codons, or its reference in scalar context
337 Args : None
338  
339 =cut
340  
341 sub all_sense_codons
342 {
343 28 ▶ my ($self) = @_;
Subroutine all_sense_codons: called CC=2 SCAR=6.9
Pod documented
344  
345 28 my $codonToAA = $self->{'_codon_to_aa'};
346 28 my $stopCodons = $self->{'_stop_codons'};
347 28 my @senseCodons = grep {!exists($stopCodons->{$_})} keys %$codonToAA;
348  
349 28 ▶ return wantarray? @senseCodons : \@senseCodons;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 27 1 28
350 }
351  
352 =head2 all_amino_acids
353  
354 Title : all_amino_acids
355 Usage : @AAs = $self->all_amino_acids
356 Function: get all the amino acids in this genetic code table
357 Returns : an array of amino acids, or its reference if in scalar
358 context
359 Args : None
360  
361 =cut
362  
363 sub all_amino_acids
364 {
365 8 ▶ my $self = shift;
Subroutine all_amino_acids: called CC=5 SCAR=16.2
Pod documented
366 8 ▶ my $codonToAA = $self->{'_codon_to_aa'} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $codonToAA = $self->{"_codon_to_aa"} or return 0 8 8
367  
368 8 my %AAs;
369 8 ▶ while(my ($k,$v) = each %$codonToAA)
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$codonToAA) 512 8 520
370 {
371 512 ▶ next if $self->_is_stop_aa($v);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_stop_aa($v) 24 488 512
372 488 $AAs{$v}++;
373 }
374  
375 8 my @tmp = keys %AAs;
376 8 ▶ return wantarray? @tmp : \@tmp;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 8 0 8
377 }
378  
379 =head2 all_start_codons
380  
381 Title : all_start_codons
382 Usage : @startCodons = $self->all_start_codons;
383 Function: get all the start codons in the genetic code table in use
384 Returns : an array of codons, or its reference if in scalar context
385 Args : None
386  
387 =cut
388  
389 sub all_start_codons
390 {
391 0 ▶ my $self = shift;
Subroutine all_start_codons: not called CC=4 SCAR=30.0
Pod documented
392 $self->warn("No marked start codons in this GC table") and return
393 0 ▶ unless(exists $self->{'_start_codons'});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"_start_codons"} 0 0 0
Condition0%0/5
exists $self->{'_start_codons'} || $self->warn('No marked start codons in this GC table') && (return)
l!l&&r!l&&!r
000
$self->warn("No marked start codons in this GC table") and return
!ll
00
MC/DC0%0/2
exists $self->{'_start_codons'} || $self->warn('No marked start codons in this GC table') && (return)
exists $self->{'_start_codons'} $self->warn("No marked start codons in this GC table")
Truth table0%0/3
A || B
A= exists $self->{'_start_codons'}B= $self->warn("No marked start codons in this GC table")
ABresult
1X1
011
000
394 0 my @codons = keys %{$self->{'_start_codons'}};
395 0 ▶ wantarray? @codons : \@codons;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
396 }
397  
398 =head2 all_stop_codons
399  
400 Title : all_stop_codons
401 Usage : @stopCodons = $self->all_stop_codons;
402 Function: get all the stop codons in the genetic code table in use
403 Returns : an array of codons, or its reference if in scalar context
404 Args : None
405  
406 =cut
407  
408 sub all_stop_codons
409 {
410 0 ▶ my @codons = keys %{$_[0]->{'_stop_codons'}};
Subroutine all_stop_codons: not called CC=2 SCAR=17.9
Pod documented
411 0 ▶ wantarray? @codons : \@codons;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
412 }
413  
414 =head2 codons_of_AA
415  
416 Title : codons_of_AA
417 Usage : @codons = $self->codons_of_AA('S');
418 Function: get codons encoding the given amino acid
419 Returns : an array of codons, or its reference if in scalar context
420 Args : a single amino acid; for stop codons, one can give '*' here
421  
422 =cut
423  
424 sub codons_of_AA
425 {
426 160 ▶ my ($self, $AA) = @_;
Subroutine codons_of_AA: called CC=3 SCAR=11.1
Pod documented
427  
428 160 $AA =~ s/\s+//g; $AA = uc($AA);
429 160 ▶ $self->throw("Can only process one amino acid each time")
Branch: 1 branch
BranchTrueFalseTotal
if length $AA > 1 0 160 160
430 if(length($AA) > 1);
431  
432 160 my $codonToAA = $self->{'_codon_to_aa'};
433 160 my @codons = grep { $codonToAA->{$_} eq $AA } keys %$codonToAA;
434  
435 160 ▶ return wantarray? @codons : \@codons;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 160 0 160
436 }
437  
438 =head2 codon_to_AA_map
439  
440 Title : codon_to_AA_map
441 Usage : $hash = $self->codon_to_AA_map
442 Function: get the mapping from codon to amino acid in a hash
443 Returns : a hash reference in which codons are keys and AAs are
444 values
445 Args : None
446  
447 =cut
448  
449 sub codon_to_AA_map
450 {
451 1 ▶ $_[0]->{'_codon_to_aa'};
Subroutine codon_to_AA_map: called CC=1 SCAR=0.0
Pod documented
452 }
453  
454 =head2 translate
455  
456 Title : translate
457 Usage : $AA_string = $self->translate('ATGGCA');
458 Function: get the translation of input nucleotides
459 Returns : a string of amino acids, unknown amino acids are
460 represented as 'X'.
461 Args : nucleotide sequence.
462 Note : if the input sequence is not multiple of 3 long, the last
463 remained 1 or 2 nucleotides would be simply ignored.
464  
465 =cut
466  
467 sub translate
468 {
469 0 ▶ my ($self, $seq) = @_;
Subroutine translate: not called CC=4 SCAR=30.0
Pod documented
470  
471 0 $seq =~ s/\s+//g;
472 0 $seq = uc($seq);
473  
474 0 my $seqLen = length($seq);
475 0 my $accuLen = 0;
476 0 my $AAs = '';
477 0 my $codonToAA = $self->{'_codon_to_aa'};
478 0 ▶ while($accuLen + 3 <= $seqLen)
Branch: 1 branch
BranchTrueFalseTotal
if ($accuLen + 3 <= $seqLen) 0 0 0
479 {
480 0 my $codon = substr($seq, $accuLen, 3);
481 0 ▶ $self->warn("'$codon' is not a valid codon")
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_valid_codon($codon) 0 0 0
482 unless($self->is_valid_codon($codon));
483 0 ▶ $AAs .= exists $codonToAA->{$codon}? $codonToAA->{$codon} :
Branch: 1 branch
BranchTrueFalseTotal
exists $codonToAA->{$codon} ? : 0 0 0
484 'X'; # X for unknown codons
485 0 $accuLen += 3;
486 }
487  
488 0 return $AAs;
489 }
490  
491 =head2 is_stop_codon
492  
493 Title : is_stop_codon
494 Usage : $test = $self->is_stop_codon('UAG');
495 Function: check whether this is a stop codon
496 Returns : 1 if true, otherwise 0
497 Args : a codon sequence
498  
499 =cut
500 # check whether
501 sub is_stop_codon
502 {
503 128 ▶ my ($self, $codon) = @_;
Subroutine is_stop_codon: called CC=2 SCAR=6.9
Pod documented
504 128 my $stopCodons = $self->{'_stop_codons'};
505 128 $codon = _process_codon($codon);
506 128 ▶ return 1 if($stopCodons->{$codon});
Branch: 1 branch
BranchTrueFalseTotal
if $stopCodons->{$codon} 6 122 128
507 122 return 0;
508 }
509  
510 # process codons before other actions
511 sub _process_codon
512 {
513 128 ▶ my $codon = shift;
Subroutine _process_codon: called CC=1 SCAR=0.0
514 128 $codon =~ s/\s+//g;
515 128 $codon =~ tr/uU/TT/; # U to T
516 128 return uc($codon);
517 }
518  
519 =head2 codon_degeneracy
520  
521 Title : codon_degeneracy
522 Usage : $hash = $self->codon_degeneracy;
523 Function: group AAs and codons into codon degeneracy groups
524 Returns : reference to a hash in which 1st level key is degeneracy
525 (i.e., 1,2,6,etc), 2nd level key is amino acids for that degeneracy
526 group, and 3rd level is reference of arrays containing coding codons
527 for each amino acid. For example:
528  
529 { 2 => { D => [GAU, GAC],
530 C => [UGU, UGC],
531 ... ...
532 },
533 4 => { A => [GCU, GCC, GCA, GCG],
534 ... ...
535 },
536 ... ... ...
537 }
538  
539 Args : None
540  
541 =cut
542  
543 # group AAs and codons into redundancy groups
544 sub codon_degeneracy
545 {
546 53 ▶ my $self = shift;
Subroutine codon_degeneracy: called CC=5 SCAR=16.1
Pod documented
547  
548 53 ▶ return $self->{'_codon_deg'} if(exists $self->{'_codon_deg'});
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"_codon_deg"} 51 2 53
549  
550 # otherwise construct it if its the first time
551 2 my $codonToAA = $self->{'_codon_to_aa'};
552 2 my %aaToCodon;
553 2 ▶ while(my ($codon, $AA) = each %$codonToAA)
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$codonToAA) 128 2 130
554 {
555 # ignore stop codons
556 128 ▶ next if($self->is_stop_codon($codon));
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_stop_codon($codon) 6 122 128
557 122 push @{$aaToCodon{$AA}}, $codon;
558 }
559  
560 2 my %redundancy;
561 2 ▶ while(my ($AA, $codons) = each %aaToCodon)
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %aaToCodon) 40 2 42
562 {
563 40 my $red = $#$codons + 1;
564 40 $redundancy{$red}->{$AA} = [sort @$codons];
565 }
566  
567 2 $self->{'_codon_deg'} = \%redundancy; # store it first
568 2 return \%redundancy;
569 }
570  
571  
572 =head1 AUTHOR
573  
574 Zhenguo Zhang, C<< <zhangz.sci at gmail.com> >>
575  
576 =head1 BUGS
577  
578 Please report any bugs or feature requests to C<bug-bio-cua at rt.cpan.org>, or through
579 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Bio-CUA>. I will be notified, and then you'll
580 automatically be notified of progress on your bug as I make changes.
581  
582  
583 =head1 SUPPORT
584  
585 You can find documentation for this module with the perldoc command.
586  
587 perldoc Bio::CUA::CodonTable
588  
589  
590 You can also look for information at:
591  
592 =over 4
593  
594 =item * RT: CPAN's request tracker (report bugs here)
595  
596 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Bio-CUA>
597  
598 =item * AnnoCPAN: Annotated CPAN documentation
599  
600 L<http://annocpan.org/dist/Bio-CUA>
601  
602 =item * CPAN Ratings
603  
604 L<http://cpanratings.perl.org/d/Bio-CUA>
605  
606 =item * Search CPAN
607  
608 L<http://search.cpan.org/dist/Bio-CUA/>
609  
610 =back
611  
612  
613 =head1 ACKNOWLEDGEMENTS
614  
615  
616 =head1 LICENSE AND COPYRIGHT
617  
618 Copyright 2015 Zhenguo Zhang.
619  
620 This program is free software: you can redistribute it and/or modify
621 it under the terms of the GNU General Public License as published by
622 the Free Software Foundation, either version 3 of the License, or
623 (at your option) any later version.
624  
625 This program is distributed in the hope that it will be useful,
626 but WITHOUT ANY WARRANTY; without even the implied warranty of
627 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
628 GNU General Public License for more details.
629  
630 You should have received a copy of the GNU General Public License
631 along with this program. If not, see L<http://www.gnu.org/licenses/>.
632  
633  
634 =cut
635  
636 5 1; # End of Bio::CUA::CodonTable
637  
638 __END__
« lib/Bio/CUA/Summarizer.pm ↑ Summary script/build_cai_param.pl »