44
This is "dumb" interface for ontology terms providing basic methods
45
(it provides no functionality related to graphs). It implements the
46
L<Bio::Ontology::TermI> interface.
43
This is a simple implementation for ontology terms providing basic
44
methods (it provides no functionality related to graphs). It
45
implements the L<Bio::Ontology::TermI> interface.
48
47
This class also implements L<Bio::IdentifiableI> and
49
48
L<Bio::DescribableI>.
56
55
Bioperl modules. Send your comments and suggestions preferably to one
57
56
of the Bioperl mailing lists. Your participation is much appreciated.
59
bioperl-l@bioperl.org - General discussion
60
http://bio.perl.org/MailList.html - About the mailing lists
58
bioperl-l@bioperl.org - General discussion
59
http://bioperl.org/wiki/Mailing_lists - About the mailing lists
62
61
=head2 Reporting Bugs
64
63
Report bugs to the Bioperl bug tracking system to help us keep track
65
the bugs and their resolution. Bug reports can be submitted via email
64
the bugs and their resolution. Bug reports can be submitted via the web:
68
bioperl-bugs@bio.perl.org
69
http://bugzilla.bioperl.org/
66
http://bugzilla.open-bio.org/
93
90
# Let the code begin...
95
92
package Bio::Ontology::Term;
98
use Bio::Root::Object;
99
use Bio::Ontology::TermI;
100
94
use Bio::Ontology::Ontology;
101
95
use Bio::Ontology::OntologyStore;
102
use Bio::IdentifiableI;
103
use Bio::DescribableI;
105
97
use constant TRUE => 1;
106
98
use constant FALSE => 0;
108
@ISA = qw( Bio::Root::Root
100
use base qw(Bio::Root::Root Bio::Ontology::TermI Bio::IdentifiableI Bio::DescribableI);
119
Usage : $term = Bio::Ontology::Term->new(
107
Usage : $term = Bio::Ontology::Term->new(
120
108
-identifier => "16847",
121
109
-name => "1-aminocyclopropane-1-carboxylate synthase",
122
110
-definition => "Catalysis of ...",
128
116
-name => the name of this term [scalar]
129
117
-definition => the definition of this term [scalar]
130
118
-ontology => the ontology this term lives in
131
(a L<Bio::Ontology::OntologyI> object)
119
(a Bio::Ontology::OntologyI object)
132
120
-version => version information [scalar]
133
121
-is_obsolete => the obsoleteness of this term [0 or 1]
134
122
-comment => a comment [scalar]
135
-dblinks => L<Bio::Annotation::DBLink> objects
137
-references => L<Bio::Annotation::Reference> objects
123
-dblinks => Bio::Annotation::DBLink objects
125
-references => Bio::Annotation::Reference objects
128
See L<Bio::Ontology::OntologyI>, L<Bio::Annotation::Reference>,
129
L<Bio::Annotation::DBLink>.
144
135
my( $class,@args ) = @_;
146
137
my $self = $class->SUPER::new( @args );
151
# my ($self, @args) =@_;
152
138
my ( $identifier,
160
$dblinks, $references)
161
= $self->_rearrange( [ qw( IDENTIFIER
148
= $self->_rearrange( [ qw( IDENTIFIER
174
162
defined($identifier) && $self->identifier( $identifier );
175
163
defined($name) && $self->name( $name );
176
164
defined($definition) && $self->definition( $definition );
280
263
Function: Get the ontology this term is in.
282
265
Note that with the ontology in hand you can query for all
283
related terms etc. See L<Bio::Ontology::OntologyI>.
285
Returns : The ontology of this Term as a L<Bio::Ontology::OntologyI>
268
Returns : The ontology of this Term as a Bio::Ontology::OntologyI
286
269
implementing object.
287
Args : On set, the ontology of this Term as a L<Bio::Ontology::OntologyI>
270
Args : On set, the ontology of this Term as a Bio::Ontology::OntologyI
288
271
implementing object or a string representing its name.
273
See L<Bio::Ontology::OntologyI>.
299
$ont = Bio::Ontology::Ontology->new(-name => $ont) if ! ref($ont);
300
if(! $ont->isa("Bio::Ontology::OntologyI")) {
301
$self->throw(ref($ont)." does not implement ".
302
"Bio::Ontology::OntologyI. Bummer.");
305
return $self->{"_ontology"} = $ont;
284
$ont = Bio::Ontology::Ontology->new(-name => $ont) if ! ref($ont);
285
if(! $ont->isa("Bio::Ontology::OntologyI")) {
286
$self->throw(ref($ont)." does not implement ".
287
"Bio::Ontology::OntologyI. Bummer.");
290
return $self->{"_ontology"} = $ont;
307
292
return $self->{"_ontology"};
412
394
# avoid duplicates
413
395
foreach my $syn (@values) {
414
next if grep { $_ eq $syn; } @{$self->{ "_synonyms" }};
415
push( @{ $self->{ "_synonyms" } }, $syn );
396
next if grep { $_ eq $syn; } @{$self->{ "_synonyms" }};
397
push( @{ $self->{ "_synonyms" } }, $syn );
443
425
Usage : @ds = $term->get_dblinks();
444
426
Function: Returns a list of each dblinks of this GO term.
445
427
Returns : A list of dblinks [array of [scalars]].
428
Args : A scalar indicating the context (optional).
429
If omitted, all dblinks will be returned.
450
433
sub get_dblinks {
451
434
my $self = shift;
453
return @{$self->{ "_dblinks" }} if exists($self->{ "_dblinks" });
437
if (defined($context)) {
438
return @{$self->{_dblinks}->{$context}}
439
if exists($self->{_dblinks}->{$context});
441
return map { @$_ } values %{$self->{_dblinks}};
447
=head2 get_dblink_context
449
Title : get_dblink_context
450
Usage : @context = $term->get_dblink_context;
451
Function: Return all context existing in Term
452
Returns : a list of scalar
457
sub get_dblink_context {
459
return keys %{$self->{_dblinks}};
458
462
=head2 add_dblink
460
464
Title : add_dblink
472
my ( $self, @values ) = @_;
474
return unless( @values );
477
foreach my $dbl (@values) {
478
next if grep { $_ eq $dbl; } @{$self->{ "_dblinks" }};
479
push( @{ $self->{ "_dblinks" } }, $dbl );
477
$self->add_dblink_context($_,'_default') foreach @_;
484
Usage : $term->has_dblink($dblink);
485
Function: Checks if a DBXref is already existing in the OBOterm object
487
Args : [arg1] A DBxref identifier
492
my ( $self, $value ) = @_;
493
return unless defined $value;
494
my $context = "_default";
495
$self->throw("'all' is a reserved word for context.") if $context eq 'all';
496
$context ||= '_default';
497
if ( ( $self->{_dblinks}->{$context} ) && grep { $_ eq $value }
498
@{ $self->{_dblinks}->{$context} } )
508
=head2 add_dblink_context
510
Title : add_dblink_context
511
Usage : $term->add_dblink_context($db, $context);
512
Function: add a dblink with its context
514
Args : [arg1] an object of Bio::Annotation::DBLink
515
[arg2] a string for context; if omitted, the
516
default/context-less one will be used.
520
sub add_dblink_context {
521
my ($self, $value, $context)=@_;
522
return unless defined $value;
523
$self->throw("'all' is a reserved word for context.") if $context eq 'all';
524
$context ||= '_default';
525
if (! exists($self->{_dblinks}->{$context})) {
526
$self->{_dblinks}->{$context} = [];
528
if (grep {$_ eq $value} @{$self->{_dblinks}->{$context}}) {
529
$self->warn("$value exists in the dblink of $context");
531
push @{$self->{_dblinks}->{$context}}, $value;
485
534
=head2 remove_dblinks
487
536
Title : remove_dblinks()
488
537
Usage : $term->remove_dblinks();
489
538
Function: Deletes (and returns) the definition references of this GO term.
490
539
Returns : A list of definition references [array of [scalars]].
540
Args : Context. If omitted or equal to 'all', all dblinks
495
545
sub remove_dblinks {
498
my @a = $self->get_dblinks();
499
$self->{ "_dblinks" } = [];
546
my ($self, $context) = @_;
547
$context = undef if $context && ($context eq "all");
548
my @old = $self->get_dblinks($context);
549
if (defined($context)) {
550
$self->{_dblinks}->{$context}=[];
552
$self->{_dblinks} = {};
502
555
} # remove_dblinks
716
770
Usage : $string = $obj->display_name()
717
771
Function: A string which is what should be displayed to the user.
719
The definition in L<Bio::DescribableI> states that the
720
string should not contain spaces. As this isn't very
773
The definition in Bio::DescribableI states that the
774
string should not contain spaces. As this is not very
721
775
sensible for ontology terms, we relax this here. The
722
776
implementation just forwards to name().
771
Function: This method is deprecated. Use ontology() instead.
782
$self->warn("TermI::category is deprecated and being phased out. ".
783
"Use TermI::ontology instead.");
785
# called in set mode?
787
# yes; what is incompatible with ontology() is if we were given
790
$arg = $arg->name() if ref($arg) && $arg->isa("Bio::Ontology::TermI");
791
return $self->ontology($arg,@_);
793
# No, called in get mode. This is always incompatible with ontology()
794
# since category is supposed to return a TermI.
795
my $ont = $self->ontology();
798
$term = Bio::Ontology::Term->new(-name => $ont->name(),
799
-identifier =>$ont->identifier());
805
821
*each_synonym = \&get_synonyms;
806
822
*add_synonyms = \&add_synonym;
807
823
*each_dblink = \&get_dblinks;