2 # BioPerl module for Bio::Annotation::OntologyTerm
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
6 # Cared for by Hilmar Lapp <hlapp at gmx.net>
8 # Copyright Hilmar Lapp
10 # You may distribute this module under the same terms as perl itself
13 # (c) Hilmar Lapp, hlapp at gmx.net, 2002.
14 # (c) GNF, Genomics Institute of the Novartis Research Foundation, 2002.
16 # You may distribute this module under the same terms as perl itself.
17 # Refer to the Perl Artistic License (see the license accompanying this
18 # software package, or see http://www.perl.com/language/misc/Artistic.html)
19 # for the terms under which you may use, modify, and redistribute this module.
21 # THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
22 # WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
23 # MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
26 # POD documentation - main docs before the code
30 Bio::Annotation::OntologyTerm - An ontology term adapted to AnnotationI
34 use Bio::Annotation::OntologyTerm;
35 use Bio::Annotation::Collection;
36 use Bio::Ontology::Term;
38 my $coll = Bio::Annotation::Collection->new();
40 # this also implements a tag/value pair, where tag _and_ value are treated
42 my $annterm = Bio::Annotation::OntologyTerm->new(-label => 'ABC1',
43 -tagname => 'Gene Name');
44 # ontology terms can be added directly - they implicitly have a tag
45 $coll->add_Annotation($annterm);
47 # implementation is by composition - you can get/set the term object
49 my $term = $annterm->term(); # term is-a Bio::Ontology::TermI
50 print "ontology term ",$term->name()," (ID ",$term->identifier(),
51 "), ontology ",$term->ontology()->name(),"\n";
52 $term = Bio::Ontology::Term->new(-name => 'ABC2',
53 -ontology => 'Gene Name');
54 $annterm->term($term);
58 Ontology term annotation object
64 User feedback is an integral part of the evolution of this and other
65 Bioperl modules. Send your comments and suggestions preferably to one
66 of the Bioperl mailing lists. Your participation is much appreciated.
68 bioperl-l@bioperl.org - General discussion
69 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
73 Please direct usage questions or support issues to the mailing list:
75 I<bioperl-l@bioperl.org>
77 rather than to the module maintainer directly. Many experienced and
78 reponsive experts will be able look at the problem and quickly
79 address it. Please include a thorough description of the problem
80 with code and data examples if at all possible.
84 Report bugs to the Bioperl bug tracking system to help us keep track
85 the bugs and their resolution. Bug reports can be submitted via
88 https://github.com/bioperl/bioperl-live/issues
90 =head1 AUTHOR - Hilmar Lapp
92 Email hlapp at gmx.net
97 The rest of the documentation details each of the object methods.
98 Internal methods are usually preceded with a _
103 # Let the code begin...
106 package Bio
::Annotation
::OntologyTerm
;
109 # Object preamble - inherits from Bio::Root::Root
111 use Bio
::Ontology
::Term
;
113 use base
qw(Bio::Root::Root Bio::AnnotationI Bio::Ontology::TermI);
118 Usage : my $sv = Bio::Annotation::OntologyTerm->new();
119 Function: Instantiate a new OntologyTerm object
120 Returns : Bio::Annotation::OntologyTerm object
121 Args : -term => $term to initialize the term data field [optional]
122 Most named arguments that Bio::Ontology::Term accepts will work
123 here too. -label is a synonym for -name, -tagname is a synonym for
129 my ($class,@args) = @_;
131 my $self = $class->SUPER::new
(@args);
132 my ($term,$name,$label,$identifier,$definition,$ont,$tag) =
133 $self->_rearrange([qw(TERM
144 $self->name($name || $label) if $name || $label;
145 $self->identifier($identifier) if $identifier;
146 $self->definition($definition) if $definition;
148 $self->ontology($ont || $tag) if $ont || $tag;
153 =head1 AnnotationI implementing functions
160 Usage : my $text = $obj->as_text
161 Function: Returns a textual representation of the annotation that
162 this object holds. Presently, it is tag name, name of the
163 term, and the is_obsolete attribute concatenated togather
164 with a delimiter (|).
175 return $self->tagname()."|".$self->name()."|".($self->is_obsolete()||'');
181 Usage : my $str = $ann->display_text();
182 Function: returns a string. Unlike as_text(), this method returns a string
183 formatted as would be expected for te specific implementation.
185 One can pass a callback as an argument which allows custom text
186 generation; the callback is passed the current instance and any text
190 Args : [optional] callback
195 my $DEFAULT_CB = sub { $_[0]->identifier || ''};
198 my ($self, $cb) = @_;
200 $self->throw("Callback must be a code reference") if ref $cb ne 'CODE';
209 Usage : my $hashtree = $value->hash_tree
210 Function: For supporting the AnnotationI interface just returns the value
211 as a hashref with the key 'value' pointing to the value
222 $h->{'name'} = $self->name();
223 $h->{'identifier'} = $self->identifier();
224 $h->{'definition'} = $self->definition();
225 $h->{'synonyms'} = [$self->get_synonyms()];
232 Usage : $obj->tagname($newval)
233 Function: Get/set the tagname for this annotation value.
235 Setting this is optional. If set, it obviates the need to provide
236 a tag to AnnotationCollection when adding this object.
238 This is aliased to ontology() here.
240 Returns : value of tagname (a scalar)
241 Args : new value (a scalar, optional)
249 return $self->ontology(@_) if @_;
250 # if in get mode we need to get the name from the ontology
251 my $ont = $self->ontology();
252 return ref($ont) ?
$ont->name() : $ont;
255 =head1 Methods for Bio::Ontology::TermI compliance
262 Usage : $obj->term($newval)
263 Function: Get/set the Bio::Ontology::TermI implementing object.
265 We implement TermI by composition, and this method sets/gets the
266 object we delegate to.
268 Returns : value of term (a Bio::Ontology::TermI compliant object)
269 Args : new value (a Bio::Ontology::TermI compliant object, optional)
275 my ($self,$value) = @_;
276 if( defined $value) {
277 $self->{'term'} = $value;
279 if(! exists($self->{'term'})) {
280 $self->{'term'} = Bio
::Ontology
::Term
->new();
282 return $self->{'term'};
288 Usage : $term->identifier( "0003947" );
290 print $term->identifier();
291 Function: Set/get for the identifier of this Term.
292 Returns : The identifier [scalar].
293 Args : The identifier [scalar] (optional).
298 return shift->term()->identifier(@_);
304 Usage : $term->name( "N-acetylgalactosaminyltransferase" );
307 Function: Set/get for the name of this Term.
308 Returns : The name [scalar].
309 Args : The name [scalar] (optional).
314 return shift->term()->name(@_);
321 Usage : $term->definition( "Catalysis of ..." );
323 print $term->definition();
324 Function: Set/get for the definition of this Term.
325 Returns : The definition [scalar].
326 Args : The definition [scalar] (optional).
331 return shift->term()->definition(@_);
337 Usage : $term->ontology( $top );
339 $top = $term->ontology();
340 Function: Set/get for a relationship between this Term and
341 another Term (e.g. the top level of the ontology).
342 Returns : The ontology of this Term [TermI].
343 Args : The ontology of this Term [TermI or scalar -- which
344 becomes the name of the category term] (optional).
349 return shift->term()->ontology(@_);
355 Usage : $term->is_obsolete( 1 );
357 if ( $term->is_obsolete() )
358 Function: Set/get for the obsoleteness of this Term.
359 Returns : the obsoleteness [0 or 1].
360 Args : the obsoleteness [0 or 1] (optional).
365 return shift->term()->is_obsolete(@_);
371 Usage : $term->comment( "Consider the term ..." );
373 print $term->comment();
374 Function: Set/get for an arbitrary comment about this Term.
376 Args : A comment (optional).
381 return shift->term()->comment(@_);
386 Title : get_synonyms()
387 Usage : @aliases = $term->get_synonyms();
388 Function: Returns a list of aliases of this Term.
389 Returns : A list of aliases [array of [scalar]].
395 return shift->term()->get_synonyms(@_);
401 Usage : $term->add_synonym( @asynonyms );
403 $term->add_synonym( $synonym );
404 Function: Pushes one or more synonyms into the list of synonyms.
406 Args : One synonym [scalar] or a list of synonyms [array of [scalar]].
411 return shift->term()->add_synonym(@_);
415 =head2 remove_synonyms
417 Title : remove_synonyms()
418 Usage : $term->remove_synonyms();
419 Function: Deletes (and returns) the synonyms of this Term.
420 Returns : A list of synonyms [array of [scalar]].
425 sub remove_synonyms
{
426 return shift->term()->remove_synonyms(@_);
431 Title : get_dblinks()
432 Usage : @ds = $term->get_dblinks();
433 Function: Returns a list of each dblinks of this GO term.
434 Returns : A list of dblinks [array of [scalars]].
436 Note : this is deprecated in favor of get_dbxrefs(), which works with strings
437 or L<Bio::Annotation::DBLink> instances
443 $self->deprecated('get_dblinks() is deprecated; use get_dbxrefs()');
444 return $self->term->get_dbxrefs(@_);
449 Title : get_dbxrefs()
450 Usage : @ds = $term->get_dbxrefs();
451 Function: Returns a list of each dblinks of this GO term.
452 Returns : A list of dblinks [array of [scalars] or Bio::Annotation::DBLink instances].
458 return shift->term->get_dbxrefs(@_);
464 Usage : $term->add_dblink( @dbls );
466 $term->add_dblink( $dbl );
467 Function: Pushes one or more dblinks
468 into the list of dblinks.
470 Args : One dblink [scalar] or a list of
471 dblinks [array of [scalars]].
472 Note : this is deprecated in favor of add_dbxref(), which works with strings
473 or L<Bio::Annotation::DBLink> instances
479 $self->deprecated('add_dblink() is deprecated; use add_dbxref()');
480 return $self->term->add_dbxref(@_);
486 Usage : $term->add_dbxref( @dbls );
488 $term->add_dbxref( $dbl );
489 Function: Pushes one or more dblinks
490 into the list of dblinks.
497 return shift->term->add_dbxref(@_);
500 =head2 remove_dblinks
502 Title : remove_dblinks()
503 Usage : $term->remove_dblinks();
504 Function: Deletes (and returns) the definition references of this GO term.
505 Returns : A list of definition references [array of [scalars]].
507 Note : this is deprecated in favor of remove_dbxrefs(), which works with strings
508 or L<Bio::Annotation::DBLink> instances
514 $self->deprecated('remove_dblinks() is deprecated; use remove_dbxrefs()');
515 return $self->term->remove_dbxrefs(@_);
518 =head2 remove_dbxrefs
520 Title : remove_dbxrefs()
521 Usage : $term->remove_dbxrefs();
522 Function: Deletes (and returns) the definition references of this GO term.
523 Returns : A list of definition references [array of [scalars]].
529 return shift->term->remove_dbxrefs(@_);
532 =head2 get_secondary_ids
534 Title : get_secondary_ids
535 Usage : @ids = $term->get_secondary_ids();
536 Function: Returns a list of secondary identifiers of this Term.
538 Secondary identifiers mostly originate from merging terms,
539 or possibly also from splitting terms.
541 Returns : A list of secondary identifiers [array of [scalar]]
546 sub get_secondary_ids
{
547 return shift->term->get_secondary_ids(@_);
548 } # get_secondary_ids
551 =head2 add_secondary_id
553 Title : add_secondary_id
554 Usage : $term->add_secondary_id( @ids );
556 $term->add_secondary_id( $id );
557 Function: Adds one or more secondary identifiers to this term.
559 Args : One or more secondary identifiers [scalars]
563 sub add_secondary_id
{
564 return shift->term->add_secondary_id(@_);
568 =head2 remove_secondary_ids
570 Title : remove_secondary_ids
571 Usage : $term->remove_secondary_ids();
572 Function: Deletes (and returns) the secondary identifiers of this Term.
573 Returns : The previous list of secondary identifiers [array of [scalars]]
578 sub remove_secondary_ids
{
579 return shift->term->remove_secondary_ids(@_);
580 } # remove_secondary_ids