in reply to Mismatch Positions of Ambiguous String
Since characters in square brackets happen to be character classes in regexes, why not use them as such!?
use strict; use warnings; use Algorithm::Loops qw(MapCarE); MapCarE { my ($s, $t) = @_; my $x= $t =~ /$s/ ? '~' : '!'; print "$t $x~ $s\n"; } [shift =~ /\[\w+\]|\w/g], # split source into chars or char classes [split //, shift]; # split target into chars
D:\temp>mm [TCG]GGGG[AT] AGGGGC A !~ [TCG] G ~~ G G ~~ G G ~~ G G ~~ G C !~ [AT] D:\temp>mm [TCG]GGGG[AT] TGGGGC T ~~ [TCG] G ~~ G G ~~ G G ~~ G G ~~ G C !~ [AT]
Using Algorithm::Loops just for the convenience to iterate over two lists at once without distracting from the main point.
|
|---|