line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: Dbxref.pm 2014-03-29 erick.antezana $ |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Module : Dbxref.pm |
4
|
|
|
|
|
|
|
# Purpose : Reference 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::Dbxref; |
11
|
|
|
|
|
|
|
|
12
|
19
|
|
|
19
|
|
7066
|
use Carp; |
|
19
|
|
|
|
|
46
|
|
|
19
|
|
|
|
|
1133
|
|
13
|
19
|
|
|
19
|
|
90
|
use strict; |
|
19
|
|
|
|
|
36
|
|
|
19
|
|
|
|
|
391
|
|
14
|
19
|
|
|
19
|
|
92
|
use warnings; |
|
19
|
|
|
|
|
38
|
|
|
19
|
|
|
|
|
32940
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub new { |
17
|
3140
|
|
|
3140
|
0
|
4450
|
my $class = shift; |
18
|
3140
|
|
|
|
|
4369
|
my $self = {}; |
19
|
|
|
|
|
|
|
|
20
|
3140
|
|
|
|
|
6887
|
$self->{DB} = ''; # required, scalar (1) |
21
|
3140
|
|
|
|
|
5316
|
$self->{ACC} = ''; # required, scalar (1) |
22
|
3140
|
|
|
|
|
5676
|
$self->{DESCRIPTION} = ''; # scalar (0..1) |
23
|
3140
|
|
|
|
|
5557
|
$self->{MODIFIER} = ''; # scalar (0..1) |
24
|
|
|
|
|
|
|
|
25
|
3140
|
|
|
|
|
4929
|
bless ($self, $class); |
26
|
3140
|
|
|
|
|
7677
|
return $self; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head2 name |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
Usage - print $dbxref->name() or $dbxref->name($name) |
32
|
|
|
|
|
|
|
Returns - the dbxref name (string) |
33
|
|
|
|
|
|
|
Args - the dbxref name (string) that follows this convention DB:ACC (ACC may be an empty string like some dbxrefs from the ChEBI ontology) |
34
|
|
|
|
|
|
|
Function - gets/sets the dbxref name |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=cut |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub name { |
39
|
21060
|
100
|
33
|
21060
|
1
|
98799
|
if ($_[1]) { |
|
|
50
|
|
|
|
|
|
40
|
3139
|
50
|
33
|
|
|
16386
|
if ($_[1] =~ /([\*\.\w-]*):([ ,;'\#~\w:\\\+\?\{\}\$\/\(\)\[\]\.=&!%_-]*)/ || # See $r_db_acc in Term.pm |
41
|
|
|
|
|
|
|
$_[1] =~ /(http):\/\/(.*)/) { |
42
|
3139
|
|
|
|
|
7927
|
$_[0]->{DB} = $1; |
43
|
3139
|
|
|
|
|
9596
|
$_[0]->{ACC} = $2; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
} elsif (!defined($_[0]->{DB}) || !defined($_[0]->{ACC})) { |
46
|
0
|
|
|
|
|
0
|
croak 'The name of this dbxref is not defined.'; |
47
|
|
|
|
|
|
|
} else { # get-mode |
48
|
17921
|
|
|
|
|
77888
|
return $_[0]->{DB}.':'.$_[0]->{ACC}; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# Alias |
53
|
|
|
|
|
|
|
*id = \&name; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head2 db |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
Usage - print $dbxref->db() or $dbxref->db($db) |
58
|
|
|
|
|
|
|
Returns - the dbxref db (string) |
59
|
|
|
|
|
|
|
Args - the dbxref db (string) |
60
|
|
|
|
|
|
|
Function - gets/sets the dbxref db |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=cut |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub db { |
65
|
3226
|
100
|
|
3226
|
1
|
8557
|
if ($_[1]) { |
|
|
50
|
|
|
|
|
|
66
|
1
|
|
|
|
|
3
|
$_[0]->{DB} = $_[1]; |
67
|
|
|
|
|
|
|
} elsif (!defined($_[0]->{DB})) { |
68
|
0
|
|
|
|
|
0
|
croak "The database (db) of this 'dbxref' is not defined."; |
69
|
|
|
|
|
|
|
} else { # get-mode |
70
|
3225
|
|
|
|
|
10957
|
return $_[0]->{DB}; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head2 acc |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
Usage - print $dbxref->acc() or $dbxref->acc($acc) |
77
|
|
|
|
|
|
|
Returns - the dbxref acc (string) |
78
|
|
|
|
|
|
|
Args - the dbxref acc (string) |
79
|
|
|
|
|
|
|
Function - gets/sets the dbxref acc |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=cut |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub acc { |
84
|
3226
|
100
|
|
3226
|
1
|
8589
|
if ($_[1]) { |
|
|
50
|
|
|
|
|
|
85
|
1
|
|
|
|
|
4
|
$_[0]->{ACC} = $_[1]; |
86
|
|
|
|
|
|
|
} elsif (!defined($_[0]->{ACC})) { |
87
|
0
|
|
|
|
|
0
|
croak 'The accession number (acc) of this dbxref is not defined.'; |
88
|
|
|
|
|
|
|
} else { # get-mode |
89
|
3225
|
|
|
|
|
10509
|
return $_[0]->{ACC}; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head2 description |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
Usage - print $dbxref->description() or $dbxref->description($description) |
96
|
|
|
|
|
|
|
Returns - the dbxref description (string) |
97
|
|
|
|
|
|
|
Args - the dbxref description (string) |
98
|
|
|
|
|
|
|
Function - gets/sets the dbxref description |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=cut |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub description { |
103
|
324
|
100
|
33
|
324
|
1
|
1774
|
if ($_[1]) { |
|
|
50
|
|
|
|
|
|
104
|
30
|
|
|
|
|
95
|
$_[0]->{DESCRIPTION} = $_[1]; |
105
|
|
|
|
|
|
|
} elsif (!defined($_[0]->{DB}) || !defined($_[0]->{ACC})) { |
106
|
0
|
|
|
|
|
0
|
croak 'The name of this dbxref is not defined.'; |
107
|
|
|
|
|
|
|
} else { # get-mode |
108
|
294
|
|
|
|
|
927
|
return $_[0]->{DESCRIPTION}; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head2 modifier |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Usage - print $dbxref->modifier() or $dbxref->modifier($modifier) |
115
|
|
|
|
|
|
|
Returns - the optional trailing modifier (string) |
116
|
|
|
|
|
|
|
Args - the optional trailing modifier (string) |
117
|
|
|
|
|
|
|
Function - gets/sets the optional trailing modifier |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=cut |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub modifier { |
122
|
299
|
100
|
33
|
299
|
1
|
1590
|
if ($_[1]) { |
|
|
50
|
|
|
|
|
|
123
|
9
|
|
|
|
|
27
|
$_[0]->{MODIFIER} = $_[1]; |
124
|
|
|
|
|
|
|
} elsif (!defined($_[0]->{DB}) || !defined($_[0]->{ACC})) { |
125
|
0
|
|
|
|
|
0
|
croak 'The name of this dbxref is not defined.'; |
126
|
|
|
|
|
|
|
} else { # get-mode |
127
|
290
|
|
|
|
|
1141
|
return $_[0]->{MODIFIER}; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head2 as_string |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Usage - print $dbxref->as_string() |
134
|
|
|
|
|
|
|
Returns - returns this dbxref ([name "description" {modifier}]) as string |
135
|
|
|
|
|
|
|
Args - none |
136
|
|
|
|
|
|
|
Function - returns this dbxref as string |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=cut |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
sub as_string { |
141
|
9851
|
50
|
33
|
9851
|
1
|
34617
|
croak 'The name of this dbxref is not defined.' if (!defined($_[0]->{DB}) || !defined($_[0]->{ACC})); |
142
|
9851
|
|
|
|
|
22649
|
my $result = $_[0]->{DB}.':'.$_[0]->{ACC}; |
143
|
9851
|
100
|
66
|
|
|
45876
|
$result .= ' "'.$_[0]->{DESCRIPTION}.'"' if (defined $_[0]->{DESCRIPTION} && $_[0]->{DESCRIPTION} ne ''); |
144
|
9851
|
100
|
66
|
|
|
42184
|
$result .= ' '.$_[0]->{MODIFIER} if (defined $_[0]->{MODIFIER} && $_[0]->{MODIFIER} ne ''); |
145
|
9851
|
|
|
|
|
34692
|
return $result; |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head2 equals |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
Usage - print $dbxref->equals($another_dbxref) |
151
|
|
|
|
|
|
|
Returns - either 1(true) or 0 (false) |
152
|
|
|
|
|
|
|
Args - the dbxref(OBO::Core::Dbxref) to compare with |
153
|
|
|
|
|
|
|
Function - tells whether this dbxref is equal to the parameter |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=cut |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
sub equals { |
158
|
8
|
50
|
33
|
8
|
1
|
28
|
if ($_[1] && eval { $_[1]->isa('OBO::Core::Dbxref') }) { |
|
8
|
|
|
|
|
51
|
|
159
|
|
|
|
|
|
|
|
160
|
8
|
50
|
33
|
|
|
37
|
if (!defined($_[0]->{DB}) || !defined($_[0]->{ACC})) { |
161
|
0
|
|
|
|
|
0
|
croak 'The name of this dbxref is undefined.'; |
162
|
|
|
|
|
|
|
} |
163
|
8
|
50
|
33
|
|
|
44
|
if (!defined($_[1]->{DB}) || !defined($_[1]->{ACC})) { |
164
|
0
|
|
|
|
|
0
|
croak 'The name of the target dbxref is undefined.'; |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
return (($_[0]->{DB} eq $_[1]->{DB}) && |
167
|
|
|
|
|
|
|
($_[0]->{ACC} eq $_[1]->{ACC}) && |
168
|
|
|
|
|
|
|
($_[0]->{DESCRIPTION} eq $_[1]->{DESCRIPTION}) && |
169
|
8
|
|
66
|
|
|
100
|
($_[0]->{MODIFIER} eq $_[1]->{MODIFIER})); |
170
|
|
|
|
|
|
|
} else { |
171
|
0
|
|
|
|
|
|
croak "An unrecognized object type (not a OBO::Core::Dbxref) was found: '", $_[1], "'"; |
172
|
|
|
|
|
|
|
} |
173
|
0
|
|
|
|
|
|
return 0; |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
1; |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
__END__ |