File Coverage

Bio/Ontology/Relationship.pm
Criterion Covered Total %
statement 70 74 94.5
branch 30 36 83.3
condition n/a
subroutine 12 12 100.0
pod 8 8 100.0
total 120 130 92.3


line stmt bran cond sub pod time code
1             #
2             # BioPerl module for Relationship
3             #
4             # Please direct questions and support issues to
5             #
6             # Cared for by Christian M. Zmasek or
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
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 5     5   1210 use strict;
  5         8  
  5         138  
116 5     5   248 use Bio::Ontology::TermI;
  5         7  
  5         177  
117              
118 5     5   23 use base qw(Bio::Root::Root Bio::Ontology::RelationshipI);
  5         7  
  5         1533  
119              
120              
121              
122              
123             =head2 new
124              
125             Title : new
126             Usage : $rel = Bio::Ontology::Relationship->new(-identifier => "16847",
127             -subject_term => $subject,
128             -object_term => $object,
129             -predicate_term => $type );
130             Function: Creates a new Bio::Ontology::Relationship.
131             Returns : A new Bio::Ontology::Relationship object.
132             Args : -identifier => the identifier of this relationship [scalar]
133             -subject_term => the subject term [Bio::Ontology::TermI]
134             -object_term => the object term [Bio::Ontology::TermI]
135             -predicate_term => the predicate term [Bio::Ontology::TermI]
136              
137             =cut
138              
139             sub new {
140              
141 1350     1350 1 2907 my( $class, @args ) = @_;
142            
143 1350         2510 my $self = $class->SUPER::new( @args );
144            
145 1350         4033 my ( $identifier,
146             $subject_term,
147             $child, # for backwards compatibility
148             $object_term,
149             $parent, # for backwards compatibility
150             $predicate_term,
151             $reltype, # for backwards compatibility
152             $ont)
153             = $self->_rearrange( [qw( IDENTIFIER
154             SUBJECT_TERM
155             CHILD_TERM
156             OBJECT_TERM
157             PARENT_TERM
158             PREDICATE_TERM
159             RELATIONSHIP_TYPE
160             ONTOLOGY)
161             ], @args );
162            
163 1350         3123 $self->init();
164            
165 1350         2070 $self->identifier( $identifier );
166 1350 100       1973 $subject_term = $child unless $subject_term;
167 1350 100       1656 $object_term = $parent unless $object_term;
168 1350 100       1806 $predicate_term = $reltype unless $predicate_term;
169 1350 100       2659 $self->subject_term( $subject_term) if $subject_term;
170 1350 100       2459 $self->object_term( $object_term) if $object_term;
171 1350 50       2565 $self->predicate_term( $predicate_term ) if $predicate_term;
172 1350 100       2434 $self->ontology($ont) if $ont;
173            
174 1350         3247 return $self;
175            
176             } # new
177              
178              
179              
180             =head2 init
181              
182             Title : init()
183             Usage : $rel->init();
184             Function: Initializes this Relationship to all undef.
185             Returns :
186             Args :
187              
188             =cut
189              
190             sub init {
191 1350     1350 1 1384 my( $self ) = @_;
192            
193 1350         1488 $self->{ "_identifier" } = undef;
194 1350         1311 $self->{ "_subject_term" } = undef;
195 1350         1257 $self->{ "_object_term" } = undef;
196 1350         1355 $self->{ "_predicate_term" } = undef;
197 1350         1697 $self->ontology(undef);
198            
199             } # init
200              
201              
202              
203             =head2 identifier
204              
205             Title : identifier
206             Usage : $rel->identifier( "100050" );
207             or
208             print $rel->identifier();
209             Function: Set/get for the identifier of this Relationship.
210             Returns : The identifier [scalar].
211             Args : The identifier [scalar] (optional).
212              
213             =cut
214              
215             sub identifier {
216 1352     1352 1 1681 my ( $self, $value ) = @_;
217              
218 1352 100       1672 if ( defined $value ) {
219 1         1 $self->{ "_identifier" } = $value;
220             }
221              
222 1352         1398 return $self->{ "_identifier" };
223             } # identifier
224              
225              
226              
227              
228             =head2 subject_term
229              
230             Title : subject_term
231             Usage : $rel->subject_term( $subject );
232             or
233             $subject = $rel->subject_term();
234             Function: Set/get for the subject term of this Relationship.
235              
236             The common convention for ontologies is to express
237             relationships between terms as triples (subject, predicate,
238             object).
239              
240             Returns : The subject term [Bio::Ontology::TermI].
241             Args : The subject term [Bio::Ontology::TermI] (optional).
242              
243             =cut
244              
245             sub subject_term {
246 2772     2772 1 6836 my ( $self, $term ) = @_;
247            
248 2772 100       3207 if ( defined $term ) {
249 1349         2285 $self->_check_class( $term, "Bio::Ontology::TermI" );
250 1349         1518 $self->{ "_subject_term" } = $term;
251             }
252              
253 2772         3809 return $self->{ "_subject_term" };
254            
255             } # subject_term
256              
257              
258              
259             =head2 object_term
260              
261             Title : object_term
262             Usage : $rel->object_term( $object );
263             or
264             $object = $rel->object_term();
265             Function: Set/get for the object term of this Relationship.
266              
267             The common convention for ontologies is to express
268             relationships between terms as triples (subject, predicate,
269             object).
270              
271             Returns : The object term [Bio::Ontology::TermI].
272             Args : The object term [Bio::Ontology::TermI] (optional).
273              
274             =cut
275              
276             sub object_term {
277 2856     2856 1 6789 my ( $self, $term ) = @_;
278            
279 2856 100       3427 if ( defined $term ) {
280 1349         1975 $self->_check_class( $term, "Bio::Ontology::TermI" );
281 1349         1566 $self->{ "_object_term" } = $term;
282             }
283              
284 2856         3884 return $self->{ "_object_term" };
285             }
286              
287              
288              
289             =head2 predicate_term
290              
291             Title : predicate_term
292             Usage : $rel->predicate_term( $type );
293             or
294             $type = $rel->predicate_term();
295             Function: Set/get for the predicate (relationship type) of this
296             relationship.
297              
298             The common convention for ontologies is to express
299             relationships between terms as triples (subject, predicate,
300             object).
301              
302             Returns : The predicate term [Bio::Ontology::TermI].
303             Args : The predicate term [Bio::Ontology::TermI] (optional).
304              
305             =cut
306              
307             sub predicate_term {
308 1388     1388 1 3185 my ( $self, $term ) = @_;
309            
310 1388 100       1733 if ( defined $term ) {
311 1350         2108 $self->_check_class( $term, "Bio::Ontology::TermI" );
312 1350         1422 $self->{ "_predicate_term" } = $term;
313             }
314              
315 1388         1353 return $self->{ "_predicate_term" };
316             }
317              
318              
319             =head2 ontology
320              
321             Title : ontology
322             Usage : $ont = $obj->ontology()
323             Function: Get/set the ontology that defined this relationship.
324             Example :
325             Returns : an object implementing L
326             Args : on set, undef or an object implementing
327             Bio::Ontology::OntologyI (optional)
328              
329             See L.
330              
331             =cut
332              
333             sub ontology{
334 4041     4041 1 3746 my $self = shift;
335 4041         3436 my $ont;
336              
337 4041 100       5344 if(@_) {
338 2699         2428 $ont = shift;
339 2699 100       3107 if($ont) {
340 1349 50       1930 $ont = Bio::Ontology::Ontology->new(-name => $ont) if ! ref($ont);
341 1349 50       2557 if(! $ont->isa("Bio::Ontology::OntologyI")) {
342 0         0 $self->throw(ref($ont)." does not implement ".
343             "Bio::Ontology::OntologyI. Bummer.");
344             }
345             }
346 2699         3456 return $self->{"_ontology"} = $ont;
347             }
348 1342         1749 return $self->{"_ontology"};
349             }
350              
351             =head2 to_string
352              
353             Title : to_string()
354             Usage : print $rel->to_string();
355             Function: to_string method for Relationship.
356             Returns : A string representation of this Relationship.
357             Args :
358              
359             =cut
360              
361             sub to_string {
362 1     1 1 2 my( $self ) = @_;
363            
364 1         3 local $^W = 0;
365              
366 1         2 my $s = "";
367              
368 1         3 $s .= "-- Identifier:\n";
369 1         2 $s .= $self->identifier()."\n";
370 1         2 $s .= "-- Subject Term Identifier:\n";
371 1         2 $s .= $self->subject_term()->identifier()."\n";
372 1         2 $s .= "-- Object Term Identifier:\n";
373 1         2 $s .= $self->object_term()->identifier()."\n";
374 1         2 $s .= "-- Relationship Type Identifier:\n";
375 1         3 $s .= $self->predicate_term()->identifier();
376            
377 1         4 return $s;
378            
379             } # to_string
380              
381              
382              
383             sub _check_class {
384 4048     4048   4207 my ( $self, $value, $expected_class ) = @_;
385            
386 4048 50       10376 if ( ! defined( $value ) ) {
    50          
    50          
387 0           $self->throw( "Found [undef] where [$expected_class] expected" );
388             }
389             elsif ( ! ref( $value ) ) {
390 0           $self->throw( "Found [scalar] where [$expected_class] expected" );
391             }
392             elsif ( ! $value->isa( $expected_class ) ) {
393 0           $self->throw( "Found [" . ref( $value ) . "] where [$expected_class] expected" );
394             }
395              
396             } # _check_type
397              
398             #################################################################
399             # aliases for backwards compatibility
400             #################################################################
401              
402             =head1 Deprecated Methods
403              
404             These methods are deprecated and defined here solely to preserve
405             backwards compatibility.
406              
407             =cut
408              
409             *child_term = \&subject_term;
410             *parent_term = \&object_term;
411             *relationship_type = \&predicate_term;
412              
413             1;