"Aiguo Li" <[EMAIL PROTECTED]> wrote in message ... > Probe id Treat1 Treat2 > AffX-BioB-5_at (2p +M)/4 =2 (2*3+0)/3=2 > FFX-BioB-M_at (2*3+0)/4 =1.7 (2*3+0)/3=2 > AFFX-BioB-3_at (2*2+0)/4 =1 (2*2+0)/3=1.3 > AFFX-BioC-5_at (2*2+1)/4 =1.25 (2*1+1)/3=1 > AFFX-BioC-3_at (2*1+1)/4 = 0.75 (2*2+1)/3=1.7 > > The denominator is always the # of replicates in each treatment.
Excellent. This is *much* clearer. The following appears to do what you want. See comments about your code below. --------------- #!/usr/bin/perl use warnings; use strict; while (<DATA>) { next unless /^A/; my @data = split; print join("\t", $data[0], PA(@data[1..4]), PA(@data[5..7])), "\n"; } sub PA { my @treat = @_; my $m = count('M', @treat); my $p = count('P', @treat); return (2*$p + $m) / @treat; } sub count { my $search = shift; return scalar grep { $_ eq $search } @_; } __DATA__ Replicates 1 1 1 1 2 2 2 AFFX-BioB-5_at P P P P P P P AFFX-BioB-M_at P P P P P P P [snip] --------------- > #!usr/bin/perl -w > > use strict; > use warnings; You don't need both -w and use warnings. I read that "use warnings;" is slightly preferred. > my @split; > my @replicate = ( 5, 3); > my @ratio; > my $p=0; > my $m=0; > my $a=0; > my $rep=0; > my $item; > my $ratio; There are way too many variables here. As a general rule you want to declare the variable right before it's used. You want it in the smallest scope possible so that you avoid having orphaned variables (you declared it but forgot to use it). Do not declare $a; it has special meaning. See "perldoc -f sort". > open (FILE, "<C:/replicate.txt") or die "Can't open file: $!"; > > > while( <FILE> ) > { > #print; > chomp; > @split = split (/\t/, $_); You are splitting on \t. The data I received were delimited by spaces. > push (@split, $_); First you split and store the results in @split. You then add the entire record to @split also. Is this really necessary? > #print "$_ \n"; > foreach $rep (@replicate) @replicate contains 5 and 3. If your code worked, shouldn't it contained 3 and 4? Doesn't this denote "the # of replicates in each treatment." > { > for(my $i=1; $i<=$rep; $i++) > { > push (@split, $_); > SWITCH: > if ($_ =~ "P") {$p++; last SWITCH;} > if ($_ =~ "M") {$m++; last SWITCH;} > if ($_ =~ "A") {$a++; last SWITCH;} Shouldn't this be next instead of last? > } > print $p, $m, $a; > @ratio = (($p*2)+$m)/$rep; You print these values but never print the result of the equation. You are also setting an array equal to the result of the equation. You should print the results of the equation or store it in a *scalar* not an array. > > > } > } > > close FILE; I would not solve this problem as you attempted here. Please see above. Good luck, ZO -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>