This is the sort of thing I think should be encapsulated in a module rather than in a funky old .txt file you have to parse every time you use it. Here's an example I put together in another context. It's directed to DNA rather than RNA (I think ... I'm not a BioMonk), but you should be able to get the general idea.

File: CodonToAmino.pm:

# CodonToAmino.pm 26apr16waw package CodonToAmino; use warnings FATAL => 'all' ; use strict; use parent 'Exporter'; our $VERSION = '0.1.0'; our @EXPORT = qw(); our @EXPORT_OK = qw( XLATE_TABLE BASES canonicalize invalid_translation_table ); use constant BASES => 'ATCG'; # associate all possible base triplets (64) to aminos use constant XLATE_TABLE => qw( GCA A CAC H CCA P ACA T GCC A CAT H CCC P ACC T GCG A CCG P ACG T GCT A ATA I CCT P ACT T ATC I TGC C ATT I CAA Q GTA V TGT C CAG Q GTC V AAA K GTG V GAC D AAG K AGA R GTT V GAT D AGG R CTA L CGA R TGG W GAA E CTC L CGC R GAG E CTG L CGG R TAC Y CTT L CGT R TAT Y TTC F TTA L TTT F TTG L AGC S TAA _ AGT S TAG _ GGA G ATG M TCA S TGA _ GGC G TCC S GGG G AAC N TCG S GGT G AAT N TCT S ); my $invalid = invalid_translation_table(XLATE_TABLE); die "invalid translation table: '$invalid'" if $invalid; # exported subroutines ############################################# sub canonicalize { return uc $_[0]; } sub invalid_translation_table { my (%xlate, # translation hash table ) = @_; my $bases = canonicalize(BASES); my $codon = qr{ \A [\Q$bases\E]{3} \z }xms; # each key should be a codon. for my $k (keys %xlate) { return qq{'$k' is not proper codon} if $k !~ $codon; } # 64 unique groups of 3-character codons: all permutations. my $n_keys = keys %xlate; return qq{$n_keys, not 64, permutations of codons in table} if $n_keys != 64; # return aok. return ''; # no report of invalidity } # end sub invalid_translation_table() 1;


Give a man a fish:  <%-{-{-{-<


In reply to Re: reading RNA codons into hash by AnomalousMonk
in thread reading RNA codons into hash by ic23oluk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.