You may want to have a look at Algorithms on Strings, Trees, and Sequences: Computer Science and Computational Biology, although I haven't got a copy on my desk right now, I'm pretty sure some nice algorithm for this problem is given. Time Warps, String Edits, and Macromolecules: The Theory and Practice of Sequence Comparison might also be worth a try.

Nevertheless I had a go at it, the code is shown below.

Just my 2 cents, -gjb-

use strict; use warnings; $a = 'ATGGAGTCGACGAATTTGAAGAAT'; $b = 'xxxxxxATGGAGyxxxTCGAzxxxxCGAATTTGAAxxwGAAT'; my $prevPos = 0; my $reA = createRegex($a); while ($b =~ /$reA/g) { my $match = $&; my $skipped = substr($`, $prevPos); print "[$skipped]\n"; $a = substr($a, length($match)); last if length($a) == 0; $prevPos = pos($b); $reA = createRegex($a); } sub createRegex { my ($str) = @_; my @chars = split(//, $str); my $firstChar = shift(@chars); my $re = ''; foreach my $char (reverse @chars) { $re = '(?:' . $char . $re . ')?'; } return $firstChar . $re; }

In reply to Re: Complicated pattern match (book recommendations) by gjb
in thread Complicated pattern match by dr_jgbn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.