Dear Rob, I was trying your script with this set of strings: __DATA__ CAGGTG CAGGTG But how come it returns: $VAR1 = { 'A' => [ 0, '0.5' ], 'T' => [ 0, 0, 0, 0, '0.5' ], 'C' => [ '0.5' ], 'G' => [ 0, 0, '0.5', '0.5', 0, '0.5' ] };
Instead of the correct: $VAR1 = { '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' ] }; Hope to hear from you again. Regards, Edward WIJAYA SINGAPORE ________________________________ From: Rob Dixon [mailto:[EMAIL PROTECTED] Sent: Wed 9/6/2006 8:14 PM To: beginners@perl.org Subject: Re: Position Weight Matrix of Set of Strings with Perl use strict; use warnings; my %pwm; while (<DATA>) { my $col = 0; foreach my $c (/\S/g) { $pwm{$c}[$col++]++; } } foreach my $freq (values %pwm) { $_ = $_ ? $_ / keys %pwm : 0 foreach @$freq; } use Data::Dumper; print Dumper \%pwm; __END__ AAA ATG TTT GTC OUTPUT $VAR1 = { 'A' => [ '0.5', '0.25', '0.25' ], 'T' => [ '0.25', '0.75', '0.25' ], 'C' => [ 0, 0, '0.25' ], 'G' => [ '0.25', 0, '0.25' ] }; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response> ------------ Institute For Infocomm Research - Disclaimer ------------- This email is confidential and may be privileged. If you are not the intended recipient, please delete it and notify us immediately. Please do not copy or use it for any purpose, or disclose its contents to any other person. Thank you. -------------------------------------------------------- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>