in reply to substring selection from a string on certain qualifying conditions
A few more examples would be good, but this produces the desired output for the two you given:
C:\test>876075 AGRTGAXWXX : [ AGRTGA ] ACRMGAHKMAHGTXX : [ GAHKMAHGT, ACRMGAHKMA ]
#! perl -slw use strict; use Data::Dump qw[ pp ]; sub maxMatches { my $s = shift; my %uniq; LOOP: for my $o ( 0 .. length( $s ) - 10 ) { my( $match ) = $s =~ m[.{$o}([ACGT].{0,8}[ACGT])]; m[$match] and next LOOP for keys %uniq; $uniq{ $match }++; } return keys %uniq; } while( <DATA> ) { chomp; printf "$_ : [ %s ]\n", join ', ', maxMatches( $_ ); } __DATA__ AGRTGAXWXX ACRMGAHKMAHGTXX
|
|---|