My code:
use strict;
use warnings;
my $seq = "ATGGT[TGA]G[TA]GC";
print "The sequences is $seq\n";
my %regex = (
AG => "R",
TC => "Y",
GT => "K",
AC => "M",
GC => "S",
AT => "M",
CGT => "B",
TGA => "D",
ACT => "H",
ACG => "V",
ACGT => "N"
);
$seq =~ s/\[(\w+)\]/$regex{$1}/g;
print "$seq\n";
My ideal output is: ATGGTDGMGC
But in the above scenario, since my hash key is AT and not TA, it doesn’t run. One way to solve this problem would be adding another key-value: TA => “M”. But I cannot do this for all key-value pairs, as there are too many possibilities.
So is there a better way to address this issue??
Thanks..
I’m guessing you mean that the order of the stuff in brackets is unimportant, so
ATis equivalent toTA, andTAGequivalent toTGA, etc.[ Note that the other Eric made a different guess. You weren’t very clear on what you wanted. ]
You could sort the letters.
or