-
Notifications
You must be signed in to change notification settings - Fork 0
/
correlation.pl
119 lines (95 loc) · 2.07 KB
/
correlation.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/perl
=head1 $0
=head1 SYNOPSIS
correlation.pl gs system
Outputs the Pearson correlation.
Example:
$ ./correlation.pl gs sys
Author: Eneko Agirre, Aitor Gonzalez-Agirre
Dec. 31, 2012
=cut
use Getopt::Long qw(:config auto_help);
use Pod::Usage;
use warnings;
use strict;
use Math::Complex;
pod2usage if $#ARGV != 1 ;
if (-e $ARGV[1]) {
my $continue = 0;
my %filtered;
my $do = 0;
my %a ;
my %b ;
my %c ;
open(I,$ARGV[0]) or die $! ;
my $filter = 0;
my $i = 0;
while (<I>) {
chomp ;
next if /^\#/ ;
if ($_ eq "") {
$filter++;
$filtered{$filter} = 1;
}
else {
my @fields = (split(/\t/,$_)) ;
my $score = $fields[4] ;
warn "wrong range of score in gold standard: $score\n" if ($score > 5) or ($score < 0) ;
$a{$i++} = $score ;
$filter++;
}
}
close(I) ;
my $j = 0 ;
open(I,$ARGV[1]) or die $! ;
my $line = 1;
while (<I>) {
if(!defined($filtered{$line})) {
chomp ;
next if /^\#/ ;
my @fields = (split(/\s+/,$_)) ;
my ($score) = @fields ;
$b{$j} = $score ;
$c{$j} = 100;
$continue = 1;
$j++;
}
$line++;
}
close(I) ;
if ($continue == 1) {
my $sumw=0;
my $sumwy=0;
for(my $y = 0; $y < $i; $y++) {
$sumwy = $sumwy + (100 * $a{$y});
$sumw = $sumw + 100;
}
my $meanyw = $sumwy/$sumw;
my $sumwx=0;
for(my $x = 0; $x < $i; $x++) {
$sumwx = $sumwx + ($c{$x} * $b{$x});
}
my $meanxw = $sumwx/$sumw;
my $sumwxy = 0;
for(my $x = 0; $x < $i; $x++) {
$sumwxy = $sumwxy + $c{$x}*($b{$x} - $meanxw)*($a{$x} - $meanyw);
}
my $covxyw = $sumwxy/$sumw;
my $sumwxx = 0;
for(my $x = 0; $x < $i; $x++) {
$sumwxx = $sumwxx + $c{$x}*($b{$x} - $meanxw)*($b{$x} - $meanxw);
}
my $covxxw = $sumwxx/$sumw;
my $sumwyy = 0;
for(my $x = 0; $x < $i; $x++) {
$sumwyy = $sumwyy + $c{$x}*($a{$x} - $meanyw)*($a{$x} - $meanyw);
}
my $covyyw = $sumwyy/$sumw;
my $corrxyw = $covxyw/sqrt($covxxw*$covyyw);
printf "Pearson: %.5f\n", $corrxyw ;
}
}
else{
printf "Pearson: nan\n";
exit(1);
}