forked from cmungall/obo-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobo-order-tags.pl
executable file
·183 lines (164 loc) · 2.54 KB
/
obo-order-tags.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#!/usr/bin/perl -w
use strict;
while ($ARGV[0] =~ /^\-.+/) {
my $opt = shift @ARGV;
if ($opt eq '-h' || $opt eq '--help') {
print usage();
exit 0;
}
}
my @TERM_TAGS = qw(
id
is_anonymous
name
namespace
alt_id
def
comment
subset
synonym
xref
property_value
is_a
intersection_of
union_of
disjoint_from
relationship
created_by
creation_date
is_obsolete
replaced_by
consider
);
my @TYPEDEF_TAGS = qw(
id
is_anonymous
name
namespace
alt_id
def
comment
subset
synonym
xref
property_value
domain
range
is_anti_symmetric
is_cyclic
is_reflexive
is_symmetric
is_transitive
is_a
intersection_of
union_of
disjoint_from
inverse_of
transitive_over
holds_over_chain
equivalent_to_chain
disjoint_over
relationship
created_by
creation_date
is_obsolete
replaced_by
consider
expand_assertion_to
expand_expression_to
is_metadata_tag
is_class_level
);
my %tagrankh =
(
'Term'=>numerify(@TERM_TAGS),
'Typedef'=>numerify(@TYPEDEF_TAGS),
);
my $id;
my $stanza_type;
my $in_body;
my @lines = ();
while (<>) {
chomp;
if (/^\[(\w+)\]/) {
$in_body = 1;
$stanza_type = $1;
if (@lines) {
die "@lines";
}
}
elsif (/^id:\s*(.*)/) {
$id = $1;
}
elsif (/^(\S+):\s*(.*)/) {
push(@lines,$_);
}
elsif (/^\!/) {
push(@lines,$_);
}
elsif (/^\s*$/) {
if ($in_body) {
write_stanza();
}
else {
# no sorting of hdr tags yet
foreach (@lines) {
print "$_\n";
}
print "\n";
@lines = ();
}
}
else {
if ($in_body) {
die $_;
}
}
}
if (@lines) {
write_stanza();
}
exit(0);
sub write_stanza {
if (!$id && !(@lines)) {
return;
}
die "no id for: @lines" unless $id;
die unless $stanza_type;
die unless @lines;
print "[$stanza_type]\n";
print "id: $id\n";
foreach (sort { rnk($a) <=> rnk($b) } @lines) {
print "$_\n";
}
print "\n";
$id = '';
@lines = ();
}
sub rnk {
my ($line) = @_;
if ($line =~ /(\S+):/) {
return $tagrankh{$stanza_type}->{$1} || die "$1 in $line";
}
die $line;
}
sub numerify {
my @arr = @_;
my $n = 1;
my %h =
map { ($_ => $n++) } @arr;
return \%h;
}
sub scriptname {
my @p = split(/\//,$0);
pop @p;
}
sub usage {
my $sn = scriptname();
<<EOM;
$sn OBO-FILE [OBO-FILE2...]
performs syntactic check on intersection_of definitions
Example:
$sn mammalian_phenotype_xp.obo
EOM
}