ic23oluk has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: reading RNA codons into hash
by choroba (Cardinal) on Jul 13, 2017 at 09:48 UTC | |
by ic23oluk (Sexton) on Jul 13, 2017 at 10:12 UTC | |
|
Re: reading RNA codons into hash
by QM (Parson) on Jul 13, 2017 at 10:00 UTC | |
by ic23oluk (Sexton) on Jul 13, 2017 at 10:13 UTC | |
|
Re: reading RNA codons into hash
by AnomalousMonk (Archbishop) on Jul 13, 2017 at 10:35 UTC | |
by Anonymous Monk on Jul 13, 2017 at 13:54 UTC |