forked from boglab/talesf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsortfilter
executable file
·70 lines (63 loc) · 1.39 KB
/
sortfilter
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
#!/usr/bin/env perl
use strict;
use Getopt::Long;
my $limit = 0;
my $sortmode = 0;
GetOptions
(
"h|help" => sub { print_usage(\*STDOUT) and exit(1); },
"l|limit=i" => \$limit,
"s|sortbyscore" => \$sortmode,
);
my @sites;
my $sites_by_seq;
while(my $line = <STDIN>)
{
next if($line =~ m/^#/);
my @v = split(/\t/, $line);
if($sortmode == 1)
{
my @r = ($v[5], $line);
push(@sites, \@r);
}
else
{
$sites_by_seq->{ $v[0] }->{ $v[3] } = $line;
}
}
printf("##gff-version\t3\n");
if($sortmode == 1)
{
my $i = 0;
foreach my $site(sort { $a->[0] <=> $b->[0] } @sites)
{
last unless($limit == 0 || $i++ < $limit);
print $site->[1];
}
}
else
{
my $i = 0;
foreach my $seq( sort keys %$sites_by_seq )
{
foreach my $start( sort {$a <=> $b} keys %{$sites_by_seq->{$seq}} )
{
print $sites_by_seq->{$seq}->{$start};
last unless($limit == 0 || $i++ < $limit);
}
last unless($limit == 0 || $i < $limit);
}
}
sub print_usage
{
my $OUT = shift(@_);
print($OUT "
Usage: sortfilter [options] < sites.gff3
Options:
-h|--help print this help message and quit
-l|--limit print only the first l sites; default is 0 (print all
binding sites
-s|--sortbyscore sort binding sites by binding site score; default is
to sort by genomic position
");
}