Bio/Ontology/Ontology.pm

filter: Statementstmt 73.1% 79 / 108 Branchbran 47.6% 20 / 42 Conditioncond 55.5% 15 / 27 MC/DCmcdc 35.2% 6 / 17 Subroutinesub 78.5% 22 / 28 Podpod 100% 26 / 26 totaltotal 67.7% 168 / 248 CC 31 SCAR 19.2
CC
31
Cov
64%
identifier
30.0
engine
14.6
new
6.1
CRAP 6.8
« Bio/SeqFeature/Computation.pm ↑ Summary Bio/SeqIO/msout.pm »
1 #
2 # BioPerl module for Bio::Ontology::Ontology
3 #
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
5 #
6 # Cared for by Hilmar Lapp <hlapp at gmx.net>
7 #
8 # Copyright Hilmar Lapp
9 #
10 # You may distribute this module under the same terms as perl itself
11  
12 #
13 # (c) Hilmar Lapp, hlapp at gmx.net, 2003.
14 # (c) GNF, Genomics Institute of the Novartis Research Foundation, 2003.
15 #
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.
20 #
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.
24 #
25  
26 # POD documentation - main docs before the code
27  
28 =head1 NAME
29  
30 Bio::Ontology::Ontology - standard implementation of an Ontology
31  
32 =head1 SYNOPSIS
33  
34 use Bio::Ontology::Ontology;
35 use Bio::Ontology::Term;
36  
37 # create ontology object
38 my $ont = Bio::Ontology::Ontology->new(-name => "OBF");
39  
40 # add terms, relationships ...
41 my $bp = Bio::Ontology::Term->new(-identifier => '02', -name => "Bioperl");
42 my $obf = Bio::Ontology::Term->new(-identifier => '01', -name => "OBF");
43 my $partof = Bio::Ontology::RelationshipType->get_instance("PART_OF");
44 $ont->add_term($bp);
45 $ont->add_term($obf);
46 $ont->add_relationship($bp, $obf, $partof);
47  
48 # then query
49 my @terms = $ont->get_root_terms(); # "OBF"
50 my @desc = $ont->get_descendant_terms($terms[0], $partof); # "Bioperl"
51 # ... see methods for other ways to query
52  
53 # for advanced users, you can re-use the query engine outside of an
54 # ontology to let one instance manage multiple ontologies
55 my $ont2 = Bio::Ontology::Ontology->new(-name => "Foundations",
56 -engine => $ont->engine());
57  
58  
59 =head1 DESCRIPTION
60  
61 This is a no-frills implementation of L<Bio::Ontology::OntologyI>.
62  
63 The query functions are implemented by delegation to an
64 OntologyEngineI implementation.
65  
66 =head1 FEEDBACK
67  
68 =head2 Mailing Lists
69  
70 User feedback is an integral part of the evolution of this and other
71 Bioperl modules. Send your comments and suggestions preferably to
72 the Bioperl mailing list. Your participation is much appreciated.
73  
74 bioperl-l@bioperl.org - General discussion
75 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
76  
77 =head2 Support
78  
79 Please direct usage questions or support issues to the mailing list:
80  
81 I<bioperl-l@bioperl.org>
82  
83 rather than to the module maintainer directly. Many experienced and
84 reponsive experts will be able look at the problem and quickly
85 address it. Please include a thorough description of the problem
86 with code and data examples if at all possible.
87  
88 =head2 Reporting Bugs
89  
90 Report bugs to the Bioperl bug tracking system to help us keep track
91 of the bugs and their resolution. Bug reports can be submitted via
92 the web:
93  
94 https://github.com/bioperl/bioperl-live/issues
95  
96 =head1 AUTHOR - Hilmar Lapp
97  
98 Email hlapp at gmx.net
99  
100 =head1 APPENDIX
101  
102 The rest of the documentation details each of the object methods.
103 Internal methods are usually preceded with a _
104  
105 =cut
106  
107  
108 # Let the code begin...
109  
110  
111 package Bio::Ontology::Ontology;
112 27 $Bio::Ontology::Ontology::VERSION = '1.7.8';
113 27 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
114  
115 # Object preamble - inherits from Bio::Root::Root
116  
117 #use Bio::Ontology::SimpleOntologyEngine; # loaded dynamically now!
118  
119 27 ▶use base qw(Bio::Root::Root Bio::Ontology::OntologyI Bio::AnnotatableI);
Subroutine BEGIN: called CC=1 SCAR=0.0
120  
121 =head2 new
122  
123 Title : new
124 Usage : my $obj = Bio::Ontology::Ontology->new();
125 Function: Builds a new Bio::Ontology::Ontology object
126 Returns : an instance of Bio::Ontology::Ontology
127 Args : any number of named arguments. The following names will be
128 recognized by this module:
129  
130 -name the name of the ontology
131 -authority the name of the authority for the ontology
132 -identifier an identifier for the ontology, if any
133 -engine the Bio::Ontology::OntologyEngineI
134 implementation that this instance should use;
135 default is Bio::Ontology::SimpleOntologyEngine
136  
137 See the corresponding get/set methods for further documentation
138 on individual properties.
139  
140 =cut
141  
142 40 ▶sub new {
Subroutine new: called CC=6 SCAR=18.2
Pod documented
143 40 my($class,@args) = @_;
144  
145 40 my $self = $class->SUPER::new(@args);
146 40 my ($name,$auth,$def,$id,$engine) =
147 $self->_rearrange([qw(NAME
148 AUTHORITY
149 DEFINITION
150 IDENTIFIER
151 ENGINE)
152 ],
153 @args);
154 40 ▶ defined($name) && $self->name($name);
Branch: 1 branch
BranchTrueFalseTotal
defined $name and $self->name($name) 33 7 40
155 40 ▶ defined($auth) && $self->authority($auth);
Branch: 1 branch
BranchTrueFalseTotal
defined $auth and $self->authority($auth) 0 40 40
156 40 ▶ defined($def) && $self->definition($def);
Branch: 1 branch
BranchTrueFalseTotal
defined $def and $self->definition($def) 0 40 40
157 40 ▶ defined($id) && $self->identifier($id);
Branch: 1 branch
BranchTrueFalseTotal
defined $id and $self->identifier($id) 0 40 40
158 40 ▶ defined($engine) && $self->engine($engine);
Branch: 1 branch
BranchTrueFalseTotal
defined $engine and $self->engine($engine) 10 30 40
159  
160 40 return $self;
161 }
162  
163 =head1 Methods from L<Bio::Ontology::OntologyI>
164  
165 =cut
166  
167 =head2 name
168  
169 Title : name
170 Usage : $obj->name($newval)
171 Function: Get/set the name of the ontology.
172 Example :
173 Returns : value of name (a scalar)
174 Args : on set, new value (a scalar or undef, optional)
175  
176  
177 =cut
178  
179 1470 ▶sub name{
Subroutine name: called CC=2 SCAR=6.9
Pod documented
180 1470 my $self = shift;
181  
182 1470 ▶ return $self->{'name'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 39 1431 1470
183 1431 return $self->{'name'};
184 }
185  
186 =head2 authority
187  
188 Title : authority
189 Usage : $obj->authority($newval)
190 Function: Get/set the authority for this ontology, for instance the
191 DNS base for the organization granting the name of the
192 ontology and identifiers for the terms.
193  
194 This attribute is optional and should not generally
195 expected by applications to have been set. It is here to
196 follow the rules for namespaces, which ontologies serve as
197 for terms.
198  
199 Example :
200 Returns : value of authority (a scalar)
201 Args : on set, new value (a scalar or undef, optional)
202  
203  
204 =cut
205  
206 0 ▶sub authority{
Subroutine authority: not called CC=2 SCAR=17.9
Pod documented
207 0 my $self = shift;
208  
209 0 ▶ return $self->{'authority'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
210 0 return $self->{'authority'};
211 }
212  
213 =head2 definition
214  
215 Title : definition
216 Usage : $obj->definition($newval)
217 Function: Get/set a descriptive definition of the ontology.
218 Example :
219 Returns : value of definition (a scalar)
220 Args : on set, new value (a scalar or undef, optional)
221  
222  
223 =cut
224  
225 0 ▶sub definition{
Subroutine definition: not called CC=2 SCAR=17.9
Pod documented
226 0 my $self = shift;
227  
228 0 ▶ return $self->{'definition'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
229 0 return $self->{'definition'};
230 }
231  
232 =head2 identifier
233  
234 Title : identifier
235 Usage : $id = $obj->identifier()
236 Function: Get an identifier for this ontology.
237  
238 This is primarily intended for look-up purposes. The value
239 is not modifiable and is determined automatically by the
240 implementation. Also, the identifier's uniqueness will only
241 hold within the scope of a particular application's run
242 time since it is derived from a memory location.
243  
244 Example :
245 Returns : value of identifier (a scalar)
246 Args :
247  
248  
249 =cut
250  
251 0 ▶sub identifier{
Subroutine identifier: not called CC=5 SCAR=34.0
Pod documented
252 0 my $self = shift;
253  
254 0 ▶ if(@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
255 $self->throw("cannot modify identifier for ".ref($self))
256 0 ▶ if exists($self->{'identifier'});
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"identifier"} 0 0 0
257 0 my $id = shift;
258 0 ▶ $self->{'identifier'} = $id if $id;
Branch: 1 branch
BranchTrueFalseTotal
if $id 0 0 0
259 }
260 0 ▶ if(! exists($self->{'identifier'})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"identifier"}) 0 0 0
261 0 ($self->{'identifier'}) = "$self" =~ /(0x[0-9a-fA-F]+)/;
262 }
263 0 return $self->{'identifier'};
264 }
265  
266 =head2 close
267  
268 Title : close
269 Usage :
270 Function: Release any resources this ontology may occupy. In order
271 to efficiently release unused memory or file handles, you
272 should call this method once you are finished with an
273 ontology.
274  
275 Example :
276 Returns : TRUE on success and FALSE otherwise
277 Args : none
278  
279  
280 =cut
281  
282 0 ▶sub close{
Subroutine close: not called CC=1 SCAR=6.9
Pod documented
283 0 my $self = shift;
284  
285 # if it is in the ontology store, remove it from there
286 0 my $store = Bio::Ontology::OntologyStore->get_instance();
287 0 $store->remove_ontology($self);
288 # essentially we need to dis-associate from the engine here
289 0 $self->engine(undef);
290 0 return 1;
291 }
292  
293 =head1 Implementation-specific public methods
294  
295 =cut
296  
297 =head2 engine
298  
299 Title : engine
300 Usage : $engine = $obj->engine()
301 Function: Get/set the ontology engine to which all the query methods
302 delegate.
303 Example :
304 Returns : an object implementing Bio::Ontology::OntologyEngineI
305 Args : on set, new value (an object implementing
306 Bio::Ontology::OntologyEngineI, or undef)
307  
308 See L<Bio::Ontology::OntologyEngineI>.
309  
310 =cut
311  
312 115 ▶sub engine{
Subroutine engine: called CC=7 SCAR=26.8
Pod documented
313 115 my $self = shift;
314  
315 115 ▶ if (@_) {
Branch: 2 branches
BranchTrueFalseTotal
if (@_) { } 11 104 115
elsif (not exists $self->{'engine'}) { } 0 104 104
316 11 my $engine = shift;
317 11 ▶ if($engine &&
Branch: 1 branch
BranchTrueFalseTotal
if ($engine and not ref $engine && $engine->isa("Bio::Ontology::OntologyEngineI")) 0 11 11
Condition33%2/6
$engine and not ref $engine && $engine->isa("Bio::Ontology::OntologyEngineI")
!ll&&!rl&&r
0110
ref $engine && $engine->isa('Bio::Ontology::OntologyEngineI')
!ll&&!rl&&r
0011
MC/DC0%0/3
$engine and not ref $engine && $engine->isa("Bio::Ontology::OntologyEngineI")
$engine ref $engine $engine->isa('Bio::Ontology::OntologyEngineI')
Truth table25%1/4
A and not(B && C)
A= $engineB= ref $engineC= $engine->isa('Bio::Ontology::OntologyEngineI')
ABCresult
0XX0
1110
10X1
1101
318 (! (ref($engine) &&
319 $engine->isa("Bio::Ontology::OntologyEngineI")))) {
320 0 $self->throw("object of class ".ref($engine)." does not implement".
321 " Bio::Ontology::OntologyEngineI. Bummer!");
322 }
323 11 $self->{'engine'} = $engine;
324 } elsif (! exists($self->{'engine'})) {
325 # instantiate on demand
326 0 eval {
327 # this introduces a dependency on Graph.pm, so load dynamically
328 0 require Bio::Ontology::SimpleOntologyEngine;
329 };
330 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
331 0 $self->throw("failed to load SimpleOntologyEngine, possibly "
332 ."Graph.pm is not installed; either install or supply "
333 ."another OntologyEngineI implementation:\n"
334 .$@);
335 }
336 0 $self->{'engine'} = Bio::Ontology::SimpleOntologyEngine->new();
337 }
338 115 return $self->{'engine'};
339 }
340  
341 =head1 Methods defined in L<Bio::Ontology::OntologyEngineI>
342  
343 =cut
344  
345 =head2 add_term
346  
347 Title : add_term
348 Usage : add_term(TermI term): TermI
349 Function: Adds TermI object to the ontology engine term store
350  
351 If the ontology property of the term object was not set,
352 this implementation will set it to itself upon adding the
353 term.
354  
355 Example : $oe->add_term($term)
356 Returns : its argument.
357 Args : object of class TermI.
358  
359  
360 =cut
361  
362 5 ▶sub add_term{
Subroutine add_term: called CC=3 SCAR=11.0
Pod documented
363 5 my $self = shift;
364 5 my $term = shift;
365  
366 # set ontology if not set already
367 5 ▶ $term->ontology($self) if $term && (! $term->ontology());
Branch: 1 branch
BranchTrueFalseTotal
if $term and not $term->ontology 1 4 5
Condition66%2/3
$term and not $term->ontology
!ll&&!rl&&r
041
MC/DC50%1/2
$term and not $term->ontology
$term not $term->ontology
Truth table66%2/3
A and not(B)
A= $termB= not $term->ontology
ABresult
0X0
100
111
368 5 return $self->engine->add_term($term,@_);
369 }
370  
371 =head2 add_relationship
372  
373 Title : add_relationship
374 Usage : add_relationship(RelationshipI relationship): RelationshipI
375 add_relatioship(TermI subject, TermI predicate, TermI object)
376 Function: Adds a relationship object to the ontology engine.
377 Example :
378 Returns : Its argument.
379 Args : A RelationshipI object.
380  
381  
382 =cut
383  
384 2 ▶sub add_relationship {
Subroutine add_relationship: called CC=4 SCAR=16.6
Pod documented
385 2 my $self = shift;
386 2 my $rel = shift;
387  
388 2 ▶ if($rel && $rel->isa("Bio::Ontology::TermI")) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rel and $rel->isa("Bio::Ontology::TermI")) 0 2 2
Condition33%1/3
$rel and $rel->isa("Bio::Ontology::TermI")
!ll&&!rl&&r
020
MC/DC0%0/2
$rel and $rel->isa("Bio::Ontology::TermI")
$rel $rel->isa("Bio::Ontology::TermI")
Truth table33%1/3
A and B
A= $relB= $rel->isa("Bio::Ontology::TermI")
ABresult
0X0
100
111
389 # we need to construct the relationship object on the fly
390 0 my ($predicate,$object) = @_;
391 0 $rel = Bio::Ontology::Relationship->new(
392 -subject_term => $rel,
393 -object_term => $object,
394 -predicate_term => $predicate,
395 -ontology => $self,
396 );
397 }
398 # set ontology if not set already
399 2 ▶ $rel->ontology($self) unless $rel->ontology();
Branch: 1 branch
BranchTrueFalseTotal
unless $rel->ontology 0 2 2
400 2 return $self->engine->add_relationship($rel);
401 }
402  
403 =head2 get_relationship_type
404  
405 Title : get_relationship_type
406 Usage : get_relationship_type(scalar): RelationshipTypeI
407 Function: Get a relationshiptype object from the ontology engine.
408 Example :
409 Returns : A RelationshipTypeI object.
410 Args : The name (scalar) of the RelationshipTypeI object desired.
411  
412  
413 =cut
414  
415 4 ▶sub get_relationship_type{
Subroutine get_relationship_type: called CC=1 SCAR=0.0
Pod documented
416 4 my $self = shift;
417 4 return $self->engine->get_relationship_type(@_);
418 }
419  
420 =head2 get_relationships
421  
422 Title : get_relationships
423 Usage : get_relationships(TermI term): RelationshipI[]
424 Function: Retrieves all relationship objects in the ontology, or all
425 relationships of a given term.
426 Example :
427 Returns : Array of Bio::Ontology::RelationshipI objects
428 Args : Optionally, a Bio::Ontology::TermI compliant object
429  
430  
431 =cut
432  
433 7 ▶sub get_relationships {
Subroutine get_relationships: called CC=3 SCAR=11.0
Pod documented
434 7 my $self = shift;
435 7 my $term = shift;
436 7 ▶ if($term) {
Branch: 1 branch
BranchTrueFalseTotal
if ($term) 3 4 7
437 # we don't need to filter in this case
438 3 return $self->engine->get_relationships($term);
439 }
440 # else we need to filter by ontology
441 4 return grep { my $ont = $_->ontology;
442 # the first condition is a superset of the second, but
443 # we add it here for efficiency reasons, as many times
444 # it will short-cut to true and is supposedly faster than
445 # string comparison
446 1330 ▶ ($ont == $self) || ($ont->name eq $self->name);
Condition66%2/3
$ont == $self || $ont->name eq $self->name
l!l&&r!l&&!r
1317013
MC/DC50%1/2
$ont == $self || $ont->name eq $self->name
$ont == $self $ont->name eq $self->name
Truth table66%2/3
A || B
A= $ont == $selfB= $ont->name eq $self->name
ABresult
1X1
011
000
447 } $self->engine->get_relationships(@_);
448 }
449  
450 =head2 get_predicate_terms
451  
452 Title : get_predicate_terms
453 Usage : get_predicate_terms(): TermI
454 Function: Retrieves all relationship types.
455 Example :
456 Returns : Array of TermI objects
457 Args :
458  
459  
460 =cut
461  
462 3 ▶sub get_predicate_terms{
Subroutine get_predicate_terms: called CC=2 SCAR=6.9
Pod documented
463 3 my $self = shift;
464
465 # skipped Bio::Ontology::Relationship w/o defined Ontology (bug 2573)
466 3 ▶ return grep { $_->ontology && ($_->ontology->name eq $self->name)
Condition100%3/3
$_->ontology && $_->ontology->name eq $self->name
!ll&&!rl&&r
3811
MC/DC100%2/2
$_->ontology && $_->ontology->name eq $self->name
$_->ontology $_->ontology->name eq $self->name
Truth table100%3/3
A && B
A= $_->ontologyB= $_->ontology->name eq $self->name
ABresult
0X0
100
111
467 } $self->engine->get_predicate_terms(@_);
468 }
469  
470 =head2 get_child_terms
471  
472 Title : get_child_terms
473 Usage : get_child_terms(TermI term, TermI predicate_terms): TermI
474 Function: Retrieves all child terms of a given term, that satisfy a
475 relationship among those that are specified in the second
476 argument or undef otherwise. get_child_terms is a special
477 case of get_descendant_terms, limiting the search to the
478 direct descendants.
479  
480 Note that a returned term may possibly be in another
481 ontology than this one, because the underlying engine may
482 manage multiple ontologies and the relationships of terms
483 between them. If you only want descendants within this
484 ontology, you need to filter the returned array.
485  
486 Example :
487 Returns : Array of TermI objects.
488 Args : First argument is the term of interest, second is the list
489 of relationship type terms.
490  
491  
492 =cut
493  
494 17 ▶sub get_child_terms{
Subroutine get_child_terms: called CC=1 SCAR=0.0
Pod documented
495 17 return shift->engine->get_child_terms(@_);
496 }
497  
498 =head2 get_descendant_terms
499  
500 Title : get_descendant_terms
501 Usage : get_descendant_terms(TermI term, TermI rel_types): TermI
502 Function: Retrieves all descendant terms of a given term, that
503 satisfy a relationship among those that are specified in
504 the second argument or undef otherwise.
505  
506 Note that a returned term may possibly be in another
507 ontology than this one, because the underlying engine may
508 manage multiple ontologies and the relationships of terms
509 between them. If you only want descendants within this
510 ontology, you need to filter the returned array.
511  
512 Example :
513 Returns : Array of TermI objects.
514 Args : First argument is the term of interest, second is the list
515 of relationship type terms.
516  
517  
518 =cut
519  
520 10 ▶sub get_descendant_terms{
Subroutine get_descendant_terms: called CC=1 SCAR=0.0
Pod documented
521 10 return shift->engine->get_descendant_terms(@_);
522 }
523  
524 =head2 get_parent_terms
525  
526 Title : get_parent_terms
527 Usage : get_parent_terms(TermI term, TermI predicate_terms): TermI
528 Function: Retrieves all parent terms of a given term, that satisfy a
529 relationship among those that are specified in the second
530 argument or undef otherwise. get_parent_terms is a special
531 case of get_ancestor_terms, limiting the search to the
532 direct ancestors.
533  
534 Note that a returned term may possibly be in another
535 ontology than this one, because the underlying engine may
536 manage multiple ontologies and the relationships of terms
537 between them. If you only want descendants within this
538 ontology, you need to filter the returned array.
539  
540 Example :
541 Returns : Array of TermI objects.
542 Args : First argument is the term of interest, second is the list
543 of relationship type terms.
544  
545  
546 =cut
547  
548 15 ▶sub get_parent_terms{
Subroutine get_parent_terms: called CC=1 SCAR=0.0
Pod documented
549 15 return shift->engine->get_parent_terms(@_);
550 }
551  
552 =head2 get_ancestor_terms
553  
554 Title : get_ancestor_terms
555 Usage : get_ancestor_terms(TermI term, TermI predicate_terms): TermI
556 Function: Retrieves all ancestor terms of a given term, that satisfy
557 a relationship among those that are specified in the second
558 argument or undef otherwise.
559  
560 Note that a returned term may possibly be in another
561 ontology than this one, because the underlying engine may
562 manage multiple ontologies and the relationships of terms
563 between them. If you only want descendants within this
564 ontology, you need to filter the returned array.
565  
566 Example :
567 Returns : Array of TermI objects.
568 Args : First argument is the term of interest, second is the list
569 of relationship type terms.
570  
571  
572 =cut
573  
574 14 ▶sub get_ancestor_terms{
Subroutine get_ancestor_terms: called CC=1 SCAR=0.0
Pod documented
575 14 return shift->engine->get_ancestor_terms(@_);
576 }
577  
578 =head2 get_leaf_terms
579  
580 Title : get_leaf_terms
581 Usage : get_leaf_terms(): TermI
582 Function: Retrieves all leaf terms from the ontology. Leaf term is a
583 term w/o descendants.
584  
585 Example : @leaf_terms = $obj->get_leaf_terms()
586 Returns : Array of TermI objects.
587 Args :
588  
589 =cut
590  
591 2 ▶sub get_leaf_terms{
Subroutine get_leaf_terms: called CC=2 SCAR=7.4
Pod documented
592 2 my $self = shift;
593 2 return grep { my $ont = $_->ontology;
594 # the first condition is a superset of the second, but
595 # we add it here for efficiency reasons, as many times
596 # it will short-cut to true and is supposedly faster than
597 # string comparison
598 23 ▶ ($ont == $self) || ($ont->name eq $self->name);
Condition33%1/3
$ont == $self || $ont->name eq $self->name
l!l&&r!l&&!r
2300
MC/DC0%0/2
$ont == $self || $ont->name eq $self->name
$ont == $self $ont->name eq $self->name
Truth table33%1/3
A || B
A= $ont == $selfB= $ont->name eq $self->name
ABresult
1X1
011
000
599 } $self->engine->get_leaf_terms(@_);
600 }
601  
602 =head2 get_root_terms()
603  
604 Title : get_root_terms
605 Usage : get_root_terms(): TermI
606 Function: Retrieves all root terms from the ontology. Root term is a
607 term w/o parents.
608  
609 Example : @root_terms = $obj->get_root_terms()
610 Returns : Array of TermI objects.
611 Args :
612  
613 =cut
614  
615 7 ▶sub get_root_terms{
Subroutine get_root_terms: called CC=2 SCAR=6.9
Pod documented
616 7 my $self = shift;
617 7 return grep { my $ont = $_->ontology;
618 # the first condition is a superset of the second, but
619 # we add it here for efficiency reasons, as many times
620 # it will short-cut to true and is supposedly faster than
621 # string comparison
622 19 ▶ ($ont == $self) || ($ont->name eq $self->name);
Condition100%3/3
$ont == $self || $ont->name eq $self->name
l!l&&r!l&&!r
1522
MC/DC100%2/2
$ont == $self || $ont->name eq $self->name
$ont == $self $ont->name eq $self->name
Truth table100%3/3
A || B
A= $ont == $selfB= $ont->name eq $self->name
ABresult
1X1
011
000
623 } $self->engine->get_root_terms(@_);
624 }
625  
626 =head2 get_all_terms
627  
628 Title : get_all_terms
629 Usage : get_all_terms: TermI
630 Function: Retrieves all terms from the ontology.
631  
632 We do not mandate an order here in which the terms are
633 returned. In fact, the default implementation will return
634 them in unpredictable order.
635  
636 Example : @terms = $obj->get_all_terms()
637 Returns : Array of TermI objects.
638 Args :
639  
640 =cut
641  
642 1 ▶sub get_all_terms{
Subroutine get_all_terms: called CC=2 SCAR=7.4
Pod documented
643 1 my $self = shift;
644 1 return grep { my $ont = $_->ontology;
645 # the first condition is a superset of the second, but
646 # we add it here for efficiency reasons, as many times
647 # it will short-cut to true and is supposedly faster than
648 # string comparison
649 44 ▶ ($ont == $self) || ($ont->name eq $self->name);
Condition33%1/3
$ont == $self || $ont->name eq $self->name
l!l&&r!l&&!r
4400
MC/DC0%0/2
$ont == $self || $ont->name eq $self->name
$ont == $self $ont->name eq $self->name
Truth table33%1/3
A || B
A= $ont == $selfB= $ont->name eq $self->name
ABresult
1X1
011
000
650 } $self->engine->get_all_terms(@_);
651 }
652  
653 =head2 find_terms
654  
655 Title : find_terms
656 Usage : ($term) = $oe->find_terms(-identifier => "SO:0000263");
657 Function: Find term instances matching queries for their attributes.
658  
659 An implementation may not support querying for arbitrary
660 attributes, but can generally be expected to accept
661 -identifier and -name as queries. If both are provided,
662 they are implicitly intersected.
663  
664 Example :
665 Returns : an array of zero or more Bio::Ontology::TermI objects
666 Args : Named parameters. The following parameters should be recognized
667 by any implementations:
668  
669 -identifier query by the given identifier
670 -name query by the given name
671  
672 =cut
673  
674 8 ▶sub find_terms{
Subroutine find_terms: called CC=1 SCAR=0.0
Pod documented
675 8 my $self = shift;
676 8 return grep { $_->ontology->name eq $self->name;
677 } $self->engine->find_terms(@_);
678 }
679  
680 =head2 find_identical_terms
681  
682 Title : find_identical_terms
683 Usage : ($term) = $oe->find_identical_terms($term0);
684 Function: Find term instances where name or synonym
685 matches the query exactly
686 Example :
687 Returns : an array of zero or more Bio::Ontology::TermI objects
688 Args : a Bio::Ontology::TermI object
689  
690 =cut
691  
692 1 ▶sub find_identical_terms{
Subroutine find_identical_terms: called CC=1 SCAR=0.0
Pod documented
693 1 my $self = shift;
694 1 return grep { $_->ontology->name eq $self->name;
695 } $self->engine->find_identical_terms(@_);
696 }
697  
698  
699 =head2 find_similar_terms
700  
701 Title : find_similar_terms
702 Usage : ($term) = $oe->find_similar_terms($term0);
703 Function: Find term instances where name or synonym, or part of one,
704 matches the query.
705 Example :
706 Returns : an array of zero or more Bio::Ontology::TermI objects
707 Args : a Bio::Ontology::TermI object
708  
709 =cut
710  
711 1 ▶sub find_similar_terms{
Subroutine find_similar_terms: called CC=1 SCAR=0.0
Pod documented
712 1 my $self = shift;
713 1 return grep { $_->ontology->name eq $self->name;
714 } $self->engine->find_similar_terms(@_);
715 }
716  
717 =head2 find_identically_named_terms
718  
719 Title : find_identically_named_terms
720 Usage : ($term) = $oe->find_identically_named_terms($term0);
721 Function: Find term instances where names match the query term
722 name exactly
723 Example :
724 Returns : an array of zero or more Bio::Ontology::TermI objects
725 Args : a Bio::Ontology::TermI object
726  
727 =cut
728  
729 1 ▶sub find_identically_named_terms{
Subroutine find_identically_named_terms: called CC=1 SCAR=0.0
Pod documented
730 1 my $self = shift;
731 1 return grep { $_->ontology->name eq $self->name
732 } $self->engine->find_identically_named_terms(@_);
733 }
734  
735 =head1 Factory for relationships and terms
736  
737 =cut
738  
739 =head2 relationship_factory
740  
741 Title : relationship_factory
742 Usage : $fact = $obj->relationship_factory()
743 Function: Get (and set, if the engine supports it) the object
744 factory to be used when relationship objects are created by
745 the implementation on-the-fly.
746  
747 Example :
748 Returns : value of relationship_factory (a Bio::Factory::ObjectFactoryI
749 compliant object)
750 Args :
751  
752 =cut
753  
754 0 ▶sub relationship_factory{
Subroutine relationship_factory: not called CC=1 SCAR=6.9
Pod documented
755 0 return shift->engine->relationship_factory(@_);
756 }
757  
758 =head2 term_factory
759  
760 Title : term_factory
761 Usage : $fact = $obj->term_factory()
762 Function: Get (and set, if the engine supports it) the object
763 factory to be used when term objects are created by
764 the implementation on-the-fly.
765  
766 Example :
767 Returns : value of term_factory (a Bio::Factory::ObjectFactoryI
768 compliant object)
769 Args :
770  
771 =cut
772  
773 0 ▶sub term_factory{
Subroutine term_factory: not called CC=1 SCAR=6.9
Pod documented
774 0 return shift->engine->term_factory(@_);
775 }
776  
777  
778 =head2 annotation
779  
780 Title : annotation
781 Usage : $annos = $obj->annotation()
782 Function: Get/Set the Bio::Annotation::Collection object
783 The collection contains Bio::Annotation::SimpleValue
784 objects to store header information like the version
785 and date present in the header section of an Ontology
786 file.
787  
788 Example :
789 Returns : value of annotation (a Bio::Annotation::Collection
790 compliant object)
791 Args : A Bio::Annotation::Collection object (Optional)
792  
793 =cut
794  
795 5 ▶sub annotation{
Subroutine annotation: called CC=2 SCAR=7.1
Pod documented
796 5 my $self = shift;
797 5 ▶ $self->{'annotation'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 5 0 5
798 5 return $self->{'annotation'};
799 }
800  
801  
802 #################################################################
803 # aliases
804 #################################################################
805  
806 27 *get_relationship_types = \&get_predicate_terms;
807  
808 27 1;
« Bio/SeqFeature/Computation.pm ↑ Summary Bio/SeqIO/msout.pm »