2 # BioPerl module for Bio::Ontology::Term
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
6 # Cared for by Christian M. Zmasek <czmasek-at-burnham.org> or <cmzmasek@yahoo.com>
8 # (c) Christian M. Zmasek, czmasek-at-burnham.org, 2002.
9 # (c) GNF, Genomics Institute of the Novartis Research Foundation, 2002.
11 # You may distribute this module under the same terms as perl itself.
12 # Refer to the Perl Artistic License (see the license accompanying this
13 # software package, or see http://www.perl.com/language/misc/Artistic.html)
14 # for the terms under which you may use, modify, and redistribute this module.
16 # THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
17 # WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
18 # MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 # You may distribute this module under the same terms as perl itself
22 # POD documentation - main docs before the code
26 Bio::Ontology::Term - implementation of the interface for ontology terms
30 #get Bio::Ontology::TermI somehow.
32 print $term->identifier(), "\n";
33 print $term->name(), "\n";
34 print $term->definition(), "\n";
35 print $term->is_obsolete(), "\n";
36 print $term->comment(), "\n";
38 foreach my $synonym ( $term->each_synonym() ) {
44 This is a simple implementation for ontology terms providing basic
45 methods (it provides no functionality related to graphs). It
46 implements the L<Bio::Ontology::TermI> interface.
48 This class also implements L<Bio::IdentifiableI> and
55 User feedback is an integral part of the evolution of this and other
56 Bioperl modules. Send your comments and suggestions preferably to one
57 of the Bioperl mailing lists. Your participation is much appreciated.
59 bioperl-l@bioperl.org - General discussion
60 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
64 Please direct usage questions or support issues to the mailing list:
66 I<bioperl-l@bioperl.org>
68 rather than to the module maintainer directly. Many experienced and
69 reponsive experts will be able look at the problem and quickly
70 address it. Please include a thorough description of the problem
71 with code and data examples if at all possible.
75 Report bugs to the Bioperl bug tracking system to help us keep track
76 the bugs and their resolution. Bug reports can be submitted via the web:
78 https://github.com/bioperl/bioperl-live/issues
84 Email: czmasek-at-burnham.org or cmzmasek@yahoo.com
86 WWW: http://monochrome-effect.net/
90 Genomics Institute of the Novartis Research Foundation
91 10675 John Jay Hopkins Drive
96 The rest of the documentation details each of the object
102 # Let the code begin...
104 package Bio
::Ontology
::Term
;
106 use Bio
::Ontology
::Ontology
;
107 use Bio
::Ontology
::OntologyStore
;
108 use Bio
::Annotation
::DBLink
;
111 use constant TRUE
=> 1;
112 use constant FALSE
=> 0;
114 use base
qw(Bio::Root::Root Bio::Ontology::TermI Bio::IdentifiableI Bio::DescribableI);
119 Usage : $term = Bio::Ontology::Term->new(
120 -identifier => "16847",
121 -name => "1-aminocyclopropane-1-carboxylate synthase",
122 -definition => "Catalysis of ...",
125 Function: Creates a new Bio::Ontology::Term.
126 Returns : A new Bio::Ontology::Term object.
127 Args : -identifier => the identifier of this term [scalar]
128 -name => the name of this term [scalar]
129 -definition => the definition of this term [scalar]
130 -ontology => the ontology this term lives in
131 (a Bio::Ontology::OntologyI object)
132 -version => version information [scalar]
133 -is_obsolete => the obsoleteness of this term [0 or 1]
134 -comment => a comment [scalar]
135 -dblinks => Bio::Annotation::DBLink objects
137 -references => Bio::Annotation::Reference objects
140 See L<Bio::Ontology::OntologyI>, L<Bio::Annotation::Reference>,
141 L<Bio::Annotation::DBLink>.
147 my( $class,@args ) = @_;
149 my $self = $class->SUPER::new
( @args );
150 my ( $identifier, $name, $definition, $category, $ont, $version,
151 $is_obsolete, $comment, $dblinks, $dbxrefs, $references)
152 = $self->_rearrange( [
153 qw(IDENTIFIER NAME DEFINITION CATEGORY ONTOLOGY VERSION IS_OBSOLETE
154 COMMENT DBLINKS DBXREFS REFERENCES) ], @args );
158 defined($identifier) && $self->identifier( $identifier );
159 defined($name) && $self->name( $name );
160 defined($definition) && $self->definition( $definition );
161 defined($category) && $self->category( $category );
162 defined($ont) && $self->ontology( $ont );
163 defined($version) && $self->version( $version );
164 defined($is_obsolete) && $self->is_obsolete( $is_obsolete );
165 defined($comment) && $self->comment( $comment );
166 defined($dbxrefs) && $self->add_dbxref(-dbxrefs
=> $dbxrefs);
167 # deprecated methods, allow one to pass on to get the dep. notification
168 ref($dblinks) && $self->add_dblink(@
$dblinks);
169 ref($references) && $self->add_reference(@
$references);
180 $self->identifier(undef);
182 $self->comment(undef);
183 $self->definition(undef);
184 $self->ontology(undef);
185 $self->is_obsolete(0);
186 $self->remove_synonyms();
187 $self->remove_dbxrefs();
188 $self->remove_references;
189 $self->remove_secondary_ids();
198 Usage : $term->identifier( "GO:0003947" );
200 print $term->identifier();
201 Function: Set/get for the identifier of this Term.
202 Returns : The identifier [scalar].
203 Args : The identifier [scalar] (optional).
210 return $self->{'identifier'} = shift if @_;
211 return $self->{'identifier'};
218 Usage : $term->name( "N-acetylgalactosaminyltransferase" );
221 Function: Set/get for the name of this Term.
222 Returns : The name [scalar].
223 Args : The name [scalar] (optional).
230 return $self->{'name'} = shift if @_;
231 return $self->{'name'};
238 Usage : $term->definition( "Catalysis of ..." );
240 print $term->definition();
241 Function: Set/get for the definition of this Term.
242 Returns : The definition [scalar].
243 Args : The definition [scalar] (optional).
250 return $self->{'definition'} = shift if @_;
251 return $self->{'definition'};
258 Usage : $ont = $term->ontology();
260 $term->ontology( $ont );
261 Function: Get the ontology this term is in.
263 Note that with the ontology in hand you can query for all
266 Returns : The ontology of this Term as a Bio::Ontology::OntologyI
268 Args : On set, the ontology of this Term as a Bio::Ontology::OntologyI
269 implementing object or a string representing its name.
271 See L<Bio::Ontology::OntologyI>.
282 $ont = Bio
::Ontology
::Ontology
->new(-name
=> $ont) if ! ref($ont);
283 if(! $ont->isa("Bio::Ontology::OntologyI")) {
284 $self->throw(ref($ont)." does not implement ".
285 "Bio::Ontology::OntologyI. Bummer.");
288 return $self->{"_ontology"} = $ont;
290 return $self->{"_ontology"};
296 Usage : $term->version( "1.00" );
298 print $term->version();
299 Function: Set/get for version information.
300 Returns : The version [scalar].
301 Args : The version [scalar] (optional).
308 return $self->{'version'} = shift if @_;
309 return $self->{'version'};
315 Usage : $term->is_obsolete( 1 );
317 if ( $term->is_obsolete() )
318 Function: Set/get for the obsoleteness of this Term.
319 Returns : the obsoleteness [0 or 1].
320 Args : the obsoleteness [0 or 1] (optional).
327 return $self->{'is_obsolete'} = shift if @_;
328 return $self->{'is_obsolete'};
335 Usage : $term->comment( "Consider the term ..." );
337 print $term->comment();
338 Function: Set/get for an arbitrary comment about this Term.
340 Args : A comment (optional).
347 return $self->{'comment'} = shift if @_;
348 return $self->{'comment'};
354 Usage : @aliases = $term->get_synonyms;
355 Function: Returns a list of aliases of this Term.
356 Returns : A list of aliases [array of [scalar]].
364 return @
{ $self->{ "_synonyms" } } if exists($self->{ "_synonyms" });
372 Usage : $term->add_synonym( @asynonyms );
374 $term->add_synonym( $synonym );
375 Function: Pushes one or more synonyms into the list of synonyms.
377 Args : One synonym [scalar] or a list of synonyms [array of [scalar]].
382 my ( $self, @values ) = @_;
384 return unless( @values );
387 foreach my $syn (@values) {
388 next if grep { $_ eq $syn; } @
{$self->{ "_synonyms" }};
389 push( @
{ $self->{ "_synonyms" } }, $syn );
395 =head2 remove_synonyms
397 Title : remove_synonyms()
398 Usage : $term->remove_synonyms();
399 Function: Deletes (and returns) the synonyms of this Term.
400 Returns : A list of synonyms [array of [scalar]].
405 sub remove_synonyms
{
408 my @a = $self->get_synonyms();
409 $self->{ "_synonyms" } = [];
416 Title : get_dblinks()
417 Usage : @ds = $term->get_dblinks();
418 Function: Returns a list of each dblinks of this GO term.
419 Returns : A list of dblinks [array of [scalars]].
420 Args : A scalar indicating the context (optional).
421 If omitted, all dblinks will be returned.
422 Note : deprecated method due to past use of mixed data types; use
423 get_dbxrefs() instead, which handles both strings and DBLink
429 my ($self, $context) = @_;
430 $self->deprecated("Use of get_dblinks is deprecated. Note that prior use\n".
431 "of this method could return either simple scalar values\n".
432 "or Bio::Annotation::DBLink instances; only \n".
433 "Bio::Annotation::DBLink is now supported.\n ".
434 "Use get_dbxrefs() instead");
435 $self->get_dbxrefs($context);
440 Title : get_dbxrefs()
441 Usage : @ds = $term->get_dbxrefs();
442 Function: Returns a list of each link for this term.
444 If an implementor of this interface permits modification of
445 this array property, the class should define at least
446 methods add_dbxref() and remove_dbxrefs(), with obvious
449 Returns : A list of L<Bio::Annotation::DBLink> instances
450 Args : [optional] string which specifies context (default : returns all dbxrefs)
455 my ($self, $context) = shift;
457 if (defined($context)) {
458 if (exists($self->{_dblinks
}->{$context})) {
459 @dbxrefs = @
{$self->{_dblinks
}->{$context}};
462 @dbxrefs = map { @
$_ } values %{$self->{_dblinks
}} ;
467 =head2 get_dblink_context
469 Title : get_dblink_context
470 Usage : @context = $term->get_dblink_context;
471 Function: Return all context existing in Term
472 Returns : a list of scalar
474 Note : deprecated method due to past use of mixed data types; use
475 get_dbxref_context() instead
479 sub get_dblink_context
{
481 $self->deprecated("Use of get_dblink_context() is deprecated; use get_dbxref_context() instead");
482 return $self->get_dbxref_context(@_);
485 =head2 get_dbxref_context
487 Title : get_dbxref_context
488 Usage : @context = $term->get_dbxref_context;
489 Function: Return all context strings existing in Term
490 Returns : a list of scalars
495 sub get_dbxref_context
{
497 return keys %{$self->{_dblinks
}};
503 Usage : $term->add_dblink( @dbls );
505 $term->add_dblink( $dbl );
506 Function: Pushes one or more dblinks onto the list of dblinks.
508 Args : One or more L<Bio::Annotation::DBLink> instances
509 Note : deprecated method due to past use of mixed data types; use
510 add_dbxref() instead, which handles both strings and
517 $self->deprecated("Use of simple strings and add_dblink() is deprecated; use\n".
518 "Bio::Annotation::DBLink instances and add_dbxref() instead");
519 # here we're assuming the data is in a simple DB:ID format
521 for my $string (@_) {
522 my ($db, $id) = split(':',$string);
523 push @dbxrefs, Bio
::Annotation
::DBLink
->new(-database
=> $db, -primary_id
=> $id);
525 return $self->add_dbxref(-dbxrefs
=> \
@dbxrefs, -context
=> '_default');
531 Usage : $term->add_dbxref( @dbls );
533 $term->add_dbxref( $dbl );
534 Function: Pushes one or more dblinks onto the list of dblinks.
536 Args : -dbxrefs : array ref of Bio::Annotation::DBLink instances
537 -context : string designating the context for the DBLink
538 (default : '_default' - contextless)
544 my ($links, $context) = $self->_rearrange([qw(DBXREFS CONTEXT)],@_);
545 return unless defined $links;
546 $context ||= '_default';
547 $self->throw("DBLinks must be passed as an array reference") if ref $links ne 'ARRAY';
548 foreach my $dbxref (@
{$links}) {
549 $self->throw("$dbxref is not a DBLink") unless ref $dbxref &&
550 $dbxref->isa('Bio::Annotation::DBLink');
551 $self->throw("'all' is a reserved word for context.") if $context eq 'all';
552 if (! exists($self->{_dblinks
}->{$context})) {
553 $self->{_dblinks
}->{$context} = [];
555 my $linktext = ref $dbxref ?
$dbxref->display_text : $dbxref;
556 if (grep {$_->display_text eq $linktext}
557 @
{$self->{_dblinks
}->{$context}})
559 $self->warn("DBLink exists in the dblink of $context");
561 push @
{$self->{_dblinks
}->{$context}}, $dbxref;
565 # alias, for consistency
566 *add_dbxrefs
= \
&add_dbxref
;
571 Usage : $term->has_dblink($dblink);
572 Function: Checks if a DBXref is already existing in the OBOterm object
574 Args : [arg1] A DBxref identifier
575 Note : deprecated method due to past use of mixed data types; use
576 has_dbxref() instead, which handles both strings and
582 my ( $self, $value ) = @_;
583 $self->deprecated("use of has_dblink() is deprecated; use has_dbxref() instead");
584 return $self->has_dbxref($value);
590 Usage : $term->has_dbxref($dbxref);
591 Function: Checks if a dbxref string is already existing in the OBOterm object
593 Args : [arg1] A DBxref identifier (string).
594 Bio::Annotation::DBLink::display_text() is used for comparison
600 my ( $self, $value ) = @_;
601 return unless defined $value;
602 my $context = "_default";
603 $self->throw("'all' is a reserved word for context.") if $context eq 'all';
604 $context ||= '_default';
605 if ( ( $self->{_dblinks
}->{$context} ) &&
606 grep { $_->display_text eq $value }
607 @
{ $self->{_dblinks
}->{$context} } )
616 =head2 add_dblink_context
618 Title : add_dblink_context
619 Usage : $term->add_dblink_context($db, $context);
620 Function: add a dblink with its context
622 Args : [arg1] a Bio::Annotation::DBLink instance
623 [arg2] a string for context; if omitted, the
624 default/context-less one will be used.
625 Note : deprecated method due to past use of mixed data types; use
630 sub add_dblink_context
{
631 my ($self, $value, $context) = @_;
632 $self->deprecated("Use of simple strings and add_dblink_context() is deprecated; use\n
633 Bio::Annotation::DBLink instances and add_dbxref() instead");
634 return $self->add_dbxref([$value],$context);
637 =head2 remove_dblinks
639 Title : remove_dblinks()
640 Usage : $term->remove_dblinks();
641 Function: Deletes (and returns) the definition references of this GO term.
642 Returns : A list of definition references [array of [scalars]].
643 Args : Context. If omitted or equal to 'all', all dblinks
645 Note : deprecated method due to past use of mixed data types; use
646 remove_dblinks() instead, which handles both strings and
652 my ($self, $context) = @_;
653 $self->deprecated("use of remove_dblinks() is deprecated; use remove_dbxrefs() instead");
654 return $self->remove_dbxrefs(@_);
657 =head2 remove_dbxrefs
659 Title : remove_dbxrefs()
660 Usage : $term->remove_dbxrefs();
661 Function: Deletes (and returns) the definition references of this GO term.
662 Returns : A list of definition references [array of [scalars]].
663 Args : Context. If omitted or equal to 'all', all dblinks
669 my ($self, $context) = @_;
670 $context = undef if $context && ($context eq "all");
671 my @old = $self->get_dbxrefs($context);
672 if (defined($context)) {
673 $self->{_dblinks
}->{$context}=[];
675 $self->{_dblinks
} = {};
680 =head2 get_references
682 Title : get_references
683 Usage : @references = $self->get_references
684 Fuctnion: Returns a list of references
685 Return : A list of objects
692 return @
{$self->{_references
}} if exists $self->{_references
};
698 Title : add_reference
699 Usage : $self->add_reference($reference);
700 $self->add_reference($reference1, $reference2);
701 Fuctnion: Add one or more references
707 my ($self, @values) =@_;
708 return unless @values;
709 # avoid duplicates and undefs
710 foreach my $reference (@values){
711 $self->throw("Passed data not an Bio::Annotation::Reference") unless ref $reference &&
712 $reference->isa('Bio::AnnotationI');
713 next unless defined $reference;
714 next if grep{$_ eq $reference} @
{$self->{_references
}};
715 push @
{$self->{_references
}}, $reference;
719 =head2 remove_references
721 Title : remove_references
722 Usage : $self->remove_references;
723 Function: Deletes (and returns) all references
724 Returns : A list of references
729 sub remove_references
{
731 my @references=$self->get_references;
732 $self->{_references
}=[];
736 =head2 get_secondary_ids
738 Title : get_secondary_ids
739 Usage : @ids = $term->get_secondary_ids();
740 Function: Returns a list of secondary identifiers of this Term.
742 Secondary identifiers mostly originate from merging terms,
743 or possibly also from splitting terms.
745 Returns : A list of secondary identifiers [array of [scalar]]
750 sub get_secondary_ids
{
753 return @
{$self->{"_secondary_ids"}} if exists($self->{"_secondary_ids"});
755 } # get_secondary_ids
758 =head2 add_secondary_id
760 Title : add_secondary_id
761 Usage : $term->add_secondary_id( @ids );
763 $term->add_secondary_id( $id );
764 Function: Adds one or more secondary identifiers to this term.
766 Args : One or more secondary identifiers [scalars]
770 sub add_secondary_id
{
776 foreach my $id (@_) {
777 next if grep { !$_ or $_ eq $id; } @
{$self->{ "_secondary_ids" }};
778 push( @
{ $self->{ "_secondary_ids" } }, $id );
784 =head2 remove_secondary_ids
786 Title : remove_secondary_ids
787 Usage : $term->remove_secondary_ids();
788 Function: Deletes (and returns) the secondary identifiers of this Term.
789 Returns : The previous list of secondary identifiers [array of [scalars]]
794 sub remove_secondary_ids
{
797 my @a = $self->get_secondary_ids();
798 $self->{ "_secondary_ids" } = [];
801 } # remove_secondary_ids
804 # Title :_is_true_or_false
805 # Function: Checks whether the argument is TRUE or FALSE.
807 # Args : The value to be checked.
808 sub _is_true_or_false
{
809 my ( $self, $value ) = @_;
810 unless ( $value !~ /\D/ && ( $value == TRUE
|| $value == FALSE
) ) {
811 $self->throw( "Found [" . $value
812 . "] where " . TRUE
. " or " . FALSE
. " expected" );
814 } # _is_true_or_false
816 =head1 Methods implementing L<Bio::IdentifiableI> and L<Bio::DescribableI>
823 Usage : $string = $obj->object_id()
824 Function: a string which represents the stable primary identifier
825 in this namespace of this object.
827 This is a synonym for identifier().
834 return shift->identifier(@_);
840 Usage : $authority = $obj->authority()
841 Function: a string which represents the organisation which
842 granted the namespace, written as the DNS name for
843 organisation (eg, wormbase.org)
845 This forwards to ontology()->authority(). Note that you
846 cannot set the authority before having set the ontology or
847 the namespace (which will set the ontology).
850 Args : on set, the new value (a scalar)
856 my $ont = $self->ontology();
858 return $ont->authority(@_) if $ont;
859 $self->throw("cannot manipulate authority prior to ".
860 "setting the namespace or ontology") if @_;
868 Usage : $string = $obj->namespace()
869 Function: A string representing the name space this identifier
870 is valid in, often the database name or the name
871 describing the collection.
873 This forwards to ontology() (set mode) and
874 ontology()->name() (get mode). I.e., setting the namespace
875 will set the ontology to one matching that name in the
876 ontology store, or to one newly created.
879 Args : on set, the new value (a scalar)
886 $self->ontology(@_) if(@_);
887 my $ont = $self->ontology();
888 return defined($ont) ?
$ont->name() : undef;
894 Usage : $string = $obj->display_name()
895 Function: A string which is what should be displayed to the user.
897 The definition in Bio::DescribableI states that the
898 string should not contain spaces. As this is not very
899 sensible for ontology terms, we relax this here. The
900 implementation just forwards to name().
903 Args : on set, the new value (a scalar)
908 return shift->name(@_);
915 Usage : $string = $obj->description()
916 Function: A text string suitable for displaying to the user a
917 description. This string is likely to have spaces, but
918 should not have any newlines or formatting - just plain
921 This forwards to definition(). The caveat is that the text
922 will often be longer for ontology term definitions than the
923 255 characters stated in the definition in
927 Args : on set, the new value (a scalar)
932 return shift->definition(@_);
935 #################################################################
936 # aliases or forwards to maintain backward compatibility
937 #################################################################
939 =head1 Deprecated methods
941 Used for looking up the methods that supersedes them.
945 sub each_dblink
{shift->throw("use of each_dblink() is deprecated; use get_dbxrefs() instead")}
946 sub add_dblinks
{shift->throw("use of add_dblinks() is deprecated; use add_dbxref() instead")}
947 *each_synonym
= \
&get_synonyms
;
948 *add_synonyms
= \
&add_synonym
;