If you really want to look for any individual common characters between all possible pairs of 2000 sequences then you just gotta do the work, and there is a lot of work to do!

It may help to tell us why you want to do that. There may be a better solution to your problem than the brute force search implied so far.

You may find this code interesting however:

use strict; use warnings; my @sequences = qw(ACGCATTCA ACTGGATAC TCAGCCATC); my %matches; for my $outer (0 .. $#sequences - 1) { for my $inner ($outer + 1 .. $#sequences) { my $mask = $sequences[$outer] ^ $sequences[$inner]; next if index ($mask, "\0") == -1; # No matching characters $mask =~ tr/\0/\xff/c; $mask |= $sequences[$outer]; $mask =~ tr/\xff/./; push @{$matches{$mask}}, [$outer + 1, $inner + 1]; } } for my $match (sort keys %matches) { print "$match pattern between ", join (', ', map {"$_->[0] and $_->[1]"} @{$matches{$match}}), "\n"; }

Prints:

.C....... pattern between 1 and 3 .C.G....C pattern between 2 and 3 AC....T.. pattern between 1 and 2

DWIM is Perl's answer to Gödel

In reply to Re: pattern finding algorithm by GrandFather
in thread pattern finding algorithm by kdt2006

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.