Re: Mismatch Positions of Two Ambiguous Strings



Wijaya Edward wrote:
Hi,
I have two strings that I want to compute the number of mismatches between them. These two strings are of the "same" size. Let's call them 'source' string and 'target' string. Now, the problem is that the 'source' and 'target' string may come in ambiguous form, meaning that in one position they may contain more than 1 (upto 4) characters. The ambiguous position is marked with square bracketed [ATCG] region. The example is as follows:

Example 1 (where the source is ambiguous):

my $source1 = '[TCG]GGGG[AT]'; # ambiguous
my $target1 = 'AGGGGC'; # No of mismatch = 2 on position 1 and 6
my $target2 = 'TGGGGC'; # No of mismatch = 1 on position 6 only


Example 2 (where the source is NOT ambiguous):

my $source2 = 'TGGGGT'; # not-ambiguous
my $target1 = 'AGGGGC'; # No of mismatch = 2 on position 1 and 6
my $target3 = 'TGGGGT'; # No of mismatch = 0 all position matches


Example 3 (where both source and target are ambiguous)
my $source1 = '[TCG]GGGG[AT]'; # ambiguous
my $target1 = 'AGGGG[CT]'; # ambiguous, no of mismatch = 1 only at position 1

For example I can use bitwise operator to do it.

I have no problem when dealing with Example 1 and 2 above.
But I'm stuck with example 3, where both source and target is ambiguous.


Here is the current snippet I have, which doesn't do the job:

__BEGIN__
sub mismatches {
my($source, $target) = @_;
my @sparts = ($source =~ /(\[.*?\]|.)/g);
my @tparts = ($target =~ /(\[.*?\]|.)/g);
scalar grep $tparts[$_] !~ /^$sparts[$_]/, 0 .. $#sparts;
}
__END__

Where did I go wrong? I humbly seek advice.

Regards
Edward WIJAYA


two negatives - use only the first!

scalar grep $tparts[$_] !~ /$sparts[$_]/, 0 .. $#sparts;

.. . . from a grass shack on the island of Tongatapu

.



Relevant Pages

  • Re: How find Pearl Harbor? Questions
    ... radio beacon of station KGMB 1320 KHz from Honolulu. ... carrier position 230 miles away from the target, ... the island was visible once they went feet dry. ... these have clouds building/growing over them ...
    (sci.military.naval)
  • Re: The Double 3D Extravaganza of October
    ... into a target you should drop the Quaker just before impact. ... to hit small targets like island defence posts with it. ... people will find that out because the GUI in Carrier Command is so damned ... I don't want to get into another F-16 Combat Pilot discussion with ...
    (comp.sys.amiga.games)
  • OT: Speaking of killing so many civilians
    ... "The ROE (rule of engagement) was to kill all military age males on ... That target, an island on a canal in the northern Salahuddin province, ...
    (alt.guitar.amps)
  • Re: The Wikipedia FAQK
    ... of command and control for the next island which was scheduled to be ... Perhaps it neglects to mention that because it's not true? ... the wiki article has a link to the minutes of one of the Target ...
    (rec.arts.sf.written)