File Coverage

blib/lib/Bio/GeneDesign/ReverseTranslate.pm
Criterion Covered Total %
statement 58 59 98.3
branch 3 4 75.0
condition n/a
subroutine 8 8 100.0
pod n/a
total 69 71 97.1


line stmt bran cond sub pod time code
1             =head1 NAME
2              
3             Bio::GeneDesign::ReverseTranslate
4              
5             =head1 VERSION
6              
7             Version 5.52
8              
9             =head1 DESCRIPTION
10              
11             Reverse translate a sequence using rscu values to set replacement likelihood
12              
13             =head1 AUTHOR
14              
15             Sarah Richardson <SMRichardson@lbl.gov>.
16              
17             =cut
18              
19             package Bio::GeneDesign::ReverseTranslate;
20             require Exporter;
21              
22 11     11   71 use Bio::GeneDesign::Random qw(_random_index _weighted_rand);
  11         25  
  11         706  
23 11     11   68 use Carp;
  11         23  
  11         627  
24              
25 11     11   70 use strict;
  11         25  
  11         405  
26 11     11   69 use warnings;
  11         24  
  11         518  
27              
28             our $VERSION = 5.52;
29              
30 11     11   544 use base qw(Exporter);
  11         26  
  11         7398  
31             our @EXPORT_OK = qw(
32             _reversetranslate_balanced
33             _reversetranslate_high
34             _reversetranslate_random
35             );
36             our %EXPORT_TAGS = (GD=> \@EXPORT_OK);
37              
38             =head2 _reversetranslate_balanced
39              
40             =cut
41              
42             sub _reversetranslate_balanced
43             {
44 10000     10000   17368 my ($reverse_codon_table, $rscu_table, $pepseq) = @_;
45            
46 10000         16095 my %changehsh = ();
47 10000         43378 foreach my $aa (keys %$reverse_codon_table)
48             {
49 210000         376667 $changehsh{$aa} = {};
50 210000         262195 my @codons = @{$reverse_codon_table->{$aa}};
  210000         503470  
51 210000         279103 my $count = scalar(@codons);
52 210000         240463 my $checksum = 0;
53 210000         307177 foreach my $coda (@codons)
54             {
55 640000         900351 my $likely = ($rscu_table->{$coda}) / $count;
56 640000         1068104 $changehsh{$aa}->{$coda} = $likely;
57 640000         1115596 $checksum += $likely;
58             }
59 210000 50       735972 if ($checksum == 0)
60             {
61 0         0 croak "This RSCU table has no positive values for $aa\n";
62             }
63             }
64              
65 10000         30764 my $newseq = q{};
66 10000         58937 $newseq .= _weighted_rand($changehsh{$_}) foreach (split q{}, $pepseq);
67 10000         157336 return $newseq;
68             }
69              
70             =head2 _reversetranslate_high
71            
72             =cut
73              
74             sub _reversetranslate_high
75             {
76 1     1   3 my ($reverse_codon_table, $rscu_table, $pepseq) = @_;
77 1         2 my $aa_highs = {};
78 1         7 foreach my $aa (keys %$reverse_codon_table)
79             {
80 21         29 my $myrscu = -1;
81 21         25 foreach my $codon (@{$reverse_codon_table->{$aa}})
  21         45  
82             {
83 64 100       225 if ($rscu_table->{$codon} > $myrscu)
84             {
85 40         65 $aa_highs->{$aa} = $codon;
86 40         102 $myrscu = $rscu_table->{$codon};
87             }
88             }
89             }
90 1         5 my $newseq = q{};
91 1         127 $newseq .= $aa_highs->{$_} foreach (split q{}, $pepseq);
92 1         27 return $newseq;
93             }
94              
95             =head2 _reversetranslate_random
96              
97             =cut
98              
99             sub _reversetranslate_random
100             {
101 10000     10000   17462 my ($reverse_codon_table, $rscu_table, $pepseq) = @_;
102            
103 10000         15827 my $cod_highs = {};
104 10000         11984 foreach my $aa (keys %{$reverse_codon_table})
  10000         45757  
105             {
106 210000         382547 $cod_highs->{$aa} = [];
107 210000         225998 foreach my $codon (@{$reverse_codon_table->{$aa}})
  210000         356129  
108             {
109 640000         651016 push @{$cod_highs->{$aa}}, $codon;
  640000         1448878  
110             }
111             }
112            
113 10000         28777 my $newseq = q{};
114 10000         27909 foreach my $aa (split q{}, $pepseq)
115             {
116 50000         52410 my $index = _random_index(scalar(@{$cod_highs->{$aa}}));
  50000         156558  
117 50000         129608 $newseq .= $cod_highs->{$aa}->[$index];
118             }
119 10000         121976 return $newseq;
120             }
121              
122             1;
123              
124             __END__
125              
126             =head1 COPYRIGHT AND LICENSE
127              
128             Copyright (c) 2013, GeneDesign developers
129             All rights reserved.
130              
131             Redistribution and use in source and binary forms, with or without modification,
132             are permitted provided that the following conditions are met:
133              
134             * Redistributions of source code must retain the above copyright notice, this
135             list of conditions and the following disclaimer.
136              
137             * Redistributions in binary form must reproduce the above copyright notice, this
138             list of conditions and the following disclaimer in the documentation and/or
139             other materials provided with the distribution.
140              
141             * The names of Johns Hopkins, the Joint Genome Institute, the Lawrence Berkeley
142             National Laboratory, the Department of Energy, and the GeneDesign developers may
143             not be used to endorse or promote products derived from this software without
144             specific prior written permission.
145              
146             THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
147             ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
148             WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
149             DISCLAIMED. IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
150             INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
151             LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
152             PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
153             LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
154             OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
155             ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
156              
157             =cut