forked from monarch-initiative/mondo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
obo-grep.pl
100 lines (86 loc) · 1.74 KB
/
obo-grep.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
#!/usr/bin/perl -w
use strict;
my %tag_h=();
my $regexp = '';
my $noheader;
my $negate;
my $count;
while ($ARGV[0] =~ /^\-.+/) {
my $opt = shift @ARGV;
if ($opt eq '-h' || $opt eq '--help') {
print usage();
exit 0;
}
if ($opt eq '-r' || $opt eq '--regexp') {
$regexp = shift @ARGV;
}
if ($opt eq '--regexp-file') {
my $f = shift @ARGV;
my @or = ();
open(F,$f);
while(<F>) {
chomp;
push(@or,$_);
}
close(F);
$regexp = sprintf('id: (%s)', join('|',@or));
}
if ($opt eq '-c' || $opt eq '--count') {
$count = 1;
}
if ($opt eq '--noheader') {
$noheader = 1;
}
if ($opt eq '-v' || $opt eq '--neg') {
$negate = 1;
}
}
$/ = "\n\n";
my $n = 0;
while (@ARGV) {
my $f = pop @ARGV;
if ($f eq '-') {
*F=*STDIN;
}
else {
open(F,$f) || die "cannot open $f";
}
my $hdr = 0;
while(<F>) {
if (!$hdr && $_ !~ /^\[/) {
print unless $noheader || $count;
$hdr = 1;
}
else {
if ($negate) {
if ($_ !~ /$regexp/) {
$n++;
print unless $count;
}
}
else {
if (/$regexp/) {
$n++;
print unless $count;
}
}
}
}
}
if ($count) {
print "$n\n";
}
exit 0;
sub scriptname {
my @p = split(/\//,$0);
pop @p;
}
sub usage {
my $sn = scriptname();
<<EOM;
$sn [--noheader] [--neg] [--r REGULAR-EXPRESSION] [--regexp-file FILE] OBO-FILE
filters out stanzas from obo files
Example:
$sn -r 'def:.*transcript' go.obo
EOM
}