line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: Root.pm,v 1.6 2007/08/07 21:43:37 cmungall Exp $ |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# This GO module is maintained by Chris Mungall |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# see also - http://www.geneontology.org |
6
|
|
|
|
|
|
|
# - http://www.godatabase.org/dev |
7
|
|
|
|
|
|
|
# |
8
|
|
|
|
|
|
|
# You may distribute this module under the same terms as perl itself |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
package GO::Model::Root; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
GO::Model::Root |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 DESCRIPTION |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
base class for all GO::Model objects |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=cut |
21
|
|
|
|
|
|
|
|
22
|
24
|
|
|
24
|
|
137
|
use strict; |
|
24
|
|
|
|
|
50
|
|
|
24
|
|
|
|
|
1036
|
|
23
|
24
|
|
|
24
|
|
133
|
use Carp; |
|
24
|
|
|
|
|
44
|
|
|
24
|
|
|
|
|
1564
|
|
24
|
24
|
|
|
24
|
|
227
|
use Exporter; |
|
24
|
|
|
|
|
49
|
|
|
24
|
|
|
|
|
1490
|
|
25
|
24
|
|
|
24
|
|
127
|
use Data::Dumper; |
|
24
|
|
|
|
|
41
|
|
|
24
|
|
|
|
|
1158
|
|
26
|
24
|
|
|
24
|
|
116
|
use vars qw(@ISA $AUTOLOAD); |
|
24
|
|
|
|
|
55
|
|
|
24
|
|
|
|
|
51041
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
my @ISA = qw(Exporter); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# - - - - - - - - - - Public functions - - - - - - - - - - - - |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 Constructors |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head2 new |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
Constructor: Basically just calls L<_initialize>(). Most subclasses |
38
|
|
|
|
|
|
|
should not need to override new, but instead should override |
39
|
|
|
|
|
|
|
L<_initialize>(). |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
If L<_initialize>() fails , the procedure will die |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
WARNING: This procedure will die if initialization is unsuccessful. |
44
|
|
|
|
|
|
|
Use an eval statement to catch such exceptions. |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=cut |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub new |
49
|
|
|
|
|
|
|
{ |
50
|
4312
|
|
66
|
4312
|
1
|
5612
|
my $proto = shift; my $class = ref($proto) || $proto;; |
|
4312
|
|
|
|
|
15110
|
|
51
|
4312
|
|
|
|
|
6406
|
my $self = {}; |
52
|
4312
|
|
|
|
|
11088
|
bless $self, $class; |
53
|
|
|
|
|
|
|
|
54
|
4312
|
|
|
|
|
11465
|
$self->_initialize(@_); |
55
|
|
|
|
|
|
|
|
56
|
4312
|
50
|
|
|
|
10520
|
if ($ENV{PERL_MEMORY_TRACE}) { |
57
|
0
|
|
|
|
|
0
|
print STDERR "NEW: ".$self->sprint_self."\n"; |
58
|
|
|
|
|
|
|
} |
59
|
4312
|
|
|
|
|
11754
|
return $self; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub throw { |
63
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
64
|
0
|
|
|
|
|
0
|
my @msg = @_; |
65
|
0
|
|
|
|
|
0
|
confess("@msg"); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
sub warn { |
68
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
69
|
0
|
|
|
|
|
0
|
my @msg = @_; |
70
|
0
|
|
|
|
|
0
|
warn("@msg"); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head2 obj_factory |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
Usage - $obj->obj_factory->create_new_term_object($h); |
76
|
|
|
|
|
|
|
Alias - apph |
77
|
|
|
|
|
|
|
Returns - L |
78
|
|
|
|
|
|
|
Args - none |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=cut |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub apph { |
83
|
3353
|
|
|
3353
|
0
|
4418
|
my $self = shift; |
84
|
3353
|
100
|
|
|
|
11937
|
$self->{apph} = shift if @_; |
85
|
3353
|
|
|
|
|
11497
|
return $self->{apph}; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
*obj_factory = \&apph; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head2 sprint_self |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Prints out a description of the object to a string. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=cut |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub sprint_self |
97
|
|
|
|
|
|
|
{ |
98
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
99
|
0
|
|
|
|
|
0
|
my $str = $self; |
100
|
0
|
0
|
0
|
|
|
0
|
if ($self->can("name") && $self->name) { |
101
|
0
|
|
|
|
|
0
|
$str.= " ".$self->name; |
102
|
|
|
|
|
|
|
} |
103
|
0
|
|
|
|
|
0
|
return $str; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head2 dump |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
dumps the object (can be read back in with eval) |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=cut |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub dump { |
114
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
115
|
0
|
|
0
|
|
|
0
|
my $ob = shift || $self; |
116
|
0
|
|
|
|
|
0
|
my $d = Data::Dumper->new(["obj", $ob]); |
117
|
0
|
|
|
|
|
0
|
return $d->Dump; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub _initialize |
121
|
|
|
|
|
|
|
{ |
122
|
|
|
|
|
|
|
|
123
|
4485
|
|
|
4485
|
|
5850
|
my $self = shift; |
124
|
4485
|
50
|
|
|
|
15077
|
$self->init if $self->can("init"); |
125
|
4485
|
|
|
|
|
14530
|
my @valid_params = $self->_valid_params; |
126
|
4485
|
|
|
|
|
9534
|
my ($paramh) = @_; # first arg |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
# arguments passed as hash? |
129
|
4485
|
100
|
|
|
|
8942
|
if (ref($paramh)) { |
130
|
|
|
|
|
|
|
map { |
131
|
2246
|
100
|
|
|
|
3554
|
if (defined($paramh->{$_})) { |
|
14858
|
|
|
|
|
45670
|
|
132
|
4368
|
|
|
|
|
15075
|
$self->$_($paramh->{$_}); |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
} @valid_params; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
else { |
137
|
|
|
|
|
|
|
# arguments passed as array |
138
|
2239
|
|
|
|
|
9675
|
for (my $i=0; $i<@_; $i++) { |
139
|
4166
|
|
|
|
|
5418
|
my $m = $valid_params[$i]; |
140
|
4166
|
|
|
|
|
12116
|
$self->$m($_[$i]); |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
sub _valid_params { |
146
|
15
|
|
|
15
|
|
47
|
(); |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
sub is_valid_param { |
150
|
16701
|
|
|
16701
|
0
|
18642
|
my $self = shift; |
151
|
16701
|
|
|
|
|
21958
|
my $param = shift; |
152
|
16701
|
|
|
|
|
50417
|
return scalar(grep {$_ eq $param} $self->_valid_params); |
|
246131
|
|
|
|
|
485289
|
|
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
sub id { |
156
|
808
|
|
|
808
|
0
|
980
|
my $self = shift; |
157
|
808
|
50
|
|
|
|
3571
|
$self->{id} = shift if @_; |
158
|
808
|
|
|
|
|
3104
|
return $self->{id}; |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head2 namespace |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
Usage - print $term->namespace(); # getting the type |
165
|
|
|
|
|
|
|
Usage - $term->namespace("molecular_function"); # setting the type |
166
|
|
|
|
|
|
|
Alias - type |
167
|
|
|
|
|
|
|
Alias - term_type |
168
|
|
|
|
|
|
|
Alias - category |
169
|
|
|
|
|
|
|
Alias - ontology |
170
|
|
|
|
|
|
|
Returns - string representing type |
171
|
|
|
|
|
|
|
Args - string represnting type [optional] |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
The OBO namespace for the L or |
174
|
|
|
|
|
|
|
L |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=cut |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
sub namespace { |
179
|
1315
|
|
|
1315
|
1
|
2549
|
my $self = shift; |
180
|
1315
|
100
|
|
|
|
6615
|
$self->{namespace} = shift if @_; |
181
|
1315
|
|
|
|
|
6417
|
return $self->{namespace}; |
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
# synonyms |
184
|
0
|
|
|
0
|
0
|
0
|
sub term_type { shift->namespace(@_) } |
185
|
0
|
|
|
0
|
0
|
0
|
sub category { shift->namespace(@_) } |
186
|
0
|
|
|
0
|
0
|
0
|
sub ontology { shift->namespace(@_) } |
187
|
65
|
|
|
65
|
0
|
295
|
sub type { shift->namespace(@_) } |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=head2 _cleanup |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
Called at object destruction time. Should be overridden to perform |
194
|
|
|
|
|
|
|
cleanup tasks. |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=cut |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
#sub _cleanup |
199
|
|
|
|
|
|
|
#{ |
200
|
|
|
|
|
|
|
# my $self = shift; |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
# # The best we can do here is clean up references left |
203
|
|
|
|
|
|
|
# # in our hash table. We'll also drop debugging alerts. |
204
|
|
|
|
|
|
|
# my $attribute; |
205
|
|
|
|
|
|
|
# foreach $attribute (keys %$self) |
206
|
|
|
|
|
|
|
# { |
207
|
|
|
|
|
|
|
# if(ref($self->{$attribute})) |
208
|
|
|
|
|
|
|
# { |
209
|
|
|
|
|
|
|
# undef $self->{$attribute}; |
210
|
|
|
|
|
|
|
# } |
211
|
|
|
|
|
|
|
# } |
212
|
|
|
|
|
|
|
#} |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
sub _initialize_attributes { |
216
|
|
|
|
|
|
|
|
217
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
218
|
0
|
0
|
|
|
|
0
|
my @att_name_arr = @{shift || []}; |
|
0
|
|
|
|
|
0
|
|
219
|
0
|
|
|
|
|
0
|
my $param_ref = shift; |
220
|
0
|
|
|
|
|
0
|
my @param = @{$param_ref}; |
|
0
|
|
|
|
|
0
|
|
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
|
223
|
0
|
0
|
0
|
|
|
0
|
if (defined($param[0]) && $param[0]=~/^-/) { |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
# attributes specified as '-key=>val' list |
226
|
|
|
|
|
|
|
|
227
|
0
|
|
|
|
|
0
|
my $i; |
228
|
0
|
|
|
|
|
0
|
for ($i=0;$i<@param;$i+=2) { |
229
|
0
|
|
|
|
|
0
|
$param[$i]=~tr/A-Z/a-z/; |
230
|
|
|
|
|
|
|
} |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
# Now we'll convert the @params variable into an associative array. |
233
|
0
|
|
|
|
|
0
|
my(%param) = @param; |
234
|
|
|
|
|
|
|
|
235
|
0
|
|
|
|
|
0
|
my(@return_array); |
236
|
|
|
|
|
|
|
my $key; |
237
|
0
|
|
|
|
|
0
|
foreach $key (@att_name_arr) { |
238
|
0
|
|
|
|
|
0
|
my $orig_key = $key; |
239
|
0
|
|
|
|
|
0
|
$key=~tr/A-Z/a-z/; |
240
|
0
|
0
|
|
|
|
0
|
if (defined($param{"-".$key})) { |
241
|
0
|
|
|
|
|
0
|
my($value) = $param{"-".$key}; |
242
|
0
|
|
|
|
|
0
|
delete $param{"-".$key}; |
243
|
0
|
|
|
|
|
0
|
$self->{"_$orig_key"} = $value; |
244
|
|
|
|
|
|
|
} |
245
|
|
|
|
|
|
|
} |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
# catch user misspellings resulting in unrecognized names |
248
|
0
|
|
|
|
|
0
|
my(@restkeys) = keys %param; |
249
|
|
|
|
|
|
|
|
250
|
0
|
|
|
|
|
0
|
@{$param_ref} = %param; |
|
0
|
|
|
|
|
0
|
|
251
|
0
|
0
|
|
|
|
0
|
if (scalar(@restkeys) > 0) { |
252
|
|
|
|
|
|
|
###### carp("@restkeys not processed in _rearrange(), did you use a non-recognized parameter name ? "); |
253
|
|
|
|
|
|
|
} |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
} |
256
|
|
|
|
|
|
|
else { |
257
|
|
|
|
|
|
|
# attributes specified as basic array |
258
|
0
|
|
|
|
|
0
|
my $i; |
259
|
0
|
|
|
|
|
0
|
for ($i=0; $i<@param; $i++) { |
260
|
0
|
0
|
|
|
|
0
|
if ($i >= @att_name_arr) { |
261
|
0
|
|
|
|
|
0
|
confess("Too many params"); |
262
|
|
|
|
|
|
|
} |
263
|
0
|
|
|
|
|
0
|
my $att_name = $att_name_arr[$i]; |
264
|
0
|
|
|
|
|
0
|
$self->{"_$att_name"} = $param[$i]; |
265
|
|
|
|
|
|
|
} |
266
|
|
|
|
|
|
|
} |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
} |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
sub from_idl { |
271
|
0
|
|
|
0
|
0
|
0
|
my $class = shift; |
272
|
0
|
|
|
|
|
0
|
my $h = shift; |
273
|
0
|
|
|
|
|
0
|
foreach my $k (%$h) { |
274
|
0
|
0
|
|
|
|
0
|
if (ref($h->{$k}) eq "HASH") { |
275
|
0
|
|
|
|
|
0
|
confess("must be dealth with in subclass of this"); |
276
|
|
|
|
|
|
|
} |
277
|
|
|
|
|
|
|
} |
278
|
0
|
|
|
|
|
0
|
return $class->new($h); |
279
|
|
|
|
|
|
|
} |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
sub to_prolog { |
282
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
283
|
0
|
|
|
|
|
0
|
my @t = $self->to_ptuples(@_); |
284
|
0
|
|
|
|
|
0
|
my @s = |
285
|
|
|
|
|
|
|
map { |
286
|
0
|
|
|
|
|
0
|
sprintf("%s(%s).\n", |
287
|
|
|
|
|
|
|
shift @$_, |
288
|
|
|
|
|
|
|
join(", ", |
289
|
0
|
|
|
|
|
0
|
map {$self->prolog_quote($_)} @$_ |
290
|
|
|
|
|
|
|
)); |
291
|
|
|
|
|
|
|
} @t; |
292
|
0
|
|
|
|
|
0
|
my %h=(); |
293
|
|
|
|
|
|
|
# uniquify |
294
|
0
|
0
|
|
|
|
0
|
@s = grep {(!$h{$_}) and ($h{$_} = 1)} @s; |
|
0
|
|
|
|
|
0
|
|
295
|
0
|
|
|
|
|
0
|
return join("", @s); |
296
|
|
|
|
|
|
|
} |
297
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
sub prolog_quote { |
299
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
300
|
0
|
|
|
|
|
0
|
my $s = shift; |
301
|
0
|
0
|
|
|
|
0
|
$s = '' unless defined $s; |
302
|
0
|
|
|
|
|
0
|
$s =~ s/\'/\\\'/g; |
303
|
0
|
|
|
|
|
0
|
"'$s'"; |
304
|
|
|
|
|
|
|
} |
305
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
|
308
|
|
|
|
|
|
|
# auto-declare accessors |
309
|
|
|
|
|
|
|
|
310
|
|
|
|
|
|
|
sub AUTOLOAD { |
311
|
|
|
|
|
|
|
|
312
|
16672
|
|
|
16672
|
|
25303
|
my $self = shift; |
313
|
|
|
|
|
|
|
|
314
|
16672
|
|
|
|
|
27305
|
my $name = $AUTOLOAD; |
315
|
16672
|
|
|
|
|
58171
|
$name =~ s/.*://; # strip fully-qualified portion |
316
|
|
|
|
|
|
|
|
317
|
16672
|
50
|
|
|
|
57719
|
if ($name eq "DESTROY") { |
318
|
|
|
|
|
|
|
# we dont want to propagate this!! |
319
|
0
|
|
|
|
|
0
|
return; |
320
|
|
|
|
|
|
|
} |
321
|
|
|
|
|
|
|
|
322
|
16672
|
50
|
|
|
|
33234
|
confess("$self") unless ref($self); |
323
|
|
|
|
|
|
|
|
324
|
16672
|
|
|
|
|
24390
|
my $add; |
325
|
16672
|
100
|
|
|
|
59476
|
if ($name =~ /add_(.+)/) { |
326
|
29
|
|
|
|
|
85
|
$add = $1."_list"; |
327
|
|
|
|
|
|
|
} |
328
|
|
|
|
|
|
|
|
329
|
16672
|
50
|
|
|
|
70043
|
if ($self->can($name)) { |
330
|
0
|
|
|
|
|
0
|
confess("assertion error!"); |
331
|
|
|
|
|
|
|
} |
332
|
16672
|
100
|
|
|
|
33368
|
if ($self->is_valid_param($name)) { |
333
|
|
|
|
|
|
|
|
334
|
16643
|
100
|
|
|
|
35386
|
$self->{$name} = shift if @_; |
335
|
16643
|
|
|
|
|
94536
|
return $self->{$name}; |
336
|
|
|
|
|
|
|
} |
337
|
29
|
50
|
33
|
|
|
139
|
if ($add && $self->is_valid_param($add)) { |
338
|
29
|
|
|
|
|
48
|
push(@{$self->{$add}}, @_); |
|
29
|
|
|
|
|
93
|
|
339
|
29
|
|
|
|
|
160
|
return $self->{$add}; |
340
|
|
|
|
|
|
|
} |
341
|
|
|
|
|
|
|
else { |
342
|
0
|
|
|
|
|
|
confess("can't do $name on $self"); |
343
|
|
|
|
|
|
|
} |
344
|
|
|
|
|
|
|
|
345
|
|
|
|
|
|
|
} |
346
|
|
|
|
|
|
|
|
347
|
|
|
|
|
|
|
|
348
|
|
|
|
|
|
|
|
349
|
|
|
|
|
|
|
|
350
|
|
|
|
|
|
|
1; |