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-2015 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
|
|
15701
|
use OBO::Util::DbxrefSet; |
|
18
|
|
|
|
|
50
|
|
|
18
|
|
|
|
|
461
|
|
13
|
|
|
|
|
|
|
|
14
|
18
|
|
|
18
|
|
111
|
use Carp; |
|
18
|
|
|
|
|
28
|
|
|
18
|
|
|
|
|
2066
|
|
15
|
18
|
|
|
18
|
|
92
|
use strict; |
|
18
|
|
|
|
|
28
|
|
|
18
|
|
|
|
|
412
|
|
16
|
18
|
|
|
18
|
|
88
|
use warnings; |
|
18
|
|
|
|
|
29
|
|
|
18
|
|
|
|
|
28728
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub new { |
19
|
5966
|
|
|
5966
|
0
|
8107
|
my $class = shift; |
20
|
5966
|
|
|
|
|
8345
|
my $self = {}; |
21
|
|
|
|
|
|
|
|
22
|
5966
|
|
|
|
|
10562
|
$self->{TEXT} = undef; # required, scalar (1) |
23
|
5966
|
|
|
|
|
16161
|
$self->{DBXREF_SET} = OBO::Util::DbxrefSet->new(); # required, Dbxref (0..n) |
24
|
|
|
|
|
|
|
|
25
|
5966
|
|
|
|
|
9152
|
bless ($self, $class); |
26
|
5966
|
|
|
|
|
13435
|
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
|
38654
|
100
|
|
38654
|
1
|
77096
|
if ($_[1]) { $_[0]->{TEXT} = $_[1] } |
|
3595
|
|
|
|
|
6812
|
|
40
|
38654
|
|
|
|
|
176141
|
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
|
24017
|
100
|
|
24017
|
1
|
46023
|
$_[0]->{DBXREF_SET} = $_[1] if ($_[1]); |
54
|
24017
|
|
|
|
|
71706
|
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
|
2270
|
|
|
2270
|
1
|
4080
|
my $dbxref_as_string = $_[1]; |
69
|
2270
|
100
|
|
|
|
4872
|
if ($dbxref_as_string) { |
70
|
1407
|
|
|
|
|
2025
|
my $xref_set = $_[0]->{DBXREF_SET}; |
71
|
|
|
|
|
|
|
|
72
|
1407
|
|
|
|
|
2864
|
__dbxref($xref_set, $dbxref_as_string); |
73
|
|
|
|
|
|
|
|
74
|
1407
|
|
|
|
|
2820
|
$_[0]->{DBXREF_SET} = $xref_set; # We are overwriting the existing set; otherwise, add the new elements to the existing set! |
75
|
|
|
|
|
|
|
} |
76
|
2270
|
|
|
|
|
3448
|
my @result = (); # a Set? |
77
|
2270
|
|
|
|
|
4818
|
foreach my $dbxref (sort {lc($b->as_string()) cmp lc($a->as_string())} $_[0]->dbxref_set()->get_set()) { |
|
436
|
|
|
|
|
1281
|
|
78
|
1648
|
|
|
|
|
4293
|
unshift @result, $dbxref->as_string(); |
79
|
|
|
|
|
|
|
} |
80
|
2270
|
|
|
|
|
10585
|
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
|
2777
|
|
|
2777
|
1
|
3941
|
my ($self, $target) = @_; |
94
|
2777
|
|
|
|
|
3320
|
my $result = 0; |
95
|
2777
|
50
|
33
|
|
|
6123
|
if ($target && eval { $target->isa('OBO::Core::Def') }) { |
|
2777
|
|
|
|
|
12469
|
|
96
|
|
|
|
|
|
|
|
97
|
2777
|
50
|
|
|
|
6116
|
if (!defined($self->{TEXT})) { |
98
|
0
|
|
|
|
|
0
|
croak 'The text of this definition is undefined.'; |
99
|
|
|
|
|
|
|
} |
100
|
2777
|
50
|
|
|
|
5367
|
if (!defined($target->{TEXT})) { |
101
|
0
|
|
|
|
|
0
|
croak 'The text of the target definition is undefined.'; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
2777
|
|
66
|
|
|
7173
|
$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
|
2777
|
|
|
|
|
10779
|
return $result; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub __dbxref () { |
112
|
1407
|
50
|
|
1407
|
|
3576
|
caller eq __PACKAGE__ or croak "You cannot call this (__dbxref) prived method!"; |
113
|
|
|
|
|
|
|
# |
114
|
|
|
|
|
|
|
# $_[0] ==> set |
115
|
|
|
|
|
|
|
# $_[1] ==> dbxref string |
116
|
|
|
|
|
|
|
# |
117
|
1407
|
|
|
|
|
1625
|
my $dbxref_set = $_[0]; |
118
|
1407
|
|
|
|
|
1944
|
my $dbxref_as_string = $_[1]; |
119
|
|
|
|
|
|
|
|
120
|
1407
|
|
|
|
|
5095
|
$dbxref_as_string =~ s/^\[//; |
121
|
1407
|
|
|
|
|
5304
|
$dbxref_as_string =~ s/\]$//; |
122
|
1407
|
|
|
|
|
2476
|
$dbxref_as_string =~ s/\\,/;;;;/g; # trick to keep the comma's |
123
|
1407
|
|
|
|
|
2037
|
$dbxref_as_string =~ s/\\"/;;;;;/g; # trick to keep the double quote's |
124
|
|
|
|
|
|
|
|
125
|
1407
|
|
|
|
|
2617
|
my @lineas = $dbxref_as_string =~ /\"([^\"]*)\"/g; # get the double-quoted pieces |
126
|
1407
|
|
|
|
|
2611
|
foreach my $l (@lineas) { |
127
|
9
|
|
|
|
|
16
|
my $cp = $l; |
128
|
9
|
|
|
|
|
19
|
$l =~ s/,/;;;;/g; # trick to keep the comma's |
129
|
9
|
|
|
|
|
136
|
$dbxref_as_string =~ s/\Q$cp\E/$l/; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
1407
|
|
|
|
|
3557
|
my @dbxrefs = split (',', $dbxref_as_string); |
133
|
|
|
|
|
|
|
|
134
|
1407
|
|
|
|
|
4598
|
my $r_db_acc = qr/([ \*\.\w-]*):([ '\#~\w:\\\+\?\{\}\$\/\(\)\[\]\.=&!%_-]*)/o; |
135
|
1407
|
|
|
|
|
3630
|
my $r_desc = qr/\s+\"([^\"]*)\"/o; |
136
|
1407
|
|
|
|
|
3487
|
my $r_mod = qr/\s+(\{[\w ]+=[\w ]+\})/o; |
137
|
|
|
|
|
|
|
|
138
|
1407
|
|
|
|
|
2984
|
foreach my $entry (@dbxrefs) { |
139
|
1533
|
|
|
|
|
2368
|
my ($match, $db, $acc, $desc, $mod) = undef; |
140
|
1533
|
|
|
|
|
4541
|
my $dbxref = OBO::Core::Dbxref->new(); |
141
|
1533
|
100
|
|
|
|
35623
|
if ($entry =~ m/$r_db_acc$r_desc$r_mod?/) { |
|
|
50
|
|
|
|
|
|
142
|
9
|
|
|
|
|
21
|
$db = __unescape($1); |
143
|
9
|
|
|
|
|
21
|
$acc = __unescape($2); |
144
|
9
|
|
|
|
|
19
|
$desc = __unescape($3); |
145
|
9
|
100
|
|
|
|
32
|
$mod = __unescape($4) if ($4); |
146
|
|
|
|
|
|
|
} elsif ($entry =~ m/$r_db_acc$r_desc?$r_mod?/) { |
147
|
1524
|
|
|
|
|
3014
|
$db = __unescape($1); |
148
|
1524
|
|
|
|
|
2771
|
$acc = __unescape($2); |
149
|
1524
|
50
|
|
|
|
3955
|
$desc = __unescape($3) if ($3); |
150
|
1524
|
50
|
|
|
|
3747
|
$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
|
1533
|
|
|
|
|
6502
|
$dbxref->name($db.':'.$acc); |
157
|
1533
|
100
|
|
|
|
3791
|
$dbxref->description($desc) if (defined $desc); |
158
|
1533
|
100
|
|
|
|
2747
|
$dbxref->modifier($mod) if (defined $mod); |
159
|
1533
|
|
|
|
|
4182
|
$dbxref_set->add($dbxref); |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
sub __unescape { |
164
|
3076
|
50
|
|
3076
|
|
7244
|
caller eq __PACKAGE__ or die; |
165
|
3076
|
|
|
|
|
5808
|
my $match = $_[0]; |
166
|
3076
|
|
|
|
|
4052
|
$match =~ s/;;;;;/\\"/g; |
167
|
3076
|
|
|
|
|
4200
|
$match =~ s/;;;;/\\,/g; |
168
|
3076
|
|
|
|
|
5823
|
return $match; |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
1; |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
__END__ |