Hi Perlmonk,
This has reference to the question "How can I count the number and kinds of letters at 1st, 2nd and 3rd positions of 3-letter words in a string?" asked by me on 25 April 2012. Thank you for providing the code. In fact, I was interested in getting the numbers of A,T, G and C at first positions (in all 3-letter words) as scalar variables $A1, $T1, $G1 and $C1, respectively under the print command; similarly for 2nd position as $A2, $T2, $G2 and $C2 and for 3rd positions as $A3, $T3, $G3 and $C3, respectively. I want to apply these scalar values further in some basic arithmetic operations. So I modified your code to suit my needs. But I have got very erroneous results from the modified code even trying for 6 hours. In the mean time I have read the pages 60, 76, 111, 106,171, 329 for using 'foreach loop' in the book "Beginning Perl for Bioinformatics" but I didn't get any clue in those pages. I didn't write "use strict" at the beginning of the code intentionally. I am really confused where I am making the mistake in the code. Can you help me to sort out this problem?
My modified code goes as:
#!usr/bin/perl-w $seq="ATCGGCGCCTAT"; #Line 2 # Line 3 perlre @trilet= $seq =~ /.../g; # Line 5 perlsyn LOOP foreach $A1('A','T','G','C'){$first{$A1}=0;} foreach $A2('A','T','G','C'){$second{$A2}=0;} foreach $A3('A','T','G','C'){$third{$A3}=0;} foreach $T1('A','T','G','C' ){$first{$T1}=0;} foreach $T2('A','T','G','C'){$second{$T2}=0;} foreach $T3('A','T','G','C'){$third{$T3}=0;} foreach $G1('A','T','G','C'){$first{$G1}=0;} foreach $G2('A','T','G','C'){$second{$G2}=0;} foreach $G3('A','T','G','C'){$third{$G3}=0;} foreach $C1('A','T','G','C'){$first{$C1}=0;} foreach $C2('A','T','G','C'){$second{$C2}=0;} foreach $C3('A','T','G','C'){$third{$C3}=0;} foreach $tri(@trilet){ # Line 18 # Line 19 perlfunc: substr $first{substr $tri,0,1}++;# Line 20 $second{substr $tri,0,1}++;# Line 21 $third{substr $tri,0,1}++;} foreach $A1('A','T','G','C'){print"$A1=$first{$A1};\n";} foreach $A2('A','T','G','C'){print"$A2=$first{$A2};\n";} foreach $A3('A','T','G','C'){print"$A3=$first{$A3};\n";} foreach $T1('A','T','G','C'){print"$T1=$first{$T1};\n";} foreach $T2('A','T','G','C'){print"$T2=$first{$T2};\n";} foreach $T3('A','T','G','C'){print"$T3=$first{$T3};\n";} foreach $G1('A','T','G','C'){print"$G1=$first{$G1};\n";} foreach $G2('A','T','G','C'){print"$G2=$first{$G2};\n";} foreach $G3('A','T','G','C'){print"$G3=$first{$G3};\n";} foreach $C1('A','T','G','C'){print"$C1=$first{$C1};\n";} foreach $C2('A','T','G','C'){print"$C2=$first{$C2};\n";} foreach $C3('A','T','G','C'){print"$C3=$first{$C3};\n";} exit;
My Results:
Microsoft Windows [Version 6.1.7600] Copyright (c) 2009 Microsoft Corporation. All rights reserved. C:\Users\ xyz>cd desktop C:\Users\ xyz\Desktop>k3.pl A=1; T=1; G=2; C=0; A=1; T=1; G=2; C=0; A=1; T=1; G=2; C=0; A=1; T=1; G=2; C=0; A=1; T=1; G=2; C=0; A=1; T=1; G=2; C=0; A=1; T=1; G=2; C=0; A=1; T=1; G=2; C=0; A=1; T=1; G=2; C=0; A=1; T=1; G=2; C=0; A=1; T=1; G=2; C=0; A=1; T=1; G=2; C=0; C:\Users\ xyz\Desktop>
In reply to Ref: How can I count the number and kinds of letters at 1st, 2nd and 3rd positions of 3-letter words in a string? by supriyoch_2008
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |