Bio/Ontology/Relationship.pm

filter: Statementstmt 94.9% 75 / 79 Branchbran 80.5% 29 / 36 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 12 / 12 Podpod 100% 8 / 8 totaltotal 91.8% 124 / 135 CC 19 SCAR 15.2
CC
19
Cov
90%
new
8.0
_check_class
6.6
ontology
5.1
CRAP 4.6
« Bio/Search/Result/ResultI.pm ↑ Summary Bio/Tools/RandomDistFunctions.pm »
1 #
2 # BioPerl module for Relationship
3 #
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
5 #
6 # Cared for by Christian M. Zmasek <czmasek-at-burnham.org> or <cmzmasek@yahoo.com>
7 #
8 # (c) Christian M. Zmasek, czmasek-at-burnham.org, 2002.
9 # (c) GNF, Genomics Institute of the Novartis Research Foundation, 2002.
10 #
11 # You may distribute this module under the same terms as perl itself.
12 # Refer to the Perl Artistic License (see the license accompanying this
13 # software package, or see http://www.perl.com/language/misc/Artistic.html)
14 # for the terms under which you may use, modify, and redistribute this module.
15 #
16 # THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
17 # WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
18 # MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 #
20 # You may distribute this module under the same terms as perl itself
21  
22 # POD documentation - main docs before the code
23  
24 =head1 NAME
25  
26 Bio::Ontology::Relationship - a relationship for an ontology
27  
28 =head1 SYNOPSIS
29  
30 $rel = Bio::Ontology::Relationship->new( -identifier => "16847",
31 -subject_term => $subj,
32 -object_term => $obj,
33 -predicate_term => $pred );
34  
35 =head1 DESCRIPTION
36  
37 This is a basic implementation of Bio::Ontology::RelationshipI.
38  
39 The terminology we use here is the one commonly used for ontologies,
40 namely the triple of (subject, predicate, object), which in addition
41 is scoped in a namespace (ontology). It is called triple because it is
42 a tuple of three ontology terms.
43  
44 There are other terminologies in use for expressing relationships. For
45 those who it helps to better understand the concept, the triple of
46 (child, relationship type, parent) would be equivalent to the
47 terminology chosen here, disregarding the question whether the notion
48 of parent and child is sensible in the context of the relationship
49 type or not. Especially in the case of ontologies with a wide variety
50 of predicates the parent/child terminology and similar ones can
51 quickly become ambiguous (e.g., A synthesises B), meaningless (e.g., A
52 binds B), or even conflicting (e.g., A is-parent-of B), and are
53 therefore strongly discouraged.
54  
55 =head1 FEEDBACK
56  
57 =head2 Mailing Lists
58  
59 User feedback is an integral part of the evolution of this and other
60 Bioperl modules. Send your comments and suggestions preferably to the
61 Bioperl mailing lists Your participation is much appreciated.
62  
63 bioperl-l@bioperl.org - General discussion
64 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
65  
66 =head2 Support
67  
68 Please direct usage questions or support issues to the mailing list:
69  
70 I<bioperl-l@bioperl.org>
71  
72 rather than to the module maintainer directly. Many experienced and
73 reponsive experts will be able look at the problem and quickly
74 address it. Please include a thorough description of the problem
75 with code and data examples if at all possible.
76  
77 =head2 Reporting Bugs
78  
79 Report bugs to the Bioperl bug tracking system to help us keep track
80 the bugs and their resolution. Bug reports can be submitted via
81 the web:
82  
83 https://github.com/bioperl/bioperl-live/issues
84  
85 =head1 AUTHOR
86  
87 Christian M. Zmasek
88  
89 Email: czmasek-at-burnham.org or cmzmasek@yahoo.com
90  
91 WWW: http://monochrome-effect.net/
92  
93 Address:
94  
95 Genomics Institute of the Novartis Research Foundation
96 10675 John Jay Hopkins Drive
97 San Diego, CA 92121
98  
99 =head1 CONTRIBUTORS
100  
101 Hilmar Lapp, email: hlapp at gmx.net
102  
103 =head1 APPENDIX
104  
105 The rest of the documentation details each of the object
106 methods. Internal methods are usually preceded with a _
107  
108 =cut
109  
110  
111 # Let the code begin...
112  
113  
114 package Bio::Ontology::Relationship;
115 9 $Bio::Ontology::Relationship::VERSION = '1.7.8';
116 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
117 9 ▶use Bio::Ontology::TermI;
Subroutine BEGIN: called CC=1 SCAR=0.0
118  
119 9 ▶use base qw(Bio::Root::Root Bio::Ontology::RelationshipI);
Subroutine BEGIN: called CC=1 SCAR=0.0
120  
121  
122  
123  
124 =head2 new
125  
126 Title : new
127 Usage : $rel = Bio::Ontology::Relationship->new(-identifier => "16847",
128 -subject_term => $subject,
129 -object_term => $object,
130 -predicate_term => $type );
131 Function: Creates a new Bio::Ontology::Relationship.
132 Returns : A new Bio::Ontology::Relationship object.
133 Args : -identifier => the identifier of this relationship [scalar]
134 -subject_term => the subject term [Bio::Ontology::TermI]
135 -object_term => the object term [Bio::Ontology::TermI]
136 -predicate_term => the predicate term [Bio::Ontology::TermI]
137  
138 =cut
139  
140 1345 ▶sub new {
Subroutine new: called CC=8 SCAR=20.8
Pod documented
141  
142 1345 my( $class, @args ) = @_;
143
144 1345 my $self = $class->SUPER::new( @args );
145
146 1345 my ( $identifier,
147 $subject_term,
148 $child, # for backwards compatibility
149 $object_term,
150 $parent, # for backwards compatibility
151 $predicate_term,
152 $reltype, # for backwards compatibility
153 $ont)
154 = $self->_rearrange( [qw( IDENTIFIER
155 SUBJECT_TERM
156 CHILD_TERM
157 OBJECT_TERM
158 PARENT_TERM
159 PREDICATE_TERM
160 RELATIONSHIP_TYPE
161 ONTOLOGY)
162 ], @args );
163
164 1345 $self->init();
165
166 1345 $self->identifier( $identifier );
167 1345 ▶ $subject_term = $child unless $subject_term;
Branch: 1 branch
BranchTrueFalseTotal
unless $subject_term 1 1344 1345
168 1345 ▶ $object_term = $parent unless $object_term;
Branch: 1 branch
BranchTrueFalseTotal
unless $object_term 2 1343 1345
169 1345 ▶ $predicate_term = $reltype unless $predicate_term;
Branch: 1 branch
BranchTrueFalseTotal
unless $predicate_term 1 1344 1345
170 1345 ▶ $self->subject_term( $subject_term) if $subject_term;
Branch: 1 branch
BranchTrueFalseTotal
if $subject_term 1345 0 1345
171 1345 ▶ $self->object_term( $object_term) if $object_term;
Branch: 1 branch
BranchTrueFalseTotal
if $object_term 1344 1 1345
172 1345 ▶ $self->predicate_term( $predicate_term ) if $predicate_term;
Branch: 1 branch
BranchTrueFalseTotal
if $predicate_term 1345 0 1345
173 1345 ▶ $self->ontology($ont) if $ont;
Branch: 1 branch
BranchTrueFalseTotal
if $ont 1344 1 1345
174
175 1345 return $self;
176
177 } # new
178  
179  
180  
181 =head2 init
182  
183 Title : init()
184 Usage : $rel->init();
185 Function: Initializes this Relationship to all undef.
186 Returns :
187 Args :
188  
189 =cut
190  
191 1345 ▶sub init {
Subroutine init: called CC=1 SCAR=0.0
Pod documented
192 1345 my( $self ) = @_;
193
194 1345 $self->{ "_identifier" } = undef;
195 1345 $self->{ "_subject_term" } = undef;
196 1345 $self->{ "_object_term" } = undef;
197 1345 $self->{ "_predicate_term" } = undef;
198 1345 $self->ontology(undef);
199
200 } # init
201  
202  
203  
204 =head2 identifier
205  
206 Title : identifier
207 Usage : $rel->identifier( "100050" );
208 or
209 print $rel->identifier();
210 Function: Set/get for the identifier of this Relationship.
211 Returns : The identifier [scalar].
212 Args : The identifier [scalar] (optional).
213  
214 =cut
215  
216 1347 ▶sub identifier {
Subroutine identifier: called CC=2 SCAR=6.9
Pod documented
217 1347 my ( $self, $value ) = @_;
218  
219 1347 ▶ if ( defined $value ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 1 1346 1347
220 1 $self->{ "_identifier" } = $value;
221 }
222  
223 1347 return $self->{ "_identifier" };
224 } # identifier
225  
226  
227  
228  
229 =head2 subject_term
230  
231 Title : subject_term
232 Usage : $rel->subject_term( $subject );
233 or
234 $subject = $rel->subject_term();
235 Function: Set/get for the subject term of this Relationship.
236  
237 The common convention for ontologies is to express
238 relationships between terms as triples (subject, predicate,
239 object).
240  
241 Returns : The subject term [Bio::Ontology::TermI].
242 Args : The subject term [Bio::Ontology::TermI] (optional).
243  
244 =cut
245  
246 2754 ▶sub subject_term {
Subroutine subject_term: called CC=2 SCAR=6.9
Pod documented
247 2754 my ( $self, $term ) = @_;
248
249 2754 ▶ if ( defined $term ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $term) 1345 1409 2754
250 1345 $self->_check_class( $term, "Bio::Ontology::TermI" );
251 1345 $self->{ "_subject_term" } = $term;
252 }
253  
254 2754 return $self->{ "_subject_term" };
255
256 } # subject_term
257  
258  
259  
260 =head2 object_term
261  
262 Title : object_term
263 Usage : $rel->object_term( $object );
264 or
265 $object = $rel->object_term();
266 Function: Set/get for the object term of this Relationship.
267  
268 The common convention for ontologies is to express
269 relationships between terms as triples (subject, predicate,
270 object).
271  
272 Returns : The object term [Bio::Ontology::TermI].
273 Args : The object term [Bio::Ontology::TermI] (optional).
274  
275 =cut
276  
277 2841 ▶sub object_term {
Subroutine object_term: called CC=2 SCAR=6.9
Pod documented
278 2841 my ( $self, $term ) = @_;
279
280 2841 ▶ if ( defined $term ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $term) 1344 1497 2841
281 1344 $self->_check_class( $term, "Bio::Ontology::TermI" );
282 1344 $self->{ "_object_term" } = $term;
283 }
284  
285 2841 return $self->{ "_object_term" };
286 }
287  
288  
289  
290 =head2 predicate_term
291  
292 Title : predicate_term
293 Usage : $rel->predicate_term( $type );
294 or
295 $type = $rel->predicate_term();
296 Function: Set/get for the predicate (relationship type) of this
297 relationship.
298  
299 The common convention for ontologies is to express
300 relationships between terms as triples (subject, predicate,
301 object).
302  
303 Returns : The predicate term [Bio::Ontology::TermI].
304 Args : The predicate term [Bio::Ontology::TermI] (optional).
305  
306 =cut
307  
308 1367 ▶sub predicate_term {
Subroutine predicate_term: called CC=2 SCAR=6.9
Pod documented
309 1367 my ( $self, $term ) = @_;
310
311 1367 ▶ if ( defined $term ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $term) 1345 22 1367
312 1345 $self->_check_class( $term, "Bio::Ontology::TermI" );
313 1345 $self->{ "_predicate_term" } = $term;
314 }
315  
316 1367 return $self->{ "_predicate_term" };
317 }
318  
319  
320 =head2 ontology
321  
322 Title : ontology
323 Usage : $ont = $obj->ontology()
324 Function: Get/set the ontology that defined this relationship.
325 Example :
326 Returns : an object implementing L<Bio::Ontology::OntologyI>
327 Args : on set, undef or an object implementing
328 Bio::Ontology::OntologyI (optional)
329  
330 See L<Bio::Ontology::OntologyI>.
331  
332 =cut
333  
334 4023 ▶sub ontology{
Subroutine ontology: called CC=5 SCAR=16.3
Pod documented
335 4023 my $self = shift;
336 4023 my $ont;
337  
338 4023 ▶ if(@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 2689 1334 4023
339 2689 $ont = shift;
340 2689 ▶ if($ont) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ont) 1344 1345 2689
341 1344 ▶ $ont = Bio::Ontology::Ontology->new(-name => $ont) if ! ref($ont);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $ont 0 1344 1344
342 1344 ▶ if(! $ont->isa("Bio::Ontology::OntologyI")) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ont->isa("Bio::Ontology::OntologyI")) 0 1344 1344
343 0 $self->throw(ref($ont)." does not implement ".
344 "Bio::Ontology::OntologyI. Bummer.");
345 }
346 }
347 2689 return $self->{"_ontology"} = $ont;
348 }
349 1334 return $self->{"_ontology"};
350 }
351  
352 =head2 to_string
353  
354 Title : to_string()
355 Usage : print $rel->to_string();
356 Function: to_string method for Relationship.
357 Returns : A string representation of this Relationship.
358 Args :
359  
360 =cut
361  
362 1 ▶sub to_string {
Subroutine to_string: called CC=1 SCAR=0.0
Pod documented
363 1 my( $self ) = @_;
364
365 1 local $^W = 0;
366  
367 1 my $s = "";
368  
369 1 $s .= "-- Identifier:\n";
370 1 $s .= $self->identifier()."\n";
371 1 $s .= "-- Subject Term Identifier:\n";
372 1 $s .= $self->subject_term()->identifier()."\n";
373 1 $s .= "-- Object Term Identifier:\n";
374 1 $s .= $self->object_term()->identifier()."\n";
375 1 $s .= "-- Relationship Type Identifier:\n";
376 1 $s .= $self->predicate_term()->identifier();
377
378 1 return $s;
379
380 } # to_string
381  
382  
383  
384 4034 ▶sub _check_class {
Subroutine _check_class: called CC=4 SCAR=18.9
385 4034 my ( $self, $value, $expected_class ) = @_;
386
387 4034 ▶ if ( ! defined( $value ) ) {
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $value) { } 0 4034 4034
elsif (not ref $value) { } 0 4034 4034
elsif (not $value->isa($expected_class)) { } 0 4034 4034
388 0 $self->throw( "Found [undef] where [$expected_class] expected" );
389 }
390 elsif ( ! ref( $value ) ) {
391 0 $self->throw( "Found [scalar] where [$expected_class] expected" );
392 }
393 elsif ( ! $value->isa( $expected_class ) ) {
394 0 $self->throw( "Found [" . ref( $value ) . "] where [$expected_class] expected" );
395 }
396  
397 } # _check_type
398  
399 #################################################################
400 # aliases for backwards compatibility
401 #################################################################
402  
403 =head1 Deprecated Methods
404  
405 These methods are deprecated and defined here solely to preserve
406 backwards compatibility.
407  
408 =cut
409  
410 9 *child_term = \&subject_term;
411 9 *parent_term = \&object_term;
412 9 *relationship_type = \&predicate_term;
413  
414 9 1;
« Bio/Search/Result/ResultI.pm ↑ Summary Bio/Tools/RandomDistFunctions.pm »