in reply to Re^4: How do you match a stretch of at least N characters
in thread How do you match a stretch of at least N characters

> is there a way that I can see which of the 10-mers are consecutive and "paste" them into one larger match?

It's not so easy. You can't paste them together, as that might increase the number of mismatches over the threshold.

But you can change the algorithm totally if you want to find the longest matches. Just move the shorter string alongside the longer one, and then for each position try to find the longest match starting there.

#!/usr/bin/perl use warnings; use strict; use feature qw{ say }; my $stretch = 10; my $mismatches = 1; substr $reference_str, 0, 0, 'x' x (length($small_str) - 1); $reference_str .= 'x' x (length($small_str) - 1); for my $start_pos (0 .. length($reference_str) - length($small_str)) { my $substr = substr $reference_str, $start_pos, length($small_str) +; my ($from, $diffs) = (0, 0); for my $inner_pos (0 .. length($small_str) ) { ++$diffs if substr($substr, $inner_pos, 1) ne substr $small_str, $inner_pos, 1; if ($diffs > $mismatches || $inner_pos == length($small_str) ) + { say join "\n\t", $start_pos + $from + 1 - length $small_str, substr($small_str, $from, $inner_pos - $from), substr($reference_str, $from + $start_pos, $inner_pos +- $from) if $inner_pos - $from >= $stretch; ++$from until (substr $small_str, $from, 1) ne substr($sub +str, $from, 1) || $from > $inner_pos; ++$from; --$diffs; } } }

> was the problem I asked for a question of finding the longest possible match with one mismatch allowed?

Basically, yes.

($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Replies are listed 'Best First'.
Re^6: How do you match a stretch of at least N characters
by Anonymous Monk on Sep 11, 2017 at 17:31 UTC
    I think it does what I needed!
    I will now study the code you kindly provided, thank you very much!