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
;
111 # Object preamble - inherits from Bio::Root::Root
113 use Bio
::Ontology
::Term
;
115 use base
qw(Bio::Root::Root Bio::AnnotationI Bio::Ontology::TermI);
120 Usage : my $sv = Bio::Annotation::OntologyTerm->new();
121 Function: Instantiate a new OntologyTerm object
122 Returns : Bio::Annotation::OntologyTerm object
123 Args : -term => $term to initialize the term data field [optional]
124 Most named arguments that Bio::Ontology::Term accepts will work
125 here too. -label is a synonym for -name, -tagname is a synonym for
131 my ($class,@args) = @_;
133 my $self = $class->SUPER::new
(@args);
134 my ($term,$name,$label,$identifier,$definition,$ont,$tag) =
135 $self->_rearrange([qw(TERM
146 $self->name($name || $label) if $name || $label;
147 $self->identifier($identifier) if $identifier;
148 $self->definition($definition) if $definition;
150 $self->ontology($ont || $tag) if $ont || $tag;
155 =head1 AnnotationI implementing functions
162 Usage : my $text = $obj->as_text
163 Function: Returns a textual representation of the annotation that
164 this object holds. Presently, it is tag name, name of the
165 term, and the is_obsolete attribute concatenated togather
166 with a delimiter (|).
177 return $self->tagname()."|".$self->name()."|".($self->is_obsolete()||'');
183 Usage : my $str = $ann->display_text();
184 Function: returns a string. Unlike as_text(), this method returns a string
185 formatted as would be expected for te specific implementation.
187 One can pass a callback as an argument which allows custom text
188 generation; the callback is passed the current instance and any text
192 Args : [optional] callback
197 my $DEFAULT_CB = sub { $_[0]->identifier || ''};
200 my ($self, $cb) = @_;
202 $self->throw("Callback must be a code reference") if ref $cb ne 'CODE';
211 Usage : my $hashtree = $value->hash_tree
212 Function: For supporting the AnnotationI interface just returns the value
213 as a hashref with the key 'value' pointing to the value
224 $h->{'name'} = $self->name();
225 $h->{'identifier'} = $self->identifier();
226 $h->{'definition'} = $self->definition();
227 $h->{'synonyms'} = [$self->get_synonyms()];
234 Usage : $obj->tagname($newval)
235 Function: Get/set the tagname for this annotation value.
237 Setting this is optional. If set, it obviates the need to provide
238 a tag to AnnotationCollection when adding this object.
240 This is aliased to ontology() here.
242 Returns : value of tagname (a scalar)
243 Args : new value (a scalar, optional)
251 return $self->ontology(@_) if @_;
252 # if in get mode we need to get the name from the ontology
253 my $ont = $self->ontology();
254 return ref($ont) ?
$ont->name() : $ont;
257 =head1 Methods for Bio::Ontology::TermI compliance
264 Usage : $obj->term($newval)
265 Function: Get/set the Bio::Ontology::TermI implementing object.
267 We implement TermI by composition, and this method sets/gets the
268 object we delegate to.
270 Returns : value of term (a Bio::Ontology::TermI compliant object)
271 Args : new value (a Bio::Ontology::TermI compliant object, optional)
277 my ($self,$value) = @_;
278 if( defined $value) {
279 $self->{'term'} = $value;
281 if(! exists($self->{'term'})) {
282 $self->{'term'} = Bio
::Ontology
::Term
->new();
284 return $self->{'term'};
290 Usage : $term->identifier( "0003947" );
292 print $term->identifier();
293 Function: Set/get for the identifier of this Term.
294 Returns : The identifier [scalar].
295 Args : The identifier [scalar] (optional).
300 return shift->term()->identifier(@_);
306 Usage : $term->name( "N-acetylgalactosaminyltransferase" );
309 Function: Set/get for the name of this Term.
310 Returns : The name [scalar].
311 Args : The name [scalar] (optional).
316 return shift->term()->name(@_);
323 Usage : $term->definition( "Catalysis of ..." );
325 print $term->definition();
326 Function: Set/get for the definition of this Term.
327 Returns : The definition [scalar].
328 Args : The definition [scalar] (optional).
333 return shift->term()->definition(@_);
339 Usage : $term->ontology( $top );
341 $top = $term->ontology();
342 Function: Set/get for a relationship between this Term and
343 another Term (e.g. the top level of the ontology).
344 Returns : The ontology of this Term [TermI].
345 Args : The ontology of this Term [TermI or scalar -- which
346 becomes the name of the category term] (optional).
351 return shift->term()->ontology(@_);
357 Usage : $term->is_obsolete( 1 );
359 if ( $term->is_obsolete() )
360 Function: Set/get for the obsoleteness of this Term.
361 Returns : the obsoleteness [0 or 1].
362 Args : the obsoleteness [0 or 1] (optional).
367 return shift->term()->is_obsolete(@_);
373 Usage : $term->comment( "Consider the term ..." );
375 print $term->comment();
376 Function: Set/get for an arbitrary comment about this Term.
378 Args : A comment (optional).
383 return shift->term()->comment(@_);
388 Title : get_synonyms()
389 Usage : @aliases = $term->get_synonyms();
390 Function: Returns a list of aliases of this Term.
391 Returns : A list of aliases [array of [scalar]].
397 return shift->term()->get_synonyms(@_);
403 Usage : $term->add_synonym( @asynonyms );
405 $term->add_synonym( $synonym );
406 Function: Pushes one or more synonyms into the list of synonyms.
408 Args : One synonym [scalar] or a list of synonyms [array of [scalar]].
413 return shift->term()->add_synonym(@_);
417 =head2 remove_synonyms
419 Title : remove_synonyms()
420 Usage : $term->remove_synonyms();
421 Function: Deletes (and returns) the synonyms of this Term.
422 Returns : A list of synonyms [array of [scalar]].
427 sub remove_synonyms
{
428 return shift->term()->remove_synonyms(@_);
433 Title : get_dblinks()
434 Usage : @ds = $term->get_dblinks();
435 Function: Returns a list of each dblinks of this GO term.
436 Returns : A list of dblinks [array of [scalars]].
438 Note : this is deprecated in favor of get_dbxrefs(), which works with strings
439 or L<Bio::Annotation::DBLink> instances
445 Carp
::carp
('get_dblinks() is deprecated; use get_dbxrefs()');
446 return $self->term->get_dbxrefs(@_);
451 Title : get_dbxrefs()
452 Usage : @ds = $term->get_dbxrefs();
453 Function: Returns a list of each dblinks of this GO term.
454 Returns : A list of dblinks [array of [scalars] or Bio::Annotation::DBLink instances].
460 return shift->term->get_dbxrefs(@_);
466 Usage : $term->add_dblink( @dbls );
468 $term->add_dblink( $dbl );
469 Function: Pushes one or more dblinks
470 into the list of dblinks.
472 Args : One dblink [scalar] or a list of
473 dblinks [array of [scalars]].
474 Note : this is deprecated in favor of add_dbxref(), which works with strings
475 or L<Bio::Annotation::DBLink> instances
481 Carp
::carp
('add_dblink() is deprecated; use add_dbxref()');
482 return $self->term->add_dbxref(@_);
488 Usage : $term->add_dbxref( @dbls );
490 $term->add_dbxref( $dbl );
491 Function: Pushes one or more dblinks
492 into the list of dblinks.
499 return shift->term->add_dbxref(@_);
502 =head2 remove_dblinks
504 Title : remove_dblinks()
505 Usage : $term->remove_dblinks();
506 Function: Deletes (and returns) the definition references of this GO term.
507 Returns : A list of definition references [array of [scalars]].
509 Note : this is deprecated in favor of remove_dbxrefs(), which works with strings
510 or L<Bio::Annotation::DBLink> instances
516 Carp
::carp
('remove_dblinks() is deprecated; use remove_dbxrefs()');
517 return $self->term->remove_dbxrefs(@_);
520 =head2 remove_dbxrefs
522 Title : remove_dbxrefs()
523 Usage : $term->remove_dbxrefs();
524 Function: Deletes (and returns) the definition references of this GO term.
525 Returns : A list of definition references [array of [scalars]].
531 return shift->term->remove_dbxrefs(@_);
534 =head2 get_secondary_ids
536 Title : get_secondary_ids
537 Usage : @ids = $term->get_secondary_ids();
538 Function: Returns a list of secondary identifiers of this Term.
540 Secondary identifiers mostly originate from merging terms,
541 or possibly also from splitting terms.
543 Returns : A list of secondary identifiers [array of [scalar]]
548 sub get_secondary_ids
{
549 return shift->term->get_secondary_ids(@_);
550 } # get_secondary_ids
553 =head2 add_secondary_id
555 Title : add_secondary_id
556 Usage : $term->add_secondary_id( @ids );
558 $term->add_secondary_id( $id );
559 Function: Adds one or more secondary identifiers to this term.
561 Args : One or more secondary identifiers [scalars]
565 sub add_secondary_id
{
566 return shift->term->add_secondary_id(@_);
570 =head2 remove_secondary_ids
572 Title : remove_secondary_ids
573 Usage : $term->remove_secondary_ids();
574 Function: Deletes (and returns) the secondary identifiers of this Term.
575 Returns : The previous list of secondary identifiers [array of [scalars]]
580 sub remove_secondary_ids
{
581 return shift->term->remove_secondary_ids(@_);
582 } # remove_secondary_ids