in reply to Re^6: Position Weight Matrix of Set of Strings
in thread Position Weight Matrix of Set of Strings

Better?

#! perl -slw use strict; use Data::Dumper; sub get_pwm { my @data = @_; my $l = length( $data[0] ); my %pwm = map{ $_ => [ (0) x length( $_[ 0 ] ) ] } qw[ A C G T ]; foreach my $line (@data) { ++$pwm{ substr $line, $_, 1 }[$_] for 0 .. $l - 1; } my $n = @data; @$_ = map { $_ ? $_ / $n : 0 } @{ $_ }[ 0 .. $l - 1 ] for values +%pwm; return \%pwm; } my @inst = ( 'GGTGTGCC', 'GCTGTGGG', 'GGTGGGCC' ); my $res = get_pwm(@inst); printf "%1s => [ %s ]\n", $_ => join ' ', map{ sprintf '%5.2f', $_ } @{ $res->{ $_ } } for keys %{ $res }; __END__ c:\test>530623.pl A => [ 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 ] T => [ 0.00 0.00 1.00 0.00 0.67 0.00 0.00 0.00 ] C => [ 0.00 0.33 0.00 0.00 0.00 0.00 0.67 0.67 ] G => [ 1.00 0.67 0.00 1.00 0.33 1.00 0.33 0.33 ]

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.