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:  <%-(-(-(-<


In reply to Re: how do i count the 22 selected di-peptides from a multifasta file separately for each sequence by AnomalousMonk
in thread how do i count the 22 selected di-peptides from a multifasta file separately for each sequence by SOMEN

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.