3 # BioPerl module for Relationship
5 # Please direct questions and support issues to <bioperl-l@bioperl.org>
7 # Cared for by Christian M. Zmasek <czmasek@gnf.org> or <cmzmasek@yahoo.com>
9 # (c) Christian M. Zmasek, czmasek@gnf.org, 2002.
10 # (c) GNF, Genomics Institute of the Novartis Research Foundation, 2002.
12 # You may distribute this module under the same terms as perl itself.
13 # Refer to the Perl Artistic License (see the license accompanying this
14 # software package, or see http://www.perl.com/language/misc/Artistic.html)
15 # for the terms under which you may use, modify, and redistribute this module.
17 # THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
18 # WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 # MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21 # You may distribute this module under the same terms as perl itself
23 # POD documentation - main docs before the code
27 Bio::Ontology::Relationship - a relationship for an ontology
31 $rel = Bio::Ontology::Relationship->new( -identifier => "16847",
32 -subject_term => $subj,
34 -predicate_term => $pred );
38 This is a basic implementation of Bio::Ontology::RelationshipI.
40 The terminology we use here is the one commonly used for ontologies,
41 namely the triple of (subject, predicate, object), which in addition
42 is scoped in a namespace (ontology). It is called triple because it is
43 a tuple of three ontology terms.
45 There are other terminologies in use for expressing relationships. For
46 those who it helps to better understand the concept, the triple of
47 (child, relationship type, parent) would be equivalent to the
48 terminology chosen here, disregarding the question whether the notion
49 of parent and child is sensible in the context of the relationship
50 type or not. Especially in the case of ontologies with a wide variety
51 of predicates the parent/child terminology and similar ones can
52 quickly become ambiguous (e.g., A synthesises B), meaningless (e.g., A
53 binds B), or even conflicting (e.g., A is-parent-of B), and are
54 therefore strongly discouraged.
60 User feedback is an integral part of the evolution of this and other
61 Bioperl modules. Send your comments and suggestions preferably to the
62 Bioperl mailing lists Your participation is much appreciated.
64 bioperl-l@bioperl.org - General discussion
65 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
69 Please direct usage questions or support issues to the mailing list:
71 L<bioperl-l@bioperl.org>
73 rather than to the module maintainer directly. Many experienced and
74 reponsive experts will be able look at the problem and quickly
75 address it. Please include a thorough description of the problem
76 with code and data examples if at all possible.
80 Report bugs to the Bioperl bug tracking system to help us keep track
81 the bugs and their resolution. Bug reports can be submitted via
84 http://bugzilla.open-bio.org/
90 Email: czmasek@gnf.org or cmzmasek@yahoo.com
92 WWW: http://www.genetics.wustl.edu/eddy/people/zmasek/
96 Genomics Institute of the Novartis Research Foundation
97 10675 John Jay Hopkins Drive
102 Hilmar Lapp, email: hlapp at gmx.net
106 The rest of the documentation details each of the object
107 methods. Internal methods are usually preceded with a _
112 # Let the code begin...
115 package Bio
::Ontology
::Relationship
;
117 use Bio
::Ontology
::TermI
;
119 use base
qw(Bio::Root::Root Bio::Ontology::RelationshipI);
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]
142 my( $class, @args ) = @_;
144 my $self = $class->SUPER::new
( @args );
148 $child, # for backwards compatibility
150 $parent, # for backwards compatibility
152 $reltype, # for backwards compatibility
154 = $self->_rearrange( [qw( IDENTIFIER
166 $self->identifier( $identifier );
167 $subject_term = $child unless $subject_term;
168 $object_term = $parent unless $object_term;
169 $predicate_term = $reltype unless $predicate_term;
170 $self->subject_term( $subject_term) if $subject_term;
171 $self->object_term( $object_term) if $object_term;
172 $self->predicate_term( $predicate_term ) if $predicate_term;
173 $self->ontology($ont) if $ont;
184 Usage : $rel->init();
185 Function: Initializes this Relationship to all undef.
194 $self->{ "_identifier" } = undef;
195 $self->{ "_subject_term" } = undef;
196 $self->{ "_object_term" } = undef;
197 $self->{ "_predicate_term" } = undef;
198 $self->ontology(undef);
207 Usage : $rel->identifier( "100050" );
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).
217 my ( $self, $value ) = @_;
219 if ( defined $value ) {
220 $self->{ "_identifier" } = $value;
223 return $self->{ "_identifier" };
232 Usage : $rel->subject_term( $subject );
234 $subject = $rel->subject_term();
235 Function: Set/get for the subject term of this Relationship.
237 The common convention for ontologies is to express
238 relationships between terms as triples (subject, predicate,
241 Returns : The subject term [Bio::Ontology::TermI].
242 Args : The subject term [Bio::Ontology::TermI] (optional).
247 my ( $self, $term ) = @_;
249 if ( defined $term ) {
250 $self->_check_class( $term, "Bio::Ontology::TermI" );
251 $self->{ "_subject_term" } = $term;
254 return $self->{ "_subject_term" };
263 Usage : $rel->object_term( $object );
265 $object = $rel->object_term();
266 Function: Set/get for the object term of this Relationship.
268 The common convention for ontologies is to express
269 relationships between terms as triples (subject, predicate,
272 Returns : The object term [Bio::Ontology::TermI].
273 Args : The object term [Bio::Ontology::TermI] (optional).
278 my ( $self, $term ) = @_;
280 if ( defined $term ) {
281 $self->_check_class( $term, "Bio::Ontology::TermI" );
282 $self->{ "_object_term" } = $term;
285 return $self->{ "_object_term" };
290 =head2 predicate_term
292 Title : predicate_term
293 Usage : $rel->predicate_term( $type );
295 $type = $rel->predicate_term();
296 Function: Set/get for the predicate (relationship type) of this
299 The common convention for ontologies is to express
300 relationships between terms as triples (subject, predicate,
303 Returns : The predicate term [Bio::Ontology::TermI].
304 Args : The predicate term [Bio::Ontology::TermI] (optional).
309 my ( $self, $term ) = @_;
311 if ( defined $term ) {
312 $self->_check_class( $term, "Bio::Ontology::TermI" );
313 $self->{ "_predicate_term" } = $term;
316 return $self->{ "_predicate_term" };
323 Usage : $ont = $obj->ontology()
324 Function: Get/set the ontology that defined this relationship.
326 Returns : an object implementing L<Bio::Ontology::OntologyI>
327 Args : on set, undef or an object implementing
328 Bio::Ontology::OntologyI (optional)
330 See L<Bio::Ontology::OntologyI>.
341 $ont = Bio
::Ontology
::Ontology
->new(-name
=> $ont) if ! ref($ont);
342 if(! $ont->isa("Bio::Ontology::OntologyI")) {
343 $self->throw(ref($ont)." does not implement ".
344 "Bio::Ontology::OntologyI. Bummer.");
347 return $self->{"_ontology"} = $ont;
349 return $self->{"_ontology"};
355 Usage : print $rel->to_string();
356 Function: to_string method for Relationship.
357 Returns : A string representation of this Relationship.
369 $s .= "-- Identifier:\n";
370 $s .= $self->identifier()."\n";
371 $s .= "-- Subject Term Identifier:\n";
372 $s .= $self->subject_term()->identifier()."\n";
373 $s .= "-- Object Term Identifier:\n";
374 $s .= $self->object_term()->identifier()."\n";
375 $s .= "-- Relationship Type Identifier:\n";
376 $s .= $self->predicate_term()->identifier();
385 my ( $self, $value, $expected_class ) = @_;
387 if ( ! defined( $value ) ) {
388 $self->throw( "Found [undef] where [$expected_class] expected" );
390 elsif ( ! ref( $value ) ) {
391 $self->throw( "Found [scalar] where [$expected_class] expected" );
393 elsif ( ! $value->isa( $expected_class ) ) {
394 $self->throw( "Found [" . ref( $value ) . "] where [$expected_class] expected" );
399 #################################################################
400 # aliases for backwards compatibility
401 #################################################################
403 =head1 Deprecated Methods
405 These methods are deprecated and defined here solely to preserve
406 backwards compatibility.
410 *child_term
= \
&subject_term
;
411 *parent_term
= \
&object_term
;
412 *relationship_type
= \
&predicate_term
;