hi how can i translate these amino acids sequence into its triplet codes.

this line is not working.

$aa =~ tr/arndceqghilkmfpstwyv/ala, arg, asn, asp, cys, glu, gln, gly, his, ile, leu, lys, met, phe, pro, ser, the, trp, tyr, val/;

is there any delimiter to separate that three letter codes.

Recommended Answers

All 2 Replies

I don't think it can be done with the tr/// operator. Can you use a hash table instead?

#!/usr/bin/perl -w
use strict;
my %hash = (
'a','ala',
'r','arg',
'n','asn',
'd','asp',
'c','cys',
'e','glu',
'q','gln',
'g','gly',
'h','his',
'i','ile',
'l','leu',
'k','lys',
'm','met',
'f','phe',
'p','pro',
's','ser',
't','the',
'w','trp',
'y','tyr',
'v','val');
print "$hash{'h'}, $hash{'w'}, and so on...";

Once you have a hash with triplet code values for all the letter keys you can translate any sequence from a string of letters into a string of triplet codes.

#!/usr/bin/perl -w
use strict;
my %hash = (
'a' => 'ala',
'r' => 'arg',
'n' => 'asn',
'd' => 'asp',
'c' => 'cys',
'e' => 'glu',
'q' => 'gln',
'g' => 'gly',
'h' => 'his',
'i' => 'ile',
'l' => 'leu',
'k' => 'lys',
'm' => 'met',
'f' => 'phe',
'p' => 'pro',
's' => 'ser',
't' => 'the',
'w' => 'trp',
'y' => 'tyr',
'v' => 'val');

my $sequence = "verydamp"; #sequence of arbitrary letters to translate into triplet codes
my $out;
print "\n" . '$sequence = ' . "'$sequence' which translates into:\n";
while ($sequence =~ m/([a-z])/g) { #match each lowercase letter in $sequence string
    $out .= "$hash{$1}, "; # $1 contains a letter from $sequence which is a key in %hash
}
$out = substr($out,0,-2); #Remove final comma and space from end of string
print $out, "\n";
commented: Great post. My thoughts exactlyy +2
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.