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

Chris Fields cjfields at illinois.edu
Wed Mar 11 14:04:14 UTC 2009


On Mar 11, 2009, at 4:14 AM, manni122 wrote:

> Hi there, if I want to access my hash of arrays %aa2cod I can print  
> out the
> array key and the first value by
>
> for my $key (keys %aa2cod) {
> print "$key => $aa2cod{$key}[0]\n";
> }
>
> How can I find a specific codon within this hash of arrays and  
> extract the
> corresponding array. For instance I am looking for GCA and want to  
> get the
> whole array [GCA GCC GCG GCT].
>
> I appreciate any comment!!

You would have to iterate through all the keys in the hash to get what  
you want.  TIMTOWDI:

------------------------
my ($codons) =
     map { $aa2cod{$_} }
     grep {
         my ($hit) = grep {
             $_ eq 'GCA'
         } @{ $aa2cod{$_} };
     } sort keys %aa2cod;

print join(',',@$codons)."\n" if ref $codons;
------------------------

while (my ($aa, $codons) = each %aa2cod) {
     if (grep {$_ eq 'GCA'} @{$codons}) {
         print join(',',@{$codons})."\n";
         last;
     }
}
------------------------

chris






More information about the Bioperl-l mailing list