[Bioperl-l] How to access an array of codons

Dave Messina David.Messina at sbc.su.se
Wed Mar 11 06:13:28 EDT 2009


>
>
> How can I find a specific codon within this hash of arrays and extract the
> corresponding array.


You can't.

Hashes are used for looking up a value based on the key. Here, your keys are
the amino acids, and the values are the codons.

The simplest solution for you, I think, would be to maintain a separate hash
with codons as keys and amino acids as values.

So, if you start with a given codon and want to find the other codons that
code for the same amino acid, you could do something like:

my %cod2aa = (
     'GCA' => 'A',
     'GCC' => 'A',
     # and so on
);

my $codon = 'GCA';
my $aa = $cod2aa{$codon};
my @codons = $aa2cod{$aa};


If you haven't already, you might want to take a look at Jim Tisdall's book
"Beginning Perl for Bioinformatics". It has some good discussion of these
sorts of things.


Dave


More information about the Bioperl-l mailing list