in reply to reading RNA codons into hash
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: <%-{-{-{-<
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: reading RNA codons into hash
by Anonymous Monk on Jul 13, 2017 at 13:54 UTC |