Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: How can I count the number and kinds of letters at 1st, 2nd and 3rd positions of 3-letter words in a string?

by brx (Pilgrim)
on Apr 25, 2012 at 17:52 UTC ( #967128=note: print w/ replies, xml ) Need Help??


in reply to How can I count the number and kinds of letters at 1st, 2nd and 3rd positions of 3-letter words in a string?

First, read davido's answer: Re: How can I count the number and kinds of letters at 1st, 2nd and 3rd positions of 3-letter words in a string?

Here, I put some code, as easy as possible (I hope) without complexe data structure:

#!perl use strict; use warnings; my $seq = "ATCGGCGCCTAT" ; my (%first,%second,%third); #perlre my @trilet = $seq =~ /.../g; #perlsyn LOOP foreach my $letter ('A','T','G','C') { #init $first{ $letter }=0; $second{ $letter }=0; $third{ $letter }=0; } foreach my $tri (@trilet) { #perlfunc : substr $first{ substr $tri,0,1 }++; $second{ substr $tri,1,1 }++; $third{ substr $tri,2,1 }++; } foreach my $letter ('A','T','G','C') { print "$letter=$first{$letter}; "; } print "\n"; foreach my $letter ('A','T','G','C') { print "$letter=$second{$letter}; "; } print "\n"; foreach my $letter ('A','T','G','C') { print "$letter=$third{$letter}; "; } print "\n";


Comment on Re: How can I count the number and kinds of letters at 1st, 2nd and 3rd positions of 3-letter words in a string?
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2015-07-07 04:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (87 votes), past polls