-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_general_stats.pl
executable file
·231 lines (219 loc) · 5.34 KB
/
get_general_stats.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#!/usr/bin/perl
use strict;
use lib '.';
use GTF;
use Eval;
use Getopt::Std;
use vars qw($opt_g $opt_h $opt_v $opt_q $opt_A);
my $MIN_DISP_LEN = 30;
my $MIN_VAL_LEN = 10;
my @GENERAL_SKIP = qw(Correct
Specificity
Sensitivity
Matched);
my %GENERAL_SKIP = (stat => {Correct => 1,
Specificity => 1,
Sensitivity => 1,
Ann_Matched => 1,
Correct_Nucleotides => 1,
Nucleotide_Specificity => 1,
Nucleotide_Sensitivity => 1,
Ann_Matched_Nucleotides => 1},
type => {Exact => 1,
Partial => 1,
Overlap => 1,
Nuc_Overlap => 1,
All_Introns => 1,
Start_Stop => 1,
Splice_Acceptor => 1,
Splice_Donor => 1,
Overlap_80p => 1});
my $Precision = "%.2f";
my %General;
my %Display;
getopts('ghvqA');
my $usage = "$0 <list 1> <list 2> ...
Get general statistics on a list of gtf sets using the Eval package.
Options:
-g: Input files are gtf not lists
-q: Quick load the gtf file. Do not check them for errors.
-A: Do not get stats for alternative splices. (Faster)
-v: Verbose mode
-h: Display this help message and exit
";
if($opt_h){
print $usage;
exit(0);
}
my $Use_ase = 1;
if($opt_A){
$Use_ase = 0;
}
die $usage unless (@ARGV >= 1);
system("date");
my $verbose = $opt_v;
my $Quick_Load = $opt_q;
init_hashes();
my @gtfs;
my @names;
if($verbose){
print STDERR "@ARGV\n";
print STDERR "loading...";
}
my $gtf_mode = 1;
foreach my $arg (@ARGV){
unless($arg =~ /\.g[tf]f$/){
$gtf_mode = 0;
}
}
if($gtf_mode){
$opt_g = 1;
}
foreach my $arg (@ARGV){
my @this_list;
if($opt_g){
push @this_list, GTF::new({gtf_filename => $arg,
no_check => $Quick_Load,
mark_ase => $Use_ase});
}
else{
open(IN,$arg) or die "Couldn't open $arg";
while(my $in = <IN>){
chomp $in;
if($in =~ /\S/){
push @this_list, GTF::new({gtf_filename => $in,
no_check => $Quick_Load,
mark_ase => $Use_ase});
}
}
}
push @gtfs, \@this_list;
push @names, $arg;
}
my $start_time = time;
if($verbose){
print STDERR "done\n";
print STDERR "running...";
}
my @data = Eval::get_statistics(\@gtfs,\@names);
adjust_data_precision(\@data);
print get_general_stats_text(\@data,\@names);
system("date");
if($verbose){
my $end_time = time;
my $total_time = $end_time - $start_time + 1;
Eval::print_time($total_time);
}
exit(0);
sub get_general_stats_text{
my ($data,$names) = @_;
my $report = "";
$report .= "\n\n**General Stats**\n";
$report .= "Predictions:\n\t\t";
for(my $i = 0;$i < $MIN_DISP_LEN;$i++){
$report .= " ";
}
for(my $i = 0; $i <= $#$data;$i++){
my $val = "$$names[$i]";
my $len = length($val);
for(my $i = $len;$i < $MIN_VAL_LEN;$i++){
$val .= " ";
}
$report .= "\t$val";
}
$report .= "\n";
my %order = Eval::get_general_list_struct();
if($#$data >= 0){
foreach my $level (@{$order{Levels}}){
my $level_disp = $level;
$level_disp =~ s/_/ /g;
$report .= "$level_disp\n";
foreach my $type (@{$order{$level}{Type}}){
if(($General{$level}{Type}{$type} == 1) &&
($Display{$level}{Type}{$type} == 1)){
my $type_disp = $type;
$type_disp =~ s/_/ /g;
my $len = length($type_disp);
for(my $i = $len;$i < $MIN_DISP_LEN;$i++){
$type_disp .= " ";
}
$report .= "\t$type_disp\n";
foreach my $stat (@{$order{$level}{Stat}}){
if(($General{$level}{Stat}{$stat} == 1) &&
($Display{$level}{Stat}{$stat} == 1) &&
($stat !~ /Ann_/)){
my $stat_disp = $stat;
$stat_disp =~ s/_/ /g;
$len = length($stat_disp);
for(my $i = $len;$i < $MIN_DISP_LEN;$i++){
$stat_disp .= " ";
}
$report .= "\t\t$stat_disp";
for(my $i = 0; $i <= $#$data;$i++){
my $val = $$data[$i]{$level}{$type}{$stat};
$len = length($val);
for(my $i = $len;$i < $MIN_VAL_LEN;$i++){
$val .= " ";
}
$report .= "\t$val";
}
$report .= "\n";
}
}
}
}
}
}
return $report;
}
sub pad_string{
my ($string,$min_len) = @_;
unless(defined($min_len)){
$min_len = $MIN_VAL_LEN;
}
my $len = length($string);
for(my $i = $len;$i < $min_len;$i++){
$string .= " ";
}
return $string;
}
# init the General and Display hashes
sub init_hashes{
my %order = Eval::get_list_struct();
foreach my $level (@{$order{Levels}}){
foreach my $type (@{$order{$level}{Type}}){
$Display{$level}{Type}{$type} = 1;
$General{$level}{Type}{$type} = 1;
}
foreach my $stat (@{$order{$level}{Stat}}){
$Display{$level}{Stat}{$stat} = 1;
$General{$level}{Stat}{$stat} = 1;
foreach my $skip (@GENERAL_SKIP){
if($stat =~ /$skip/){
$General{$level}{Stat}{$stat} = 0;
}
}
}
}
}
sub adjust_data_precision{
my ($data) = @_;
my %order = Eval::get_list_struct();
for(my $i = 0; $i <= $#$data;$i++){
foreach my $level (@{$order{Levels}}){
foreach my $type (@{$order{$level}{Type}}){
foreach my $stat (@{$order{$level}{Stat}}){
$$data[$i]{$level}{$type}{$stat} =
sprintf $Precision, $$data[$i]{$level}{$type}{$stat};
if(($stat =~ /Sensitivity/) ||
($stat =~ /Specificity/)){
$$data[$i]{$level}{$type}{$stat} .= "%";
}
else{
$$data[$i]{$level}{$type}{$stat} .= " ";
}
}
}
}
}
}