-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathobo-filter-relationships.pl
executable file
·68 lines (57 loc) · 1.08 KB
/
obo-filter-relationships.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
#!/usr/bin/perl -w
use strict;
my %rel_h=();
my $negate = 0;
my $typedef = 1;
my $show_header = 1;
while ($ARGV[0] =~ /^\-/) {
my $opt = shift @ARGV;
if ($opt eq '-h' || $opt eq '--help') {
print usage();
exit 0;
}
elsif ($opt eq '-n' || $opt eq '--negate') {
$negate = 1;
}
elsif ($opt eq '-t' || $opt eq '--rel') {
$rel_h{shift @ARGV} = 1;
}
elsif ($opt eq '-') {
}
else {
die "$opt";
}
}
my $on = 1;
my $in_header = 1;
my @lines = <>;
while($_ = shift @lines) {
my $ok = 1;
if (/^relationship:\s*(\S+)\s+(\S+)/) {
my ($rel,$y) = ($1,$2);
if ($rel_h{$rel}) {
$ok = 1;
}
else {
$ok = 0;
}
if ($negate) {
$ok = !$ok;
}
}
print if $ok;
}
exit 0;
sub scriptname {
my @p = split(/\//,$0);
pop @p;
}
sub usage {
my $sn = scriptname();
<<EOM;
$sn [-t rel]* FILE [FILE...]
strips all relationships except those with selected relationship type
Example:
$sn -t part_of gene_ontology_ext.obo
EOM
}