-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfilter_repeats.pl
executable file
·147 lines (114 loc) · 4.1 KB
/
filter_repeats.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
#!/usr/bin/env perl
use warnings;
use strict;
use Data::Dumper;
use Carp;
use Getopt::Long qw(:config gnu_getopt);
use Pod::Usage;
my $INH = *ARGV;
my $ERRH = *STDERR;
my $OUTH = *STDOUT;
GetOptions (
\%ARGV,
'input|i=s',
'output|o=s',
'debug:i',
'quiet' => sub {$ARGV{quiet} = 1; no diagnostics; no warnings },
'verbose' => sub {$ARGV{verbose} = 1; use diagnostics; use warnings},
'version' => sub {pod2usage -sections => ['VERSION','REVISION'],
-verbose => 99 },
'license' => sub {pod2usage -sections => ['AUTHOR','COPYRIGHT'],
-verbose => 99 },
'usage' => sub {pod2usage -sections => ['SYNOPSIS'],
-verbose => 99 },
'help' => sub {pod2usage -verbose => 1 },
'manual' => sub {pod2usage -verbose => 2 },
)
or pod2usage (-verbose => 1);
IO:
{
# We use the ARGV magical handle to read input
# If user explicitly sets -i, put the argument in @ARGV
if (exists $ARGV{input}) {
unshift @ARGV, $ARGV{input};
}
# Allow in-situ arguments (equal input and output filenames)
# FIXME: infinite loop. Why?
if (exists $ARGV{input} and exists $ARGV{output}
and $ARGV{input} eq $ARGV{output}) {
croak "Bug: don't use in-situ editing (same input and output files";
open $INH, q{<}, $ARGV{input}
or croak "Can't read $ARGV{input}: $!";
unlink $ARGV{input};
}
# Redirect STDOUT to a file if so specified
if (exists $ARGV{output} and q{-} ne $ARGV{output}) {
open $OUTH, q{>}, $ARGV{output}
or croak "Can't write $ARGV{output}: $!";
}
}
my @buffer;
my %chr_counts;
MAIN:
while(<$INH>){
chomp;
local $_ = [split /\t/, $_];
# flush buffer
if (@buffer and ("@{$_}[0,3,4,6]" ne "@{$buffer[-1]}[0,3,4,6]")) {
$buffer[-1]->[5] = scalar @buffer - 1;
$chr_counts{$buffer[-1]->[0]} += $buffer[-1]->[5];
print {$OUTH} join ("\t", @{$buffer[-1]}), "\n";
@buffer = ();
}
push @buffer, $_;
}
print {$OUTH} join ("\t", @{$buffer[-1]}), "\n"
if @buffer;
for (sort keys %chr_counts) {
print {$ERRH} "$_\t$chr_counts{$_}\n";
}
__DATA__
__END__
=head1 NAME
filter_repeats.pl - Filter out GFF records with same seqid, start, end, strand
=head1 SYNOPSIS
filter_repeats.pl [OPTION]... [FILE]...
perl filter_repeats.pl some.gff -o filtered.gff 2> some.repeats
=head1 DESCRIPTION
Long description
=head1 OPTIONS
-i, --input filename to read from (STDIN)
-o, --output filename to write to (STDOUT)
--debug print additional information
--verbose print diagnostic and warning messages
--quiet print no diagnostic or warning messages
--version print current version
--license print author's contact and copyright information
--help print this information
--manual print the plain old documentation page
=head1 VERSION
0.0.1
=head1 REVISION
$Rev: $:
$Author: $:
$Date: $:
$HeadURL: $:
$Id: $:
=head1 AUTHOR
Pedro Silva <[email protected]/>
Zilberman Lab <http://dzlab.pmb.berkeley.edu/>
Plant and Microbial Biology Department
College of Natural Resources
University of California, Berkeley
=head1 COPYRIGHT
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
=cut