Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: how do i count the 22 selected di-peptides from a multifasta file separately for each sequence

by AnomalousMonk (Archbishop)
on Apr 26, 2015 at 14:54 UTC ( [id://1124755]=note: print w/replies, xml ) Need Help??


in reply to how do i count the 22 selected di-peptides from a multifasta file separately for each sequence

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

  • Comment on Re: how do i count the 22 selected di-peptides from a multifasta file separately for each sequence
  • Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1124755]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-04-24 05:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found