If I've understood the rules, I *think* this would do the job, but it is a compicated thing to generate testcases for. Do you have any?
#! perl -slw use strict; my $polar = 'DEHAW'; # Uniq E my $charged = 'DGYAH'; # Uniq Y my $hydphb = 'GAFIVL'; # Uniq FIVL my $re_seq = qr[ # Capture ( # start char [$polar$charged] # Must contain motif (?= .* H[$hydphb][$polar][$hydphb]W .* ) # Mustn't contain more than 4 polar chars (?! (?: .* [$polar] ){5} ) # 18-24 polar|hydphb chars # Excludes the start and end chars (Adjust if wrong!) [$polar$hydphb]{18,24} # # end char [$polar$charged] ) ]x; while( <DATA> ) { chomp; print "\nTesting '$_'"; s[\s+#.*$][]; print "matched: '$1'" while m[$re_seq]g; } __DATA__ YVVVVVVVVVVHVEVWVVY # 1 too short YVVVVVVVVVVHVEVWVVVY # min match YVVVVVVVVVVHVEVWVVVVVVVVVY # max match YVVVVVVVVVVHVEVWVVVVVVVVVVY # 1 too long YVVVVVVVVVVHVEVWVVVVVVVVEY # max polar YVVVVVVVVVVHVEVWVVVVVVVEEY # too many polar YVVVVVVVVVVHVYVWVVVY # missing motif
Results
P:\test>junk Testing 'YVVVVVVVVVVHVEVWVVY # 1 too short' Testing 'YVVVVVVVVVVHVEVWVVVY # min match' matched: 'YVVVVVVVVVVHVEVWVVVY' Testing 'YVVVVVVVVVVHVEVWVVVVVVVVVY # max match' matched: 'YVVVVVVVVVVHVEVWVVVVVVVVVY' Testing 'YVVVVVVVVVVHVEVWVVVVVVVVVVY # 1 too long' Testing 'YVVVVVVVVVVHVEVWVVVVVVVVEY # max polar' matched: 'YVVVVVVVVVVHVEVWVVVVVVVVEY' Testing 'YVVVVVVVVVVHVEVWVVVVVVVEEY # too many pol +ar' Testing 'YVVVVVVVVVVHVYVWVVVY # missing moti +f'
I make no predictions about efficiency:)
In reply to Re: Searching for character classes of various quantities AND a motif
by BrowserUk
in thread Searching for character classes of various quantities AND a motif
by seaver
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |