Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: Translation Substring Error

by johngg (Canon)
on Nov 09, 2017 at 23:10 UTC ( #1203088=note: print w/replies, xml ) Need Help??

in reply to Translation Substring Error

This is not addressing the problem you were having, rather it is a suggestion for a simpler way of initialising your %genetic_code hash that would save some typing. The glob function can be used to generate combinations of letters. Your hash contains 64 keys which are all possible 3-character combinations of A, C, G and T. These can be generated using glob like this ...

johngg@shiraz:~/perl/Monks > perl -E 'say for glob q{{A,C,G,T}} x 3' AAA AAC AAG AAT ACA ACC ACG ACT ... TGA TGC TGG TGT TTA TTC TTG TTT

Arranging the corresponding amino acid letters in an array allows us to map keys (genetic codes) and values (amino acids) shift'ed from the array together to create the hash lookup.

my %genetic_code = do { my @amino_acids = qw{ K N K N T T T T R S R S I I M I Q H Q H P P P P R R R R L L L L E D E D A A A A G G G G V V V V * Y * Y S S S S * C W C L F L F }; map { $_ => shift @amino_acids } glob q{{A,C,G,T}} x 3; };

I hope this is of interest.



Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1203088]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (8)
As of 2018-11-21 20:07 GMT
Find Nodes?
    Voting Booth?
    My code is most likely broken because:

    Results (250 votes). Check out past polls.