2 # BioPerl module for Relationship
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
6 # Cared for by Christian M. Zmasek <czmasek-at-burnham.org> or <cmzmasek@yahoo.com>
8 # (c) Christian M. Zmasek, czmasek-at-burnham.org, 2002.
9 # (c) GNF, Genomics Institute of the Novartis Research Foundation, 2002.
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.
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.
20 # You may distribute this module under the same terms as perl itself
22 # POD documentation - main docs before the code
26 Bio::Ontology::Relationship - a relationship for an ontology
30 $rel = Bio::Ontology::Relationship->new( -identifier => "16847",
31 -subject_term => $subj,
33 -predicate_term => $pred );
37 This is a basic implementation of Bio::Ontology::RelationshipI.
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.
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.
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.
63 bioperl-l@bioperl.org - General discussion
64 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
68 Please direct usage questions or support issues to the mailing list:
70 I<bioperl-l@bioperl.org>
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.
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
83 https://github.com/bioperl/bioperl-live/issues
89 Email: czmasek-at-burnham.org or cmzmasek@yahoo.com
91 WWW: http://monochrome-effect.net/
95 Genomics Institute of the Novartis Research Foundation
96 10675 John Jay Hopkins Drive
101 Hilmar Lapp, email: hlapp at gmx.net
105 The rest of the documentation details each of the object
106 methods. Internal methods are usually preceded with a _
111 # Let the code begin...
114 package Bio
::Ontology
::Relationship
;
116 use Bio
::Ontology
::TermI
;
118 use base
qw(Bio::Root::Root Bio::Ontology::RelationshipI);
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]
141 my( $class, @args ) = @_;
143 my $self = $class->SUPER::new
( @args );
147 $child, # for backwards compatibility
149 $parent, # for backwards compatibility
151 $reltype, # for backwards compatibility
153 = $self->_rearrange( [qw( IDENTIFIER
165 $self->identifier( $identifier );
166 $subject_term = $child unless $subject_term;
167 $object_term = $parent unless $object_term;
168 $predicate_term = $reltype unless $predicate_term;
169 $self->subject_term( $subject_term) if $subject_term;
170 $self->object_term( $object_term) if $object_term;
171 $self->predicate_term( $predicate_term ) if $predicate_term;
172 $self->ontology($ont) if $ont;
183 Usage : $rel->init();
184 Function: Initializes this Relationship to all undef.
193 $self->{ "_identifier" } = undef;
194 $self->{ "_subject_term" } = undef;
195 $self->{ "_object_term" } = undef;
196 $self->{ "_predicate_term" } = undef;
197 $self->ontology(undef);
206 Usage : $rel->identifier( "100050" );
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).
216 my ( $self, $value ) = @_;
218 if ( defined $value ) {
219 $self->{ "_identifier" } = $value;
222 return $self->{ "_identifier" };
231 Usage : $rel->subject_term( $subject );
233 $subject = $rel->subject_term();
234 Function: Set/get for the subject term of this Relationship.
236 The common convention for ontologies is to express
237 relationships between terms as triples (subject, predicate,
240 Returns : The subject term [Bio::Ontology::TermI].
241 Args : The subject term [Bio::Ontology::TermI] (optional).
246 my ( $self, $term ) = @_;
248 if ( defined $term ) {
249 $self->_check_class( $term, "Bio::Ontology::TermI" );
250 $self->{ "_subject_term" } = $term;
253 return $self->{ "_subject_term" };
262 Usage : $rel->object_term( $object );
264 $object = $rel->object_term();
265 Function: Set/get for the object term of this Relationship.
267 The common convention for ontologies is to express
268 relationships between terms as triples (subject, predicate,
271 Returns : The object term [Bio::Ontology::TermI].
272 Args : The object term [Bio::Ontology::TermI] (optional).
277 my ( $self, $term ) = @_;
279 if ( defined $term ) {
280 $self->_check_class( $term, "Bio::Ontology::TermI" );
281 $self->{ "_object_term" } = $term;
284 return $self->{ "_object_term" };
289 =head2 predicate_term
291 Title : predicate_term
292 Usage : $rel->predicate_term( $type );
294 $type = $rel->predicate_term();
295 Function: Set/get for the predicate (relationship type) of this
298 The common convention for ontologies is to express
299 relationships between terms as triples (subject, predicate,
302 Returns : The predicate term [Bio::Ontology::TermI].
303 Args : The predicate term [Bio::Ontology::TermI] (optional).
308 my ( $self, $term ) = @_;
310 if ( defined $term ) {
311 $self->_check_class( $term, "Bio::Ontology::TermI" );
312 $self->{ "_predicate_term" } = $term;
315 return $self->{ "_predicate_term" };
322 Usage : $ont = $obj->ontology()
323 Function: Get/set the ontology that defined this relationship.
325 Returns : an object implementing L<Bio::Ontology::OntologyI>
326 Args : on set, undef or an object implementing
327 Bio::Ontology::OntologyI (optional)
329 See L<Bio::Ontology::OntologyI>.
340 $ont = Bio
::Ontology
::Ontology
->new(-name
=> $ont) if ! ref($ont);
341 if(! $ont->isa("Bio::Ontology::OntologyI")) {
342 $self->throw(ref($ont)." does not implement ".
343 "Bio::Ontology::OntologyI. Bummer.");
346 return $self->{"_ontology"} = $ont;
348 return $self->{"_ontology"};
354 Usage : print $rel->to_string();
355 Function: to_string method for Relationship.
356 Returns : A string representation of this Relationship.
368 $s .= "-- Identifier:\n";
369 $s .= $self->identifier()."\n";
370 $s .= "-- Subject Term Identifier:\n";
371 $s .= $self->subject_term()->identifier()."\n";
372 $s .= "-- Object Term Identifier:\n";
373 $s .= $self->object_term()->identifier()."\n";
374 $s .= "-- Relationship Type Identifier:\n";
375 $s .= $self->predicate_term()->identifier();
384 my ( $self, $value, $expected_class ) = @_;
386 if ( ! defined( $value ) ) {
387 $self->throw( "Found [undef] where [$expected_class] expected" );
389 elsif ( ! ref( $value ) ) {
390 $self->throw( "Found [scalar] where [$expected_class] expected" );
392 elsif ( ! $value->isa( $expected_class ) ) {
393 $self->throw( "Found [" . ref( $value ) . "] where [$expected_class] expected" );
398 #################################################################
399 # aliases for backwards compatibility
400 #################################################################
402 =head1 Deprecated Methods
404 These methods are deprecated and defined here solely to preserve
405 backwards compatibility.
409 *child_term
= \
&subject_term
;
410 *parent_term
= \
&object_term
;
411 *relationship_type
= \
&predicate_term
;