line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: Utils.pm,v 1.2 2004/11/24 02:28:00 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::Utils; |
11
|
|
|
|
|
|
|
|
12
|
24
|
|
|
24
|
|
127
|
use Exporter; |
|
24
|
|
|
|
|
40
|
|
|
24
|
|
|
|
|
1904
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
@EXPORT_OK = qw(rearrange remove_duplicates merge_hashes get_method_ref |
17
|
|
|
|
|
|
|
get_param pset2hash dd spell_greek max check_obj_graph); |
18
|
|
|
|
|
|
|
|
19
|
24
|
|
|
24
|
|
128
|
use strict; |
|
24
|
|
|
|
|
41
|
|
|
24
|
|
|
|
|
813
|
|
20
|
24
|
|
|
24
|
|
126
|
use Carp; |
|
24
|
|
|
|
|
63
|
|
|
24
|
|
|
|
|
1608
|
|
21
|
24
|
|
|
24
|
|
35893
|
use Data::Dumper; |
|
24
|
|
|
|
|
398785
|
|
|
24
|
|
|
|
|
80677
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head2 rearrange() |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
Usage : n/a |
26
|
|
|
|
|
|
|
Function : Rearranges named parameters to requested order. |
27
|
|
|
|
|
|
|
Returns : @params - an array of parameters in the requested order. |
28
|
|
|
|
|
|
|
Argument : $order : a reference to an array which describes the desired |
29
|
|
|
|
|
|
|
order of the named parameters. |
30
|
|
|
|
|
|
|
@param : an array of parameters, either as a list (in |
31
|
|
|
|
|
|
|
which case the function simply returns the list), |
32
|
|
|
|
|
|
|
or as an associative array (in which case the |
33
|
|
|
|
|
|
|
function sorts the values according to @{$order} |
34
|
|
|
|
|
|
|
and returns that new array. |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
Exceptions : carps if a non-recognised parameter is sent |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=cut |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub rearrange { |
41
|
|
|
|
|
|
|
# This function was taken from CGI.pm, written by Dr. Lincoln |
42
|
|
|
|
|
|
|
# Stein, and adapted for use in Bio::Seq by Richard Resnick. |
43
|
|
|
|
|
|
|
# ...then Chris Mungall came along and adapted it for BDGP |
44
|
1172
|
|
|
1172
|
1
|
2133
|
my($order,@param) = @_; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# If there are no parameters, we simply wish to return |
47
|
|
|
|
|
|
|
# an undef array which is the size of the @{$order} array. |
48
|
1172
|
100
|
|
|
|
3002
|
return (undef) x $#{$order} unless @param; |
|
1167
|
|
|
|
|
5357
|
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# If we've got parameters, we need to check to see whether |
51
|
|
|
|
|
|
|
# they are named or simply listed. If they are listed, we |
52
|
|
|
|
|
|
|
# can just return them. |
53
|
5
|
50
|
33
|
|
|
39
|
return @param unless (defined($param[0]) && $param[0]=~/^-/); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# Now we've got to do some work on the named parameters. |
56
|
|
|
|
|
|
|
# The next few lines strip out the '-' characters which |
57
|
|
|
|
|
|
|
# preceed the keys, and capitalizes them. |
58
|
5
|
|
|
|
|
7
|
my $i; |
59
|
5
|
|
|
|
|
16
|
for ($i=0;$i<@param;$i+=2) { |
60
|
15
|
50
|
|
|
|
29
|
if (!defined($param[$i])) { |
61
|
0
|
|
|
|
|
0
|
carp("Hmmm in $i ".join(";", @param)." == ".join(";",@$order)."\n"); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
else { |
64
|
15
|
|
|
|
|
42
|
$param[$i]=~s/^\-//; |
65
|
15
|
|
|
|
|
47
|
$param[$i]=~tr/a-z/A-Z/; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# Now we'll convert the @params variable into an associative array. |
70
|
5
|
|
|
|
|
20
|
my(%param) = @param; |
71
|
|
|
|
|
|
|
|
72
|
5
|
|
|
|
|
7
|
my(@return_array); |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# What we intend to do is loop through the @{$order} variable, |
75
|
|
|
|
|
|
|
# and for each value, we use that as a key into our associative |
76
|
|
|
|
|
|
|
# array, pushing the value at that key onto our return array. |
77
|
|
|
|
|
|
|
my($key); |
78
|
|
|
|
|
|
|
|
79
|
5
|
|
|
|
|
8
|
foreach $key (@{$order}) { |
|
5
|
|
|
|
|
10
|
|
80
|
20
|
|
|
|
|
29
|
$key=~tr/a-z/A-Z/; |
81
|
20
|
|
|
|
|
31
|
my($value) = $param{$key}; |
82
|
20
|
|
|
|
|
31
|
delete $param{$key}; |
83
|
20
|
|
|
|
|
41
|
push(@return_array,$value); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# catch user misspellings resulting in unrecognized names |
87
|
5
|
|
|
|
|
13
|
my(@restkeys) = keys %param; |
88
|
5
|
50
|
|
|
|
16
|
if (scalar(@restkeys) > 0) { |
89
|
0
|
|
|
|
|
0
|
carp("@restkeys not processed in rearrange(), did you use a |
90
|
|
|
|
|
|
|
non-recognized parameter name ? "); |
91
|
|
|
|
|
|
|
} |
92
|
5
|
|
|
|
|
27
|
return @return_array; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head2 get_param() |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Usage : get_param('name',(-att1=>'ben',-name=>'the_name')) |
101
|
|
|
|
|
|
|
Function : Fetches a named parameter. |
102
|
|
|
|
|
|
|
Returns : The value of the requested parameter. |
103
|
|
|
|
|
|
|
Argument : $name : The name of the the parameter desired |
104
|
|
|
|
|
|
|
@param : an array of parameters, as an associative array |
105
|
|
|
|
|
|
|
Exceptions : carps if a non-recognised parameter is sent |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Based on rearrange(), which is originally from CGI.pm by Lincoln |
108
|
|
|
|
|
|
|
Stein and BioPerl by Richard Resnick. See rearrange() for details. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=cut |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub get_param |
113
|
|
|
|
|
|
|
{ |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
# This function was taken from CGI.pm, written by Dr. Lincoln |
116
|
|
|
|
|
|
|
# Stein, and adapted for use in Bio::Seq by Richard Resnick. |
117
|
|
|
|
|
|
|
# ...then Chris Mungall came along and adapted it for BDGP |
118
|
|
|
|
|
|
|
# ... and ben berman added his 2 cents. |
119
|
|
|
|
|
|
|
|
120
|
0
|
|
|
0
|
1
|
|
my($name,@param) = @_; |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
# If there are no parameters, we simply wish to return |
123
|
|
|
|
|
|
|
# false. |
124
|
0
|
0
|
|
|
|
|
return '' unless @param; |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
# If we've got parameters, we need to check to see whether |
127
|
|
|
|
|
|
|
# they are named or simply listed. If they are listed, we |
128
|
|
|
|
|
|
|
# can't return anything. |
129
|
0
|
0
|
0
|
|
|
|
return '' unless (defined($param[0]) && $param[0]=~/^-/); |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
# Now we've got to do some work on the named parameters. |
132
|
|
|
|
|
|
|
# The next few lines strip out the '-' characters which |
133
|
|
|
|
|
|
|
# preceed the keys, and capitalizes them. |
134
|
0
|
|
|
|
|
|
my $i; |
135
|
0
|
|
|
|
|
|
for ($i=0;$i<@param;$i+=2) { |
136
|
0
|
|
|
|
|
|
$param[$i]=~s/^\-//; |
137
|
0
|
|
|
|
|
|
$param[$i] = uc($param[$i]); |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
# Now we'll convert the @params variable into an associative array. |
141
|
0
|
|
|
|
|
|
my(%param) = @param; |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
# We capitalize the key, and use it as a key into our |
144
|
|
|
|
|
|
|
# associative array |
145
|
0
|
|
|
|
|
|
my $key = uc($name); |
146
|
0
|
|
|
|
|
|
my $val = $param{$key}; |
147
|
|
|
|
|
|
|
|
148
|
0
|
|
|
|
|
|
return $val; |
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
|
|
|
|
|
|
|
=head2 remove_duplicates |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
remove duplicate items from an array |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
usage: remove_duplicates(\@arr) |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
affects the array passed in, and returns the modified array |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=cut |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
sub remove_duplicates { |
191
|
|
|
|
|
|
|
|
192
|
0
|
|
|
0
|
1
|
|
my $arr_r = shift; |
193
|
0
|
|
|
|
|
|
my @arr = @{$arr_r}; |
|
0
|
|
|
|
|
|
|
194
|
0
|
|
|
|
|
|
my %h = (); |
195
|
0
|
|
|
|
|
|
my $el; |
196
|
0
|
|
|
|
|
|
foreach $el (@arr) { |
197
|
0
|
|
|
|
|
|
$h{$el} = 1; |
198
|
|
|
|
|
|
|
} |
199
|
0
|
|
|
|
|
|
my @new_arr = (); |
200
|
0
|
|
|
|
|
|
foreach $el (keys %h) { |
201
|
0
|
|
|
|
|
|
push (@new_arr, $el); |
202
|
|
|
|
|
|
|
} |
203
|
0
|
|
|
|
|
|
@{$arr_r} = @new_arr; |
|
0
|
|
|
|
|
|
|
204
|
0
|
|
|
|
|
|
@new_arr; |
205
|
|
|
|
|
|
|
} |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=head1 merge_hashes |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
joins two hashes together |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
usage: merge_hashes(\%h1, \%h2); |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
%h1 will now contain the key/val pairs of %h2 as well. if there are |
214
|
|
|
|
|
|
|
key conflicts, %h2 values will take precedence. |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=cut |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
sub merge_hashes { |
219
|
0
|
|
|
0
|
0
|
|
my ($h1, $h2) = @_; |
220
|
0
|
|
|
|
|
|
map { |
221
|
0
|
|
|
|
|
|
$h1->{$_} = $h2->{$_}; |
222
|
0
|
|
|
|
|
|
} keys %{$h2}; |
223
|
0
|
|
|
|
|
|
return $h1; |
224
|
|
|
|
|
|
|
} |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
=head1 get_method_ref |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
returns a pointer to a particular objects method |
229
|
|
|
|
|
|
|
e.g. my $length_f = get_method_ref($seq, 'length'); |
230
|
|
|
|
|
|
|
$len = &$length_f(); |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
=cut |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
sub get_method_ref { |
235
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
236
|
0
|
|
|
|
|
|
my $method = shift; |
237
|
0
|
|
|
0
|
|
|
return sub {return $self->$method(@_)}; |
|
0
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
} |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
=head2 pset2hash |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
Usage - my $h = pset2hash([{name=>"id", value=>"56"}, {name=>"name", value=>"jim"}]); |
244
|
|
|
|
|
|
|
Returns - hashref |
245
|
|
|
|
|
|
|
Args - arrayref of name/value keyed hashrefs |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
=cut |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
sub pset2hash { |
250
|
0
|
|
|
0
|
1
|
|
my $pset = shift; |
251
|
0
|
|
|
|
|
|
my $h = {}; |
252
|
|
|
|
|
|
|
# printf STDERR "REF=%s;\n", ref($pset); |
253
|
0
|
0
|
|
|
|
|
if (ref($pset) eq "ARRAY") { |
|
|
0
|
|
|
|
|
|
254
|
0
|
|
|
|
|
|
map {$h->{$_->{name}} = $_->{value}} @$pset; |
|
0
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
} |
256
|
|
|
|
|
|
|
elsif (ref($pset) eq "HASH") { |
257
|
0
|
|
|
|
|
|
$h = $pset; |
258
|
|
|
|
|
|
|
} |
259
|
|
|
|
|
|
|
else { |
260
|
0
|
|
|
|
|
|
$h = $pset; |
261
|
|
|
|
|
|
|
} |
262
|
0
|
|
|
|
|
|
return $h; |
263
|
|
|
|
|
|
|
} |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
sub dd { |
266
|
0
|
|
|
0
|
0
|
|
my $obj = shift; |
267
|
0
|
|
|
|
|
|
my $d= Data::Dumper->new(['obj',$obj]); |
268
|
0
|
|
|
|
|
|
print $d->Dump; |
269
|
|
|
|
|
|
|
} |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
=head2 spell_greek |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
takes a word as a parameter and spells out any greek symbols encoded |
274
|
|
|
|
|
|
|
within (eg s/&agr;/alpha/g) |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
=cut |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
sub spell_greek |
279
|
|
|
|
|
|
|
{ |
280
|
0
|
|
|
0
|
1
|
|
my $name = shift; |
281
|
|
|
|
|
|
|
|
282
|
0
|
|
|
|
|
|
$name =~ s/&agr\;/alpha/g; |
283
|
0
|
|
|
|
|
|
$name =~ s/&Agr\;/Alpha/g; |
284
|
0
|
|
|
|
|
|
$name =~ s/&bgr\;/beta/g; |
285
|
0
|
|
|
|
|
|
$name =~ s/&Bgr\;/Beta/g; |
286
|
0
|
|
|
|
|
|
$name =~ s/&ggr\;/gamma/g; |
287
|
0
|
|
|
|
|
|
$name =~ s/&Ggr\;/Gamma/g; |
288
|
0
|
|
|
|
|
|
$name =~ s/&dgr\;/delta/g; |
289
|
0
|
|
|
|
|
|
$name =~ s/&Dgr\;/Delta/g; |
290
|
0
|
|
|
|
|
|
$name =~ s/&egr\;/epsilon/g; |
291
|
0
|
|
|
|
|
|
$name =~ s/&Egr\;/Epsilon/g; |
292
|
0
|
|
|
|
|
|
$name =~ s/&zgr\;/zeta/g; |
293
|
0
|
|
|
|
|
|
$name =~ s/&Zgr\;/Zeta/g; |
294
|
0
|
|
|
|
|
|
$name =~ s/&eegr\;/eta/g; |
295
|
0
|
|
|
|
|
|
$name =~ s/&EEgr\;/Eta/g; |
296
|
0
|
|
|
|
|
|
$name =~ s/&thgr\;/theta/g; |
297
|
0
|
|
|
|
|
|
$name =~ s/&THgr\;/Theta/g; |
298
|
0
|
|
|
|
|
|
$name =~ s/&igr\;/iota/g; |
299
|
0
|
|
|
|
|
|
$name =~ s/&Igr\;/Iota/g; |
300
|
0
|
|
|
|
|
|
$name =~ s/&kgr\;/kappa/g; |
301
|
0
|
|
|
|
|
|
$name =~ s/&Kgr\;/Kappa/g; |
302
|
0
|
|
|
|
|
|
$name =~ s/&lgr\;/lambda/g; |
303
|
0
|
|
|
|
|
|
$name =~ s/&Lgr\;/Lambda/g; |
304
|
0
|
|
|
|
|
|
$name =~ s/&mgr\;/mu/g; |
305
|
0
|
|
|
|
|
|
$name =~ s/&Mgr\;/Mu/g; |
306
|
0
|
|
|
|
|
|
$name =~ s/&ngr\;/nu/g; |
307
|
0
|
|
|
|
|
|
$name =~ s/&Ngr\;/Nu/g; |
308
|
0
|
|
|
|
|
|
$name =~ s/&xgr\;/xi/g; |
309
|
0
|
|
|
|
|
|
$name =~ s/&Xgr\;/Xi/g; |
310
|
0
|
|
|
|
|
|
$name =~ s/&ogr\;/omicron/g; |
311
|
0
|
|
|
|
|
|
$name =~ s/&Ogr\;/Omicron/g; |
312
|
0
|
|
|
|
|
|
$name =~ s/&pgr\;/pi/g; |
313
|
0
|
|
|
|
|
|
$name =~ s/&Pgr\;/Pi/g; |
314
|
0
|
|
|
|
|
|
$name =~ s/&rgr\;/rho/g; |
315
|
0
|
|
|
|
|
|
$name =~ s/&Rgr\;/Rho/g; |
316
|
0
|
|
|
|
|
|
$name =~ s/&sgr\;/sigma/g; |
317
|
0
|
|
|
|
|
|
$name =~ s/&Sgr\;/Sigma/g; |
318
|
0
|
|
|
|
|
|
$name =~ s/&tgr\;/tau/g; |
319
|
0
|
|
|
|
|
|
$name =~ s/&Tgr\;/Tau/g; |
320
|
0
|
|
|
|
|
|
$name =~ s/&ugr\;/upsilon/g; |
321
|
0
|
|
|
|
|
|
$name =~ s/&Ugr\;/Upsilon/g; |
322
|
0
|
|
|
|
|
|
$name =~ s/&phgr\;/phi/g; |
323
|
0
|
|
|
|
|
|
$name =~ s/&PHgr\;/Phi/g; |
324
|
0
|
|
|
|
|
|
$name =~ s/&khgr\;/chi/g; |
325
|
0
|
|
|
|
|
|
$name =~ s/&KHgr\;/Chi/g; |
326
|
0
|
|
|
|
|
|
$name =~ s/&psgr\;/psi/g; |
327
|
0
|
|
|
|
|
|
$name =~ s/&PSgr\;/Psi/g; |
328
|
0
|
|
|
|
|
|
$name =~ s/&ohgr\;/omega/g; |
329
|
0
|
|
|
|
|
|
$name =~ s/&OHgr\;/Omega/g; |
330
|
0
|
|
|
|
|
|
$name =~ s//\[/g; |
331
|
0
|
|
|
|
|
|
$name =~ s/<\/up>/\]/g; |
332
|
0
|
|
|
|
|
|
$name =~ s//\[\[/g; |
333
|
0
|
|
|
|
|
|
$name =~ s/<\/down>/\]\]/g; |
334
|
|
|
|
|
|
|
|
335
|
0
|
|
|
|
|
|
return $name; |
336
|
|
|
|
|
|
|
} |
337
|
|
|
|
|
|
|
|
338
|
|
|
|
|
|
|
|
339
|
|
|
|
|
|
|
=head2 check_obj_graph |
340
|
|
|
|
|
|
|
|
341
|
|
|
|
|
|
|
Usage - |
342
|
|
|
|
|
|
|
Returns - true if cycle detected |
343
|
|
|
|
|
|
|
Args - any object |
344
|
|
|
|
|
|
|
|
345
|
|
|
|
|
|
|
=cut |
346
|
|
|
|
|
|
|
|
347
|
|
|
|
|
|
|
sub check_obj_graph { |
348
|
0
|
|
|
0
|
1
|
|
my $object = shift; |
349
|
|
|
|
|
|
|
|
350
|
0
|
|
|
|
|
|
my $h = {}; |
351
|
0
|
|
|
|
|
|
my $cnt = 1; |
352
|
0
|
|
|
|
|
|
my @nodes = ({obj=>$object,path=>[]}); |
353
|
0
|
|
|
|
|
|
my @path = (); |
354
|
0
|
|
|
|
|
|
my $cycle = 0; |
355
|
0
|
|
0
|
|
|
|
while (!$cycle && @nodes) { |
356
|
0
|
|
|
|
|
|
my $node = shift @nodes; |
357
|
0
|
|
|
|
|
|
my $obj = $node->{obj}; |
358
|
0
|
|
|
|
|
|
my $id = sprintf("%s", $node->{obj}); |
359
|
0
|
0
|
0
|
|
|
|
if (ref($obj) && $id !~ /GLOB/) { |
360
|
|
|
|
|
|
|
|
361
|
0
|
0
|
|
|
|
|
if (!$h->{$id}) { |
362
|
0
|
|
|
|
|
|
$h->{$id} = $cnt; |
363
|
0
|
|
|
|
|
|
$cnt++; |
364
|
|
|
|
|
|
|
} |
365
|
|
|
|
|
|
|
|
366
|
|
|
|
|
|
|
# check for cycles |
367
|
0
|
0
|
|
|
|
|
if (grep {my $idelt = sprintf("%s", $_); $idelt eq $id} |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
368
|
|
|
|
|
|
|
@{$node->{path}}) { |
369
|
0
|
|
|
|
|
|
$cycle = $node; |
370
|
|
|
|
|
|
|
} |
371
|
|
|
|
|
|
|
|
372
|
|
|
|
|
|
|
printf |
373
|
0
|
|
|
|
|
|
"* OB:%5s %20s [%s]\n", |
374
|
|
|
|
|
|
|
$h->{$id}, |
375
|
|
|
|
|
|
|
$obj, |
376
|
0
|
|
|
|
|
|
join(", ", map {$h->{$_}} @{$node->{path}}); |
|
0
|
|
|
|
|
|
|
377
|
|
|
|
|
|
|
|
378
|
0
|
|
|
|
|
|
my @newobjs = (); |
379
|
0
|
0
|
|
|
|
|
if (ref($obj) eq "ARRAY") { |
|
|
0
|
|
|
|
|
|
380
|
0
|
|
|
|
|
|
@newobjs = @$obj; |
381
|
|
|
|
|
|
|
} |
382
|
|
|
|
|
|
|
## if (ref($obj) eq "HASH") { |
383
|
|
|
|
|
|
|
elsif (ref($obj) eq "GLOB") { |
384
|
|
|
|
|
|
|
} |
385
|
|
|
|
|
|
|
else { |
386
|
0
|
|
|
|
|
|
@newobjs = values %$obj; |
387
|
|
|
|
|
|
|
} |
388
|
0
|
|
|
|
|
|
map { |
389
|
0
|
|
|
|
|
|
my @newpath = (@{$node->{path}}, $obj); |
|
0
|
|
|
|
|
|
|
390
|
0
|
|
|
|
|
|
my $newnode = {obj=>$_, path=>\@newpath}; |
391
|
0
|
|
|
|
|
|
push(@nodes, $newnode); |
392
|
|
|
|
|
|
|
} @newobjs; |
393
|
|
|
|
|
|
|
} |
394
|
|
|
|
|
|
|
} |
395
|
0
|
|
|
|
|
|
return $cycle; |
396
|
|
|
|
|
|
|
|
397
|
|
|
|
|
|
|
} |
398
|
|
|
|
|
|
|
|
399
|
|
|
|
|
|
|
|
400
|
|
|
|
|
|
|
|
401
|
|
|
|
|
|
|
sub max |
402
|
|
|
|
|
|
|
{ |
403
|
0
|
|
|
0
|
0
|
|
my @items = @_; |
404
|
|
|
|
|
|
|
|
405
|
0
|
|
|
|
|
|
my $max; |
406
|
|
|
|
|
|
|
my $item; |
407
|
0
|
|
|
|
|
|
foreach $item (@items) |
408
|
|
|
|
|
|
|
{ |
409
|
0
|
0
|
|
|
|
|
if (!defined($max)) |
410
|
|
|
|
|
|
|
{ |
411
|
0
|
|
|
|
|
|
$max = $item; |
412
|
|
|
|
|
|
|
} |
413
|
|
|
|
|
|
|
else |
414
|
|
|
|
|
|
|
{ |
415
|
0
|
0
|
|
|
|
|
$max = $item if ($item > $max); |
416
|
|
|
|
|
|
|
} |
417
|
|
|
|
|
|
|
} |
418
|
|
|
|
|
|
|
|
419
|
0
|
|
|
|
|
|
return $max; |
420
|
|
|
|
|
|
|
} |
421
|
|
|
|
|
|
|
|
422
|
|
|
|
|
|
|
|
423
|
|
|
|
|
|
|
|
424
|
|
|
|
|
|
|
1; |