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
;
112 # Object preamble - inherits from Bio::Root::Root
114 use Bio
::Ontology
::Term
;
116 use base
qw(Bio::Root::Root Bio::AnnotationI Bio::Ontology::TermI);
121 Usage : my $sv = Bio::Annotation::OntologyTerm->new();
122 Function: Instantiate a new OntologyTerm object
123 Returns : Bio::Annotation::OntologyTerm object
124 Args : -term => $term to initialize the term data field [optional]
125 Most named arguments that Bio::Ontology::Term accepts will work
126 here too. -label is a synonym for -name, -tagname is a synonym for
132 my ($class,@args) = @_;
134 my $self = $class->SUPER::new
(@args);
135 my ($term,$name,$label,$identifier,$definition,$ont,$tag) =
136 $self->_rearrange([qw(TERM
147 $self->name($name || $label) if $name || $label;
148 $self->identifier($identifier) if $identifier;
149 $self->definition($definition) if $definition;
151 $self->ontology($ont || $tag) if $ont || $tag;
156 =head1 AnnotationI implementing functions
163 Usage : my $text = $obj->as_text
164 Function: Returns a textual representation of the annotation that
165 this object holds. Presently, it is tag name, name of the
166 term, and the is_obsolete attribute concatenated togather
167 with a delimiter (|).
178 return $self->tagname()."|".$self->name()."|".($self->is_obsolete()||'');
184 Usage : my $str = $ann->display_text();
185 Function: returns a string. Unlike as_text(), this method returns a string
186 formatted as would be expected for te specific implementation.
188 One can pass a callback as an argument which allows custom text
189 generation; the callback is passed the current instance and any text
193 Args : [optional] callback
198 my $DEFAULT_CB = sub { $_[0]->identifier || ''};
201 my ($self, $cb) = @_;
203 $self->throw("Callback must be a code reference") if ref $cb ne 'CODE';
212 Usage : my $hashtree = $value->hash_tree
213 Function: For supporting the AnnotationI interface just returns the value
214 as a hashref with the key 'value' pointing to the value
225 $h->{'name'} = $self->name();
226 $h->{'identifier'} = $self->identifier();
227 $h->{'definition'} = $self->definition();
228 $h->{'synonyms'} = [$self->get_synonyms()];
235 Usage : $obj->tagname($newval)
236 Function: Get/set the tagname for this annotation value.
238 Setting this is optional. If set, it obviates the need to provide
239 a tag to AnnotationCollection when adding this object.
241 This is aliased to ontology() here.
243 Returns : value of tagname (a scalar)
244 Args : new value (a scalar, optional)
252 return $self->ontology(@_) if @_;
253 # if in get mode we need to get the name from the ontology
254 my $ont = $self->ontology();
255 return ref($ont) ?
$ont->name() : $ont;
258 =head1 Methods for Bio::Ontology::TermI compliance
265 Usage : $obj->term($newval)
266 Function: Get/set the Bio::Ontology::TermI implementing object.
268 We implement TermI by composition, and this method sets/gets the
269 object we delegate to.
271 Returns : value of term (a Bio::Ontology::TermI compliant object)
272 Args : new value (a Bio::Ontology::TermI compliant object, optional)
278 my ($self,$value) = @_;
279 if( defined $value) {
280 $self->{'term'} = $value;
282 if(! exists($self->{'term'})) {
283 $self->{'term'} = Bio
::Ontology
::Term
->new();
285 return $self->{'term'};
291 Usage : $term->identifier( "0003947" );
293 print $term->identifier();
294 Function: Set/get for the identifier of this Term.
295 Returns : The identifier [scalar].
296 Args : The identifier [scalar] (optional).
301 return shift->term()->identifier(@_);
307 Usage : $term->name( "N-acetylgalactosaminyltransferase" );
310 Function: Set/get for the name of this Term.
311 Returns : The name [scalar].
312 Args : The name [scalar] (optional).
317 return shift->term()->name(@_);
324 Usage : $term->definition( "Catalysis of ..." );
326 print $term->definition();
327 Function: Set/get for the definition of this Term.
328 Returns : The definition [scalar].
329 Args : The definition [scalar] (optional).
334 return shift->term()->definition(@_);
340 Usage : $term->ontology( $top );
342 $top = $term->ontology();
343 Function: Set/get for a relationship between this Term and
344 another Term (e.g. the top level of the ontology).
345 Returns : The ontology of this Term [TermI].
346 Args : The ontology of this Term [TermI or scalar -- which
347 becomes the name of the category term] (optional).
352 return shift->term()->ontology(@_);
358 Usage : $term->is_obsolete( 1 );
360 if ( $term->is_obsolete() )
361 Function: Set/get for the obsoleteness of this Term.
362 Returns : the obsoleteness [0 or 1].
363 Args : the obsoleteness [0 or 1] (optional).
368 return shift->term()->is_obsolete(@_);
374 Usage : $term->comment( "Consider the term ..." );
376 print $term->comment();
377 Function: Set/get for an arbitrary comment about this Term.
379 Args : A comment (optional).
384 return shift->term()->comment(@_);
389 Title : get_synonyms()
390 Usage : @aliases = $term->get_synonyms();
391 Function: Returns a list of aliases of this Term.
392 Returns : A list of aliases [array of [scalar]].
398 return shift->term()->get_synonyms(@_);
404 Usage : $term->add_synonym( @asynonyms );
406 $term->add_synonym( $synonym );
407 Function: Pushes one or more synonyms into the list of synonyms.
409 Args : One synonym [scalar] or a list of synonyms [array of [scalar]].
414 return shift->term()->add_synonym(@_);
418 =head2 remove_synonyms
420 Title : remove_synonyms()
421 Usage : $term->remove_synonyms();
422 Function: Deletes (and returns) the synonyms of this Term.
423 Returns : A list of synonyms [array of [scalar]].
428 sub remove_synonyms
{
429 return shift->term()->remove_synonyms(@_);
434 Title : get_dblinks()
435 Usage : @ds = $term->get_dblinks();
436 Function: Returns a list of each dblinks of this GO term.
437 Returns : A list of dblinks [array of [scalars]].
439 Note : this is deprecated in favor of get_dbxrefs(), which works with strings
440 or L<Bio::Annotation::DBLink> instances
446 Carp
::carp
('get_dblinks() is deprecated; use get_dbxrefs()');
447 return $self->term->get_dbxrefs(@_);
452 Title : get_dbxrefs()
453 Usage : @ds = $term->get_dbxrefs();
454 Function: Returns a list of each dblinks of this GO term.
455 Returns : A list of dblinks [array of [scalars] or Bio::Annotation::DBLink instances].
461 return shift->term->get_dbxrefs(@_);
467 Usage : $term->add_dblink( @dbls );
469 $term->add_dblink( $dbl );
470 Function: Pushes one or more dblinks
471 into the list of dblinks.
473 Args : One dblink [scalar] or a list of
474 dblinks [array of [scalars]].
475 Note : this is deprecated in favor of add_dbxref(), which works with strings
476 or L<Bio::Annotation::DBLink> instances
482 Carp
::carp
('add_dblink() is deprecated; use add_dbxref()');
483 return $self->term->add_dbxref(@_);
489 Usage : $term->add_dbxref( @dbls );
491 $term->add_dbxref( $dbl );
492 Function: Pushes one or more dblinks
493 into the list of dblinks.
500 return shift->term->add_dbxref(@_);
503 =head2 remove_dblinks
505 Title : remove_dblinks()
506 Usage : $term->remove_dblinks();
507 Function: Deletes (and returns) the definition references of this GO term.
508 Returns : A list of definition references [array of [scalars]].
510 Note : this is deprecated in favor of remove_dbxrefs(), which works with strings
511 or L<Bio::Annotation::DBLink> instances
517 Carp
::carp
('remove_dblinks() is deprecated; use remove_dbxrefs()');
518 return $self->term->remove_dbxrefs(@_);
521 =head2 remove_dbxrefs
523 Title : remove_dbxrefs()
524 Usage : $term->remove_dbxrefs();
525 Function: Deletes (and returns) the definition references of this GO term.
526 Returns : A list of definition references [array of [scalars]].
532 return shift->term->remove_dbxrefs(@_);
535 =head2 get_secondary_ids
537 Title : get_secondary_ids
538 Usage : @ids = $term->get_secondary_ids();
539 Function: Returns a list of secondary identifiers of this Term.
541 Secondary identifiers mostly originate from merging terms,
542 or possibly also from splitting terms.
544 Returns : A list of secondary identifiers [array of [scalar]]
549 sub get_secondary_ids
{
550 return shift->term->get_secondary_ids(@_);
551 } # get_secondary_ids
554 =head2 add_secondary_id
556 Title : add_secondary_id
557 Usage : $term->add_secondary_id( @ids );
559 $term->add_secondary_id( $id );
560 Function: Adds one or more secondary identifiers to this term.
562 Args : One or more secondary identifiers [scalars]
566 sub add_secondary_id
{
567 return shift->term->add_secondary_id(@_);
571 =head2 remove_secondary_ids
573 Title : remove_secondary_ids
574 Usage : $term->remove_secondary_ids();
575 Function: Deletes (and returns) the secondary identifiers of this Term.
576 Returns : The previous list of secondary identifiers [array of [scalars]]
581 sub remove_secondary_ids
{
582 return shift->term->remove_secondary_ids(@_);
583 } # remove_secondary_ids