Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: mismatching characters in dna sequence

by Eliya (Vicar)
on Dec 30, 2011 at 03:26 UTC ( [id://945592]=note: print w/replies, xml ) Need Help??


in reply to mismatching characters in dna sequence

Clever mapping of the characters in one of the strings could work around the problems with the XOR approach.  For example, using tr/ATCG/HRDZ/:

my %change; # reverse lookup table my @t = qw(A T C G); for my $t1 (@t) { for my $t2 (@t) { my $t = $t2; $t =~ tr/ATCG/HRDZ/; $change{ $t1 ^ $t } = "$t1->$t2"; } } sub diff { my ($target, $str) = @_; $str =~ tr/ATCG/HRDZ/; my $diff = $target ^ $str; while ($diff =~ /([^\x09\x06\x07\x1d])/g) { printf " %d: %s\n", pos($diff), $change{$1}; } } my $target = "ATTCCGGG"; for (qw(ATTGCGGG ATACCGGC)) { print "\n$target\n$_\n"; diff($target, $_); } __END__ ATTCCGGG ATTGCGGG 4: C->G ATTCCGGG ATACCGGC 3: T->A 8: G->C

The reverse lookup table just needs to be set up once, and the remaining operations (string bit operation, tr///, m//g) should all be pretty fast.

(As the keys in the lookup table are integers < 256, you could in theory also set up an array, and use the xor value as the index.)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2024-04-24 09:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found