hello monks,
I try to read the RNA triplet code into a hash, where the triplets are keys, and the one letter code of amino acids are the values. I read the information from an txt file that has the following structure: :
X whitespace codon_1 codon_2 ...
. . .X stands for the Letter of the amino acid
Here's my code
my %code; my $file = 'code.txt'; open (READ, $file) || die "Cannot open $file: $!\n"; while (my $line = <READ>){ chomp $line; if ($line =~ /^(\w+)\s+([\w]+)$/i){ (%code) = ( "$2" => $1 ); next; } if ($line =~ /^(\w+)\s+([\w]+)\s+([\w]+)$/i){ (%code) = ( "$2" => $1, "$3" => $1 ); next; } if ($line =~ /^(\w+)\s+([\w]+)\s+([\w]+)\s+([\w]+)$/i){ (%code) = ( "$2" => $1, "$3" => $1, "$4" => $1 ); next; } if ($line =~ /^(\w+)\s+([\w]+)\s+([\w]+)\s+([\w]+)\s+([\w]+)$/i){ (%code) = ( "$2" => $1, "$3" => $1, "$4" => $1, "$5" => $1 ); next; } if ($line =~ /^(\w+)\s+([\w]+)\s+([\w]+)\s+([\w]+)\s+([\w]+)\s+([\ +w]+)$/i){ (%code) = ( "$2" => $1, "$3" => $1, "$4" => $1, "$5" => $1, "$6" => $1 ); next; } if ($line =~ /^(\w+)\s+([\w]+)\s+([\w]+)\s+([\w]+)\s+([\w]+)\s+([\ +w]+)\s+([\w]+)$/i){ (%code) = ( "$2" => $1, "$3" => $1, "$4" => $1, "$5" => $1, "$6" => $1, "$ +7" => $1 ); next; } } foreach (keys %code){ print $_, "\t", $code{"$_"}, "\n"; }
the output i get is just the last line (UAA, UAG, UGA Stop). Could anyone indicate the problem?
thanks in advance
In reply to reading RNA codons into hash by ic23oluk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |