line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package PomBase::Chobo::OntologyConf; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
PomBase::Chobo::OntologyConf - Configuration for ontology data |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 AUTHOR |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
Kim Rutherford C<< >> |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 BUGS |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Please report any bugs or feature requests to C. |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 SUPPORT |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
perldoc PomBase::Chobo::OntologyConf |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=over 4 |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=back |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
Copyright 2012 Kim Rutherford, all rights reserved. |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
30
|
|
|
|
|
|
|
under the same terms as Perl itself. |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 FUNCTIONS |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=cut |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
our $VERSION = '0.039'; # VERSION |
37
|
|
|
|
|
|
|
|
38
|
5
|
|
|
5
|
|
35
|
use warnings; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
196
|
|
39
|
5
|
|
|
5
|
|
29
|
use Carp; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
8140
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
our %field_conf = ( |
42
|
|
|
|
|
|
|
id => { |
43
|
|
|
|
|
|
|
type => 'SINGLE', |
44
|
|
|
|
|
|
|
}, |
45
|
|
|
|
|
|
|
name => { |
46
|
|
|
|
|
|
|
type => 'SINGLE', |
47
|
|
|
|
|
|
|
process => sub { |
48
|
|
|
|
|
|
|
my $val = shift; |
49
|
|
|
|
|
|
|
$val =~ s/\\"/"/g; |
50
|
|
|
|
|
|
|
$val; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
}, |
53
|
|
|
|
|
|
|
def => { |
54
|
|
|
|
|
|
|
type => 'SINGLE_HASH', |
55
|
|
|
|
|
|
|
process => sub { |
56
|
|
|
|
|
|
|
my $val = shift; |
57
|
|
|
|
|
|
|
if ($val =~ /"(.*)"(?:\s+\[(.*)\])?/) { |
58
|
|
|
|
|
|
|
my $definition = $1; |
59
|
|
|
|
|
|
|
my $dbxrefs = $2 // ''; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
my @dbxrefs = |
62
|
|
|
|
|
|
|
map { |
63
|
|
|
|
|
|
|
# remove quoting |
64
|
|
|
|
|
|
|
s|\\(.)|$1|g; |
65
|
|
|
|
|
|
|
$_; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
grep { |
68
|
|
|
|
|
|
|
!m|^(?:url:)?https?\\?:| && /^\S+:\S+$/; |
69
|
|
|
|
|
|
|
} split /\s*,\s/, $dbxrefs; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
return { |
72
|
|
|
|
|
|
|
definition => $definition, |
73
|
|
|
|
|
|
|
dbxrefs => \@dbxrefs, |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
} else { |
76
|
|
|
|
|
|
|
croak qq(failed to parse "def:" line: $val); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
}, |
79
|
|
|
|
|
|
|
merge => sub { |
80
|
|
|
|
|
|
|
my $self = shift; |
81
|
|
|
|
|
|
|
my $other = shift; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
if (!defined $other->def()) { |
84
|
|
|
|
|
|
|
return $self->def(); |
85
|
|
|
|
|
|
|
} else { |
86
|
|
|
|
|
|
|
if (!defined $self->def()) { |
87
|
|
|
|
|
|
|
return $other->def(); |
88
|
|
|
|
|
|
|
} else { |
89
|
|
|
|
|
|
|
if ($self->def()->{definition} ne $other->def()->{definition}) { |
90
|
|
|
|
|
|
|
warn qq("def:" line differ\n ) . $self->def()->{definition} . "\nversus:\n " . |
91
|
|
|
|
|
|
|
$other->def()->{definition}; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
return $self->def(); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
}, |
97
|
|
|
|
|
|
|
to_string => sub { |
98
|
|
|
|
|
|
|
my $val = shift; |
99
|
|
|
|
|
|
|
my $ret_string = $val->{definition}; |
100
|
|
|
|
|
|
|
$ret_string .= ' [' . (join ", ", @{$val->{dbxrefs}}) . ']'; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
}, |
103
|
|
|
|
|
|
|
comment => { |
104
|
|
|
|
|
|
|
type => 'SINGLE', |
105
|
|
|
|
|
|
|
}, |
106
|
|
|
|
|
|
|
replaced_by => { |
107
|
|
|
|
|
|
|
type => 'SINGLE', |
108
|
|
|
|
|
|
|
}, |
109
|
|
|
|
|
|
|
consider => { |
110
|
|
|
|
|
|
|
type => 'SINGLE', |
111
|
|
|
|
|
|
|
}, |
112
|
|
|
|
|
|
|
is_obsolete => { |
113
|
|
|
|
|
|
|
type => 'SINGLE', |
114
|
|
|
|
|
|
|
process => sub { |
115
|
|
|
|
|
|
|
my $val = shift; |
116
|
|
|
|
|
|
|
if ($val eq 'true') { |
117
|
|
|
|
|
|
|
return 1; |
118
|
|
|
|
|
|
|
} else { |
119
|
|
|
|
|
|
|
return 0; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
}, |
122
|
|
|
|
|
|
|
}, |
123
|
|
|
|
|
|
|
namespace => { |
124
|
|
|
|
|
|
|
type => 'SINGLE', |
125
|
|
|
|
|
|
|
merge => sub { |
126
|
|
|
|
|
|
|
my $self = shift; |
127
|
|
|
|
|
|
|
my $other = shift; |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
my $self_namespace = $self->{namespace}; |
130
|
|
|
|
|
|
|
my $other_namespace = $other->{namespace}; |
131
|
|
|
|
|
|
|
if (defined $self_namespace && |
132
|
|
|
|
|
|
|
defined $other_namespace) { |
133
|
|
|
|
|
|
|
# if the namespace is the same as the db_name, remove it and use the |
134
|
|
|
|
|
|
|
# namespace from the other term to avoid a namespace clash |
135
|
|
|
|
|
|
|
if ($self_namespace eq $self->{db_name}) { |
136
|
|
|
|
|
|
|
$self->{namespace} = undef; |
137
|
|
|
|
|
|
|
} else { |
138
|
|
|
|
|
|
|
if ($other_namespace eq $other->{db_name}) { |
139
|
|
|
|
|
|
|
$other->{namespace} = undef; |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
# do default merging |
144
|
|
|
|
|
|
|
return undef; |
145
|
|
|
|
|
|
|
}, |
146
|
|
|
|
|
|
|
}, |
147
|
|
|
|
|
|
|
alt_id => { |
148
|
|
|
|
|
|
|
type => 'ARRAY', |
149
|
|
|
|
|
|
|
}, |
150
|
|
|
|
|
|
|
is_a => { |
151
|
|
|
|
|
|
|
type => 'ARRAY', |
152
|
|
|
|
|
|
|
}, |
153
|
|
|
|
|
|
|
part_of => { |
154
|
|
|
|
|
|
|
type => 'ARRAY', |
155
|
|
|
|
|
|
|
}, |
156
|
|
|
|
|
|
|
subset => { |
157
|
|
|
|
|
|
|
type => 'ARRAY', |
158
|
|
|
|
|
|
|
}, |
159
|
|
|
|
|
|
|
xref => { |
160
|
|
|
|
|
|
|
type => 'ARRAY', |
161
|
|
|
|
|
|
|
process => sub { |
162
|
|
|
|
|
|
|
my $val = shift; |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
if ($val =~ /^([^\s:]+:[^\s]+)(?:$|\s)/) { |
165
|
|
|
|
|
|
|
return $1; |
166
|
|
|
|
|
|
|
} else { |
167
|
|
|
|
|
|
|
return undef; |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
}, |
170
|
|
|
|
|
|
|
}, |
171
|
|
|
|
|
|
|
relationship => { |
172
|
|
|
|
|
|
|
type => 'ARRAY', |
173
|
|
|
|
|
|
|
process => sub { |
174
|
|
|
|
|
|
|
my $val = shift; |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
if ($val =~ /^\s*(\S+)\s+(\S+)\s*(?:\{(.*)\})?$/) { |
177
|
|
|
|
|
|
|
my $relationship_name = $1; |
178
|
|
|
|
|
|
|
my $other_term = $2; |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
if ($relationship_name =~ /^:|:$/) { |
181
|
|
|
|
|
|
|
warn "illegal relationship name: $relationship_name\n"; |
182
|
|
|
|
|
|
|
return undef; |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
return { |
186
|
|
|
|
|
|
|
relationship_name => $relationship_name, |
187
|
|
|
|
|
|
|
other_term => $other_term, |
188
|
|
|
|
|
|
|
}; |
189
|
|
|
|
|
|
|
} else { |
190
|
|
|
|
|
|
|
warn "can't parse relationship: $val\n"; |
191
|
|
|
|
|
|
|
return undef; |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
}, |
194
|
|
|
|
|
|
|
to_string => sub { |
195
|
|
|
|
|
|
|
my $val = shift; |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
if (ref $val) { |
198
|
|
|
|
|
|
|
return $val->{relationship_name} . ' ' . $val->{other_term}; |
199
|
|
|
|
|
|
|
} else { |
200
|
|
|
|
|
|
|
croak "can't output relationship '$val' - expected a reference"; |
201
|
|
|
|
|
|
|
} |
202
|
|
|
|
|
|
|
}, |
203
|
|
|
|
|
|
|
}, |
204
|
|
|
|
|
|
|
synonym => { |
205
|
|
|
|
|
|
|
type => 'ARRAY', |
206
|
|
|
|
|
|
|
process => sub { |
207
|
|
|
|
|
|
|
my $val = shift; |
208
|
|
|
|
|
|
|
if ($val =~ /^"(.*?[^\\])"\s*(.*)/) { |
209
|
|
|
|
|
|
|
my $synonym = $1; |
210
|
|
|
|
|
|
|
my @dbxrefs = (); |
211
|
|
|
|
|
|
|
my $rest = $2; |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
$synonym =~ s/\\(.)/$1/g; |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
my %ret = ( |
216
|
|
|
|
|
|
|
synonym => $synonym, |
217
|
|
|
|
|
|
|
); |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
my $scope_and_type; |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
if ($rest =~ /^(?:\s*(\S.*)\s+)?\[([^\]]*)\]/) { |
222
|
|
|
|
|
|
|
if (defined $1) { |
223
|
|
|
|
|
|
|
$scope_and_type = $1; |
224
|
|
|
|
|
|
|
} else { |
225
|
|
|
|
|
|
|
$scope_and_type = 'RELATED'; |
226
|
|
|
|
|
|
|
} |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
my $dbxrefs_match = $2; |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
if (defined $dbxrefs_match) { |
231
|
|
|
|
|
|
|
@dbxrefs = split /\s*,\s*/, $dbxrefs_match; |
232
|
|
|
|
|
|
|
} |
233
|
|
|
|
|
|
|
} else { |
234
|
|
|
|
|
|
|
$scope_and_type = $rest; |
235
|
|
|
|
|
|
|
} |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
if (defined $scope_and_type) { |
238
|
|
|
|
|
|
|
if ($scope_and_type =~ /(\S+)\s+(\S+)/) { |
239
|
|
|
|
|
|
|
my ($scope, $type) = ($1, $2, $3); |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
$ret{scope} = $scope; |
242
|
|
|
|
|
|
|
$ret{type} = $type; |
243
|
|
|
|
|
|
|
} else { |
244
|
|
|
|
|
|
|
$ret{scope} = $scope_and_type; |
245
|
|
|
|
|
|
|
} |
246
|
|
|
|
|
|
|
} |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
$ret{dbxrefs} = \@dbxrefs; |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
return \%ret; |
251
|
|
|
|
|
|
|
} else { |
252
|
|
|
|
|
|
|
die "unknown synonym format: $val\n"; |
253
|
|
|
|
|
|
|
} |
254
|
|
|
|
|
|
|
}, |
255
|
|
|
|
|
|
|
to_string => sub { |
256
|
|
|
|
|
|
|
my $val = shift; |
257
|
|
|
|
|
|
|
my $ret_string = $val->{synonym}; |
258
|
|
|
|
|
|
|
if (defined $val->{scope}) { |
259
|
|
|
|
|
|
|
$ret_string .= ' ' . $val->{scope}; |
260
|
|
|
|
|
|
|
} |
261
|
|
|
|
|
|
|
if (defined $val->{type}) { |
262
|
|
|
|
|
|
|
$ret_string .= ' ' . $val->{type}; |
263
|
|
|
|
|
|
|
} |
264
|
|
|
|
|
|
|
if (defined $val->{dbxrefs}) { |
265
|
|
|
|
|
|
|
$ret_string .= ' [' . (join ", ", @{$val->{dbxrefs}}) . ']'; |
266
|
|
|
|
|
|
|
} |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
return $ret_string; |
269
|
|
|
|
|
|
|
}, |
270
|
|
|
|
|
|
|
}, |
271
|
|
|
|
|
|
|
property_value => { |
272
|
|
|
|
|
|
|
type => 'ARRAY', |
273
|
|
|
|
|
|
|
process => sub { |
274
|
|
|
|
|
|
|
my $raw_value = shift; |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
$raw_value =~ s/\s+xsd:\w+\s*$//; |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
my ($name, $value) = split(/\s+/, $raw_value, 2); |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
return [ |
281
|
|
|
|
|
|
|
$name, $value |
282
|
|
|
|
|
|
|
] |
283
|
|
|
|
|
|
|
}, |
284
|
|
|
|
|
|
|
}, |
285
|
|
|
|
|
|
|
); |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
1; |