Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use warnings;
- use strict;
- my $input = $ARGV[0];
- my %dict;
- open(INPUT, "$input");
- my $headers = <INPUT>;
- while (my $line = <INPUT>)
- {
- my @currentLine = split(/\t/, $line);
- next if $#currentLine < 0;
- next if $currentLine[4] == 0;
- my $_key = "$currentLine[0]\t$currentLine[1]";
- $dict{$_key}{$currentLine[$#currentLine]} = $currentLine[4];
- }
- close(INPUT);
- my %return_dict;
- foreach my $key (keys %dict)
- {
- my %_hash = %{$dict{$key}};
- my @key_list = keys %_hash;
- my $max_key = pop @key_list;
- foreach (@key_list)
- {
- $max_key = $_ if $_hash{$_} > $_hash{$max_key};
- }
- my $c = calc($_hash{$max_key}, \%_hash);
- print STDOUT "$key\t$c\n";
- }
- sub log2
- {
- my $num1 = shift;
- return log($num1)/log(2);
- }
- sub calc
- {
- my $max = shift;
- my $hashRef = shift;
- my %hash = %{$hashRef};
- my @keylist = keys %hash;
- my $N = $#keylist;
- if ($N == 0)
- {
- return 0
- }
- my $TSMI = 0;
- for my $i (0..$#keylist)
- {
- #print "$hash{$keylist[$i]}\t$max\n";
- my $_sum = (log2($hash{$keylist[$i]})/log2($max) - 1)/$N;
- $TSMI += $_sum;
- }
- return $TSMI;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement