On 09/06/2006 05:41 AM, Mumia W. wrote:
On 09/06/2006 04:02 AM, Wijaya Edward wrote:
Dear Experts,
I am looking for a really efficient way to compute a position weight
matrix (PWM) [...]
Although I'm sure that smarter posters than I will [...]
do it right.
Ugh, I forgot about Wijaya's requirement that the PWM be
calculated in probabilities, and I also forgot that the
lengths of the base-pair strings can be different. Here is my
updated code:
use strict;
use warnings;
use Data::Dumper;
local our @deep;
local $" = ', ';
my $length = 5;
my @data = qw(AAA ATG TTT GTC);
@data = map [ split // ], @data;
my (%hash);
for my $entry (@data) {
*deep = $entry;
for my $nx (0..$#deep) {
$hash{$deep[$nx]}[$nx]++;
}
}
my $count = keys %hash;
while (my ($key, $values) = each %hash) {
$#{$values} = $length;
@$values = map defined $_ ? $_ / ($count) : 0, @$values;
@$values = map sprintf('%4.2f',$_), @$values;
print "$key => [ @{$hash{$key}} ]\n";
}
__END__
Output:
A => [ 0.50, 0.25, 0.25, 0.00, 0.00, 0.00 ]
T => [ 0.25, 0.75, 0.25, 0.00, 0.00, 0.00 ]
C => [ 0.00, 0.00, 0.25, 0.00, 0.00, 0.00 ]
G => [ 0.25, 0.00, 0.25, 0.00, 0.00, 0.00 ]
End output.
Note: I use $length to set the maximal array index value.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>