On Thu, Jun 03, 2004 at 01:23:19AM +0800, Edward Wijaya wrote: > The codes below gives this result: > > ATGC GGGG > A:2 2 > T:1 1 > C:1 1 > G:2 5 > _____END_____ > > which I found strange, because the value for first > row of second column should be 0.
> My question is how can I avoid my code > of taking first element of the array, > at the same time giving a zero when the @array strings > doesn't match any of @pwmA element? There are a few problems here. Your program is apparently not doing what you want it to do, but you've not told us what it should be doing, and my knowledge of biology is not sufficient to "just know". You've also guessed at the reason for the problem, and I don't think it is a correct guess. My counter guess is that you need to reset $scA, $scT, $scC and $scG within the main loop. But the names of those variables should be a big red flag. You have four sets of variables each ending in A, T, C and G. Each set is crying out to be a hash instead, and doing so simplifies your program immensely. If my assumptions as to what output you are expecting, and why, are correct, the following program should do what you want in a much more understandable and maintainable fashion. I hope you get some useful ideas from it. #!/usr/bin/perl -w use strict; my @array = qw(ATGC GGGG); my %pwm = ( A => [ 2, 0, 0, 1 ], T => [ 4, 1, 1, 0 ], C => [ 0, 0, 0, 1 ], G => [ 1, 1, 2, 1 ], ); my %pvalue; for my $lmers (@array) { my %sc; for my $k (0 .. (length $lmers) - 1) { my $lmerSB = uc substr($lmers, $k, 1); $sc{$lmerSB} += $pwm{$lmerSB}[$k]; } push @{$pvalue{$_}}, $sc{$_} || 0 for keys %pwm; } print "@array\n"; print "$_: @{$pvalue{$_}}\n" for qw( A T C G ); -- Paul Johnson - [EMAIL PROTECTED] http://www.pjcj.net -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>