Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Mismatch Positions of Ambiguous String

by GrandFather (Saint)
on Jan 25, 2006 at 11:10 UTC ( [id://525407]=note: print w/replies, xml ) Need Help??


in reply to Mismatch Positions of Ambiguous String

I like bitwise operators :)

use strict; use warnings; my @targets = qw(AGGGGC TGGGGC); my @sources = (<DATA>); chomp @sources; for my $source (@sources) { my @fields = grep length, split /(\[[^[\]]+\]|[^[\]]+)/, $source; my @cells = map {(index $_, '[') == 0 ? $_ : split ''} @fields; my $matchStr = join '', map {/\[/ ? "\x80" : $_} @fields; for my $target (@targets) { my @segments = grep length, split /(\x00+|.)/, $target ^ $matchStr +; my $index = 0; for my $field (@segments) { next if length ($field) > 1 or $field eq "\x00"; # Only here for an ambiguous char my $str = $cells[$index]; my $chr = substr $target, $index, 1; next if $chr =~ /$str/; print "Mismatch at index $index in $source against $target\n"; } continue { $index += length $field; } } } __DATA__ [TCG]GGGG[AT] TGGGGT [AC][TCG]GGG[AT]

Prints:

Mismatch at index 0 in [TCG]GGGG[AT] against AGGGGC Mismatch at index 5 in [TCG]GGGG[AT] against AGGGGC Mismatch at index 5 in [TCG]GGGG[AT] against TGGGGC Mismatch at index 0 in TGGGGT against AGGGGC Mismatch at index 5 in TGGGGT against AGGGGC Mismatch at index 5 in TGGGGT against TGGGGC Mismatch at index 5 in [AC][TCG]GGG[AT] against AGGGGC Mismatch at index 0 in [AC][TCG]GGG[AT] against TGGGGC Mismatch at index 5 in [AC][TCG]GGG[AT] against TGGGGC

DWIM is Perl's answer to Gödel

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://525407]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (2)
As of 2024-04-25 02:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found