note
johngg
<p>Just in case you need offsets as well, here's a solution for that.</p>
<code>
use strict;
use warnings;
use feature qw{ say };
my $string
= q{AAATTTAGTTCTTAAGGCTGACATCGGTTTACGTCAGCGTTACCCCCCAAGTTATTGGGGACTTT};
my @matches;
push @matches, [ length $1, $1, $-[ 0 ] ]
while $string =~ m{(([ACGT])\2+)}g;
say qq{Found $_->[ 1 ], length $_->[ 0 ] at offset $_->[ 2 ]} for
sort { $b->[ 0 ] <=> $a->[ 0 ]
||
$a->[ 1 ] cmp $b->[ 1 ]
||
$a->[ 2 ] <=> $b->[ 2 ]
} @matches;
</code>
<p>The output, sorted ascending offset within ascending letter within descending length.</p>
<code>
Found CCCCCC, length 6 at offset 42
Found GGGG, length 4 at offset 56
Found AAA, length 3 at offset 0
Found TTT, length 3 at offset 3
Found TTT, length 3 at offset 27
Found TTT, length 3 at offset 62
Found AA, length 2 at offset 13
Found AA, length 2 at offset 48
Found GG, length 2 at offset 15
Found GG, length 2 at offset 25
Found TT, length 2 at offset 8
Found TT, length 2 at offset 11
Found TT, length 2 at offset 39
Found TT, length 2 at offset 51
Found TT, length 2 at offset 54
</code>
<p>I hope this is helpful.</p>
<!-- Node text goes above. Div tags should contain sig only -->
<div class="pmsig"><div class="pmsig-401112">
<p>Cheers,</p><p>JohnGG</p>
</div></div>
11122267
11122267