line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: GoaAssociationSet.pm 2010-09-29 erick.antezana $ |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Module : GoaAssociationSet.pm |
4
|
|
|
|
|
|
|
# Purpose : GOA association set. |
5
|
|
|
|
|
|
|
# License : Copyright (c) 2006-2015 by ONTO-perl. All rights reserved. |
6
|
|
|
|
|
|
|
# This program is free software; you can redistribute it and/or |
7
|
|
|
|
|
|
|
# modify it under the same terms as Perl itself. |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
package OBO::APO::GoaAssociationSet; |
10
|
|
|
|
|
|
|
our @ISA = qw(OBO::Util::Set); # TODO change inheritence |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
OBO::APO::GoaAssociationSet - A GoaAssociationSet implementation |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 SYNOPSIS |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
use OBO::APO::GoaAssociationSet; |
19
|
|
|
|
|
|
|
use OBO::APO::GoaAssociation; |
20
|
|
|
|
|
|
|
use strict; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
my $my_set = OBO::APO::GoaAssociationSet->new(); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# three new goa_association's |
25
|
|
|
|
|
|
|
my $goa_association1 = OBO::APO::GoaAssociation->new(); |
26
|
|
|
|
|
|
|
my $goa_association2 = OBO::APO::GoaAssociation->new(); |
27
|
|
|
|
|
|
|
my $goa_association3 = OBO::APO::GoaAssociation->new(); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
$goa_association1->assc_id("APO:vm"); |
30
|
|
|
|
|
|
|
$goa_association2->assc_id("APO:ls"); |
31
|
|
|
|
|
|
|
$goa_association3->assc_id("APO:ea"); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# remove from my_set |
34
|
|
|
|
|
|
|
$my_set->remove($goa_association1); |
35
|
|
|
|
|
|
|
$my_set->add($goa_association1); |
36
|
|
|
|
|
|
|
$my_set->remove($goa_association1); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
### set versions ### |
39
|
|
|
|
|
|
|
$my_set->add($goa_association1); |
40
|
|
|
|
|
|
|
$my_set->add($goa_association2); |
41
|
|
|
|
|
|
|
$my_set->add($goa_association3); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
my $goa_association4 = OBO::APO::GoaAssociation->new(); |
44
|
|
|
|
|
|
|
my $goa_association5 = OBO::APO::GoaAssociation->new(); |
45
|
|
|
|
|
|
|
my $goa_association6 = OBO::APO::GoaAssociation->new(); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
$goa_association4->assc_id("APO:ef"); |
48
|
|
|
|
|
|
|
$goa_association5->assc_id("APO:sz"); |
49
|
|
|
|
|
|
|
$goa_association6->assc_id("APO:qa"); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
$my_set->add_all($goa_association4, $goa_association5, $goa_association6); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
$my_set->add_all($goa_association4, $goa_association5, $goa_association6); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# remove from my_set |
56
|
|
|
|
|
|
|
$my_set->remove($goa_association4); |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
my $goa_association7 = $goa_association4; |
59
|
|
|
|
|
|
|
my $goa_association8 = $goa_association5; |
60
|
|
|
|
|
|
|
my $goa_association9 = $goa_association6; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
my $my_set2 = OBO::APO::GoaAssociationSet->new(); |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
$my_set->add_all($goa_association4, $goa_association5, $goa_association6); |
65
|
|
|
|
|
|
|
$my_set2->add_all($goa_association7, $goa_association8, $goa_association9, $goa_association1, $goa_association2, $goa_association3); |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
$my_set2->clear(); |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 DESCRIPTION |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
A set (OBO::Util::Set) of goa_association records. |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
Copyright (C) 2006 by ONTO-perl |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
78
|
|
|
|
|
|
|
it under the same terms as Perl itself, either Perl version 5.8.7 or, |
79
|
|
|
|
|
|
|
at your option, any later version of Perl 5 you may have available. |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=cut |
82
|
|
|
|
|
|
|
|
83
|
3
|
|
|
3
|
|
617
|
use OBO::Util::Set; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
70
|
|
84
|
3
|
|
|
3
|
|
16
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
65
|
|
85
|
3
|
|
|
3
|
|
14
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
64
|
|
86
|
3
|
|
|
3
|
|
14
|
use Carp; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
2413
|
|
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head2 add |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Usage - $set->add($goa_association) |
91
|
|
|
|
|
|
|
Returns - true if the element was successfully added |
92
|
|
|
|
|
|
|
Args - the element (OBO::APO::GoaAssociation) to be added |
93
|
|
|
|
|
|
|
Function - adds an element to this set |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=cut |
96
|
|
|
|
|
|
|
sub add { |
97
|
27
|
|
|
27
|
1
|
35
|
my $self = shift; |
98
|
27
|
|
|
|
|
38
|
my $result = 0; # nothing added |
99
|
27
|
50
|
|
|
|
53
|
if (@_) { |
100
|
27
|
|
|
|
|
34
|
my $ele = shift; |
101
|
27
|
100
|
|
|
|
46
|
if ( !$self -> contains($ele) ) { |
102
|
20
|
|
|
|
|
23
|
push @{$self->{SET}}, $ele; |
|
20
|
|
|
|
|
36
|
|
103
|
20
|
|
|
|
|
31
|
$result = 1; # successfully added |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
} |
106
|
27
|
|
|
|
|
62
|
return $result; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head2 add_unique |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Usage - $set->add_unique($goa_association) |
112
|
|
|
|
|
|
|
Returns - 1 (the element is always added) |
113
|
|
|
|
|
|
|
Args - the element (OBO::APO::GoaAssociation) to be added which is known to be unique! |
114
|
|
|
|
|
|
|
Function - adds an element to this set |
115
|
|
|
|
|
|
|
Remark - this function should be used when the element to be added is known to be unique, |
116
|
|
|
|
|
|
|
this function has a tremendous impact on the performance (compared to simply add()) |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=cut |
119
|
|
|
|
|
|
|
sub add_unique { |
120
|
29
|
|
|
29
|
1
|
37
|
my $self = shift; |
121
|
29
|
|
|
|
|
36
|
my $result = 0; # nothing added |
122
|
29
|
50
|
|
|
|
58
|
if (@_) { |
123
|
29
|
|
|
|
|
33
|
my $ele = shift; |
124
|
29
|
|
|
|
|
30
|
push @{$self->{SET}}, $ele; |
|
29
|
|
|
|
|
70
|
|
125
|
|
|
|
|
|
|
} |
126
|
29
|
|
|
|
|
165
|
return 1; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head2 remove |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Usage - $set->remove($element) |
132
|
|
|
|
|
|
|
Returns - the removed element (OBO::APO::GoaAssociation) |
133
|
|
|
|
|
|
|
Args - the element to be removed (OBO::APO::GoaAssociation) |
134
|
|
|
|
|
|
|
Function - removes an element from this set |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=cut |
137
|
|
|
|
|
|
|
sub remove { |
138
|
3
|
|
|
3
|
1
|
9
|
my $self = shift; |
139
|
3
|
|
|
|
|
5
|
my $result = undef; |
140
|
3
|
50
|
|
|
|
8
|
if (@_) { |
141
|
3
|
|
|
|
|
5
|
my $ele = shift; |
142
|
3
|
100
|
|
|
|
11
|
if ($self->size() > 0) { |
143
|
2
|
|
|
|
|
6
|
for (my $i = 0; $i < scalar(@{$self->{SET}}); $i++){ |
|
5
|
|
|
|
|
12
|
|
144
|
5
|
|
|
|
|
6
|
my $e = ${$self->{SET}}[$i]; |
|
5
|
|
|
|
|
10
|
|
145
|
5
|
100
|
|
|
|
13
|
if ($ele->equals($e)) { |
146
|
2
|
100
|
|
|
|
7
|
if ($self->size() > 1) { |
|
|
50
|
|
|
|
|
|
147
|
1
|
|
|
|
|
2
|
my $first_elem = shift (@{$self->{SET}}); |
|
1
|
|
|
|
|
2
|
|
148
|
1
|
|
|
|
|
2
|
${$self->{SET}}[$i-1] = $first_elem; |
|
1
|
|
|
|
|
3
|
|
149
|
|
|
|
|
|
|
} elsif ($self->size() == 1) { |
150
|
1
|
|
|
|
|
2
|
shift (@{$self->{SET}}); |
|
1
|
|
|
|
|
2
|
|
151
|
|
|
|
|
|
|
} |
152
|
2
|
|
|
|
|
4
|
$result = $ele; |
153
|
2
|
|
|
|
|
4
|
last; |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
} |
158
|
3
|
|
|
|
|
7
|
return $result; |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head2 remove_duplicates |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
Usage - $set->remove_duplicates() |
164
|
|
|
|
|
|
|
Returns - a set object (OBO::APO::GoaAssociationSet) |
165
|
|
|
|
|
|
|
Args - none |
166
|
|
|
|
|
|
|
Function - eliminates redundency in a GOA association set object (OBO::APO::GoaAssociationSet) |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=cut |
169
|
|
|
|
|
|
|
sub remove_duplicates { |
170
|
2
|
|
|
2
|
1
|
4
|
my $self = shift; |
171
|
2
|
|
|
|
|
4
|
my @list = @{$self->{SET}}; |
|
2
|
|
|
|
|
7
|
|
172
|
2
|
|
|
|
|
3
|
my @set = (); |
173
|
2
|
|
|
|
|
5
|
while (scalar (@list)) { |
174
|
12
|
|
|
|
|
17
|
my $ele = pop(@list); |
175
|
12
|
|
|
|
|
13
|
my $result = 0; |
176
|
12
|
|
|
|
|
24
|
foreach (@list) { |
177
|
29
|
100
|
|
|
|
69
|
if ($ele->equals($_)) { |
178
|
2
|
|
|
|
|
3
|
$result = 1; |
179
|
2
|
|
|
|
|
3
|
last; |
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
} |
182
|
12
|
100
|
|
|
|
42
|
unshift @set, $ele if $result == 0; |
183
|
|
|
|
|
|
|
} |
184
|
2
|
|
|
|
|
3
|
@{$self->{SET}} = @set; |
|
2
|
|
|
|
|
6
|
|
185
|
2
|
|
|
|
|
5
|
return $self; |
186
|
|
|
|
|
|
|
} |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=head2 contains |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
Usage - $set->contains($goa_association) |
192
|
|
|
|
|
|
|
Returns - either 1(true) or 0 (false) |
193
|
|
|
|
|
|
|
Args - the element (OBO::APO::GoaAssociation) to be checked |
194
|
|
|
|
|
|
|
Function - checks if this set constains the given element |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=cut |
197
|
|
|
|
|
|
|
sub contains { |
198
|
40
|
|
|
40
|
1
|
74
|
my $self = shift; |
199
|
40
|
|
|
|
|
47
|
my $result = 0; |
200
|
40
|
50
|
|
|
|
82
|
if (@_){ |
201
|
40
|
|
|
|
|
44
|
my $target = shift; |
202
|
40
|
|
|
|
|
48
|
foreach my $ele (@{$self->{SET}}){ |
|
40
|
|
|
|
|
80
|
|
203
|
116
|
100
|
|
|
|
294
|
if ($target->equals($ele)) { |
204
|
17
|
|
|
|
|
17
|
$result = 1; |
205
|
17
|
|
|
|
|
26
|
last; |
206
|
|
|
|
|
|
|
} |
207
|
|
|
|
|
|
|
} |
208
|
|
|
|
|
|
|
} |
209
|
40
|
|
|
|
|
113
|
return $result; |
210
|
|
|
|
|
|
|
} |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=head2 equals |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
Usage - $set->equals($another_goa_assocations_set) |
215
|
|
|
|
|
|
|
Returns - either 1 (true) or 0 (false) |
216
|
|
|
|
|
|
|
Args - the set (OBO::APO::GoaAssociationSet) to compare with |
217
|
|
|
|
|
|
|
Function - tells whether this set is equal to the given one |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=cut |
220
|
|
|
|
|
|
|
sub equals { |
221
|
3
|
|
|
3
|
1
|
4
|
my $self = shift; |
222
|
3
|
|
|
|
|
6
|
my $result = 0; # I guess they'are NOT identical |
223
|
3
|
50
|
|
|
|
9
|
if (@_) { |
224
|
3
|
|
|
|
|
10
|
my $other_set = shift; |
225
|
3
|
|
|
|
|
7
|
my %count = (); |
226
|
3
|
|
|
|
|
4
|
my @this = @{$self->{SET}}; |
|
3
|
|
|
|
|
9
|
|
227
|
3
|
|
|
|
|
16
|
my @that = $other_set->get_set(); |
228
|
|
|
|
|
|
|
|
229
|
3
|
100
|
|
|
|
12
|
if ($#this == $#that) { |
230
|
2
|
50
|
|
|
|
7
|
if ($#this != -1) { |
231
|
2
|
|
|
|
|
5
|
foreach (@this, @that) { |
232
|
18
|
|
|
|
|
47
|
$count{ $_->annot_src(). |
233
|
|
|
|
|
|
|
$_->aspect(). |
234
|
|
|
|
|
|
|
$_->assc_id(). |
235
|
|
|
|
|
|
|
$_->date(). |
236
|
|
|
|
|
|
|
$_->description(). |
237
|
|
|
|
|
|
|
$_->evid_code(). |
238
|
|
|
|
|
|
|
$_->go_id(). |
239
|
|
|
|
|
|
|
$_->obj_id(). |
240
|
|
|
|
|
|
|
$_->obj_src(). |
241
|
|
|
|
|
|
|
$_->obj_symb(). |
242
|
|
|
|
|
|
|
$_->qualifier(). |
243
|
|
|
|
|
|
|
$_->refer(). |
244
|
|
|
|
|
|
|
$_->sup_ref(). |
245
|
|
|
|
|
|
|
$_->synonym(). |
246
|
|
|
|
|
|
|
$_->taxon(). |
247
|
|
|
|
|
|
|
$_->type()}++; |
248
|
|
|
|
|
|
|
} |
249
|
2
|
|
|
|
|
6
|
foreach my $count (values %count) { |
250
|
9
|
50
|
|
|
|
15
|
if ($count != 2) { |
251
|
0
|
|
|
|
|
0
|
$result = 0; |
252
|
0
|
|
|
|
|
0
|
last; |
253
|
|
|
|
|
|
|
} else { |
254
|
9
|
|
|
|
|
18
|
$result = 1; |
255
|
|
|
|
|
|
|
} |
256
|
|
|
|
|
|
|
} |
257
|
|
|
|
|
|
|
} else { |
258
|
0
|
|
|
|
|
0
|
$result = 1; # they are equal: empty arrays |
259
|
|
|
|
|
|
|
} |
260
|
|
|
|
|
|
|
} |
261
|
|
|
|
|
|
|
} |
262
|
3
|
|
|
|
|
12
|
return $result; |
263
|
|
|
|
|
|
|
} |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
1; |