| 1 | # | ||||||||||||||||||||||||||||||||
| 2 | # BioPerl module for Bio::CodonUsage::IO | ||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||
| 4 | # Please direct questions and support issues to <bioperl-l@bioperl.org> | ||||||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||||||
| 6 | # Cared for by Richard Adams (richard.adams@ed.ac.uk) | ||||||||||||||||||||||||||||||||
| 7 | # | ||||||||||||||||||||||||||||||||
| 8 | # Copyright Richard Adams | ||||||||||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||||||||||
| 10 | # You may distribute this module under the same terms as perl itself | ||||||||||||||||||||||||||||||||
| 11 | # POD documentation - main docs before the code | ||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||
| 13 | =head1 NAME | ||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||
| 15 | Bio::CodonUsage::IO - for reading and writing codon usage tables to file | ||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||
| 17 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||
| 19 | use Bio::CodonUsage::IO; | ||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||
| 21 | ## read in a codon usage file | ||||||||||||||||||||||||||||||||
| 22 | my $io = Bio::CodonUsage::IO->new(-file => "in"); | ||||||||||||||||||||||||||||||||
| 23 | my $cut = $io->next_data(); | ||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||
| 25 | ## write it out again | ||||||||||||||||||||||||||||||||
| 26 | my $out = Bio::CodonUsage::IO->new(-file => ">out"); | ||||||||||||||||||||||||||||||||
| 27 | $out->write_data($cut); | ||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||
| 29 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||
| 31 | This class provides standard IO methods for reading and writing text files | ||||||||||||||||||||||||||||||||
| 32 | of codon usage tables. These tables can initially be retrieved using | ||||||||||||||||||||||||||||||||
| 33 | Bio::DB::CUTG. At present only this format is supported for read/write. | ||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||
| 35 | Reading a CUTG will return a Bio::CodonUsage::Table object. | ||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||
| 37 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||
| 39 | L<Bio::Tools::CodonTable>, | ||||||||||||||||||||||||||||||||
| 40 | L<Bio::WebAgent>, | ||||||||||||||||||||||||||||||||
| 41 | L<Bio::CodonUsage::Table>, | ||||||||||||||||||||||||||||||||
| 42 | L<Bio::CodonUsage::IO> | ||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||
| 44 | =head1 FEEDBACK | ||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||
| 46 | =head2 Mailing Lists | ||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||
| 48 | User feedback is an integral part of the evolution of this and other | ||||||||||||||||||||||||||||||||
| 49 | Bioperl modules. Send your comments and suggestions preferably to one | ||||||||||||||||||||||||||||||||
| 50 | of the Bioperl mailing lists. Your participation is much appreciated. | ||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||
| 52 | bioperl-l@bioperl.org - General discussion | ||||||||||||||||||||||||||||||||
| 53 | http://bioperl.org/wiki/Mailing_lists - About the mailing lists | ||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||
| 55 | =head2 Support | ||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||
| 57 | Please direct usage questions or support issues to the mailing list: | ||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||
| 59 | I<bioperl-l@bioperl.org> | ||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||
| 61 | rather than to the module maintainer directly. Many experienced and | ||||||||||||||||||||||||||||||||
| 62 | reponsive experts will be able look at the problem and quickly | ||||||||||||||||||||||||||||||||
| 63 | address it. Please include a thorough description of the problem | ||||||||||||||||||||||||||||||||
| 64 | with code and data examples if at all possible. | ||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||
| 66 | =head2 Reporting Bugs | ||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||
| 68 | Report bugs to the Bioperl bug tracking system to help us keep track | ||||||||||||||||||||||||||||||||
| 69 | the bugs and their resolution. Bug reports can be submitted via the | ||||||||||||||||||||||||||||||||
| 70 | web: | ||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||
| 72 | https://github.com/bioperl/bioperl-live/issues | ||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||
| 74 | =head1 AUTHORS | ||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||
| 76 | Richard Adams, Richard.Adams@ed.ac.uk | ||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||
| 78 | =head1 APPENDIX | ||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||
| 80 | The rest of the documentation details each of the object | ||||||||||||||||||||||||||||||||
| 81 | methods. Internal methods are usually preceded with a _ | ||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||
| 83 | =cut | ||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||
| 86 | # Let the code begin | ||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||
| 88 | package Bio::CodonUsage::IO; | ||||||||||||||||||||||||||||||||
| 89 | 2 | $Bio::CodonUsage::IO::VERSION = '1.7.8'; | |||||||||||||||||||||||||||||||
| 90 | 2 | ▶ | use Bio::CodonUsage::Table; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||
| 92 | 2 | ▶ | use base qw(Bio::Root::IO); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||
| 94 | =head2 new | ||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||
| 96 | Title : new | ||||||||||||||||||||||||||||||||
| 97 | Usage : my $io = Bio::CodonUsage::IO->new(-file => "CUTfile"); | ||||||||||||||||||||||||||||||||
| 98 | Purpose: To read/write a Bio:CodonUsage::Table object | ||||||||||||||||||||||||||||||||
| 99 | Returns: A Bio:CodonUsage::IO object | ||||||||||||||||||||||||||||||||
| 100 | Args : a file or file handle | ||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||
| 102 | =cut | ||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||
| 104 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 105 | 1 | my ($class , @args) = @_; | |||||||||||||||||||||||||||||||
| 106 | 1 | my $self = $class->SUPER::new(@args); | |||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||
| 110 | =head2 next_data | ||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||
| 112 | Title : next_data | ||||||||||||||||||||||||||||||||
| 113 | Usage : my $cut = $io->next_data(); | ||||||||||||||||||||||||||||||||
| 114 | Purpose: To obtain a Bio:CodonUsage::Table object | ||||||||||||||||||||||||||||||||
| 115 | Returns: A Bio:CodonUsage::Table object | ||||||||||||||||||||||||||||||||
| 116 | Args : none | ||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||
| 118 | =cut | ||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||
| 120 | 1 | ▶ | sub next_data { | ||||||||||||||||||||||||||||||
|
Subroutine
next_data: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 121 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||
| 122 | 1 | my $cut = $self->_parse; | |||||||||||||||||||||||||||||||
| 123 | 1 | return $cut; | |||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||
| 126 | =head2 write_data | ||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||
| 128 | Title : write_data | ||||||||||||||||||||||||||||||||
| 129 | Usage : $io->write_data($cut); | ||||||||||||||||||||||||||||||||
| 130 | Purpose: To write a CUT to file | ||||||||||||||||||||||||||||||||
| 131 | Returns: void | ||||||||||||||||||||||||||||||||
| 132 | Args : a Bio::CodonUsage::Table object reference | ||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||
| 134 | =cut | ||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||
| 137 | 0 | ▶ | sub write_data { | ||||||||||||||||||||||||||||||
|
Subroutine
write_data: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 138 | 0 | my ($self, $cut) = @_; | |||||||||||||||||||||||||||||||
| 139 | 0 | ▶ | if (!$cut || ! $cut->isa(Bio::CodonUsage::Table)) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$cut and $cut->isa("Bio::CodonUsage::Table")
MC/DC0%0/2
$cut and $cut->isa("Bio::CodonUsage::Table")
$cut
$cut->isa("Bio::CodonUsage::Table")
Truth table0%0/3
A and B
A= $cutB= $cut->isa("Bio::CodonUsage::Table")
| |||||||||||||||||||||||||||||||||
| 140 | 0 | $self->throw("must supply a Bio::CodonUsage::Table object for writing\n"); | |||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||
| 142 | 0 | my $outstring = "Codon usage table\n\n"; | |||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||
| 144 | 0 | my $sp_string = $cut->species . "[" . $cut->_gb_db . "] " . | |||||||||||||||||||||||||||||||
| 145 | $cut->cds_count . " CDS's\n\n"; | ||||||||||||||||||||||||||||||||
| 146 | 0 | $outstring .= $sp_string; | |||||||||||||||||||||||||||||||
| 147 | 0 | my $colhead = sprintf("%-9s%-9s%15s%12s%12s\n\n", "AmAcid", | |||||||||||||||||||||||||||||||
| 148 | "Codon", "Number", "/1000", "Fraction"); | ||||||||||||||||||||||||||||||||
| 149 | 0 | $outstring .= $colhead; | |||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||
| 151 | ### now write bulk of codon data ## | ||||||||||||||||||||||||||||||||
| 152 | 0 | my $ctable = Bio::Tools::CodonTable->new; | |||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||
| 154 | 0 | for my $f (qw(G A T C)) { | |||||||||||||||||||||||||||||||
| 155 | 0 | for my $s (qw(G A T C)) { | |||||||||||||||||||||||||||||||
| 156 | 0 | for my $t (qw(G A T C)) { | |||||||||||||||||||||||||||||||
| 157 | 0 | $cod = $f . $s . $t; | |||||||||||||||||||||||||||||||
| 158 | 0 | my $aa =$Bio::SeqUtils::THREECODE {$ctable->translate($cod)}; | |||||||||||||||||||||||||||||||
| 159 | my $codstr = sprintf("%-9s%-9s%15.2f%12.2f%12.2f\n", | ||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||
| 161 | $aa, $cod, my $tt = $cut->codon_count($cod)|| 0.00, | ||||||||||||||||||||||||||||||||
| 162 | 0 | ▶ | my $ll =$cut->{'_table'}{$aa}{$cod}{'per1000'}|| 0.00, | ||||||||||||||||||||||||||||||
|
Condition0%0/6
$cut->codon_count($cod) || 0.0
$cut->{'_table'}{$aa}{$cod}{'per1000'} || 0.0
$cut->codon_rel_frequency($cod) || 0.0
MC/DC0%0/1
$cut->codon_count($cod) || 0.0
$cut->codon_count($cod)
MC/DC0%0/1
$cut->{'_table'}{$aa}{$cod}{'per1000'} || 0.0
$cut->{'_table'}{$aa}{$cod}{'per1000'}
MC/DC0%0/1
$cut->codon_rel_frequency($cod) || 0.0
$cut->codon_rel_frequency($cod)
Truth table0%0/2
A
A= $cut->codon_count($cod)
Truth table0%0/2
A
A= $cut->{'_table'}{$aa}{$cod}{'per1000'}
Truth table0%0/2
A
A= $cut->codon_rel_frequency($cod)
| |||||||||||||||||||||||||||||||||
| 163 | my $ss = $cut->codon_rel_frequency($cod) || 0.00); | ||||||||||||||||||||||||||||||||
| 164 | 0 | $outstring .= $codstr; | |||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||
| 166 | 0 | $outstring .= "\n"; | |||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||
| 169 | 0 | $outstring .= "\n\n"; | |||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||
| 171 | ## now append GC data | ||||||||||||||||||||||||||||||||
| 172 | 0 | $outstring .= "Coding GC ". $cut->get_coding_gc('all'). "%\n"; | |||||||||||||||||||||||||||||||
| 173 | 0 | $outstring .= "1st letter GC ". $cut->get_coding_gc(1). "%\n"; | |||||||||||||||||||||||||||||||
| 174 | 0 | $outstring .= "2nd letter GC ". $cut->get_coding_gc(2). "%\n"; | |||||||||||||||||||||||||||||||
| 175 | 0 | $outstring .= "3rd letter GC ". $cut->get_coding_gc(3). "%\n"; | |||||||||||||||||||||||||||||||
| 176 | 0 | $outstring .= "Genetic code " . $cut->genetic_code() ."\n\n\n"; | |||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||
| 178 | 0 | $self->_print ($outstring); | |||||||||||||||||||||||||||||||
| 179 | 0 | $self->flush(); | |||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||
| 183 | 1 | ▶ | sub _parse { | ||||||||||||||||||||||||||||||
|
Subroutine
_parse: called CC=12 SCAR=24.9
| |||||||||||||||||||||||||||||||||
| 184 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||
| 185 | 1 | my $cdtableobj = Bio::CodonUsage::Table->new(); | |||||||||||||||||||||||||||||||
| 186 | 1 | ▶ | while (my $line = $self->_readline() ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 187 | 93 | ▶ | next if $line =~ /^$/ ; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 188 | 72 | $line =~ s/End/Ter/; | |||||||||||||||||||||||||||||||
| 189 | ## now parse in species name, cds number | ||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||
| 191 | 72 | ▶ | if ($line =~ /^(.+?)\s*\[(\w+)\].+?(\d+)/) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 192 | 1 | $cdtableobj->species($1); | |||||||||||||||||||||||||||||||
| 193 | 1 | $cdtableobj->{'_gb_db'} = $2; | |||||||||||||||||||||||||||||||
| 194 | 1 | $cdtableobj->cds_count($3); | |||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||
| 197 | ## now parse in bulk of codon usage table | ||||||||||||||||||||||||||||||||
| 198 | elsif ( $line =~ /^(\w\w\w)\s+(\w+)\s+(\d+\.\d+) | ||||||||||||||||||||||||||||||||
| 199 | \s+(\d+\.\d+)\s+(\d+\.\d+)/x){ | ||||||||||||||||||||||||||||||||
| 200 | 64 | ▶ | if (defined ($1)) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 201 | 64 | $cdtableobj->{'_table'}{$1}{$2} = { | |||||||||||||||||||||||||||||||
| 202 | 'abs_count'=>$3, | ||||||||||||||||||||||||||||||||
| 203 | 'per1000'=> $4, | ||||||||||||||||||||||||||||||||
| 204 | 'rel_freq'=> $5, | ||||||||||||||||||||||||||||||||
| 205 | }; | ||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||
| 209 | ## now parse in gc data #### | ||||||||||||||||||||||||||||||||
| 210 | 72 | ▶ | if($line =~ /^Cod.+?(\d\d\.\d\d)/ ){ | ||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||
| 211 | 1 | $cdtableobj->{'_coding_gc'}{'all'} = $1; | |||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||
| 213 | elsif ($line =~ /^1st.+?(\d\d\.\d\d)/){ | ||||||||||||||||||||||||||||||||
| 214 | 1 | $cdtableobj->{'_coding_gc'}{'1'} = $1; | |||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||
| 216 | elsif($line =~ /^2nd.+?(\d\d\.\d\d)/){ | ||||||||||||||||||||||||||||||||
| 217 | 1 | $cdtableobj->{'_coding_gc'}{'2'} = $1; | |||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||
| 219 | elsif ($line =~ /^3rd.+?(\d\d\.\d\d)/){ | ||||||||||||||||||||||||||||||||
| 220 | 1 | $cdtableobj->{'_coding_gc'}{'3'} = $1; | |||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||
| 223 | elsif ($line =~ /^Gen.+?(\d+)/){ | ||||||||||||||||||||||||||||||||
| 224 | 1 | $cdtableobj->{'_genetic_code'} = $1; | |||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||
| 227 | ## check has been parsed ok ## | ||||||||||||||||||||||||||||||||
| 228 | 1 | ▶ | if (scalar keys %{$cdtableobj->{'_table'}} != 21) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 229 | 0 | $cdtableobj->warn("probable parsing error - should be 21 entries for 20aa + stop codon"); | |||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||
| 231 | 1 | return $cdtableobj; | |||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||
| 235 | 2 | 1; | |||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||
| 237 | __END__ | ||||||||||||||||||||||||||||||||