root/lib/shadow_AED.pm

Revision 228, 2.1 kB (checked in by cholt, 5 months ago)

update mpi_iprscan

Line 
1 #------------------------------------------------------------------------
2 #----                          shadow_AED.pm                         ----
3 #------------------------------------------------------------------------
4 package shadow_AED;
5 use strict;
6
7 sub get_abAED{
8     my $hits = shift;
9     my $tran = shift;
10
11     my $sum;
12     foreach my $h (@$hits){
13         $sum += get_AED([$h], $tran);
14     }
15     return 1 if(! @$hits);
16     return $sum/@$hits;
17 }
18
19 sub get_AED {
20    my $hits = shift;
21    my $tran = shift;
22
23    return 1 if(! @{$hits} || ! $tran);
24
25    my ($start, $end) = ($tran->start('query'), $tran->end('query'));
26
27    foreach my $hit (@{$hits}){
28       my ($hs, $he) = ($hit->start('query'), $hit->end('query'));
29
30       $start = $hs if($hs < $start);
31       $end = $he if($he > $end);
32    }
33
34    my $length = $end - $start + 1;
35    my $offset = $start; # do not - 1 so as to give array space coors
36    my @b_seq = map {0} (1..$length);
37    
38    #map out hit space
39    foreach my $hit (@{$hits}){
40       my @hsps = $hit->hsps() if defined $hit->hsps();     
41      
42       foreach my $hsp (@hsps){
43          my $s = $hsp->start('query') - $offset;
44          my $e = $hsp->end('query') - $offset;
45
46          #array space coors
47          die "ERROR: Start value not permited!!\n" if($s >= $length || $s < 0);
48          die "ERROR: End value not permited!!\n" if($e < 0 || $e >= $length);
49
50          @b_seq[$s..$e] = map {1} ($s..$e);
51       }
52    }
53
54    #map out transcript space
55    my @hsps = $tran->hsps() if defined $tran->hsps();     
56    
57    foreach my $hsp (@hsps){
58       my $s = $hsp->start('query') - $offset;
59       my $e = $hsp->end('query') - $offset;
60      
61       #array space coors
62       die "ERROR: Start value not permited!!\n" if($s >= $length || $s < 0);
63       die "ERROR: End value not permited!!\n" if($e < 0 || $e >= $length);
64      
65       foreach my $i ($s..$e){
66          $b_seq[$i] += 2;
67       }
68    }
69    
70    #calculate AED
71    my %index = (0 => 0,
72                 1 => 0,
73                 2 => 0,
74                 3 => 0,
75                );
76
77    foreach my $i (@b_seq){
78       $index{$i}++;
79    }
80
81    my $spec = $index{3}/($index{2} + $index{3}); #specificity
82    my $sens = $index{3}/($index{1} + $index{3}); #sensitivity
83    my $AED = 1 - ($spec + $sens)/2;
84
85    return $AED;
86 }
87
88 1;
Note: See TracBrowser for help on using the browser.