lib/Bio/CUA/CodonTable.pm

filter: Statementstmt 67.2% 125 / 186 Branchbran 52.1% 49 / 94 Conditioncond 27.2% 6 / 22 MC/DCmcdc 20.0% 2 / 10 Subroutinesub 62.5% 15 / 24 Podpod 100% 15 / 15 totaltotal 60.4% 212 / 351 CC 55 SCAR 26.8
CC
55
Cov
60%
_build_table_by_file
42.0
all_codons
30.0
_build_table_by_id
20.8
CRAP 14.6
« lib/Bio/CUA/Summarizer.pm ↑ Summary lib/Bio/CUA/SeqIO.pm »
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 4 ▶{
Subroutine new: called CC=4 SCAR=17.3
Pod documented
105 4 my ($caller, @args) = @_;
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 0 ▶{
Subroutine _build_table_by_file: not called CC=6 SCAR=37.4
130 0 my ($self, $file) = @_;
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 4 ▶{
Subroutine _build_table_by_id: called CC=20 SCAR=30.4
161 4 my ($self, $id) = @_;
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)) 3756 0 3756
176 {
177 3756 ▶ $inDataSection = 1 if(/^__END__/);
Branch: 1 branch
BranchTrueFalseTotal
if /^__END__/ 4 3752 3756
178 3756 ▶ next unless($inDataSection);
Branch: 1 branch
BranchTrueFalseTotal
unless $inDataSection 2688 1068 3756
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 0 ▶{
Subroutine name: not called CC=1 SCAR=6.9
Pod documented
258 0 $_[0]->get_tag('name');
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 0 ▶{
Subroutine id: not called CC=1 SCAR=6.9
Pod documented
273 0 $_[0]->get_tag('id');
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 number of 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 0 ▶{
Subroutine total_num_of_codons: not called CC=1 SCAR=6.9
Pod documented
288 0 $_[0]->{'_num_codons'};
289 }
290  
291 sub _is_valid_gc_id
292 4 ▶{
Subroutine _is_valid_gc_id: called CC=2 SCAR=8.1
293 4 my ($self, $id) = @_;
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 768 ▶{
Subroutine _is_stop_aa: called CC=2 SCAR=6.9
302 768 my ($self, $AA) = @_;
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 0 ▶{
Subroutine is_valid_codon: not called CC=3 SCAR=24.8
Pod documented
321 0 my ($self,$codon,$allowAmb) = @_;
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_codons
332  
333 Title : all_codons
334 Usage : @codons = $self->all_codons;
335 Function: get all the codons in this genetic code table. Codons are
336 ordered by the coded amino acids. Stop codons are also included.
337 Returns : an array of codons, or its reference in scalar context
338 Args : None
339  
340 =cut
341  
342 sub all_codons
343 0 ▶{
Subroutine all_codons: not called CC=5 SCAR=34.0
Pod documented
344 0 my ($self) = @_;
345  
346 0 ▶ my $codonToAA = $self->{'_codon_to_aa'} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $codonToAA = $self->{"_codon_to_aa"} or return 0 0 0
347  
348 0 my %AAs;
349 0 ▶ while(my ($k,$v) = each %$codonToAA)
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$codonToAA) 0 0 0
350 {
351 0 push @{$AAs{$v}}, $k;
352 }
353  
354 # now order the codons
355 0 my @sortedAAs = sort keys(%AAs);
356 0 my @codons;
357 0 foreach my $AA (@sortedAAs)
358 {
359 0 push @codons, @{$AAs{$AA}};
360 }
361  
362 0 ▶ return wantarray? @codons : \@codons;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
363 }
364  
365 =head2 all_sense_codons
366  
367 Title : all_sense_codons
368 Usage : @codons = $self->all_sense_codons;
369 Function: get all the sense codons in this genetic code table
370 Returns : an array of codons, or its reference in scalar context
371 Args : None
372  
373 =cut
374  
375 sub all_sense_codons
376 28 ▶{
Subroutine all_sense_codons: called CC=2 SCAR=6.9
Pod documented
377 28 my ($self) = @_;
378  
379 28 my $codonToAA = $self->{'_codon_to_aa'};
380 28 my $stopCodons = $self->{'_stop_codons'};
381 28 my @senseCodons = grep {!exists($stopCodons->{$_})} keys %$codonToAA;
382  
383 28 ▶ return wantarray? @senseCodons : \@senseCodons;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 27 1 28
384 }
385  
386 =head2 all_amino_acids
387  
388 Title : all_amino_acids
389 Usage : @AAs = $self->all_amino_acids
390 Function: get all the amino acids in this genetic code table. Stop
391 codons are excluded.
392 Returns : an array of amino acids, or its reference if in scalar
393 context
394 Args : None
395  
396 =cut
397  
398 sub all_amino_acids
399 8 ▶{
Subroutine all_amino_acids: called CC=5 SCAR=16.2
Pod documented
400 8 my $self = shift;
401 8 ▶ my $codonToAA = $self->{'_codon_to_aa'} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $codonToAA = $self->{"_codon_to_aa"} or return 8 0 8
402  
403 8 my %AAs;
404 8 ▶ while(my ($k,$v) = each %$codonToAA)
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$codonToAA) 512 8 520
405 {
406 512 ▶ next if $self->_is_stop_aa($v);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_stop_aa($v) 24 488 512
407 488 $AAs{$v}++;
408 }
409  
410 8 my @tmp = keys %AAs;
411 8 ▶ return wantarray? @tmp : \@tmp;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 8 0 8
412 }
413  
414 =head2 all_start_codons
415  
416 Title : all_start_codons
417 Usage : @startCodons = $self->all_start_codons;
418 Function: get all the start codons in the genetic code table in use
419 Returns : an array of codons, or its reference if in scalar context
420 Args : None
421  
422 =cut
423  
424 sub all_start_codons
425 0 ▶{
Subroutine all_start_codons: not called CC=4 SCAR=30.0
Pod documented
426 0 my $self = shift;
427 $self->warn("No marked start codons in this GC table") and return
428 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
429 0 my @codons = keys %{$self->{'_start_codons'}};
430 0 ▶ wantarray? @codons : \@codons;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
431 }
432  
433 =head2 all_stop_codons
434  
435 Title : all_stop_codons
436 Usage : @stopCodons = $self->all_stop_codons;
437 Function: get all the stop codons in the genetic code table in use
438 Returns : an array of codons, or its reference if in scalar context
439 Args : None
440  
441 =cut
442  
443 sub all_stop_codons
444 0 ▶{
Subroutine all_stop_codons: not called CC=2 SCAR=17.9
Pod documented
445 0 my @codons = keys %{$_[0]->{'_stop_codons'}};
446 0 ▶ wantarray? @codons : \@codons;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
447 }
448  
449 =head2 codons_of_AA
450  
451 Title : codons_of_AA
452 Usage : @codons = $self->codons_of_AA('S');
453 Function: get codons encoding the given amino acid
454 Returns : an array of codons, or its reference if in scalar context
455 Args : a single amino acid; for stop codons, one can give '*' here
456  
457 =cut
458  
459 sub codons_of_AA
460 160 ▶{
Subroutine codons_of_AA: called CC=3 SCAR=11.1
Pod documented
461 160 my ($self, $AA) = @_;
462  
463 160 $AA =~ s/\s+//g; $AA = uc($AA);
464 160 ▶ $self->throw("Can only process one amino acid each time")
Branch: 1 branch
BranchTrueFalseTotal
if length $AA > 1 0 160 160
465 if(length($AA) > 1);
466  
467 160 my $codonToAA = $self->{'_codon_to_aa'};
468 160 my @codons = grep { $codonToAA->{$_} eq $AA } keys %$codonToAA;
469  
470 160 ▶ return wantarray? @codons : \@codons;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 160 0 160
471 }
472  
473 =head2 codon_to_AA_map
474  
475 Title : codon_to_AA_map
476 Usage : $hash = $self->codon_to_AA_map
477 Function: get the mapping from codon to amino acid in a hash
478 Returns : a hash reference in which codons are keys and AAs are
479 values
480 Args : None
481  
482 =cut
483  
484 sub codon_to_AA_map
485 1 ▶{
Subroutine codon_to_AA_map: called CC=1 SCAR=0.0
Pod documented
486 1 $_[0]->{'_codon_to_aa'};
487 }
488  
489 =head2 translate
490  
491 Title : translate
492 Usage : $AA_string = $self->translate('ATGGCA');
493 Function: get the translation of input nucleotides
494 Returns : a string of amino acids, unknown amino acids are
495 represented as 'X'.
496 Args : nucleotide sequence.
497 Note : if the input sequence is not multiple of 3 long, the last
498 remained 1 or 2 nucleotides would be simply ignored.
499  
500 =cut
501  
502 sub translate
503 0 ▶{
Subroutine translate: not called CC=4 SCAR=30.0
Pod documented
504 0 my ($self, $seq) = @_;
505  
506 0 $seq =~ s/\s+//g;
507 0 $seq = uc($seq);
508  
509 0 my $seqLen = length($seq);
510 0 my $accuLen = 0;
511 0 my $AAs = '';
512 0 my $codonToAA = $self->{'_codon_to_aa'};
513 0 ▶ while($accuLen + 3 <= $seqLen)
Branch: 1 branch
BranchTrueFalseTotal
if ($accuLen + 3 <= $seqLen) 0 0 0
514 {
515 0 my $codon = substr($seq, $accuLen, 3);
516 0 ▶ $self->warn("'$codon' is not a valid codon")
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_valid_codon($codon) 0 0 0
517 unless($self->is_valid_codon($codon));
518 0 ▶ $AAs .= exists $codonToAA->{$codon}? $codonToAA->{$codon} :
Branch: 1 branch
BranchTrueFalseTotal
exists $codonToAA->{$codon} ? : 0 0 0
519 'X'; # X for unknown codons
520 0 $accuLen += 3;
521 }
522  
523 0 return $AAs;
524 }
525  
526 =head2 is_stop_codon
527  
528 Title : is_stop_codon
529 Usage : $test = $self->is_stop_codon('UAG');
530 Function: check whether this is a stop codon
531 Returns : 1 if true, otherwise 0
532 Args : a codon sequence
533  
534 =cut
535 # check whether
536 sub is_stop_codon
537 128 ▶{
Subroutine is_stop_codon: called CC=2 SCAR=6.9
Pod documented
538 128 my ($self, $codon) = @_;
539 128 my $stopCodons = $self->{'_stop_codons'};
540 128 $codon = _process_codon($codon);
541 128 ▶ return 1 if($stopCodons->{$codon});
Branch: 1 branch
BranchTrueFalseTotal
if $stopCodons->{$codon} 6 122 128
542 122 return 0;
543 }
544  
545 # process codons before other actions
546 sub _process_codon
547 128 ▶{
Subroutine _process_codon: called CC=1 SCAR=0.0
548 128 my $codon = shift;
549 128 $codon =~ s/\s+//g;
550 128 $codon =~ tr/uU/TT/; # U to T
551 128 return uc($codon);
552 }
553  
554 =head2 codon_degeneracy
555  
556 Title : codon_degeneracy
557 Usage : $hash = $self->codon_degeneracy;
558 Function: group AAs and codons into codon degeneracy groups
559 Returns : reference to a hash in which 1st level key is degeneracy
560 (i.e., 1,2,6,etc), 2nd level key is amino acids for that degeneracy
561 group, and 3rd level is reference of arrays containing coding codons
562 for each amino acid. For example:
563  
564 { 2 => { D => [GAU, GAC],
565 C => [UGU, UGC],
566 ... ...
567 },
568 4 => { A => [GCU, GCC, GCA, GCG],
569 ... ...
570 },
571 ... ... ...
572 }
573  
574 Args : None
575  
576 =cut
577  
578 # group AAs and codons into redundancy groups
579 sub codon_degeneracy
580 53 ▶{
Subroutine codon_degeneracy: called CC=5 SCAR=16.1
Pod documented
581 53 my $self = shift;
582  
583 53 ▶ return $self->{'_codon_deg'} if(exists $self->{'_codon_deg'});
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"_codon_deg"} 51 2 53
584  
585 # otherwise construct it if its the first time
586 2 my $codonToAA = $self->{'_codon_to_aa'};
587 2 my %aaToCodon;
588 2 ▶ while(my ($codon, $AA) = each %$codonToAA)
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$codonToAA) 128 2 130
589 {
590 # ignore stop codons
591 128 ▶ next if($self->is_stop_codon($codon));
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_stop_codon($codon) 6 122 128
592 122 push @{$aaToCodon{$AA}}, $codon;
593 }
594  
595 2 my %redundancy;
596 2 ▶ while(my ($AA, $codons) = each %aaToCodon)
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %aaToCodon) 40 2 42
597 {
598 40 my $red = $#$codons + 1;
599 40 $redundancy{$red}->{$AA} = [sort @$codons];
600 }
601  
602 2 $self->{'_codon_deg'} = \%redundancy; # store it first
603 2 return \%redundancy;
604 }
605  
606  
607 =head1 AUTHOR
608  
609 Zhenguo Zhang, C<< <zhangz.sci at gmail.com> >>
610  
611 =head1 BUGS
612  
613 Please report any bugs or feature requests to C<bug-bio-cua at rt.cpan.org>, or through
614 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Bio-CUA>. I will be notified, and then you'll
615 automatically be notified of progress on your bug as I make changes.
616  
617  
618 =head1 SUPPORT
619  
620 You can find documentation for this module with the perldoc command.
621  
622 perldoc Bio::CUA::CodonTable
623  
624  
625 You can also look for information at:
626  
627 =over 4
628  
629 =item * RT: CPAN's request tracker (report bugs here)
630  
631 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Bio-CUA>
632  
633 =item * AnnoCPAN: Annotated CPAN documentation
634  
635 L<http://annocpan.org/dist/Bio-CUA>
636  
637 =item * CPAN Ratings
638  
639 L<http://cpanratings.perl.org/d/Bio-CUA>
640  
641 =item * Search CPAN
642  
643 L<http://search.cpan.org/dist/Bio-CUA/>
644  
645 =back
646  
647  
648 =head1 ACKNOWLEDGEMENTS
649  
650  
651 =head1 LICENSE AND COPYRIGHT
652  
653 Copyright 2015 Zhenguo Zhang.
654  
655 This program is free software: you can redistribute it and/or modify
656 it under the terms of the GNU General Public License as published by
657 the Free Software Foundation, either version 3 of the License, or
658 (at your option) any later version.
659  
660 This program is distributed in the hope that it will be useful,
661 but WITHOUT ANY WARRANTY; without even the implied warranty of
662 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
663 GNU General Public License for more details.
664  
665 You should have received a copy of the GNU General Public License
666 along with this program. If not, see L<http://www.gnu.org/licenses/>.
667  
668  
669 =cut
670  
671 5 1; # End of Bio::CUA::CodonTable
672  
673 __END__
« lib/Bio/CUA/Summarizer.pm ↑ Summary lib/Bio/CUA/SeqIO.pm »