-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathget_intergenic.pl
More file actions
executable file
·83 lines (71 loc) · 1.97 KB
/
Copy pathget_intergenic.pl
File metadata and controls
executable file
·83 lines (71 loc) · 1.97 KB
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
#!/usr/bin/env perl
use strict;
use warnings;
use Getopt::Long;
use Sort::Naturally;
use Statistics::Descriptive;
my $usage = "
Get intergenic distances from a GFF3 file
Prints to file <INPUT>.intergenic and summary stats to STDOUT
USAGE: get_intergenic.pl [options] <GFFFILE>
OPTIONS:
-s|--scaffold : prints mean intergenic dist per scaffold
-h|--help : this message\n
";
my ($scaffold,$help);
GetOptions (
's|scaffold' => \$scaffold,
'h|help' => \$help
);
die $usage if $help;
die $usage if @ARGV == 0;
open (my $OUT, ">$ARGV[0].intergenic") or die $!;
my %h;
open (my $GFF, $ARGV[0]) or die $!;
while (<$GFF>) {
chomp;
my @F = split (/\s+/, $_);
if ($F[2] =~ "gene") {
push ( @{$h{$F[0]}{STARTS}}, $F[3] );
push ( @{$h{$F[0]}{ENDS}}, $F[4] );
} else {
next;
}
}
close $GFF;
my %scaffold;
my @distances;
my $stat = Statistics::Descriptive::Full->new();
foreach my $chrom (nsort keys %h) {
my @STARTS = @{$h{$chrom}{STARTS}};
my @ENDS = @{$h{$chrom}{ENDS}};
#print "$chrom\n@STARTS\n@ENDS\n";
for my $i (1 .. $#STARTS) {
my $distance = $STARTS[$i] - $ENDS[($i-1)];
if ($scaffold) {
push ( @{$scaffold{$chrom}}, $distance ) unless $distance < 0;
} else {
print $OUT "$chrom\t$distance\n" unless $distance < 0;
push (@distances, $distance) unless $distance < 0;
}
}
}
if ($scaffold) {
foreach my $chrom (nsort keys %scaffold) {
my @a = @{$scaffold{$chrom}};
my $mean = sum(@a)/scalar(@a);
print $OUT "$chrom\t$mean\n";
}
}
close $OUT;
## stats
$stat->add_data(@distances);
print STDERR "[INFO] Input file: $ARGV[0]\n";
print STDERR "[INFO] Count: ".$stat->count()."\n";
print STDERR "[INFO] Mean: ".$stat->mean()."\n";
print STDERR "[INFO] Standard deviation: ".$stat->standard_deviation()."\n";
print STDERR "[INFO] Median: ".$stat->median()."\n";
print STDERR "[INFO] Min: ".$stat->min()."\n";
print STDERR "[INFO] Max: ".$stat->max()."\n";
print STDERR "[INFO] Finished on ".`date`."\n";
__END__