forked from obophenotype/uberon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake-bridge-ontologies-from-xrefs.pl
executable file
·190 lines (173 loc) · 5.19 KB
/
make-bridge-ontologies-from-xrefs.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
183
184
185
186
187
188
189
190
#!/usr/bin/perl -w
use strict;
use FileHandle;
my %fhmap = ();
my %tmap = ();
my $id;
my $n;
my $n_xrefs = 0;
my $stype;
my %nh = ();
my @fns = ();
my $base = 'uberon';
while ($ARGV[0] =~ /^\-/) {
my $opt = shift @ARGV;
if ($opt eq '-b' || $opt eq '--base') {
$base = shift @ARGV;
}
}
while (<>) {
chomp;
if (/^treat-xrefs-as-equivalent:\s*(\S+)/) {
mk_bridge('equivalent',$1);
}
elsif (/^treat-xrefs-as-has-subclass:\s*(\S+)/) {
mk_bridge('has-subclass',$1);
}
#elsif (/^treat-xrefs-as-is_a:\s*(\S+)/) {
# mk_bridge('is_a',$1);
#}
elsif (/^treat-xrefs-as-reverse-genus-differentia:\s*(\S+)\s+(\S+)\s+(\S+)/) {
mk_bridge('gd',$1,$2,$3);
}
elsif (/^\[(\S+)\]/) {
$stype = $1;
}
elsif (/^id:\s*(\S+)/) {
$id = $1;
$n = '';
if (/^id:\s*\S+\s+\!\s+(.*)/) {
$n = $1;
}
}
elsif (/^name:\s*(.*)/) {
$n = $1;
$nh{$id} = $n;
}
elsif (/^xref:\s*(\S+)(.*)/) {
next unless $stype eq 'Term';
my $x = $1;
my $cmt = $2;
$cmt =~ s/.*\!\s*//;
if ($x =~ /^(\S+)[:\/]([\w\-]+)$/) {
my $s = $1;
my $fh = $fhmap{$s};
if ($fh) {
$n_xrefs++;
my ($t,$rel,$filler) = @{$tmap{$s}};
$n = $nh{$id};
print $fh "[Term]\n";
print $fh "id: $x ! $cmt\n";
my $unique_label = mk_unique_label($s,$n);
if ($n) {
print $fh "property_value: IAO:0000589 \"$unique_label\" xsd:string\n";
}
if ($t eq 'equivalent') {
print $fh "equivalent_to: $id ! $n\n";
}
elsif ($t eq 'has-subclass') {
print $fh "is_a: $id ! $n\n";
}
elsif ($t eq 'gd') {
print $fh "intersection_of: $id ! $n\n";
print $fh "intersection_of: $rel $filler\n";
}
else {
die $t;
}
print $fh "\n";
}
}
}
}
print STDERR "n_xrefs: $n_xrefs\n";
foreach my $s (keys %fhmap) {
my $fh = $fhmap{$s};
#if ($tmap{$s}->[0] eq 'gd' && $base eq 'uberon') {
if ($tmap{$s}->[0] eq 'gd') {
my ($t,$rel,$filler) = @{$tmap{$s}};
# hidden GCI
print $fh "[Term]\n";
print $fh "id: $s:ENTITY\n";
print $fh "name: $s entity\n";
print $fh "intersection_of: UBERON:0001062 ! anatomical entity\n";
print $fh "intersection_of: $rel $filler\n";
print $fh "relationship: only_in_taxon $filler\n\n";
print $fh "[Typedef]\n";
print $fh "id: part_of\n";
print $fh "xref: BFO:0000050\n";
print $fh "is_transitive: true\n\n";
print $fh "[Typedef]\n";
print $fh "id: only_in_taxon\n";
print $fh "xref: RO:0002160\n\n";
}
my $prefix = "http://purl.obolibrary.org/obo/".lc($s);
print $fh "[Typedef]\n";
print $fh "id: $prefix#part_of\n";
print $fh "equivalent_to: BFO:0000050\n\n";
print $fh "[Typedef]\n";
print $fh "id: $prefix#develops_from\n";
print $fh "equivalent_to: RO:0002225\n\n";
open(F,"ftr.obo");
while(<F>) {
print $fh $_;
}
close(F);
$fh->close;
}
foreach my $ont (@fns) {
#my $cmd = "obolib-obo2owl --allow-dangling $ont.obo -o $ont.owl";
my $cmd = "owltools $ont.obo -o $ont.owl";
if ($ont eq '') {
# TODO - fix obo2owl
$cmd .= ' && perl -pi -ne "s@http://purl.obolibrary.org/obo/NIF_GrossAnatomy#_@http://ontology.neuinfo.org/NIF/BiomaterialEntities/NIF-GrossAnatomy.owl#@" '."$ont.owl";
}
if (system($cmd)) {
print STDERR "REMOVING: $ont.obo\n";
system("rm $ont.obo");
}
}
print STDERR "n_xrefs: $n_xrefs\n";
exit 0;
sub mk_unique_label {
my ($s,$n) = @_;
$s =~ s/^AAO$/amphibian/;
$s =~ s/^FBbt$/drosophila/;
$s =~ s/^FMA$/post-embryonic human/;
$s =~ s/^HAO$/hymenoptera/;
$s =~ s/^MA$/post-embryonic mouse/;
$s =~ s/^SPD$/spider/;
$s =~ s/^TAO$/teleost/;
$s =~ s/^WBbt$/worm/;
$s =~ s/^WBls$/worm/;
$s =~ s/^XAO$/xenopus/;
$s =~ s/^ZFA$/zebrafish/;
$s =~ s/^EHDAA2$/embryonic human/;
$s =~ s/^EMAPA$/embryonic mouse/;
return "$n ($s)";
}
sub mk_bridge {
my ($t,$s,@args) = @_;
my $ont = lc("$base-bridge-to-$s");
my $fn = "$ont.obo";
push(@fns,$ont);
print STDERR "Writing to: $fn\n";
my $date = `date "+%Y-%m-%d"`;
chomp $date;
my $fh = FileHandle->new(">$fn") || die $fn;
print $fh "ontology: uberon/bridge/$ont\n";
print $fh "data-version: $date\n";
print $fh "property_value: seeAlso \"http://purl.obolibrary.org/obo/uberon/references/reference_0000026\" xsd:anyURI\n";
if (-f "hdr-$fn") {
open(F,"hdr-$fn");
while(<F>) {
print $fh $_;
}
close(F);
}
#print $fh ann_str('dc-description' =>"bridging axioms between uberon and $ont");
#print $fh ann_uri('foaf-homepage' => "bridging axioms between uberon and $ont");
print $fh "\n";
$fhmap{$s} = $fh;
$tmap{$s} = [$t,@args];
}