Bio/Ontology/Term.pm

filter: Statementstmt 72.3% 162 / 224 Branchbran 67.6% 69 / 102 Conditioncond 20.0% 5 / 25 MC/DCmcdc 6.6% 1 / 15 Subroutinesub 67.3% 31 / 46 Podpod 91.6% 33 / 36 totaltotal 67.1% 301 / 448 CC 66 SCAR 23.1
CC
66
Cov
67%
has_dbxref
42.0
add_reference
37.9
_is_true_or_false
20.0
CRAP 10.0
« Bio/SeqIO/asciitree.pm ↑ Summary Bio/Annotation/Collection.pm »
1 #
2 # BioPerl module for Bio::Ontology::Term
3 #
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
5 #
6 # Cared for by Christian M. Zmasek <czmasek-at-burnham.org> or <cmzmasek@yahoo.com>
7 #
8 # (c) Christian M. Zmasek, czmasek-at-burnham.org, 2002.
9 # (c) GNF, Genomics Institute of the Novartis Research Foundation, 2002.
10 #
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.
15 #
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.
19 #
20 # You may distribute this module under the same terms as perl itself
21  
22 # POD documentation - main docs before the code
23  
24 =head1 NAME
25  
26 Bio::Ontology::Term - implementation of the interface for ontology terms
27  
28 =head1 SYNOPSIS
29  
30 #get Bio::Ontology::TermI somehow.
31  
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";
37  
38 foreach my $synonym ( $term->each_synonym() ) {
39 print $synonym, "\n";
40 }
41  
42 =head1 DESCRIPTION
43  
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.
47  
48 This class also implements L<Bio::IdentifiableI> and
49 L<Bio::DescribableI>.
50  
51 =head1 FEEDBACK
52  
53 =head2 Mailing Lists
54  
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.
58  
59 bioperl-l@bioperl.org - General discussion
60 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
61  
62 =head2 Support
63  
64 Please direct usage questions or support issues to the mailing list:
65  
66 I<bioperl-l@bioperl.org>
67  
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.
72  
73 =head2 Reporting Bugs
74  
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:
77  
78 https://github.com/bioperl/bioperl-live/issues
79  
80 =head1 AUTHOR
81  
82 Christian M. Zmasek
83  
84 Email: czmasek-at-burnham.org or cmzmasek@yahoo.com
85  
86 WWW: http://monochrome-effect.net/
87  
88 Address:
89  
90 Genomics Institute of the Novartis Research Foundation
91 10675 John Jay Hopkins Drive
92 San Diego, CA 92121
93  
94 =head1 APPENDIX
95  
96 The rest of the documentation details each of the object
97 methods.
98  
99 =cut
100  
101  
102 # Let the code begin...
103  
104 package Bio::Ontology::Term;
105 26 $Bio::Ontology::Term::VERSION = '1.7.8';
106 26 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
107  
108 26 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
109  
110 26 ▶use Bio::Ontology::Ontology;
Subroutine BEGIN: called CC=1 SCAR=0.0
111 26 ▶use Bio::Ontology::OntologyStore;
Subroutine BEGIN: called CC=1 SCAR=0.0
112 26 ▶use Bio::Annotation::DBLink;
Subroutine BEGIN: called CC=1 SCAR=0.0
113 26 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
114  
115 26 ▶use constant TRUE => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
116 26 ▶use constant FALSE => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
117  
118 26 ▶use base qw(Bio::Root::Root Bio::Ontology::TermI Bio::IdentifiableI Bio::DescribableI);
Subroutine BEGIN: called CC=1 SCAR=0.0
119  
120 =head2 new
121  
122 Title : new
123 Usage : $term = Bio::Ontology::Term->new(
124 -identifier => "16847",
125 -name => "1-aminocyclopropane-1-carboxylate synthase",
126 -definition => "Catalysis of ...",
127 -is_obsolete => 0,
128 -comment => "" );
129 Function: Creates a new Bio::Ontology::Term.
130 Returns : A new Bio::Ontology::Term object.
131 Args : -identifier => the identifier of this term [scalar]
132 -name => the name of this term [scalar]
133 -definition => the definition of this term [scalar]
134 -ontology => the ontology this term lives in
135 (a Bio::Ontology::OntologyI object)
136 -version => version information [scalar]
137 -is_obsolete => the obsoleteness of this term [0 or 1]
138 -comment => a comment [scalar]
139 -dblinks => Bio::Annotation::DBLink objects
140 [reference to array]
141 -references => Bio::Annotation::Reference objects
142 [reference to array]
143  
144 See L<Bio::Ontology::OntologyI>, L<Bio::Annotation::Reference>,
145 L<Bio::Annotation::DBLink>.
146  
147 =cut
148  
149 2561 ▶sub new {
Subroutine new: called CC=12 SCAR=24.9
Pod documented
150  
151 2561 my( $class,@args ) = @_;
152  
153 2561 my $self = $class->SUPER::new( @args );
154 2561 my ( $identifier, $name, $definition, $category, $ont, $version,
155 $is_obsolete, $comment, $dblinks, $dbxrefs, $references)
156 = $self->_rearrange( [
157 qw(IDENTIFIER NAME DEFINITION CATEGORY ONTOLOGY VERSION IS_OBSOLETE
158 COMMENT DBLINKS DBXREFS REFERENCES) ], @args );
159  
160 2561 $self->init();
161  
162 2561 ▶ defined($identifier) && $self->identifier( $identifier );
Branch: 1 branch
BranchTrueFalseTotal
defined $identifier and $self->identifier($identifier) 234 2327 2561
163 2561 ▶ defined($name) && $self->name( $name );
Branch: 1 branch
BranchTrueFalseTotal
defined $name and $self->name($name) 292 2269 2561
164 2561 ▶ defined($definition) && $self->definition( $definition );
Branch: 1 branch
BranchTrueFalseTotal
defined $definition and $self->definition($definition) 15 2546 2561
165 2561 ▶ defined($category) && $self->category( $category );
Branch: 1 branch
BranchTrueFalseTotal
defined $category and $self->category($category) 0 2561 2561
166 2561 ▶ defined($ont) && $self->ontology( $ont );
Branch: 1 branch
BranchTrueFalseTotal
defined $ont and $self->ontology($ont) 20 2541 2561
167 2561 ▶ defined($version) && $self->version( $version );
Branch: 1 branch
BranchTrueFalseTotal
defined $version and $self->version($version) 2 2559 2561
168 2561 ▶ defined($is_obsolete) && $self->is_obsolete( $is_obsolete );
Branch: 1 branch
BranchTrueFalseTotal
defined $is_obsolete and $self->is_obsolete($is_obsolete) 2 2559 2561
169 2561 ▶ defined($comment) && $self->comment( $comment );
Branch: 1 branch
BranchTrueFalseTotal
defined $comment and $self->comment($comment) 11 2550 2561
170 2561 ▶ defined($dbxrefs) && $self->add_dbxref(-dbxrefs => $dbxrefs);
Branch: 1 branch
BranchTrueFalseTotal
defined $dbxrefs and $self->add_dbxref("-dbxrefs", $dbxrefs) 10 2551 2561
171 # deprecated methods, allow one to pass on to get the dep. notification
172 2561 ▶ ref($dblinks) && $self->add_dblink(@$dblinks);
Branch: 1 branch
BranchTrueFalseTotal
ref $dblinks and $self->add_dblink(@$dblinks) 0 2561 2561
173 2561 ▶ ref($references) && $self->add_reference(@$references);
Branch: 1 branch
BranchTrueFalseTotal
ref $references and $self->add_reference(@$references) 1 2560 2561
174  
175 2561 return $self;
176 } # new
177  
178  
179  
180 2563 ▶sub init {
Subroutine init: called CC=1 SCAR=0.0
Pod undocumented
181  
182 2563 my $self = shift;
183  
184 2563 $self->identifier(undef);
185 2563 $self->name(undef);
186 2563 $self->comment(undef);
187 2563 $self->definition(undef);
188 2563 $self->ontology(undef);
189 2563 $self->is_obsolete(0);
190 2563 $self->remove_synonyms();
191 2563 $self->remove_dbxrefs();
192 2563 $self->remove_references;
193 2563 $self->remove_secondary_ids();
194  
195 } # init
196  
197  
198  
199 =head2 identifier
200  
201 Title : identifier
202 Usage : $term->identifier( "GO:0003947" );
203 or
204 print $term->identifier();
205 Function: Set/get for the identifier of this Term.
206 Returns : The identifier [scalar].
207 Args : The identifier [scalar] (optional).
208  
209 =cut
210  
211 14958 ▶sub identifier {
Subroutine identifier: called CC=2 SCAR=6.9
Pod documented
212 14958 my $self = shift;
213  
214 14958 ▶ return $self->{'identifier'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 5065 9893 14958
215 9893 return $self->{'identifier'};
216 } # identifier
217  
218  
219 =head2 name
220  
221 Title : name
222 Usage : $term->name( "N-acetylgalactosaminyltransferase" );
223 or
224 print $term->name();
225 Function: Set/get for the name of this Term.
226 Returns : The name [scalar].
227 Args : The name [scalar] (optional).
228  
229 =cut
230  
231 15740 ▶sub name {
Subroutine name: called CC=2 SCAR=6.9
Pod documented
232 15740 my $self = shift;
233  
234 15740 ▶ return $self->{'name'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 3893 11847 15740
235 11847 return $self->{'name'};
236 } # name
237  
238  
239 =head2 definition
240  
241 Title : definition
242 Usage : $term->definition( "Catalysis of ..." );
243 or
244 print $term->definition();
245 Function: Set/get for the definition of this Term.
246 Returns : The definition [scalar].
247 Args : The definition [scalar] (optional).
248  
249 =cut
250  
251 3224 ▶sub definition {
Subroutine definition: called CC=2 SCAR=6.9
Pod documented
252 3224 my $self = shift;
253  
254 3224 ▶ return $self->{'definition'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 3156 68 3224
255 68 return $self->{'definition'};
256 } # definition
257  
258  
259 =head2 ontology
260  
261 Title : ontology
262 Usage : $ont = $term->ontology();
263 or
264 $term->ontology( $ont );
265 Function: Get the ontology this term is in.
266  
267 Note that with the ontology in hand you can query for all
268 related terms etc.
269  
270 Returns : The ontology of this Term as a Bio::Ontology::OntologyI
271 implementing object.
272 Args : On set, the ontology of this Term as a Bio::Ontology::OntologyI
273 implementing object or a string representing its name.
274  
275 See L<Bio::Ontology::OntologyI>.
276  
277 =cut
278  
279 7930 ▶sub ontology {
Subroutine ontology: called CC=5 SCAR=16.2
Pod documented
280 7930 my $self = shift;
281 7930 my $ont;
282  
283 7930 ▶ if(@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 4276 3654 7930
284 4276 $ont = shift;
285 4276 ▶ if($ont) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ont) 1713 2563 4276
286 1713 ▶ $ont = Bio::Ontology::Ontology->new(-name => $ont) if ! ref($ont);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $ont 26 1687 1713
287 1713 ▶ if(! $ont->isa("Bio::Ontology::OntologyI")) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ont->isa("Bio::Ontology::OntologyI")) 0 1713 1713
288 0 $self->throw(ref($ont)." does not implement ".
289 "Bio::Ontology::OntologyI. Bummer.");
290 }
291 }
292 4276 return $self->{"_ontology"} = $ont;
293 }
294 3654 return $self->{"_ontology"};
295 } # ontology
296  
297 =head2 version
298  
299 Title : version
300 Usage : $term->version( "1.00" );
301 or
302 print $term->version();
303 Function: Set/get for version information.
304 Returns : The version [scalar].
305 Args : The version [scalar] (optional).
306  
307 =cut
308  
309 9 ▶sub version {
Subroutine version: called CC=2 SCAR=6.9
Pod documented
310 9 my $self = shift;
311  
312 9 ▶ return $self->{'version'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 4 5 9
313 5 return $self->{'version'};
314 } # version
315  
316 =head2 is_obsolete
317  
318 Title : is_obsolete
319 Usage : $term->is_obsolete( 1 );
320 or
321 if ( $term->is_obsolete() )
322 Function: Set/get for the obsoleteness of this Term.
323 Returns : the obsoleteness [0 or 1].
324 Args : the obsoleteness [0 or 1] (optional).
325  
326 =cut
327  
328 2660 ▶sub is_obsolete{
Subroutine is_obsolete: called CC=2 SCAR=6.9
Pod documented
329 2660 my $self = shift;
330  
331 2660 ▶ return $self->{'is_obsolete'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 2587 73 2660
332 73 return $self->{'is_obsolete'};
333 } # is_obsolete
334  
335  
336 =head2 comment
337  
338 Title : comment
339 Usage : $term->comment( "Consider the term ..." );
340 or
341 print $term->comment();
342 Function: Set/get for an arbitrary comment about this Term.
343 Returns : A comment.
344 Args : A comment (optional).
345  
346 =cut
347  
348 2684 ▶sub comment{
Subroutine comment: called CC=2 SCAR=6.9
Pod documented
349 2684 my $self = shift;
350  
351 2684 ▶ return $self->{'comment'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 2621 63 2684
352 63 return $self->{'comment'};
353 } # comment
354  
355 =head2 get_synonyms
356  
357 Title : get_synonyms
358 Usage : @aliases = $term->get_synonyms;
359 Function: Returns a list of aliases of this Term.
360 Returns : A list of aliases [array of [scalar]].
361 Args :
362  
363 =cut
364  
365 4595 ▶sub get_synonyms {
Subroutine get_synonyms: called CC=2 SCAR=6.9
Pod documented
366 4595 my $self = shift;
367  
368 4595 ▶ return @{ $self->{ "_synonyms" } } if exists($self->{ "_synonyms" });
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"_synonyms"} 2034 2561 4595
369 2561 return ();
370 } # get_synonyms
371  
372  
373 =head2 add_synonym
374  
375 Title : add_synonym
376 Usage : $term->add_synonym( @asynonyms );
377 or
378 $term->add_synonym( $synonym );
379 Function: Pushes one or more synonyms into the list of synonyms.
380 Returns :
381 Args : One synonym [scalar] or a list of synonyms [array of [scalar]].
382  
383 =cut
384  
385 519 ▶sub add_synonym {
Subroutine add_synonym: called CC=4 SCAR=13.9
Pod documented
386 519 my ( $self, @values ) = @_;
387  
388 519 ▶ return unless( @values );
Branch: 1 branch
BranchTrueFalseTotal
unless @values 193 326 519
389  
390 # avoid duplicates
391 326 foreach my $syn (@values) {
392 339 ▶ next if grep { $_ eq $syn; } @{$self->{ "_synonyms" }};
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ eq $syn;} @{$$self{"_synonyms"};} 2 337 339
393 337 push( @{ $self->{ "_synonyms" } }, $syn );
394 }
395  
396 } # add_synonym
397  
398  
399 =head2 remove_synonyms
400  
401 Title : remove_synonyms()
402 Usage : $term->remove_synonyms();
403 Function: Deletes (and returns) the synonyms of this Term.
404 Returns : A list of synonyms [array of [scalar]].
405 Args :
406  
407 =cut
408  
409 2567 ▶sub remove_synonyms {
Subroutine remove_synonyms: called CC=1 SCAR=0.0
Pod documented
410 2567 my ( $self ) = @_;
411  
412 2567 my @a = $self->get_synonyms();
413 2567 $self->{ "_synonyms" } = [];
414 2567 return @a;
415  
416 } # remove_synonyms
417  
418 =head2 get_dblinks
419  
420 Title : get_dblinks()
421 Usage : @ds = $term->get_dblinks();
422 Function: Returns a list of each dblinks of this GO term.
423 Returns : A list of dblinks [array of [scalars]].
424 Args : A scalar indicating the context (optional).
425 If omitted, all dblinks will be returned.
426 Note : deprecated method due to past use of mixed data types; use
427 get_dbxrefs() instead, which handles both strings and DBLink
428 instances
429  
430 =cut
431  
432 0 ▶sub get_dblinks {
Subroutine get_dblinks: not called CC=1 SCAR=6.9
Pod documented
433 0 my ($self, $context) = @_;
434 0 Carp::carp("Use of get_dblinks is deprecated. Note that prior use\n".
435 "of this method could return either simple scalar values\n".
436 "or Bio::Annotation::DBLink instances; only \n".
437 "Bio::Annotation::DBLink is now supported.\n ".
438 "Use get_dbxrefs() instead");
439 0 $self->get_dbxrefs($context);
440 } # get_dblinks
441  
442 =head2 get_dbxrefs
443  
444 Title : get_dbxrefs()
445 Usage : @ds = $term->get_dbxrefs();
446 Function: Returns a list of each link for this term.
447  
448 If an implementor of this interface permits modification of
449 this array property, the class should define at least
450 methods add_dbxref() and remove_dbxrefs(), with obvious
451 functionality.
452  
453 Returns : A list of L<Bio::Annotation::DBLink> instances
454 Args : [optional] string which specifies context (default : returns all dbxrefs)
455  
456 =cut
457  
458 2574 ▶sub get_dbxrefs {
Subroutine get_dbxrefs: called CC=3 SCAR=13.1
Pod documented
459 2574 my ($self, $context) = shift;
460 2574 my @dbxrefs;
461 2574 ▶ if (defined($context)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $context) { } 0 2574 2574
462 0 ▶ if (exists($self->{_dblinks}->{$context})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"_dblinks"}{$context}) 0 0 0
463 0 @dbxrefs = @{$self->{_dblinks}->{$context}};
464 }
465 } else {
466 2574 @dbxrefs = map { @$_ } values %{$self->{_dblinks}} ;
467 }
468 2574 return @dbxrefs;
469 } # get_dbxrefs
470  
471 =head2 get_dblink_context
472  
473 Title : get_dblink_context
474 Usage : @context = $term->get_dblink_context;
475 Function: Return all context existing in Term
476 Returns : a list of scalar
477 Args : [none]
478 Note : deprecated method due to past use of mixed data types; use
479 get_dbxref_context() instead
480  
481 =cut
482  
483 0 ▶sub get_dblink_context {
Subroutine get_dblink_context: not called CC=1 SCAR=6.9
Pod documented
484 0 my $self=shift;
485 0 Carp::carp("Use of get_dblink_context() is deprecated; use get_dbxref_context() instead");
486 0 return $self->get_dbxref_context(@_);
487 }
488  
489 =head2 get_dbxref_context
490  
491 Title : get_dbxref_context
492 Usage : @context = $term->get_dbxref_context;
493 Function: Return all context strings existing in Term
494 Returns : a list of scalars
495 Args : [none]
496  
497 =cut
498  
499 0 ▶sub get_dbxref_context {
Subroutine get_dbxref_context: not called CC=1 SCAR=6.9
Pod documented
500 0 my $self=shift;
501 0 return keys %{$self->{_dblinks}};
502 }
503  
504 =head2 add_dblink
505  
506 Title : add_dblink
507 Usage : $term->add_dblink( @dbls );
508 or
509 $term->add_dblink( $dbl );
510 Function: Pushes one or more dblinks onto the list of dblinks.
511 Returns :
512 Args : One or more L<Bio::Annotation::DBLink> instances
513 Note : deprecated method due to past use of mixed data types; use
514 add_dbxref() instead, which handles both strings and
515 DBLink instances
516  
517 =cut
518  
519 0 ▶sub add_dblink {
Subroutine add_dblink: not called CC=2 SCAR=17.9
Pod documented
520 0 my $self = shift;
521 0 Carp::carp("Use of simple strings and add_dblink() is deprecated; use\n".
522 "Bio::Annotation::DBLink instances and add_dbxref() instead");
523 # here we're assuming the data is in a simple DB:ID format
524 0 my @dbxrefs;
525 0 for my $string (@_) {
526 0 my ($db, $id) = split(':',$string);
527 0 push @dbxrefs, Bio::Annotation::DBLink->new(-database => $db, -primary_id => $id);
528 }
529 0 return $self->add_dbxref(-dbxrefs => \@dbxrefs, -context => '_default');
530 } # add_dblink
531  
532 =head2 add_dbxref
533  
534 Title : add_dbxref
535 Usage : $term->add_dbxref( @dbls );
536 or
537 $term->add_dbxref( $dbl );
538 Function: Pushes one or more dblinks onto the list of dblinks.
539 Returns :
540 Args : -dbxrefs : array ref of Bio::Annotation::DBLink instances
541 -context : string designating the context for the DBLink
542 (default : '_default' - contextless)
543  
544 =cut
545  
546 809 ▶sub add_dbxref {
Subroutine add_dbxref: called CC=11 SCAR=25.9
Pod documented
547 809 my $self = shift;
548 809 my ($links, $context) = $self->_rearrange([qw(DBXREFS CONTEXT)],@_);
549 809 ▶ return unless defined $links;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $links 0 809 809
550 809 ▶ $context ||= '_default';
Condition50%1/2
$context ||= "_default"
l!l
0809
MC/DC0%0/1
$context ||= "_default"
$context
Truth table50%1/2
A
A= $context
Aresult
11
00
551 809 ▶ $self->throw("DBLinks must be passed as an array reference") if ref $links ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $links ne "ARRAY" 0 809 809
552 809 foreach my $dbxref (@{$links}) {
553 503 ▶ $self->throw("$dbxref is not a DBLink") unless ref $dbxref &&
Branch: 1 branch
BranchTrueFalseTotal
unless ref $dbxref and $dbxref->isa("Bio::Annotation::DBLink") 0 503 503
Condition33%1/3
ref $dbxref and $dbxref->isa("Bio::Annotation::DBLink")
!ll&&!rl&&r
00503
MC/DC0%0/2
ref $dbxref and $dbxref->isa("Bio::Annotation::DBLink")
ref $dbxref $dbxref->isa("Bio::Annotation::DBLink")
Truth table33%1/3
A and B
A= ref $dbxrefB= $dbxref->isa("Bio::Annotation::DBLink")
ABresult
0X0
100
111
554 $dbxref->isa('Bio::Annotation::DBLink');
555 503 ▶ $self->throw("'all' is a reserved word for context.") if $context eq 'all';
Branch: 1 branch
BranchTrueFalseTotal
if $context eq "all" 0 503 503
556 503 ▶ if (! exists($self->{_dblinks}->{$context})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"_dblinks"}{$context}) 494 9 503
557 494 $self->{_dblinks}->{$context} = [];
558 }
559 503 ▶ my $linktext = ref $dbxref ? $dbxref->display_text : $dbxref;
Branch: 1 branch
BranchTrueFalseTotal
ref $dbxref ? : 503 0 503
560 503 ▶ if (grep {$_->display_text eq $linktext}
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_->display_text eq $linktext;} @{$$self{"_dblinks"}{$context};}) 0 503 503
561 503 @{$self->{_dblinks}->{$context}})
562 {
563 0 $self->warn("DBLink exists in the dblink of $context");
564 }
565 503 push @{$self->{_dblinks}->{$context}}, $dbxref;
566 }
567 } # add_dbxref
568  
569 # alias, for consistency
570 26 *add_dbxrefs = \&add_dbxref;
571  
572 =head2 has_dblink
573  
574 Title : has_dblink
575 Usage : $term->has_dblink($dblink);
576 Function: Checks if a DBXref is already existing in the OBOterm object
577 Return : TRUE/FALSE
578 Args : [arg1] A DBxref identifier
579 Note : deprecated method due to past use of mixed data types; use
580 has_dbxref() instead, which handles both strings and
581 DBLink instances
582  
583 =cut
584  
585 0 ▶sub has_dblink {
Subroutine has_dblink: not called CC=1 SCAR=6.9
Pod documented
586 0 my ( $self, $value ) = @_;
587 0 Carp::carp("use of has_dblink() is deprecated; use has_dbxref() instead");
588 0 return $self->has_dbxref($value);
589 }
590  
591 =head2 has_dbxref
592  
593 Title : has_dbxref
594 Usage : $term->has_dbxref($dbxref);
595 Function: Checks if a dbxref string is already existing in the OBOterm object
596 Return : TRUE/FALSE
597 Args : [arg1] A DBxref identifier (string).
598 Bio::Annotation::DBLink::display_text() is used for comparison
599 against the string.
600  
601 =cut
602  
603 0 ▶sub has_dbxref {
Subroutine has_dbxref: not called CC=6 SCAR=37.4
Pod documented
604 0 my ( $self, $value ) = @_;
605 0 ▶ return unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 0 0
606 0 my $context = "_default";
607 0 ▶ $self->throw("'all' is a reserved word for context.") if $context eq 'all';
Branch: 1 branch
BranchTrueFalseTotal
if $context eq "all" 0 0 0
608 0 ▶ $context ||= '_default';
Condition0%0/2
$context ||= "_default"
l!l
00
MC/DC0%0/1
$context ||= "_default"
$context
Truth table0%0/2
A
A= $context
Aresult
11
00
609 0 ▶ if ( ( $self->{_dblinks}->{$context} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'_dblinks'}{$context} and grep {$_->display_text eq $value;} @{$$self{'_dblinks'}{$context};}) { } 0 0 0
Condition0%0/3
$self->{"_dblinks"}{$context} and grep {$_->display_text eq $value;} @{$$self{"_dblinks"}{$context};}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"_dblinks"}{$context} and grep {$_->display_text eq $value;} @{$$self{"_dblinks"}{$context};}
$self->{"_dblinks"}{$context} grep {$_->display_text eq $value;} @{$$self{"_dblinks"}{$context};}
Truth table0%0/3
A and B
A= $self->{"_dblinks"}{$context}B= grep {$_->display_text eq $value;} @{$$self{"_dblinks"}{$context};}
ABresult
0X0
100
111
610 0 grep { $_->display_text eq $value }
611 0 @{ $self->{_dblinks}->{$context} } )
612 {
613 0 return TRUE;
614 }
615 else {
616 0 return FALSE;
617 }
618 }
619  
620 =head2 add_dblink_context
621  
622 Title : add_dblink_context
623 Usage : $term->add_dblink_context($db, $context);
624 Function: add a dblink with its context
625 Return : [none]
626 Args : [arg1] a Bio::Annotation::DBLink instance
627 [arg2] a string for context; if omitted, the
628 default/context-less one will be used.
629 Note : deprecated method due to past use of mixed data types; use
630 add_dbxref() instead
631  
632 =cut
633  
634 0 ▶sub add_dblink_context {
Subroutine add_dblink_context: not called CC=1 SCAR=6.9
Pod documented
635 0 my ($self, $value, $context) = @_;
636 0 Carp::carp("Use of simple strings and add_dblink_context() is deprecated; use\n
637 Bio::Annotation::DBLink instances and add_dbxref() instead");
638 0 return $self->add_dbxref([$value],$context);
639 }
640  
641 =head2 remove_dblinks
642  
643 Title : remove_dblinks()
644 Usage : $term->remove_dblinks();
645 Function: Deletes (and returns) the definition references of this GO term.
646 Returns : A list of definition references [array of [scalars]].
647 Args : Context. If omitted or equal to 'all', all dblinks
648 will be removed.
649 Note : deprecated method due to past use of mixed data types; use
650 remove_dblinks() instead, which handles both strings and
651 DBLink instances
652  
653 =cut
654  
655 0 ▶sub remove_dblinks {
Subroutine remove_dblinks: not called CC=1 SCAR=6.9
Pod documented
656 0 my ($self, $context) = @_;
657 0 Carp::carp("use of remove_dblinks() is deprecated; use remove_dbxrefs() instead");
658 0 return $self->remove_dbxrefs(@_);
659 } # remove_dblinks
660  
661 =head2 remove_dbxrefs
662  
663 Title : remove_dbxrefs()
664 Usage : $term->remove_dbxrefs();
665 Function: Deletes (and returns) the definition references of this GO term.
666 Returns : A list of definition references [array of [scalars]].
667 Args : Context. If omitted or equal to 'all', all dblinks
668 will be removed.
669  
670 =cut
671  
672 2565 ▶sub remove_dbxrefs {
Subroutine remove_dbxrefs: called CC=4 SCAR=15.5
Pod documented
673 2565 my ($self, $context) = @_;
674 2565 ▶ $context = undef if $context && ($context eq "all");
Branch: 1 branch
BranchTrueFalseTotal
if $context and $context eq "all" 0 2565 2565
Condition33%1/3
$context and $context eq "all"
!ll&&!rl&&r
256500
MC/DC0%0/2
$context and $context eq "all"
$context $context eq "all"
Truth table33%1/3
A and B
A= $contextB= $context eq "all"
ABresult
0X0
100
111
675 2565 my @old = $self->get_dbxrefs($context);
676 2565 ▶ if (defined($context)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $context) { } 0 2565 2565
677 0 $self->{_dblinks}->{$context}=[];
678 } else {
679 2565 $self->{_dblinks} = {};
680 }
681 2565 return @old;
682 } # remove_dbxrefs
683  
684 =head2 get_references
685  
686 Title : get_references
687 Usage : @references = $self->get_references
688 Fuctnion: Returns a list of references
689 Return : A list of objects
690 Args : [none]
691  
692 =cut
693  
694 2564 ▶sub get_references {
Subroutine get_references: called CC=2 SCAR=6.9
Pod documented
695 2564 my $self=shift;
696 2564 ▶ return @{$self->{_references}} if exists $self->{_references};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"_references"} 3 2561 2564
697 2561 return ();
698 }
699  
700 =head2 add_reference
701  
702 Title : add_reference
703 Usage : $self->add_reference($reference);
704 $self->add_reference($reference1, $reference2);
705 Fuctnion: Add one or more references
706 Returns : [none]
707  
708 =cut
709  
710 1 ▶sub add_reference {
Subroutine add_reference: called CC=7 SCAR=36.3
Pod documented
711 1 my ($self, @values) =@_;
712 1 ▶ return unless @values;
Branch: 1 branch
BranchTrueFalseTotal
unless @values 1 0 1
713 # avoid duplicates and undefs
714 0 foreach my $reference (@values){
715 0 ▶ $self->throw("Passed data not an Bio::Annotation::Reference") unless ref $reference &&
Branch: 1 branch
BranchTrueFalseTotal
unless ref $reference and $reference->isa("Bio::AnnotationI") 0 0 0
Condition0%0/3
ref $reference and $reference->isa("Bio::AnnotationI")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $reference and $reference->isa("Bio::AnnotationI")
ref $reference $reference->isa("Bio::AnnotationI")
Truth table0%0/3
A and B
A= ref $referenceB= $reference->isa("Bio::AnnotationI")
ABresult
0X0
100
111
716 $reference->isa('Bio::AnnotationI');
717 0 ▶ next unless defined $reference;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $reference 0 0 0
718 0 ▶ next if grep{$_ eq $reference} @{$self->{_references}};
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ eq $reference;} @{$$self{"_references"};} 0 0 0
719 0 push @{$self->{_references}}, $reference;
720 }
721 }
722  
723 =head2 remove_references
724  
725 Title : remove_references
726 Usage : $self->remove_references;
727 Function: Deletes (and returns) all references
728 Returns : A list of references
729 Args : [none]
730  
731 =cut
732  
733 2563 ▶sub remove_references {
Subroutine remove_references: called CC=1 SCAR=0.0
Pod documented
734 2563 my $self=shift;
735 2563 my @references=$self->get_references;
736 2563 $self->{_references}=[];
737 2563 return @references;
738 }
739  
740 =head2 get_secondary_ids
741  
742 Title : get_secondary_ids
743 Usage : @ids = $term->get_secondary_ids();
744 Function: Returns a list of secondary identifiers of this Term.
745  
746 Secondary identifiers mostly originate from merging terms,
747 or possibly also from splitting terms.
748  
749 Returns : A list of secondary identifiers [array of [scalar]]
750 Args :
751  
752 =cut
753  
754 2573 ▶sub get_secondary_ids {
Subroutine get_secondary_ids: called CC=2 SCAR=6.9
Pod documented
755 2573 my $self = shift;
756  
757 2573 ▶ return @{$self->{"_secondary_ids"}} if exists($self->{"_secondary_ids"});
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"_secondary_ids"} 12 2561 2573
758 2561 return ();
759 } # get_secondary_ids
760  
761  
762 =head2 add_secondary_id
763  
764 Title : add_secondary_id
765 Usage : $term->add_secondary_id( @ids );
766 or
767 $term->add_secondary_id( $id );
768 Function: Adds one or more secondary identifiers to this term.
769 Returns :
770 Args : One or more secondary identifiers [scalars]
771  
772 =cut
773  
774 231 ▶sub add_secondary_id {
Subroutine add_secondary_id: called CC=5 SCAR=16.1
Pod documented
775 231 my $self = shift;
776  
777 231 ▶ return unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 221 10 231
778  
779 # avoid duplicates
780 10 foreach my $id (@_) {
781 12 ▶ next if grep { !$_ or $_ eq $id; } @{$self->{ "_secondary_ids" }};
Branch: 1 branch
BranchTrueFalseTotal
if grep {not $_ or $_ eq $id;} @{$$self{"_secondary_ids"};} 1 11 12
Condition66%2/3
!$_ || $_ eq $id
l!l&&r!l&&!r
017
MC/DC50%1/2
!$_ || $_ eq $id
!$_ $_ eq $id
Truth table66%2/3
not(A) || B
A= !$_B= $_ eq $id
ABresult
1X1
011
000
782 11 push( @{ $self->{ "_secondary_ids" } }, $id );
783 }
784  
785 } # add_secondary_id
786  
787  
788 =head2 remove_secondary_ids
789  
790 Title : remove_secondary_ids
791 Usage : $term->remove_secondary_ids();
792 Function: Deletes (and returns) the secondary identifiers of this Term.
793 Returns : The previous list of secondary identifiers [array of [scalars]]
794 Args :
795  
796 =cut
797  
798 2565 ▶sub remove_secondary_ids {
Subroutine remove_secondary_ids: called CC=1 SCAR=0.0
Pod documented
799 2565 my $self = shift;
800  
801 2565 my @a = $self->get_secondary_ids();
802 2565 $self->{ "_secondary_ids" } = [];
803 2565 return @a;
804  
805 } # remove_secondary_ids
806  
807  
808 # Title :_is_true_or_false
809 # Function: Checks whether the argument is TRUE or FALSE.
810 # Returns :
811 # Args : The value to be checked.
812 0 ▶sub _is_true_or_false {
Subroutine _is_true_or_false: not called CC=4 SCAR=30.0
813 0 my ( $self, $value ) = @_;
814 0 ▶ unless ( $value !~ /\D/ && ( $value == TRUE || $value == FALSE ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (not $value =~ /\D/ and $value == 1 || $value == 0) 0 0 0
Condition0%0/6
not $value =~ /\D/ and $value == 1 || $value == 0
!ll&&!rl&&r
000
$value == 1 or $value == 0
l!l&&r!l&&!r
000
MC/DC0%0/3
not $value =~ /\D/ and $value == 1 || $value == 0
not $value =~ /\D/ $value == 1 $value == 0
Truth table0%0/4
not(A) and B or C
A= not $value =~ /\D/B= $value == 1C= $value == 0
ABCresult
0XX0
1000
11X1
1011
815 0 $self->throw( "Found [" . $value
816 . "] where " . TRUE . " or " . FALSE . " expected" );
817 }
818 } # _is_true_or_false
819  
820 =head1 Methods implementing L<Bio::IdentifiableI> and L<Bio::DescribableI>
821  
822 =cut
823  
824 =head2 object_id
825  
826 Title : object_id
827 Usage : $string = $obj->object_id()
828 Function: a string which represents the stable primary identifier
829 in this namespace of this object.
830  
831 This is a synonym for identifier().
832  
833 Returns : A scalar
834  
835 =cut
836  
837 0 ▶sub object_id {
Subroutine object_id: not called CC=1 SCAR=6.9
Pod documented
838 0 return shift->identifier(@_);
839 }
840  
841 =head2 authority
842  
843 Title : authority
844 Usage : $authority = $obj->authority()
845 Function: a string which represents the organisation which
846 granted the namespace, written as the DNS name for
847 organisation (eg, wormbase.org)
848  
849 This forwards to ontology()->authority(). Note that you
850 cannot set the authority before having set the ontology or
851 the namespace (which will set the ontology).
852  
853 Returns : A scalar
854 Args : on set, the new value (a scalar)
855  
856 =cut
857  
858 0 ▶sub authority {
Subroutine authority: not called CC=3 SCAR=24.8
Pod documented
859 0 my $self = shift;
860 0 my $ont = $self->ontology();
861  
862 0 ▶ return $ont->authority(@_) if $ont;
Branch: 1 branch
BranchTrueFalseTotal
if $ont 0 0 0
863 0 ▶ $self->throw("cannot manipulate authority prior to ".
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
864 "setting the namespace or ontology") if @_;
865 0 return;
866 }
867  
868  
869 =head2 namespace
870  
871 Title : namespace
872 Usage : $string = $obj->namespace()
873 Function: A string representing the name space this identifier
874 is valid in, often the database name or the name
875 describing the collection.
876  
877 This forwards to ontology() (set mode) and
878 ontology()->name() (get mode). I.e., setting the namespace
879 will set the ontology to one matching that name in the
880 ontology store, or to one newly created.
881  
882 Returns : A scalar
883 Args : on set, the new value (a scalar)
884  
885 =cut
886  
887 1901 ▶sub namespace {
Subroutine namespace: called CC=3 SCAR=11.0
Pod documented
888 1901 my $self = shift;
889  
890 1901 ▶ $self->ontology(@_) if(@_);
Branch: 1 branch
BranchTrueFalseTotal
if @_ 10 1891 1901
891 1901 my $ont = $self->ontology();
892 1901 ▶ return defined($ont) ? $ont->name() : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $ont ? : 201 1700 1901
893 }
894  
895 =head2 display_name
896  
897 Title : display_name
898 Usage : $string = $obj->display_name()
899 Function: A string which is what should be displayed to the user.
900  
901 The definition in Bio::DescribableI states that the
902 string should not contain spaces. As this is not very
903 sensible for ontology terms, we relax this here. The
904 implementation just forwards to name().
905  
906 Returns : A scalar
907 Args : on set, the new value (a scalar)
908  
909 =cut
910  
911 0 ▶sub display_name {
Subroutine display_name: not called CC=1 SCAR=6.9
Pod documented
912 0 return shift->name(@_);
913 }
914  
915  
916 =head2 description
917  
918 Title : description
919 Usage : $string = $obj->description()
920 Function: A text string suitable for displaying to the user a
921 description. This string is likely to have spaces, but
922 should not have any newlines or formatting - just plain
923 text.
924  
925 This forwards to definition(). The caveat is that the text
926 will often be longer for ontology term definitions than the
927 255 characters stated in the definition in
928 Bio::DescribableI.
929  
930 Returns : A scalar
931 Args : on set, the new value (a scalar)
932  
933 =cut
934  
935 0 ▶sub description {
Subroutine description: not called CC=1 SCAR=6.9
Pod documented
936 0 return shift->definition(@_);
937 }
938  
939 #################################################################
940 # aliases or forwards to maintain backward compatibility
941 #################################################################
942  
943 =head1 Deprecated methods
944  
945 Used for looking up the methods that supersedes them.
946  
947 =cut
948  
949 0 ▶sub each_dblink {shift->throw("use of each_dblink() is deprecated; use get_dbxrefs() instead")}
Subroutine each_dblink: not called CC=1 SCAR=6.9
Pod undocumented
950 0 ▶sub add_dblinks {shift->throw("use of add_dblinks() is deprecated; use add_dbxref() instead")}
Subroutine add_dblinks: not called CC=1 SCAR=6.9
Pod undocumented
951 26 *each_synonym = \&get_synonyms;
952 26 *add_synonyms = \&add_synonym;
953  
954 26 1;
« Bio/SeqIO/asciitree.pm ↑ Summary Bio/Annotation/Collection.pm »