Skip to content

Instantly share code, notes, and snippets.

@ktnyt
Last active August 29, 2015 14:05
Show Gist options
  • Select an option

  • Save ktnyt/da33acaf1d2041f17314 to your computer and use it in GitHub Desktop.

Select an option

Save ktnyt/da33acaf1d2041f17314 to your computer and use it in GitHub Desktop.
Best codon hashtable
use strict;
use warnings;
use G;
my $gb = load("ecoli", "no msg");
my $w_val = w_tai($gb, -output=>"f", -filename=>"/dev/null");
my $table;
foreach my $key (keys %{$w_val}) {
my $aa = substr($key, 0, 1);
my $codon = substr($key, 1, 3);
my $value = $w_val->{$key};
$table->{$aa}->{$codon} = $value;
}
p $table;
my $aaseq = join("", keys(%{$table}));
my $seq = "";
foreach my $aa (split //, $aaseq) {
my $best_codon = best_codon($aa, $table);
print "$aa: $best_codon\n";
}
sub best_codon {
my $aa = shift;
my $table = shift;
my $best_codon = "";
my %codon_table = %{$table->{$aa}};
my @sorted = sort{$codon_table{$b} <=> $codon_table{$a}}keys %codon_table;
$best_codon = $sorted[0];
return $best_codon;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment