Dear Sirs,

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.

For example in the element of @array = GGGG, it takes
the value of the first element of the array @pwmA (i.e 2)
instead of 0.

That is:

ATGC GGGG
A:2 0  <---------------- the intended value
T:1 1
C:1 1
G:2 5
_____END_____


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?

Thanks so much for your time.

Hope to hear from you again.
Regards,
Edward WIJAYA
SINGAPORE

Code:

#!/usr/bin/perl -w
use strict;

my @array = qw(ATGC GGGG);
my @pwmA   = ( 2, 0, 0, 1 );
my @pwmT   = ( 4, 1, 1, 0 );
my @pwmC   = ( 0, 0, 0, 1 );
my @pwmG   = ( 1, 1, 2, 1 );


my @pvalueA=(); my @pvalueT=(); my @pvalueC=(); my @pvalueG=();

my $lmerSB;
my $scA;
my $scT;
my $scC;
my $scG;
my $valA;
my $valT;
my $valC;
my $valG;


foreach my $lmers (@array)

     {
        my @base_scoreA=();
        my @base_scoreT=();
        my @base_scoreC=();
        my @base_scoreG=();

        
        for (my $k=0; $k<=$#pwmA; $k++)
        {
           chomp($lmers);
           $lmerSB= substr($lmers,$k,1);

           while ($lmerSB =~ /a/ig){
                $valA=$pwmA[$k];
                push(@base_scoreA,$valA);
                $scA = sumArray(@base_scoreA);
                }
           while ($lmerSB =~ /t/ig){
                $valT=$pwmT[$k];
                push(@base_scoreT,$valT);
                $scT = sumArray(@base_scoreT);
            }

           while ($lmerSB =~ /c/ig){
                $valC=$pwmC[$k];
                push(@base_scoreC,$valC);
                $scC = sumArray(@base_scoreC);
                }

           while ($lmerSB =~ /g/ig){
                $valG=$pwmG[$k];
                push(@base_scoreG,$valG);
                $scG = sumArray(@base_scoreG);
                  }
        }
          push(@pvalueA,$scA);
          push(@pvalueT,$scT);
          push(@pvalueC,$scC);
          push(@pvalueG,$scG);
      }


print "@array\n"; print "A: @pvalueA\n"; print "T: @pvalueT\n"; print "C: @pvalueC\n"; print "G: @pvalueG\n";

sub sumArray{
    my @params = @_;
    my $Key;
    my $Total=0;

    foreach $Key (@params) {
        $Total += $Key;
    }
    return $Total;
}

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to