Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
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 examining the Monastery: (5)
As of 2014-12-28 14:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (181 votes), past polls