3 # BioPerl module for Relationship
5 # Cared for by Christian M. Zmasek <czmasek@gnf.org> or <cmzmasek@yahoo.com>
7 # (c) Christian M. Zmasek, czmasek@gnf.org, 2002.
8 # (c) GNF, Genomics Institute of the Novartis Research Foundation, 2002.
10 # You may distribute this module under the same terms as perl itself.
11 # Refer to the Perl Artistic License (see the license accompanying this
12 # software package, or see http://www.perl.com/language/misc/Artistic.html)
13 # for the terms under which you may use, modify, and redistribute this module.
15 # THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
16 # WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
17 # MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 # You may distribute this module under the same terms as perl itself
21 # POD documentation - main docs before the code
25 Bio::Ontology::Relationship - a relationship for an ontology
29 $rel = Bio::Ontology::Relationship->new( -identifier => "16847",
30 -subject_term => $subj,
32 -predicate_term => $pred );
36 This is a basic implementation of Bio::Ontology::RelationshipI.
38 The terminology we use here is the one commonly used for ontologies,
39 namely the triple of (subject, predicate, object), which in addition
40 is scoped in a namespace (ontology). It is called triple because it is
41 a tuple of three ontology terms.
43 There are other terminologies in use for expressing relationships. For
44 those who it helps to better understand the concept, the triple of
45 (child, relationship type, parent) would be equivalent to the
46 terminology chosen here, disregarding the question whether the notion
47 of parent and child is sensible in the context of the relationship
48 type or not. Especially in the case of ontologies with a wide variety
49 of predicates the parent/child terminology and similar ones can
50 quickly become ambiguous (e.g., A synthesises B), meaningless (e.g., A
51 binds B), or even conflicting (e.g., A is-parent-of B), and are
52 therefore strongly discouraged.
58 User feedback is an integral part of the evolution of this and other
59 Bioperl modules. Send your comments and suggestions preferably to the
60 Bioperl mailing lists Your participation is much appreciated.
62 bioperl-l@bioperl.org - General discussion
63 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
67 Report bugs to the Bioperl bug tracking system to help us keep track
68 the bugs and their resolution. Bug reports can be submitted via
71 http://bugzilla.open-bio.org/
77 Email: czmasek@gnf.org or cmzmasek@yahoo.com
79 WWW: http://www.genetics.wustl.edu/eddy/people/zmasek/
83 Genomics Institute of the Novartis Research Foundation
84 10675 John Jay Hopkins Drive
89 Hilmar Lapp, email: hlapp at gmx.net
93 The rest of the documentation details each of the object
94 methods. Internal methods are usually preceded with a _
99 # Let the code begin...
102 package Bio
::Ontology
::Relationship
;
104 use Bio
::Ontology
::TermI
;
106 use base
qw(Bio::Root::Root Bio::Ontology::RelationshipI);
114 Usage : $rel = Bio::Ontology::Relationship->new(-identifier => "16847",
115 -subject_term => $subject,
116 -object_term => $object,
117 -predicate_term => $type );
118 Function: Creates a new Bio::Ontology::Relationship.
119 Returns : A new Bio::Ontology::Relationship object.
120 Args : -identifier => the identifier of this relationship [scalar]
121 -subject_term => the subject term [Bio::Ontology::TermI]
122 -object_term => the object term [Bio::Ontology::TermI]
123 -predicate_term => the predicate term [Bio::Ontology::TermI]
129 my( $class, @args ) = @_;
131 my $self = $class->SUPER::new
( @args );
135 $child, # for backwards compatibility
137 $parent, # for backwards compatibility
139 $reltype, # for backwards compatibility
141 = $self->_rearrange( [qw( IDENTIFIER
153 $self->identifier( $identifier );
154 $subject_term = $child unless $subject_term;
155 $object_term = $parent unless $object_term;
156 $predicate_term = $reltype unless $predicate_term;
157 $self->subject_term( $subject_term) if $subject_term;
158 $self->object_term( $object_term) if $object_term;
159 $self->predicate_term( $predicate_term ) if $predicate_term;
160 $self->ontology($ont) if $ont;
171 Usage : $rel->init();
172 Function: Initializes this Relationship to all undef.
181 $self->{ "_identifier" } = undef;
182 $self->{ "_subject_term" } = undef;
183 $self->{ "_object_term" } = undef;
184 $self->{ "_predicate_term" } = undef;
185 $self->ontology(undef);
194 Usage : $rel->identifier( "100050" );
196 print $rel->identifier();
197 Function: Set/get for the identifier of this Relationship.
198 Returns : The identifier [scalar].
199 Args : The identifier [scalar] (optional).
204 my ( $self, $value ) = @_;
206 if ( defined $value ) {
207 $self->{ "_identifier" } = $value;
210 return $self->{ "_identifier" };
219 Usage : $rel->subject_term( $subject );
221 $subject = $rel->subject_term();
222 Function: Set/get for the subject term of this Relationship.
224 The common convention for ontologies is to express
225 relationships between terms as triples (subject, predicate,
228 Returns : The subject term [Bio::Ontology::TermI].
229 Args : The subject term [Bio::Ontology::TermI] (optional).
234 my ( $self, $term ) = @_;
236 if ( defined $term ) {
237 $self->_check_class( $term, "Bio::Ontology::TermI" );
238 $self->{ "_subject_term" } = $term;
241 return $self->{ "_subject_term" };
250 Usage : $rel->object_term( $object );
252 $object = $rel->object_term();
253 Function: Set/get for the object term of this Relationship.
255 The common convention for ontologies is to express
256 relationships between terms as triples (subject, predicate,
259 Returns : The object term [Bio::Ontology::TermI].
260 Args : The object term [Bio::Ontology::TermI] (optional).
265 my ( $self, $term ) = @_;
267 if ( defined $term ) {
268 $self->_check_class( $term, "Bio::Ontology::TermI" );
269 $self->{ "_object_term" } = $term;
272 return $self->{ "_object_term" };
277 =head2 predicate_term
279 Title : predicate_term
280 Usage : $rel->predicate_term( $type );
282 $type = $rel->predicate_term();
283 Function: Set/get for the predicate (relationship type) of this
286 The common convention for ontologies is to express
287 relationships between terms as triples (subject, predicate,
290 Returns : The predicate term [Bio::Ontology::TermI].
291 Args : The predicate term [Bio::Ontology::TermI] (optional).
296 my ( $self, $term ) = @_;
298 if ( defined $term ) {
299 $self->_check_class( $term, "Bio::Ontology::TermI" );
300 $self->{ "_predicate_term" } = $term;
303 return $self->{ "_predicate_term" };
310 Usage : $ont = $obj->ontology()
311 Function: Get/set the ontology that defined this relationship.
313 Returns : an object implementing L<Bio::Ontology::OntologyI>
314 Args : on set, undef or an object implementing
315 Bio::Ontology::OntologyI (optional)
317 See L<Bio::Ontology::OntologyI>.
328 $ont = Bio
::Ontology
::Ontology
->new(-name
=> $ont) if ! ref($ont);
329 if(! $ont->isa("Bio::Ontology::OntologyI")) {
330 $self->throw(ref($ont)." does not implement ".
331 "Bio::Ontology::OntologyI. Bummer.");
334 return $self->{"_ontology"} = $ont;
336 return $self->{"_ontology"};
342 Usage : print $rel->to_string();
343 Function: to_string method for Relationship.
344 Returns : A string representation of this Relationship.
356 $s .= "-- Identifier:\n";
357 $s .= $self->identifier()."\n";
358 $s .= "-- Subject Term Identifier:\n";
359 $s .= $self->subject_term()->identifier()."\n";
360 $s .= "-- Object Term Identifier:\n";
361 $s .= $self->object_term()->identifier()."\n";
362 $s .= "-- Relationship Type Identifier:\n";
363 $s .= $self->predicate_term()->identifier();
372 my ( $self, $value, $expected_class ) = @_;
374 if ( ! defined( $value ) ) {
375 $self->throw( "Found [undef] where [$expected_class] expected" );
377 elsif ( ! ref( $value ) ) {
378 $self->throw( "Found [scalar] where [$expected_class] expected" );
380 elsif ( ! $value->isa( $expected_class ) ) {
381 $self->throw( "Found [" . ref( $value ) . "] where [$expected_class] expected" );
386 #################################################################
387 # aliases for backwards compatibility
388 #################################################################
390 =head1 Deprecated Methods
392 These methods are deprecated and defined here solely to preserve
393 backwards compatibility.
397 *child_term
= \
&subject_term
;
398 *parent_term
= \
&object_term
;
399 *relationship_type
= \
&predicate_term
;