Perl: the Markov chain saw PerlMonks

### Re^2: How do you match a stretch of at least N characters

 on Sep 12, 2017 at 19:27 UTC ( #1199225=note: print w/replies, xml ) Need Help??

Original post deleted. What I posted was completely wrong.

You're supposed to <strike></strike> out the wrong answer not delete

• Comment on Re^2: How do you match a stretch of at least N characters

Replies are listed 'Best First'.
Re^3: How do you match a stretch of at least N characters
by paisani (Initiate) on Sep 13, 2017 at 20:43 UTC

Is this what you were looking for? The longest matching DNA string? You can save the max length found below to get your result.

Found match of length (102) at position(506, 0):

AAATTGGTGTATATGAAAGACCTCGACGCTATTTAGAAAGAGAGAGCAATATTTCAAGAATGCATGCGTCAATTTTACGCAGACTATCTTTCTAGGGTTAAT
AAATTGGTGTATATGAAAGACCTCGACGCTATTTAGAAAGAGAGAGCAATATTTCAAGAATGCATGCGTCAATTTTACGCAGACTATCTTTCTAGGGTTAAA

```my \$i=-1;
while(++\$i < length(\$reference_str)) {
my \$j=-1;
while(++\$j < length(\$small_str)) {

my \$length = 9;
my \$match=undef;
while ( \$i+\$length < length(\$reference_str) and
\$j+\$length < length(\$small_str) and
compareSnippet(\$i, \$j, ++\$length) ) {
\$match++;
}
if ( \$match) {
\$length--;
print "Found match of length (\$length) at position(\$i, \$j):
+\n";
print substr(\$reference_str, \$i, \$length) . "\n";
print substr(\$small_str, \$j, \$length). "\n";
\$i+= \$length;
\$j+= \$length;
next;
}
}
}

sub compareSnippet {
my ( \$pos_i, \$pos_j, \$length) = @_;
my \$ref = substr(\$reference_str, \$pos_i, \$length); my @ref_arr = sp
+lit('', \$ref);
my \$small = substr(\$small_str, \$pos_j, \$length); my @small_arr = sp
+lit('', \$small);

return undef if length(\$ref) < \$length or length(\$small) < \$length;

return equal(\@ref_arr, \@small_arr);

}

sub equal {
my (\$first, \$second) = @_;
my \$mismatch=0;
foreach my \$i (0..(@\$first-1)) {
\$mismatch++ if \$first->[\$i] ne \$second->[\$i];
return undef if \$mismatch > 1;
}
# print "Woo! (@\$first, @\$second)\n" if \$mismatch == 0;
return 1;
}

Create A New User
Node Status?
node history
Node Type: note [id://1199225]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2017-11-23 00:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
In order to be able to say "I know Perl", you must have:

Results (327 votes). Check out past polls.

Notices?