line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: Def.pm 2013-09-17 erick.antezana $ |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Module : Def.pm |
4
|
|
|
|
|
|
|
# Purpose : Definition structure. |
5
|
|
|
|
|
|
|
# License : Copyright (c) 2006-2014 by Erick Antezana. 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
|
|
|
|
|
|
|
# Contact : Erick Antezana |
9
|
|
|
|
|
|
|
# |
10
|
|
|
|
|
|
|
package OBO::Core::Def; |
11
|
|
|
|
|
|
|
|
12
|
18
|
|
|
18
|
|
11081
|
use OBO::Util::DbxrefSet; |
|
18
|
|
|
|
|
31
|
|
|
18
|
|
|
|
|
394
|
|
13
|
|
|
|
|
|
|
|
14
|
18
|
|
|
18
|
|
82
|
use Carp; |
|
18
|
|
|
|
|
21
|
|
|
18
|
|
|
|
|
851
|
|
15
|
18
|
|
|
18
|
|
68
|
use strict; |
|
18
|
|
|
|
|
22
|
|
|
18
|
|
|
|
|
356
|
|
16
|
18
|
|
|
18
|
|
58
|
use warnings; |
|
18
|
|
|
|
|
21
|
|
|
18
|
|
|
|
|
21090
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub new { |
19
|
5958
|
|
|
5958
|
0
|
5900
|
my $class = shift; |
20
|
5958
|
|
|
|
|
5569
|
my $self = {}; |
21
|
|
|
|
|
|
|
|
22
|
5958
|
|
|
|
|
7660
|
$self->{TEXT} = undef; # required, scalar (1) |
23
|
5958
|
|
|
|
|
13255
|
$self->{DBXREF_SET} = OBO::Util::DbxrefSet->new(); # required, Dbxref (0..n) |
24
|
|
|
|
|
|
|
|
25
|
5958
|
|
|
|
|
8979
|
bless ($self, $class); |
26
|
5958
|
|
|
|
|
9989
|
return $self; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head2 text |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
Usage - print $def->text() or $def->text($text) |
32
|
|
|
|
|
|
|
Returns - the definition text (string) |
33
|
|
|
|
|
|
|
Args - the definition text (string) |
34
|
|
|
|
|
|
|
Function - gets/sets the definition text |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=cut |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub text { |
39
|
38569
|
100
|
|
38569
|
1
|
55196
|
if ($_[1]) { $_[0]->{TEXT} = $_[1] } |
|
3588
|
|
|
|
|
5799
|
|
40
|
38569
|
|
|
|
|
124798
|
return $_[0]->{TEXT}; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head2 dbxref_set |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Usage - $def->dbxref_set() or $def->dbxref_set($dbxref_set) |
46
|
|
|
|
|
|
|
Returns - the definition dbxref set (OBO::Util::DbxrefSet) |
47
|
|
|
|
|
|
|
Args - the definition dbxref set (OBO::Util::DbxrefSet) |
48
|
|
|
|
|
|
|
Function - gets/sets the definition dbxref set |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=cut |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub dbxref_set { |
53
|
23962
|
100
|
|
23962
|
1
|
35802
|
$_[0]->{DBXREF_SET} = $_[1] if ($_[1]); |
54
|
23962
|
|
|
|
|
48748
|
return $_[0]->{DBXREF_SET}; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head2 dbxref_set_as_string |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Usage - $definition->dbxref_set_as_string() or $definition->dbxref_set_as_string("[GOC:elh, PMID:9334324, UM-BBD_pathwayID:2\,4\,5-t]") |
60
|
|
|
|
|
|
|
Returns - the dbxref set (string) of this definition; [] if the set is empty |
61
|
|
|
|
|
|
|
Args - the dbxref set (string) describing the source(s) of this definition |
62
|
|
|
|
|
|
|
Function - gets/sets the dbxref set of this definition. The set operation actually *adds* the new dbxrefs to the existing set |
63
|
|
|
|
|
|
|
Remark - make sure that colons (,) are scaped (\,) when necessary |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=cut |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub dbxref_set_as_string { |
68
|
2269
|
|
|
2269
|
1
|
2538
|
my $dbxref_as_string = $_[1]; |
69
|
2269
|
100
|
|
|
|
3517
|
if ($dbxref_as_string) { |
70
|
1406
|
|
|
|
|
1418
|
my $xref_set = $_[0]->{DBXREF_SET}; |
71
|
|
|
|
|
|
|
|
72
|
1406
|
|
|
|
|
1983
|
__dbxref($xref_set, $dbxref_as_string); |
73
|
|
|
|
|
|
|
|
74
|
1406
|
|
|
|
|
2336
|
$_[0]->{DBXREF_SET} = $xref_set; # We are overwriting the existing set; otherwise, add the new elements to the existing set! |
75
|
|
|
|
|
|
|
} |
76
|
2269
|
|
|
|
|
2474
|
my @result = (); # a Set? |
77
|
2269
|
|
|
|
|
3636
|
foreach my $dbxref (sort {lc($b->as_string()) cmp lc($a->as_string())} $_[0]->dbxref_set()->get_set()) { |
|
431
|
|
|
|
|
923
|
|
78
|
1643
|
|
|
|
|
2954
|
unshift @result, $dbxref->as_string(); |
79
|
|
|
|
|
|
|
} |
80
|
2269
|
|
|
|
|
8405
|
return '['.join(', ', @result).']'; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head2 equals |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Usage - $def->equals($another_def) |
86
|
|
|
|
|
|
|
Returns - either 1 (true) or 0 (false) |
87
|
|
|
|
|
|
|
Args - the definition to compare with |
88
|
|
|
|
|
|
|
Function - tells whether this definition is equal to the parameter |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=cut |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub equals { |
93
|
2767
|
|
|
2767
|
1
|
2890
|
my ($self, $target) = @_; |
94
|
2767
|
|
|
|
|
2116
|
my $result = 0; |
95
|
2767
|
50
|
33
|
|
|
4213
|
if ($target && eval { $target->isa('OBO::Core::Def') }) { |
|
2767
|
|
|
|
|
7999
|
|
96
|
|
|
|
|
|
|
|
97
|
2767
|
50
|
|
|
|
4202
|
if (!defined($self->{TEXT})) { |
98
|
0
|
|
|
|
|
0
|
croak 'The text of this definition is undefined.'; |
99
|
|
|
|
|
|
|
} |
100
|
2767
|
50
|
|
|
|
3700
|
if (!defined($target->{TEXT})) { |
101
|
0
|
|
|
|
|
0
|
croak 'The text of the target definition is undefined.'; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
2767
|
|
66
|
|
|
5435
|
$result = (($self->{TEXT} eq $target->{TEXT}) && ($self->{DBXREF_SET}->equals($target->{DBXREF_SET}))); |
105
|
|
|
|
|
|
|
} else { |
106
|
0
|
|
|
|
|
0
|
croak "An unrecognized object type (not a OBO::Core::Def) was found: '", $target, "'"; |
107
|
|
|
|
|
|
|
} |
108
|
2767
|
|
|
|
|
7554
|
return $result; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub __dbxref () { |
112
|
1406
|
50
|
|
1406
|
|
3302
|
caller eq __PACKAGE__ or croak "You cannot call this (__dbxref) prived method!"; |
113
|
|
|
|
|
|
|
# |
114
|
|
|
|
|
|
|
# $_[0] ==> set |
115
|
|
|
|
|
|
|
# $_[1] ==> dbxref string |
116
|
|
|
|
|
|
|
# |
117
|
1406
|
|
|
|
|
1241
|
my $dbxref_set = $_[0]; |
118
|
1406
|
|
|
|
|
1329
|
my $dbxref_as_string = $_[1]; |
119
|
|
|
|
|
|
|
|
120
|
1406
|
|
|
|
|
4625
|
$dbxref_as_string =~ s/^\[//; |
121
|
1406
|
|
|
|
|
4256
|
$dbxref_as_string =~ s/\]$//; |
122
|
1406
|
|
|
|
|
1646
|
$dbxref_as_string =~ s/\\,/;;;;/g; # trick to keep the comma's |
123
|
1406
|
|
|
|
|
1360
|
$dbxref_as_string =~ s/\\"/;;;;;/g; # trick to keep the double quote's |
124
|
|
|
|
|
|
|
|
125
|
1406
|
|
|
|
|
2267
|
my @lineas = $dbxref_as_string =~ /\"([^\"]*)\"/g; # get the double-quoted pieces |
126
|
1406
|
|
|
|
|
2068
|
foreach my $l (@lineas) { |
127
|
9
|
|
|
|
|
14
|
my $cp = $l; |
128
|
9
|
|
|
|
|
15
|
$l =~ s/,/;;;;/g; # trick to keep the comma's |
129
|
9
|
|
|
|
|
122
|
$dbxref_as_string =~ s/\Q$cp\E/$l/; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
1406
|
|
|
|
|
2984
|
my @dbxrefs = split (',', $dbxref_as_string); |
133
|
|
|
|
|
|
|
|
134
|
1406
|
|
|
|
|
4252
|
my $r_db_acc = qr/([ \*\.\w-]*):([ '\#~\w:\\\+\?\{\}\$\/\(\)\[\]\.=&!%_-]*)/o; |
135
|
1406
|
|
|
|
|
2457
|
my $r_desc = qr/\s+\"([^\"]*)\"/o; |
136
|
1406
|
|
|
|
|
2424
|
my $r_mod = qr/\s+(\{[\w ]+=[\w ]+\})/o; |
137
|
|
|
|
|
|
|
|
138
|
1406
|
|
|
|
|
1896
|
foreach my $entry (@dbxrefs) { |
139
|
1528
|
|
|
|
|
1581
|
my ($match, $db, $acc, $desc, $mod) = undef; |
140
|
1528
|
|
|
|
|
3826
|
my $dbxref = OBO::Core::Dbxref->new(); |
141
|
1528
|
100
|
|
|
|
28274
|
if ($entry =~ m/$r_db_acc$r_desc$r_mod?/) { |
|
|
50
|
|
|
|
|
|
142
|
9
|
|
|
|
|
24
|
$db = __unescape($1); |
143
|
9
|
|
|
|
|
15
|
$acc = __unescape($2); |
144
|
9
|
|
|
|
|
12
|
$desc = __unescape($3); |
145
|
9
|
100
|
|
|
|
25
|
$mod = __unescape($4) if ($4); |
146
|
|
|
|
|
|
|
} elsif ($entry =~ m/$r_db_acc$r_desc?$r_mod?/) { |
147
|
1519
|
|
|
|
|
2328
|
$db = __unescape($1); |
148
|
1519
|
|
|
|
|
1992
|
$acc = __unescape($2); |
149
|
1519
|
50
|
|
|
|
2877
|
$desc = __unescape($3) if ($3); |
150
|
1519
|
50
|
|
|
|
2817
|
$mod = __unescape($4) if ($4); |
151
|
|
|
|
|
|
|
} else { |
152
|
0
|
|
|
|
|
0
|
croak "ERROR: Check the 'dbxref' field of '", $entry, "'."; |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
# set the dbxref: |
156
|
1528
|
|
|
|
|
4852
|
$dbxref->name($db.':'.$acc); |
157
|
1528
|
100
|
|
|
|
2755
|
$dbxref->description($desc) if (defined $desc); |
158
|
1528
|
100
|
|
|
|
2037
|
$dbxref->modifier($mod) if (defined $mod); |
159
|
1528
|
|
|
|
|
3207
|
$dbxref_set->add($dbxref); |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
sub __unescape { |
164
|
3066
|
50
|
|
3066
|
|
5014
|
caller eq __PACKAGE__ or die; |
165
|
3066
|
|
|
|
|
3566
|
my $match = $_[0]; |
166
|
3066
|
|
|
|
|
2751
|
$match =~ s/;;;;;/\\"/g; |
167
|
3066
|
|
|
|
|
2374
|
$match =~ s/;;;;/\\,/g; |
168
|
3066
|
|
|
|
|
3706
|
return $match; |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
1; |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
__END__ |