Bio-Tools-CodonOptTable
view release on metacpan or search on metacpan
lib/Bio/Tools/CodonOptTable.pm view on Meta::CPAN
}
sub prefered_codon {
my ( $self, $codons ) = @_;
my $prefered_codon;
for my $each_aa (@$codons) {
my $aa_name = $each_aa->{'aa_name'};
my $rscu = $each_aa->{'rscu'};
my $codon = $each_aa->{'codon'};
my $frequency = $each_aa->{'frequency'};
if ( !defined( $prefered_codon->{$aa_name} )
|| ( $prefered_codon->{$aa_name} < $rscu ) )
{
$prefered_codon->{$aa_name} = $codon;
}
}
return $prefered_codon;
}
sub generate_graph {
my ( $self, $codons, $output_file ) = @_;
my ( @x_axis_labels, @rscu, @rac, @x_axis_values, @codons_table,
@codon_freq );
my $y_axis_max = 8;
my @category_colours = qw(red dgreen);
my $bar_graph = new GD::Graph::bars( 1000, 500 );
foreach my $each_aa (@$codons) {
if ( $each_aa->{'aa_name'} ) {
push( @codons_table,
$each_aa->{'aa_name'} . "(" . $each_aa->{'codon'} . ")" );
push( @codon_freq, $each_aa->{'frequency'} );
push( @x_axis_labels,
$each_aa->{'codon'} . "("
. $each_aa->{'frequency'} . ")" . "-"
. $each_aa->{'aa_name'} );
push( @rscu, $each_aa->{'rscu'} );
push( @rac, $each_aa->{'rac'} );
}
}
my @bar_graph_table;
push( @bar_graph_table, \@x_axis_labels );
push( @bar_graph_table, \@rscu );
push( @bar_graph_table, \@rac );
$bar_graph->set(
title =>
'Graph Representing : Relative Synonymous Codons Uses and Relative Adaptiveness of a Codon for '
. $self->display_id,
y_label => 'RSCU and RAC values', #y-axis label
y_max_value => $y_axis_max, #the max value of the y-axis
y_min_value => 0
, #the min value of y-axis, note set below 0 if negative values are required
y_tick_number => 20, #y-axis scale increment
y_label_skip => 1, #label every other y-axis marker
box_axis => 0, #do not draw border around graph
line_width => 2, #width of lines
legend_spacing => 5, #spacing between legend elements
legend_placement => 'RC', #put legend to the centre right of chart
dclrs => \@category_colours
, #reference to array of category colours for each line
bgclr => 'red',
long_ticks => 0,
tick_length => 3,
x_labels_vertical => 1,
) || die "\nFailed to create line graph: $bar_graph->error()";
$bar_graph->set_legend( 'RSCU Value', 'RAC Value' );
my $plot = $bar_graph->plot( \@bar_graph_table );
my $line_file = $output_file;
open( GPH, ">$line_file" )
|| die("\nFailed to save graph to file: $line_file. $!");
binmode(GPH);
print GPH $plot->gif();
close(GPH);
}
sub generate_report {
my ( $self, $out_file ) = @_;
my $myCodons = $self->rscu_rac_table();
my $sequence_id = $self->id;
my $genetic_code = $self->{genetic_code};
my $monomers = $self->{monomers_count};
my $cai = $self->calculate_cai($myCodons);
my %colors = (
'Ala' => '#f4f4f4', 'Arg' => '#FF99FF', 'Asn' => '#CC99CC',
'Asp' => '#99FFCC', 'Cys' => '#99CC99', 'Gln' => '#CCFF00',
'Glu' => '#FF00CC', 'Gly' => '#33FFCC', 'His' => '#66CCFF',
'Ile' => '#c9c9c9', 'Leu' => '#CCFFFF', 'Lys' => '#FFFFCC',
'Met' => '#FFFF66', 'Phe' => '#FFCC00', 'Pro' => '#F4F4F4',
'Ser' => '#FF99FF', 'Thr' => '#CC99CC', 'Trp' => '#99FFCC',
'Tyr' => '#CCFF00', 'Val' => '#33FFCC', 'Asx' => '#6666CC',
'glx' => '#FF00CC', 'Xaa' => '#cccccc', 'Stop' => '#f8f8f8'
);
my $codons = "|%{color:red}CODON%|";
my $aa_name = "|%{color:red}AMINOACID%|";
my $counts = "|%{color:red}COUNT%|";
my $rscu = "|%{color:red}RSCU%|";
my $rac = "|%{color:red}RAC%|";
foreach my $each_codon (@$myCodons) {
my $frequency = $each_codon->{frequency} || 'O';
my $amino_acid = $each_codon->{aa_name};
my $codon = $each_codon->{codon};
my $rscu_value = $each_codon->{rscu};
my $rac_value = $each_codon->{rac};
my $aa_color = $colors{$amino_acid};
$codons .= "%{background:$aa_color}$codon%|";
$aa_name .= "%{background:$aa_color}$amino_acid%|";
$counts .= "%{background:$aa_color}$frequency%|";
$rscu .= "%{background:$aa_color}$rscu_value%|";
$rac .= "%{background:$aa_color}$rac_value%|";
}
my $codon_uses = "$codons\n$aa_name\n$counts\n";
my $rscu_uses = "$codons\n$aa_name\n$rscu\n";
my $rac_uses = "$codons\n$aa_name\n$rac\n";
my $mono_mers =
"|%{color:red}A%|"
. $monomers->{A} . "|\n"
. "|%{color:red}T%|"
. $monomers->{T} . "|\n"
. "|%{color:red}G%|"
( run in 2.063 seconds using v1.01-cache-2.11-cpan-5b529ec07f3 )