It seems to me that the count of individual di-peptides in each sequence does not matter, but only the number of unique (overlapping) di-peptides found. If I understand this correctly, here's another approach, including some approaches from other replies (with some debug statements):
c:\@Work\Perl\monks>perl -wMstrict -le
"use Data::Dump;
;;
use constant DIPEPS => qw(AA AL DA DE DV VD DW QD SD HD ED DY VE EN
+ EI KE NV VP FV SS WK KK);
use constant N_DIPEPS => scalar DIPEPS;
;;
my ($dipep) =
map qr{ (?i) (?: $_) }xms,
join '|',
DIPEPS
;
print $dipep;
;;
my %count;
for my $seq (qw(AAALVDENEC AATLVDEGDG)) {
$count{$seq}{$1} = 1 while $seq =~ m{ (?= ($dipep)) }xmsg;
}
dd \%count;
;;
for my $seq (keys %count) {
my $sum = keys %{ $count{$seq} };
my $abs = N_DIPEPS - $sum;
print qq{$seq: sum = $sum, abs = $abs};
}
"
(?^msx: (?i) (?: AA|AL|DA|DE|DV|VD|DW|QD|SD|HD|ED|DY|VE|EN|EI|KE|NV|VP
+|FV|SS|WK|KK) )
{
AAALVDENEC => { AA => 1, AL => 1, DE => 1, EN => 1, VD => 1 },
AATLVDEGDG => { AA => 1, DE => 1, VD => 1 },
}
AAALVDENEC: sum = 5, abs = 17
AATLVDEGDG: sum = 3, abs = 19
Update: And another approach, based on the same (mis?)understanding that only the number of unique di-peptides matter and not their individual counts:
c:\@Work\Perl\monks>perl -wMstrict -le
"use List::MoreUtils qw(uniq);
use Data::Dump;
;;
use constant DIPEPS => qw(AA AL DA DE DV VD DW QD SD HD ED DY VE EN
+ EI KE NV VP FV SS WK KK);
use constant N_DIPEPS => scalar DIPEPS;
;;
my ($dipep) =
map qr{ (?i) (?: $_) }xms,
join '|',
DIPEPS
;
;;
my %count;
for my $seq (qw(AAALVDENEC AATLVDEGDG)) {
$count{$seq} = uniq $seq =~ m{ (?= ($dipep)) }xmsg;
}
dd \%count;
;;
for my $seq (keys %count) {
my $sum = $count{$seq};
my $abs = N_DIPEPS - $sum;
print qq{$seq: sum = $sum, abs = $abs};
}
"
{ AAALVDENEC => 5, AATLVDEGDG => 3 }
AAALVDENEC: sum = 5, abs = 17
AATLVDEGDG: sum = 3, abs = 19
Give a man a fish: <%-(-(-(-<