lib/Bio/CUA/CUB/Builder.pm

filter: Statementstmt 93.5% 159 / 170 Branchbran 65.1% 56 / 86 Conditioncond 43.3% 13 / 30 MC/DCmcdc 17.6% 3 / 17 Subroutinesub 92.8% 13 / 14 Podpod 83.3% 5 / 6 totaltotal 77.0% 249 / 323 CC 69 SCAR 29.5
CC
69
Cov
80%
build_rscu
30.9
build_tai
30.2
build_cai
15.2
CRAP 19.1
« lib/Bio/CUA/CUB/Calculator.pm ↑ Summary script/cai_codon.pl »
1 package Bio::CUA::CUB::Builder;
2  
3 =pod
4  
5 =head1 NAME
6  
7 Bio::CUA::CUB::Builder -- A module to calculate codon usage bias (CUB)
8 metrics at codon level and other parameters
9  
10 =head1 SYNOPSIS
11  
12 use Bio::CUA::CUB::Builder;
13  
14 # initialize the builder
15 my $builder = Bio::CUA::CUB::Builder->new(
16 codon_table => 1 ); # using stardard genetic code
17
18 # calculate RSCU for each codon, and result is stored in "rscu.out" as
19 # well as returned as a hash reference
20 my $rscuHash = $builder->build_rscu("seqs.fa",undef, 0.5,"rscu.out");
21  
22 # calculate CAI for each codon, normalizing RSCU values of codons
23 # for each amino acid by the expected RSCUs under even usage,
24 # rather than the maximal RSCU used by the traditional CAI method.
25 my $caiHash = $builder->build_cai($codonList,2,'mean',"cai.out");
26  
27 # calculate tAI for each codon
28 my $taiHash = $builder->build_tai("tRNA_copy_number.txt","tai.out", undef, 1);
29  
30 =head1 DESCRIPTION
31  
32 Codon usage bias (CUB) can be represented at two levels, codon and
33 sequence. The latter is often computed as the geometric means of the
34 sequence's codons. This module caculates CUB metrics at codon level.
35  
36 Supported CUB metrics include CAI (codon adaptation index), tAI (tRNA
37 adaptation index), RSCU (relative synonymous codon usage), and their
38 variants. See the methods below for details.
39  
40 The output can be stored in a file which is then used by methods in
41 L<Bio::CUA::CUB::Calculator> to calculate CUB indice for each
42 protein-coding sequence.
43  
44 =cut
45  
46 2 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
47 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
48 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
49 2 ▶use parent qw/Bio::CUA::CUB/;
Subroutine BEGIN: called CC=1 SCAR=0.0
50  
51 # paired codon bases for each anticodon base at wobble position.
52 # According to Crick, FH, 1966, JMB
53 2 my %wobbleBasePairsAnti = (
54 #Anti => Codon at 3rd position
55 A => [qw/T/],
56 C => [qw/G/],
57 T => [qw/A G/],
58 G => [qw/C T/],
59 I => [qw/A C T/]
60 );
61  
62 # get the version using codon's position as key
63 sub _build_pairing_anti_base
64 1 ▶{
Subroutine _build_pairing_anti_base: called CC=5 SCAR=16.4
65 1 my $self = shift;
66 my %wobbleAntiKey = $self->get_tag('anti_wobble_pair')?
67 0 ▶ %{$self->get_tag('anti_wobble_pair')} : %wobbleBasePairsAnti;
Branch: 1 branch
BranchTrueFalseTotal
$self->get_tag('anti_wobble_pair') ? : 0 1 1
68  
69 1 ▶ if($self->_a_to_i)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_a_to_i) 1 0 1
70 {
71 1 $wobbleAntiKey{'A'} = $wobbleAntiKey{'I'};
72 }
73 1 my %wobbleBasePairs;
74 1 ▶ while(my ($antiPos, $codonMatches) = each %wobbleAntiKey)
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %wobbleAntiKey) 5 1 6
75 {
76 5 foreach (@$codonMatches)
77 {
78 11 push @{$wobbleBasePairs{$_}}, $antiPos;
79 }
80 }
81 1 $self->{'_wobble_pair'} = \%wobbleBasePairs;
82 }
83  
84 #default codon selective constraints from dos Reis, et al., 2004 NAR.
85 # key is anticodon-codon at wobbling site
86 2 my %defaultSC = (
87 'I-T' => 0, # 1
88 'A-T' => 0,
89 'G-C' => 0,
90 'T-A' => 0,
91 'C-G' => 0, # 5
92 'G-T' => 0.41,
93 'I-C' => 0.28,
94 'I-A' => 0.9999,
95 'A-C' => 0.28, # for cases when A is
96 'A-A' => 0.9999, # regarded as I
97 'T-G' => 0.68,
98 'L-A' => 0.89 # 10, L=lysidine present in prokaryotes
99 );
100  
101 =head1 METHODS
102  
103 =head2 new
104  
105 Title : new
106 Usage : $analyzer = Bio::CUA::CUB::Builder->new(-codon_table => 1)
107 Function: initiate the analyzer
108 Returns : an object
109 Args : accepted options are as follows
110  
111 B<options needed for building parameters of all CUB indice>
112  
113 =over
114  
115 =item C<-codon_table>
116  
117 the genetic code table applied for following sequence analyses. It can
118 be specified by an integer (genetic code table id), an object of
119 L<Bio::CUA::CodonTable>, or a map-file. See the method
120 L<Bio::CUA::Summarizer/new> for details.
121  
122 =back
123  
124 B<options needed for building tAI index's parameters>
125  
126 =over
127  
128 =item C<-a_to_i>
129  
130 a switch option. If true (any nonzero values), all
131 'A' nucleotides at the 1st position of anticodon will be regarded as I
132 (inosine) which can pair with more nucleotides at codons's wobbling
133 position (A,T,C at the 3rd position). The default is true.
134  
135 =item C<-no_atg>
136  
137 a switch option to indicate whether ATG codons should be
138 excluded in tAI calculation. Default is true, following I<dos Reis,
139 et al., 2004, NAR>. To include ATG in tAI calculation, provide '0' here.
140  
141 =item C<-wobble>
142  
143 reference to a hash containing anticodon-codon basepairs at
144 wobbling position, such as ('U' is equivalent to 'T')
145 %wobblePairs = (
146 A => [qw/T/],
147 C => [qw/G/],
148 T => [qw/A G/],
149 G => [qw/C T/],
150 I => [qw/A C T/]
151 ); # this is the default setting
152 Hash keys are the bases in anticodons and hash values are paired
153 bases in codons's 3rd positions. This option is optional and default
154 value is shown above by the example.
155  
156 =back
157  
158 =cut
159  
160 sub new
161 1 ▶{
Subroutine new: called CC=5 SCAR=17.6
Pod documented
162 1 my ($caller, @args) = @_;
163 1 ▶ my $class = ref($caller)? ref($caller) : $caller;
Branch: 1 branch
BranchTrueFalseTotal
ref $caller ? : 0 1 1
164 1 my $self = $class->SUPER::new(@args);
165  
166 1 my $hashRef = $self->_array_to_hash(\@args);
167 1 ▶ if(exists $hashRef->{'a_to_i'})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $hashRef->{'a_to_i'}) { } 0 1 1
168 {
169 0 $self->set_tag('a2i',$hashRef->{'a_to_i'});
170 }else
171 {
172 1 $self->set_tag('a2i', 1); # true, default
173 }
174 1 ▶ if(exists $hashRef->{'no_atg'})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $hashRef->{'no_atg'}) { } 0 1 1
175 {
176 0 $self->set_tag('no_atg', $hashRef->{'no_atg'});
177 }else
178 {
179 1 $self->set_tag('no_atg',1); # default is true
180 }
181 1 ▶ if(exists $hashRef->{'wobble'})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $hashRef->{"wobble"}) 0 1 1
182 {
183 0 $self->set_tag('anti_wobble_pair', $hashRef->{'wobble'});
184 }
185  
186 1 $self->_build_pairing_anti_base; # make wobble pairing hash
187 1 return $self;
188 }
189  
190 # indicator whether A should be regarded as I
191 sub _a_to_i
192 1 ▶{
Subroutine _a_to_i: called CC=1 SCAR=0.0
193 1 my $self = shift;
194 1 $self->get_tag('a2i');
195 }
196  
197 =head2 no_atg
198  
199 Title : no_atg
200 Usage : $status = $self->no_atg([$newVal])
201 Function: get/set the status whether ATG should be excluded in tAI
202 calculation.
203 Returns : current status after updating
204 Args : optional. 1 for true, 0 for false
205  
206 =cut
207 # implement in parent class Bio::CUA
208  
209 #=head2 detect_optimal_codons
210 #
211 # Title : detect_optimal_codons
212 # Usage : $ok = $self->detect_optimal_codons();
213 # Function:
214 # Returns :
215 # Args :
216 #
217 #=cut
218  
219 sub detect_optimal_codons
220 0 ▶{
Subroutine detect_optimal_codons: not called CC=1 SCAR=6.9
Pod undocumented
221 0 die "detect_optimal_codons has not implemented, yet.$!";
222 }
223  
224 =head2 build_rscu
225  
226 Title : build_rscu
227 Usage : $ok = $self->build_rscu($input,[$minTotal,$pseudoCnt,$output]);
228 Function: calculate RSCU values for all sense codons
229 Returns : reference of a hash using the format 'codon => RSCU value'.
230 return undef if failed.
231 Args : accepted arguments are as follows (note: not as hash):
232  
233 =over
234  
235 =item C<input>
236  
237 name of a file containing fasta CDS sequences of interested
238 genes, or a sequence object with method I<seq> to extract sequence
239 string, or a plain sequence string, or reference to a hash containing
240 codon counts with structure like I<{ AGC => 50, GTC => 124}>.
241  
242 =item C<output>
243  
244 optional, name of the file to store the result. If omitted,
245 no result will be written.
246  
247 =item C<minTotal>
248  
249 optional, minimal count of an amino acid in sequences; if observed
250 count is smaller than this minimum, all codons of this amino acid would
251 be assigned equal RSCU values. This is to reduce sampling errors in
252 rarely observed amino acids. Default value is 5.
253  
254 =item C<pseudoCnt>
255  
256 optional. Pseudo-counts for unobserved codons. Default is 0.5.
257  
258 =back
259  
260 =cut
261  
262 sub build_rscu
263 5 ▶{
Subroutine build_rscu: called CC=16 SCAR=34.3
Pod documented
264 5 my ($self, $input, $minTotal, $pseudoCnt, $output) = @_;
265  
266 5 ▶ $pseudoCnt = 0.5 unless($pseudoCnt and $pseudoCnt > 0);
Branch: 1 branch
BranchTrueFalseTotal
unless $pseudoCnt and $pseudoCnt > 0 0 5 5
Condition33%1/3
$pseudoCnt and $pseudoCnt > 0
!ll&&!rl&&r
005
MC/DC0%0/2
$pseudoCnt and $pseudoCnt > 0
$pseudoCnt $pseudoCnt > 0
Truth table33%1/3
A and B
A= $pseudoCntB= $pseudoCnt > 0
ABresult
0X0
100
111
267 5 ▶ $minTotal = 5 unless($minTotal and $minTotal > 0);
Branch: 1 branch
BranchTrueFalseTotal
unless $minTotal and $minTotal > 0 0 5 5
Condition33%1/3
$minTotal and $minTotal > 0
!ll&&!rl&&r
005
MC/DC0%0/2
$minTotal and $minTotal > 0
$minTotal $minTotal > 0
Truth table33%1/3
A and B
A= $minTotalB= $minTotal > 0
ABresult
0X0
100
111
268 5 ▶ my $codonList = $self->get_codon_list($input) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $codonList = $self->get_codon_list($input) or return 5 0 5
269  
270 5 my @allAAs = $self->all_AAs_in_table; # get all the amino acids in the codon table
271 5 my %rscu;
272 5 foreach my $AA (@allAAs)
273 {
274 # get the codons encoding this AA
275 100 my @codons = $self->codons_of_AA($AA);
276 100 my $cntSum = 0; # total observations of this AA's codons
277 100 my $zeroCnt = 0; # number of codons with zero values
278 100 foreach (@codons)
279 {
280 305 ▶ ++$zeroCnt and next unless($codonList->{$_});
Branch: 1 branch
BranchTrueFalseTotal
unless $codonList->{$_} 0 305 305
Condition20%1/5
$codonList->{$_} || ++$zeroCnt && (next)
l!l&&r!l&&!r
30500
++$zeroCnt and next
!ll
00
MC/DC0%0/2
$codonList->{$_} || ++$zeroCnt && (next)
$codonList->{$_} ++$zeroCnt
Truth table33%1/3
A || B
A= $codonList->{$_}B= ++$zeroCnt
ABresult
1X1
011
000
281 305 $cntSum += $codonList->{$_};
282 }
283 # get the rscu values
284 100 ▶ if($cntSum < $minTotal) # too small sample
Branch: 1 branch
BranchTrueFalseTotal
if ($cntSum < $minTotal) { } 0 100 100
285 {
286 # assign equal usage to all codons of this amino acid
287 0 foreach (@codons)
288 {
289 0 $rscu{$_} = 1/($#codons+1);
290 }
291 }else
292 {
293 # add the pseudoCnt correction
294 100 $cntSum += $zeroCnt*$pseudoCnt;
295 100 foreach (@codons)
296 {
297 305 ▶ $rscu{$_} = ($codonList->{$_} || $pseudoCnt)/($cntSum || 1);
Condition40%2/5
$codonList->{$_} || $pseudoCnt
l!l&&r!l&&!r
30500
$cntSum || 1
l!l
3050
MC/DC0%0/2
$codonList->{$_} || $pseudoCnt
$codonList->{$_} $pseudoCnt
MC/DC0%0/1
$cntSum || 1
$cntSum
Truth table33%1/3
A || B
A= $codonList->{$_}B= $pseudoCnt
ABresult
1X1
011
000
Truth table50%1/2
A
A= $cntSum
Aresult
11
00
298 }
299 }
300 }
301  
302 5 ▶ $self->_write_out_hash($output, \%rscu) if($output);
Branch: 1 branch
BranchTrueFalseTotal
if $output 0 5 5
303 5 return \%rscu;
304 }
305  
306 =head2 build_cai
307  
308 Title : build_cai
309 Usage : $ok = $self->build_cai($input,[$minTotal,$norm_method,$output]);
310 Function: calculate CAI values for all sense codons
311 Returns : reference of a hash in which codons are keys and CAI values
312 are values. return undef if failed.
313 Args : accepted arguments are as follows:
314  
315 =over
316  
317 =item C<input>
318  
319 name of a file containing fasta CDS sequences of interested
320 genes, or a sequence object with method I<seq> to derive sequence
321 string, or a plain sequence string, or reference to a hash containing
322 codon list with structure like I<{ AGC => 50, GTC => 124}>.
323  
324 =item C<minTotal>
325  
326 optional, minimal codon count for an amino acid; if observed
327 count is smaller than this count, all codons of this amino acid would
328 be assigned equal CAI values. This is to reduce sampling errors in
329 rarely observed amino acids. Default value is 5.
330  
331 =item C<norm_method>
332  
333 optional, indicating how to normalize RSCU to get CAI
334 values. Valid values are 'max' and 'mean'; the former represents the
335 original method used by I<Sharp and Li, 1987, NAR>, i.e., dividing
336 all RSCUs by the maximum of an amino acid, while 'mean' indicates
337 dividing RSCU by expected average fraction assuming even usage of
338 all codons, i.e., 0.5 for amino acids encoded by 2 codons, 0.25 for
339 amino acids encoded by 4 codons, etc. The CAI metric determined by
340 the latter method is named I<mCAI>. mCAI can assign
341 different CAI values for the most preferred codons of different
342 amino acids, which otherwise would be the same by CAI (i.e., 1).
343  
344 =item C<output>
345  
346 optional. If provided, result will be stored in the file
347 specified by this argument.
348
349 =back
350  
351 Note: for codons which are not observed will be assigned a count of
352 0.5, and codons which are not degenerate (such as AUG and UGG in
353 standard genetic code table) are excluded. These are the default of
354 the paper I<Sharp and Li, 1986, NAR>. Here you can also reduce
355 sampling error by setting parameter $minTotal.
356  
357 =cut
358  
359 sub build_cai
360 2 ▶{
Subroutine build_cai: called CC=15 SCAR=27.2
Pod documented
361 2 my ($self, $input, $minTotal, $norm, $output) = @_;
362  
363 2 ▶ $minTotal = 5 unless(defined $minTotal);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $minTotal 0 2 2
364 # get RSCU values first
365 2 my $rscuHash = $self->build_rscu($input,$minTotal,0.5);
366  
367 2 my @AAs = $self->all_AAs_in_table;
368  
369 2 my %cai;
370 2 my $maxCAI = 0; # the maximum value of CAI in this dataset
371 2 foreach my $AA (@AAs)
372 {
373 40 my @codons = $self->codons_of_AA($AA);
374 # skip non-degenerate codons
375 40 ▶ next unless($#codons > 0);
Branch: 1 branch
BranchTrueFalseTotal
unless $#codons > 0 4 36 40
376  
377 # determine the factor to normalize the values
378 36 my $scaleFactor;
379 36 ▶ if($norm and $norm =~ /mean/i) # normalized by average
Branch: 1 branch
BranchTrueFalseTotal
if ($norm and $norm =~ /mean/i) { } 18 18 36
Condition66%2/3
$norm and $norm =~ /mean/i
!ll&&!rl&&r
01818
MC/DC50%1/2
$norm and $norm =~ /mean/i
$norm $norm =~ /mean/i
Truth table66%2/3
A and B
A= $normB= $norm =~ /mean/i
ABresult
0X0
100
111
380 {
381 18 $scaleFactor = $#codons + 1;
382 }else # old method, by maximum
383 {
384 # get the maximum RSCU value for this codon
385 18 my $maxRSCU = 0;
386 18 foreach (@codons)
387 {
388 59 my $rscu = $rscuHash->{$_};
389 59 ▶ $maxRSCU = $rscu if($maxRSCU < $rscu);
Branch: 1 branch
BranchTrueFalseTotal
if $maxRSCU < $rscu 27 32 59
390 }
391 18 ▶ $scaleFactor = $maxRSCU > 0? 1/$maxRSCU : 0;
Branch: 1 branch
BranchTrueFalseTotal
$maxRSCU > 0 ? : 18 0 18
392 }
393 # get CAI values now
394 36 foreach (@codons)
395 {
396 118 my $rscu = $rscuHash->{$_};
397 118 $cai{$_} = $rscu*$scaleFactor;
398 # global maximum of CAI
399 118 ▶ $maxCAI = $cai{$_} if($cai{$_} > $maxCAI);
Branch: 1 branch
BranchTrueFalseTotal
if $cai{$_} > $maxCAI 6 112 118
400 }
401 }
402  
403 #***********************
404 # further normalize all CAI by the global maximal CAI, like tAI,
405 # but one can opt out this, because without normalize by maxCAI
406 # one can distinguish genes more often use less-preferred codons.
407 # In this way, value 1 means no bias, > 1 means towards preferred
408 # codons while < 1 means towards non-preferred codons
409 2 ▶ map { $cai{$_} /= $maxCAI } keys(%cai)
Branch: 1 branch
BranchTrueFalseTotal
if $norm and $norm =~ /mean/i and $maxCAI 1 1 2
Condition66%4/6
$norm and $norm =~ /mean/i and $maxCAI
!ll&&!rl&&r
101
$norm and $norm =~ /mean/i
!ll&&!rl&&r
011
MC/DC33%1/3
$norm and $norm =~ /mean/i and $maxCAI
$norm $norm =~ /mean/i $maxCAI
Truth table50%2/4
A and B and C
A= $normB= $norm =~ /mean/iC= $maxCAI
ABCresult
0XX0
10X0
1100
1111
410 if($norm and $norm =~ /mean/i and $maxCAI);
411  
412 2 ▶ $self->_write_out_hash($output, \%cai) if($output);
Branch: 1 branch
BranchTrueFalseTotal
if $output 1 1 2
413 2 return \%cai;
414 }
415  
416 =head2 build_b_cai
417  
418 Title : build_b_cai
419 Usage : $caiHash =
420 $self->build_b_cai($input,$background,[$minTotal,$output]);
421 Function: calculate CAI values for all sense codons. Instead of
422 normalizing RSCUs by maximal RSCU or expected fractions, each RSCU value is
423 normalized by the corresponding background RSCU, then these
424 normalized RSCUs are used to calculate CAI values.
425 Returns : reference of a hash in which codons are keys and CAI values
426 are values. return undef if failed.
427 Args : accepted arguments are as follows:
428  
429 =over
430  
431 =item C<input>
432  
433 name of a file containing fasta CDS sequences of interested
434 genes, or a sequence object with metho I<seq> to derive sequence
435 string, or a plain sequence string, or reference to a hash containing
436 codon list with structure like I<{ AGC => 50, GTC => 124}>.
437  
438 =item C<background>
439  
440 background data from which background codon usage (RSCUs)
441 is computed. Acceptable formats are the same as the above argument
442 'input'.
443  
444 =item C<minTotal>
445  
446 optional, minimal codon count for an amino acid; if observed
447 count is smaller than this count, all codons of this amino acid would
448 be assigned equal RSCU values. This is to reduce sampling errors in
449 rarely observed amino acids. Default value is 5.
450  
451 =item C<outpu>
452  
453 optional. If provided, result will be stored in the file
454 specified by this argument.
455  
456 =back
457  
458 Note: for codons which are not observed will be assigned a count of
459 0.5, and codons which are not degenerate (such as AUG and UGG in
460 standard genetic code table) are excluded.
461  
462 =cut
463  
464 sub build_b_cai
465 1 ▶{
Subroutine build_b_cai: called CC=9 SCAR=22.0
Pod documented
466 1 my ($self, $input, $background, $minTotal, $output) = @_;
467  
468 1 ▶ $minTotal = 5 unless(defined $minTotal);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $minTotal 0 1 1
469 # get RSCU values first for input as well as background
470 1 my $rscuHash = $self->build_rscu($input,$minTotal,0.5);
471 1 my $backRscuHash = $self->build_rscu($background,$minTotal,0.5);
472  
473 # normalize all RSCU values by background RSCUs
474 1 my @senseCodons = $self->all_sense_codons();
475 1 foreach (@senseCodons)
476 {
477 61 $rscuHash->{$_} /= $backRscuHash->{$_};
478 }
479  
480 # now calculate CAIs for each amino acid
481 1 my @AAs = $self->all_AAs_in_table;
482  
483 1 my %cai;
484 1 my $maxCAI = 0; # the maximum value of CAI in this dataset
485 1 foreach my $AA (@AAs)
486 {
487 20 my @codons = $self->codons_of_AA($AA);
488 # skip non-degenerate codons
489 20 ▶ next unless($#codons > 0);
Branch: 1 branch
BranchTrueFalseTotal
unless $#codons > 0 2 18 20
490  
491 # get the maximum RSCU value for this amino acid
492 18 my $maxRSCU = 0;
493 18 foreach (@codons)
494 {
495 59 my $rscu = $rscuHash->{$_};
496 59 ▶ $maxRSCU = $rscu if($maxRSCU < $rscu);
Branch: 1 branch
BranchTrueFalseTotal
if $maxRSCU < $rscu 18 41 59
497 }
498  
499 # get CAI values now
500 18 foreach (@codons)
501 {
502 59 my $rscu = $rscuHash->{$_}; # normalized one
503 59 $cai{$_} = $rscu/$maxRSCU;
504 }
505 }
506  
507 1 ▶ $self->_write_out_hash($output, \%cai) if($output);
Branch: 1 branch
BranchTrueFalseTotal
if $output 0 1 1
508 1 return \%cai;
509 }
510  
511 =head2 build_tai
512  
513 Title : build_tai
514 Usage : $taiHash =
515 $self->build_tai($input,[$output,$selective_constraints, $kingdom]);
516 Function: build tAI values for all sense codons
517 Returns : reference of a hash in which codons are keys and tAI indice
518 are values. return undef if failed. See Formula 1 and 2 in I<dos
519 Reis, 2004, NAR> to see how they are computed.
520 Args : accepted arguments are as follows:
521
522 =over
523  
524 =item C<input>
525  
526 name of a file containing tRNA copies/abundance in the format
527 'anticodon<tab>count' per line, where 'anticodon' is anticodon in
528 the tRNA and count can be the tRNA gene copy number or abundance.
529  
530 =item C<output>
531  
532 optional. If provided, result will be stored in the file
533 specified by this argument.
534  
535 =item C<selective_constraints>
536  
537 optional, reference to hash containing wobble base-pairing and its
538 selective constraint compared to Watson-Crick base-pair, the format
539 is like this:
540 $selective_constraints = {
541 ... ... ...
542 'C-G' => 0,
543 'G-T' => 0.41,
544 'I-C' => 0.28,
545 ... ... ...
546 };
547 The key follows the 'anticodon-codon' order, and the values are codon
548 selective constraints. The smaller the constraint, the stronger the
549 pairing, so all Watson-Crick pairings have value 0.
550 If this option is omitted, values will be searched for in the 'input' file,
551 following the section of anticodons and started with a line '>SC'. If it is
552 not in the input file, then the values in the Table 2 of
553 I<dos Reis, 2004, NAR> are used.
554  
555 =item C<kingdom>
556  
557 kingdom = 1 for prokaryota and 0 or undef for eukaryota, which
558 affects the cacluation for bacteria isoleucine ATA codon. Default is
559 undef for eukaryota
560  
561 =back
562
563 =cut
564  
565 sub build_tai
566 1 ▶{
Subroutine build_tai: called CC=23 SCAR=34.1
Pod documented
567 1 my ($self, $input, $output, $SC, $kingdom) = @_;
568  
569 # the input copy number of each tRNA
570 1 my $fh = $self->_open_file($input);
571  
572 # read into tRNA abundance and if provided, selective constraints
573 1 my %antiCodonCopyNum;
574 my %scHash;
575 1 my $metSC = 0;
576 1 ▶ while(<$fh>)
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 45 1 46
577 {
578 45 ▶ if(/^>SC/) # constraint section
Branch: 1 branch
BranchTrueFalseTotal
if (/^>SC/) 0 45 45
579 {
580 0 ▶ last if $SC; # provided in this call
Branch: 1 branch
BranchTrueFalseTotal
if $SC 0 0 0
581 # otherwise record it
582 0 $metSC = 1;
583 0 next;
584 }
585 45 chomp;
586 45 my ($k, $v) = split /\s+/;
587 45 ▶ $metSC? $scHash{$k} = $v : $antiCodonCopyNum{$k} = $v;
Branch: 1 branch
BranchTrueFalseTotal
$metSC ? : 0 45 45
588 }
589 1 close $fh;
590 1 ▶ $SC ||= \%scHash if(%scHash);
Branch: 1 branch
BranchTrueFalseTotal
if %scHash 0 1 1
Condition0%0/2
$SC ||= \%scHash
l!l
00
MC/DC0%0/1
$SC ||= \%scHash
$SC
Truth table0%0/2
A
A= $SC
Aresult
11
00
591 1 ▶ unless($SC)
Branch: 1 branch
BranchTrueFalseTotal
unless ($SC) 1 0 1
592 {
593 1 ▶ $self->warn("default codon selective constraints (dos Reis) are used")
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 0 1 1
594 if($self->debug);
595 1 $SC = \%defaultSC;
596 }
597  
598 # now calculate tAI for each codon
599 1 my $allSenseCodons = $self->all_sense_codons;
600 1 my $maxW = 0; # maximum W of all codons
601 1 my %codonWs;
602 1 my $nonzeroWcnt = 0;
603 1 my $nonzeroWsumLog = 0;
604 1 my $excludeATG = $self->no_atg;
605 1 foreach my $codon (@$allSenseCodons)
606 {
607 # exclude ATG
608 61 ▶ next if($excludeATG and $codon eq 'ATG');
Branch: 1 branch
BranchTrueFalseTotal
if $excludeATG and $codon eq "ATG" 1 60 61
Condition66%2/3
$excludeATG and $codon eq "ATG"
!ll&&!rl&&r
0601
MC/DC50%1/2
$excludeATG and $codon eq "ATG"
$excludeATG $codon eq "ATG"
Truth table66%2/3
A and B
A= $excludeATGB= $codon eq "ATG"
ABresult
0X0
100
111
609 # find its recognizable anticodons
610 60 my $antiCodons = $self->_find_anticodons($codon);
611 60 ▶ $self->throw("No anticodons found for codon '$codon'")
Branch: 1 branch
BranchTrueFalseTotal
unless $antiCodons->$#* > 0 0 60 60
612 unless($#$antiCodons > 0);
613 #print "$codon: ", join(',', @$antiCodons), "\n";
614 60 my $W = 0;
615 # this codon may have no anticodons at all, so $W will be 0
616 60 foreach my $anti (@$antiCodons)
617 {
618 # check whether this tRNA exists here
619 166 ▶ next unless(exists $antiCodonCopyNum{$anti});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $antiCodonCopyNum{$anti} 86 80 166
620 # now determine the wobble pair
621 80 my $wobble = substr($anti,0,1).'-'.substr($codon,2,1);
622 #my $s = $SC->{$wobble} || 0;
623 $self->throw("Unknow wobble '$wobble' pair found")
624 80 ▶ unless(exists $SC->{$wobble});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $SC->{$wobble} 0 80 80
625 80 my $s = $SC->{$wobble};
626 80 $W += (1-$s)*$antiCodonCopyNum{$anti};
627 }
628 60 ▶ $maxW = $W if($W > $maxW);
Branch: 1 branch
BranchTrueFalseTotal
if $W > $maxW 4 56 60
629 60 $codonWs{$codon} = $W;
630 60 ▶ if($W > 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($W > 0) 60 0 60
631 {
632 60 $nonzeroWcnt++;
633 60 $nonzeroWsumLog += log($W);
634 }
635 60 ▶ $self->warn("The raw W for codon $codon is 0")
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 0 60 60
636 if($self->debug);
637 }
638  
639 # geometric mean of non-zero ws
640 1 my $geoMean = exp($nonzeroWsumLog/$nonzeroWcnt)/$maxW;
641 # normalize all W values by the max
642 1 ▶ while(my ($c, $w) = each %codonWs)
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %codonWs) 60 1 61
643 {
644 # assign zero w an geometric mean of other ws
645 60 ▶ $codonWs{$c} = $w > 0? $w/$maxW : $geoMean;
Branch: 1 branch
BranchTrueFalseTotal
$w > 0 ? : 60 0 60
646 }
647  
648 # modify prokaryotic ATA if present
649 1 ▶ if($kingdom)
Branch: 1 branch
BranchTrueFalseTotal
if ($kingdom) 0 1 1
650 {
651 0 $codonWs{'ATA'} = (1-$SC->{'L-A'})/$maxW;
652 }
653  
654 1 ▶ $self->_write_out_hash($output, \%codonWs) if($output);
Branch: 1 branch
BranchTrueFalseTotal
if $output 1 0 1
655  
656 1 return \%codonWs;
657 }
658  
659 sub _find_anticodons
660 60 ▶{
Subroutine _find_anticodons: called CC=2 SCAR=6.9
661 60 my ($self, $codon) = @_;
662  
663 60 my @bases = split //, $codon;
664 60 my $fixedBases = _complement($bases[0])._complement($bases[1]);
665 60 my $wobbleBasePairs = $self->{'_wobble_pair'};
666 60 my $matchAntiBases = $wobbleBasePairs->{$bases[2]};
667 60 my @antiCodons;
668 60 foreach (@$matchAntiBases)
669 {
670 166 my $anti = $fixedBases.$_;
671 166 push @antiCodons, scalar(reverse($anti)); # convert to 5'->3'
672 }
673  
674 60 return \@antiCodons;
675 }
676  
677 sub _complement
678 120 ▶{
Subroutine _complement: called CC=1 SCAR=0.0
679 120 my ($base) = @_;
680  
681 120 $base =~ tr/ATCG/TAGC/;
682  
683 120 return $base;
684 }
685  
686 =head1 AUTHOR
687  
688 Zhenguo Zhang, C<< <zhangz.sci at gmail.com> >>
689  
690 =head1 BUGS
691  
692 Please report any bugs or feature requests to C<bug-bio-cua at rt.cpan.org>, or through
693 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Bio-CUA>. I will be notified, and then you'll
694 automatically be notified of progress on your bug as I make changes.
695  
696  
697 =head1 SUPPORT
698  
699 You can find documentation for this module with the perldoc command.
700  
701 perldoc Bio::CUA::CUB::Builder
702  
703  
704 You can also look for information at:
705  
706 =over 4
707  
708 =item * RT: CPAN's request tracker (report bugs here)
709  
710 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Bio-CUA>
711  
712 =item * AnnoCPAN: Annotated CPAN documentation
713  
714 L<http://annocpan.org/dist/Bio-CUA>
715  
716 =item * CPAN Ratings
717  
718 L<http://cpanratings.perl.org/d/Bio-CUA>
719  
720 =item * Search CPAN
721  
722 L<http://search.cpan.org/dist/Bio-CUA/>
723  
724 =back
725  
726  
727 =head1 ACKNOWLEDGEMENTS
728  
729  
730 =head1 LICENSE AND COPYRIGHT
731  
732 Copyright 2015 Zhenguo Zhang.
733  
734 This program is free software: you can redistribute it and/or modify
735 it under the terms of the GNU General Public License as published by
736 the Free Software Foundation, either version 3 of the License, or
737 (at your option) any later version.
738  
739 This program is distributed in the hope that it will be useful,
740 but WITHOUT ANY WARRANTY; without even the implied warranty of
741 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
742 GNU General Public License for more details.
743  
744 You should have received a copy of the GNU General Public License
745 along with this program. If not, see L<http://www.gnu.org/licenses/>.
746  
747  
748 =cut
749  
750 2 1; # End of Bio::CUA::CUB::Builder
751  
« lib/Bio/CUA/CUB/Calculator.pm ↑ Summary script/cai_codon.pl »