in reply to Displayng the correct codon in a DNA string.
Another approach. I recommend leaving off the experimental dereferencing stuff but to each her own and it’s your cup of hemlock. :P
#!/usr/bin/env perl use 5.01; use strict; use warnings; my $dna = shift || "TTATATAAAAGU"; my $matcher = make_matcher(); my @protein; while ( $dna =~ /\G(?<codon>...)/g ) # Or maybe [ACTGU]{3} + /i { push @protein, $matcher->($+{codon}); } say $_ || "DERP!" for @protein; exit; sub make_matcher { my %map = ( qr/GC./ => "A", qr/TG[TC]/ => "C", qr/GA[TC]/ => "D", qr/GA[AG]/ => "E", qr/TT[TC]/ => "F", qr/GG./ => "G", qr/CA[TC]/ => "H", qr/AT[TCA]/ => "I", qr/AA[AG]/ => "K", qr/TT[AG]|CT./ => "L", qr/ATG/ => "M", qr/AA[TC]/ => "N", qr/CC./ => "P", qr/CA[AG]/ => "Q", qr/CG.|AG[AG]/ => "R", qr/TC.|AG[TC]/ => "S", qr/AC./ => "T", qr/GT./ => "V", qr/TGG/ => "W", qr/TA[TC]/ => "Y", qr/TA[AG]|TGA/ => "_" ); sub { my $codon = uc +shift; for my $key ( keys %map ) { return $map{$key} if $codon =~ $key; } }; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Displayng the correct codon in a DNA string.
by Anonymous Monk on Apr 25, 2016 at 02:52 UTC | |
by Your Mother (Archbishop) on Apr 25, 2016 at 02:56 UTC | |
|
Re^2: Displayng the correct codon in a DNA string.
by Anonymous Monk on Apr 25, 2016 at 10:11 UTC | |
by Your Mother (Archbishop) on Apr 25, 2016 at 12:29 UTC |