-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathobo-strip.pl
executable file
·109 lines (93 loc) · 1.69 KB
/
obo-strip.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
#!/usr/bin/perl -w
use strict;
my %tag_h=();
my $negate = 0;
my $typedef = 1;
my $show_header = 1;
my %idspace_h = ();
while ($ARGV[0] =~ /^\-/) {
my $opt = shift @ARGV;
if ($opt eq '-h' || $opt eq '--help') {
print usage();
exit 0;
}
elsif ($opt eq '--typedef') {
$typedef = 1; # now the default
}
elsif ($opt eq '--no-typedef') {
$typedef = 0;
}
elsif ($opt eq '--no-header') {
$show_header = 0;
}
elsif ($opt eq '-n' || $opt eq '--negate') {
$negate = 1;
}
elsif ($opt eq '-s' || $opt eq '--idspace') {
$idspace_h{shift @ARGV} = 1;
}
elsif ($opt eq '-t' || $opt eq '--tag') {
$tag_h{shift @ARGV} = 1;
}
elsif ($opt eq '-') {
}
else {
die "$opt";
}
}
#print STDERR "Tags: ", join(', ',keys %tag_h),"\n";
my $on = 1;
my $in_header = 1;
my @lines = <>;
my $id;
while($_ = shift @lines) {
if (/^\[(\S+)\]/) {
$in_header=0;
if ($1 eq 'Typedef' && !$typedef) {
$on = 0;
}
else {
$on = 1;
}
}
if ($in_header) {
if ($show_header) {
print;
}
}
else {
if (/^\[/) {
$on = 1;
}
if (/^id:\s*(\S+)/) {
$id = $1;
if ($id =~ /(\w+):/) {
$on = !$idspace_h{$1};
}
print $_
}
elsif (/^(\w+):\s*(.*)/) {
print $_ if $tag_h{$1} && $on;
}
elsif (/^\s*\n$/) {
print $_;
}
else {
print $_;
}
}
}
exit 0;
sub scriptname {
my @p = split(/\//,$0);
pop @p;
}
sub usage {
my $sn = scriptname();
<<EOM;
$sn [-t tag]* [--no-header] FILE [FILE...]
strips all tags except selected
Example:
$sn -t id -t xref gene_ontology.obo
EOM
}