in reply to Re^4: Position Weight Matrix of Set of Strings
in thread Position Weight Matrix of Set of Strings
Try this
#! perl -slw use strict; use Data::Dumper; sub get_pwm { my @data = @_; my $l = length( $data[0] ); my %pwm; 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 = ( 'CAGGTG', 'CAGGTG' ); my $res = get_pwm(@inst); print "$_ => @{ $res->{ $_ } }" for keys %{ $res }; __END__ c:\test>530623 A => 0 1 0 0 0 0 T => 0 0 0 0 1 0 C => 1 0 0 0 0 0 G => 0 0 1 1 0 1
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: Position Weight Matrix of Set of Strings
by monkfan (Curate) on Sep 19, 2006 at 01:05 UTC | |
by BrowserUk (Patriarch) on Sep 19, 2006 at 01:23 UTC |