#!/usr/bin/perl # Time-stamp: <2005-03-21 16:21:06 kasper> use warnings; use strict; use Getopt::Long; use constant USAGE =>< Sum only features with specified feature. EXAMPLES: sumgff.pl file.gff output.txt cat file.gff | sumgff.pl output.txt DEPENDENCIES: None. AUTHOR: Kasper Munch COPYRIGHT: This program is free software. You may copy, modify, and redistribute it under the same terms as Perl itself. END my $help = 0; my $feature = '.*'; GetOptions( "help" => \$help, "feature=s" => \$feature, ) or die USAGE; $help and die USAGE; @ARGV = ('-') unless @ARGV; my $input = shift @ARGV; open my $in, "$input" or die "$input: $!\n"; @ARGV = ('>&STDOUT') unless @ARGV; my $output = shift @ARGV; open my $out, ">$output" or die "$output: $!\n"; my $sum = 0; while (my $line = <$in>) { chomp $line; my @gff = split /\t/, $line; if ($gff[2] =~ /^$feature$/) { $sum += $gff[4] - $gff[3] + 1; } } print "$sum\n"; =head1 SYNOPSIS: sumgff.pl [OPTIONS] [ infile [outfile] ] =head1 DESCRIPTION: This script sums the length of gfflines in a file or stream. =head1 OPTIONS: =over 4 =item --help Prints this help. =item --feature Sum only features with specified feature. =back =head1 EXAMPLES: sumgff.pl file.gff output.txt cat file.gff | sumgff.pl output.txt =head1 DEPENDENCIES: None. =head1 AUTHOR: Kasper Munch =head1 COPYRIGHT: This program is free software. You may copy, modify, and redistribute it under the same terms as Perl itself. =cut