Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
summarize feature type lengths from a GFF3 file
- Loading branch information
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/usr/bin/perl -w | ||
use strict; | ||
use List::Util qw(sum); | ||
use Statistics::Descriptive; | ||
|
||
# this script expects a GFF file as input | ||
# and that it is GFF3 with Parent and ID tags | ||
|
||
my $file = shift || die "cannot run without input file"; | ||
|
||
open(my $fh => $file) || die "cannot open $file\n"; | ||
my %types; | ||
while (<$fh>) { | ||
next if /^\#/ || /^\s+$/;; | ||
my ($chrom,$src,$type,$start,$end,$score,$strand,$frame,$info) = split; | ||
my %info = map { split(/=/,$_) } split(/;/,$info); | ||
my ($parent) = ($info{'Parent'} || $info{'ID'} ); | ||
$types{$type}->{$parent} += abs($end - $start); | ||
} | ||
|
||
for my $type ( keys %types ) { | ||
my @lens; | ||
for my $gene ( keys %{$types{$type}} ) { | ||
push @lens, $types{$type}->{$gene}; | ||
} | ||
my $stats = Statistics::Descriptive::Full->new(); | ||
$stats->add_data(@lens); | ||
printf "%s mean=%.2f median=%d total_count=%d total_length=%d\n",$type, $stats->mean, $stats->median, $stats->count,$stats->sum; | ||
} |