File Coverage

blib/lib/Bio/GeneDesign/ReverseTranslate.pm
Criterion Covered Total %
statement 58 61 95.0
branch 3 4 75.0
condition n/a
subroutine 8 9 88.8
pod n/a
total 69 74 93.2


line stmt bran cond sub pod time code
1             =head1 NAME
2              
3             Bio::GeneDesign::ReverseTranslate
4              
5             =head1 VERSION
6              
7             Version 5.56
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 .
16              
17             =cut
18              
19             package Bio::GeneDesign::ReverseTranslate;
20             require Exporter;
21              
22 11     11   72 use Bio::GeneDesign::Random qw(_random_index _weighted_rand);
  11         20  
  11         550  
23 11     11   58 use Carp;
  11         20  
  11         495  
24              
25 11     11   67 use strict;
  11         29  
  11         244  
26 11     11   63 use warnings;
  11         26  
  11         478  
27              
28             our $VERSION = 5.56;
29              
30 11     11   61 use base qw(Exporter);
  11         20  
  11         6328  
31             our @EXPORT_OK = qw(
32             _list_algorithms
33             _reversetranslate_balanced
34             _reversetranslate_high
35             _reversetranslate_random
36             );
37             our %EXPORT_TAGS = (GD=> \@EXPORT_OK);
38              
39             =head2 _list_algorithms
40              
41             =cut
42              
43             sub _list_algorithms
44             {
45 0     0   0 my %hsh =
46             (
47             balanced => 'weighted averages',
48             high => 'uniformly most used',
49             random => 'random',
50             );
51 0         0 return \%hsh;
52             }
53              
54             =head2 _reversetranslate_balanced
55              
56             =cut
57              
58             sub _reversetranslate_balanced
59             {
60 10000     10000   20948 my ($reverse_codon_table, $rscu_table, $pepseq) = @_;
61              
62 10000         16546 my %changehsh = ();
63 10000         42271 foreach my $aa (keys %$reverse_codon_table)
64             {
65 210000         334569 $changehsh{$aa} = {};
66 210000         278734 my @codons = @{$reverse_codon_table->{$aa}};
  210000         411374  
67 210000         304496 my $count = scalar(@codons);
68 210000         283852 my $checksum = 0;
69 210000         308511 foreach my $coda (@codons)
70             {
71 640000         917084 my $likely = ($rscu_table->{$coda}) / $count;
72 640000         958015 $changehsh{$aa}->{$coda} = $likely;
73 640000         958299 $checksum += $likely;
74             }
75 210000 50       452369 if ($checksum == 0)
76             {
77 0         0 croak "This RSCU table has no positive values for $aa\n";
78             }
79             }
80              
81 10000         23694 my $newseq = q{};
82 10000         47150 $newseq .= _weighted_rand($changehsh{$_}) foreach (split q{}, $pepseq);
83 10000         103870 return $newseq;
84             }
85              
86             =head2 _reversetranslate_high
87              
88             =cut
89              
90             sub _reversetranslate_high
91             {
92 1     1   4 my ($reverse_codon_table, $rscu_table, $pepseq) = @_;
93 1         2 my $aa_highs = {};
94 1         7 foreach my $aa (keys %$reverse_codon_table)
95             {
96 21         30 my $myrscu = -1;
97 21         25 foreach my $codon (@{$reverse_codon_table->{$aa}})
  21         34  
98             {
99 64 100       143 if ($rscu_table->{$codon} > $myrscu)
100             {
101 35         60 $aa_highs->{$aa} = $codon;
102 35         55 $myrscu = $rscu_table->{$codon};
103             }
104             }
105             }
106 1         3 my $newseq = q{};
107 1         71 $newseq .= $aa_highs->{$_} foreach (split q{}, $pepseq);
108 1         16 return $newseq;
109             }
110              
111             =head2 _reversetranslate_random
112              
113             =cut
114              
115             sub _reversetranslate_random
116             {
117 10000     10000   18434 my ($reverse_codon_table, $rscu_table, $pepseq) = @_;
118              
119 10000         16087 my $cod_highs = {};
120 10000         13935 foreach my $aa (keys %{$reverse_codon_table})
  10000         38884  
121             {
122 210000         320605 $cod_highs->{$aa} = [];
123 210000         238475 foreach my $codon (@{$reverse_codon_table->{$aa}})
  210000         319346  
124             {
125 640000         731042 push @{$cod_highs->{$aa}}, $codon;
  640000         1084550  
126             }
127             }
128              
129 10000         21931 my $newseq = q{};
130 10000         25764 foreach my $aa (split q{}, $pepseq)
131             {
132 50000         62783 my $index = _random_index(scalar(@{$cod_highs->{$aa}}));
  50000         101291  
133 50000         91374 $newseq .= $cod_highs->{$aa}->[$index];
134             }
135 10000         72223 return $newseq;
136             }
137              
138             1;
139              
140             __END__