Bio/Tree/Tree.pm

filter: Statementstmt 95.7% 134 / 140 Branchbran 77.0% 37 / 48 Conditioncond 64.4% 29 / 45 MC/DCmcdc 29.6% 8 / 27 Subroutinesub 100% 21 / 21 Podpod 94.7% 18 / 19 totaltotal 82.3% 247 / 300 CC 47 SCAR 17.6
CC
47
Cov
86%
new
14.2
get_nodes
7.0
subtree_length
5.1
CRAP 5.8
« Bio/Search/Hit/BlastPullHit.pm ↑ Summary Bio/Index/BlastTable.pm »
1 #
2 # BioPerl module for Bio::Tree::Tree
3 #
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
5 #
6 # Cared for by Jason Stajich <jason@bioperl.org>
7 #
8 # Copyright Jason Stajich
9 #
10 # You may distribute this module under the same terms as perl itself
11  
12 # POD documentation - main docs before the code
13  
14  
15 =head1 NAME
16  
17 Bio::Tree::Tree - An implementation of the TreeI interface.
18  
19 =head1 SYNOPSIS
20  
21 use Bio::TreeIO;
22  
23 # like from a TreeIO
24 my $treeio = Bio::TreeIO->new(-format => 'newick', -file => 'treefile.dnd');
25 my $tree = $treeio->next_tree;
26 my @nodes = $tree->get_nodes;
27 my $root = $tree->get_root_node;
28  
29 =head1 DESCRIPTION
30  
31 This object holds handles to Nodes which make up a tree.
32  
33 =head1 IMPLEMENTATION NOTE
34  
35 This implementation of Bio::Tree::Tree contains Bio::Tree:::NodeI; mainly linked
36 via the root node. As NodeI can potentially contain circular references (as
37 nodes will need to refer to both parent and child nodes), Bio::Tree::Tree will
38 remove those circular references when the object is garbage-collected. This has
39 some side effects; primarily, one must keep the Tree in scope or have at least
40 one reference to it if working with nodes. The fix is to count the references to
41 the nodes and if it is greater than expected retain all of them, but it requires
42 an additional prereq and thus may not be worth the effort. This only shows up
43 in minor edge cases, though (see Bug #2869).
44  
45 Example of issue:
46  
47 # tree is not assigned to a variable, so passes from memory after
48 # root node is passed
49 my $root = Bio::TreeIO->new(-format => 'newick', -file => 'foo.txt')->next_tree
50 ->get_root_node;
51  
52 # gets nothing, as all Node links are broken when Tree is garbage-collected above
53 my @descendents = $root->get_all_Descendents;
54  
55 =head1 FEEDBACK
56  
57 =head2 Mailing Lists
58  
59 User feedback is an integral part of the evolution of this and other
60 Bioperl modules. Send your comments and suggestions preferably to
61 the Bioperl mailing list. Your participation is much appreciated.
62  
63 bioperl-l@bioperl.org - General discussion
64 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
65  
66 =head2 Support
67  
68 Please direct usage questions or support issues to the mailing list:
69  
70 I<bioperl-l@bioperl.org>
71  
72 rather than to the module maintainer directly. Many experienced and
73 reponsive experts will be able look at the problem and quickly
74 address it. Please include a thorough description of the problem
75 with code and data examples if at all possible.
76  
77 =head2 Reporting Bugs
78  
79 Report bugs to the Bioperl bug tracking system to help us keep track
80 of the bugs and their resolution. Bug reports can be submitted via
81 the web:
82  
83 https://github.com/bioperl/bioperl-live/issues
84  
85 =head1 AUTHOR - Jason Stajich
86  
87 Email jason@bioperl.org
88  
89 =head1 CONTRIBUTORS
90  
91 Aaron Mackey amackey@virginia.edu
92 Sendu Bala bix@sendu.me.uk
93 Mark A. Jensen maj@fortinbras.us
94  
95 =head1 APPENDIX
96  
97 The rest of the documentation details each of the object methods.
98 Internal methods are usually preceded with a _
99  
100 =cut
101  
102  
103 # Let the code begin...
104  
105  
106 package Bio::Tree::Tree;
107 79 $Bio::Tree::Tree::VERSION = '1.7.8';
108 79 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
109  
110 # Object preamble - inherits from Bio::Root::Root
111  
112  
113 79 ▶use base qw(Bio::Root::Root Bio::Tree::TreeI Bio::Tree::TreeFunctionsI);
Subroutine BEGIN: called CC=1 SCAR=0.0
114  
115 =head2 new
116  
117 Title : new
118 Usage : my $obj = Bio::Tree::Tree->new();
119 Function: Builds a new Bio::Tree::Tree object
120 Returns : Bio::Tree::Tree
121 Args : -root => L<Bio::Tree::NodeI> object which is the root
122 OR
123 -node => L<Bio::Tree::NodeI> object from which the root will be
124 determined
125
126 -nodelete => boolean, whether or not to try and cleanup all
127 the nodes when this this tree goes out of scope.
128 -id => optional tree ID
129 -score => optional tree score value
130  
131 =cut
132  
133 571 ▶sub new {
Subroutine new: called CC=13 SCAR=26.5
Pod documented
134 571 my ($class, @args) = @_;
135
136 571 my $self = $class->SUPER::new(@args);
137 571 $self->{'_rootnode'} = undef;
138 571 $self->{'_maxbranchlen'} = 0;
139 571 $self->_register_for_cleanup(\&cleanup_tree);
140 571 my ($root, $node, $nodel, $id, $score) =
141 $self->_rearrange([qw(ROOT NODE NODELETE ID SCORE)], @args);
142
143 571 ▶ if ($node && ! $root) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node and not $root) 211 360 571
Condition66%2/3
$node and not $root
!ll&&!rl&&r
3600211
MC/DC50%1/2
$node and not $root
$node not $root
Truth table66%2/3
A and not(B)
A= $nodeB= not $root
ABresult
0X0
100
111
144 211 ▶ $self->throw("Must supply a Bio::Tree::NodeI") unless ref($node) && $node->isa('Bio::Tree::NodeI');
Branch: 1 branch
BranchTrueFalseTotal
unless ref $node and $node->isa("Bio::Tree::NodeI") 0 211 211
Condition33%1/3
ref $node and $node->isa("Bio::Tree::NodeI")
!ll&&!rl&&r
00211
MC/DC0%0/2
ref $node and $node->isa("Bio::Tree::NodeI")
ref $node $node->isa("Bio::Tree::NodeI")
Truth table33%1/3
A and B
A= ref $nodeB= $node->isa("Bio::Tree::NodeI")
ABresult
0X0
100
111
145 211 my @lineage = $self->get_lineage_nodes($node);
146 211 ▶ $root = shift(@lineage) || $node;
Condition33%1/3
shift @lineage || $node
l!l&&r!l&&!r
21100
MC/DC0%0/2
shift @lineage || $node
shift @lineage $node
Truth table33%1/3
A || B
A= shift @lineageB= $node
ABresult
1X1
011
000
147
148 # to stop us pulling in entire database of a Bio::Taxon when we later do
149 # get_nodes() or similar, specifically set ancestor() for each node
150 211 ▶ if ($node->isa('Bio::Taxon')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa("Bio::Taxon")) 211 0 211
151 211 ▶ push(@lineage, $node) unless $node eq $root;
Branch: 1 branch
BranchTrueFalseTotal
unless $node eq $root 211 0 211
152 211 my $ancestor = $root;
153 211 foreach my $lineage_node (@lineage) {
154 1925 $lineage_node->ancestor($ancestor);
155 1925 } continue { $ancestor = $lineage_node; }
156 }
157 }
158 571 ▶ if ($root) {
Branch: 1 branch
BranchTrueFalseTotal
if ($root) 371 200 571
159 371 $self->set_root_node($root);
160 }
161
162 571 ▶ $self->nodelete($nodel || 0);
Condition100%2/2
$nodel || 0
l!l
2569
MC/DC100%1/1
$nodel || 0
$nodel
Truth table100%2/2
A
A= $nodel
Aresult
11
00
163 571 ▶ $self->id($id) if defined $id;
Branch: 1 branch
BranchTrueFalseTotal
if defined $id 13 558 571
164 571 ▶ $self->score($score) if defined $score;
Branch: 1 branch
BranchTrueFalseTotal
if defined $score 0 571 571
165 571 return $self;
166 }
167  
168  
169 =head2 nodelete
170  
171 Title : nodelete
172 Usage : $obj->nodelete($newval)
173 Function: Get/Set Boolean whether or not to delete the underlying
174 nodes when it goes out of scope. By default this is false
175 meaning trees are cleaned up.
176 Returns : boolean
177 Args : on set, new boolean value
178  
179 =cut
180  
181 993 ▶sub nodelete {
Subroutine nodelete: called CC=2 SCAR=6.9
Pod documented
182 993 my $self = shift;
183 993 ▶ return $self->{'nodelete'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 571 422 993
184 422 return $self->{'nodelete'};
185 }
186  
187  
188 =head2 get_nodes
189  
190 Title : get_nodes
191 Usage : my @nodes = $tree->get_nodes()
192 Function: Return list of Bio::Tree::NodeI objects
193 Returns : array of Bio::Tree::NodeI objects
194 Args : (named values) hash with one value
195 order => 'b|breadth' first order or 'd|depth' first order
196 sortby => [optional] "height", "creation", "alpha", "revalpha",
197 or coderef to be used to sort the order of children nodes. See L<Bio::Tree::Node> for details
198  
199 =cut
200  
201 939 ▶sub get_nodes {
Subroutine get_nodes: called CC=7 SCAR=19.5
Pod documented
202 939 my ($self, @args) = @_;
203 939 my ($order, $sortby) = $self->_rearrange([qw(ORDER SORTBY)], @args);
204 939 ▶ $order ||= 'depth';
Condition100%2/2
$order ||= "depth"
l!l
426513
MC/DC100%1/1
$order ||= "depth"
$order
Truth table100%2/2
A
A= $order
Aresult
11
00
205 939 ▶ $sortby ||= 'none';
Condition100%2/2
$sortby ||= "none"
l!l
442497
MC/DC100%1/1
$sortby ||= "none"
$sortby
Truth table100%2/2
A
A= $sortby
Aresult
11
00
206  
207 939 my @children;
208 939 my $node = $self->get_root_node;
209 939 ▶ if ($node) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node) 931 8 939
210 931 ▶ if ($order =~ m/^b/oi) { # breadth-first
Branch: 2 branches
BranchTrueFalseTotal
if ($order =~ /^b/io) { } 414 517 931
elsif ($order =~ /^d/io) { } 517 0 517
211 414 @children = ($node);
212 414 my @to_process = ($node);
213 414 ▶ while( @to_process ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@to_process) 7822 414 8236
214 7822 my $n = shift @to_process;
215 7822 my @c = $n->each_Descendent($sortby);
216 7822 push @children, @c;
217 7822 push @to_process, @c;
218 }
219 } elsif ($order =~ m/^d/oi) { # depth-first
220 517 @children = ($node, $node->get_all_Descendents($sortby));
221 } else {
222 0 $self->verbose(1);
223 0 $self->warn("specified an order '$order' which I don't understan\n");
224 }
225 }
226  
227 939 return @children;
228 }
229  
230  
231 =head2 get_root_node
232  
233 Title : get_root_node
234 Usage : my $node = $tree->get_root_node();
235 Function: Get the Top Node in the tree, in this implementation
236 Trees only have one top node.
237 Returns : Bio::Tree::NodeI object
238 Args : none
239  
240 =cut
241  
242 2059 ▶sub get_root_node {
Subroutine get_root_node: called CC=1 SCAR=0.0
Pod documented
243 2059 my ($self) = @_;
244 2059 return $self->{'_rootnode'};
245 }
246  
247  
248 =head2 set_root_node
249  
250 Title : set_root_node
251 Usage : $tree->set_root_node($node)
252 Function: Set the Root Node for the Tree
253 Returns : Bio::Tree::NodeI
254 Args : Bio::Tree::NodeI
255  
256 =cut
257  
258 388 ▶sub set_root_node {
Subroutine set_root_node: called CC=4 SCAR=16.1
Pod documented
259 388 my $self = shift;
260 388 ▶ if ( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 388 0 388
261 388 my $value = shift;
262 388 ▶ if ( defined $value && ! $value->isa('Bio::Tree::NodeI') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value and not $value->isa("Bio::Tree::NodeI")) 0 388 388
Condition33%1/3
defined $value and not $value->isa("Bio::Tree::NodeI")
!ll&&!rl&&r
03880
MC/DC0%0/2
defined $value and not $value->isa("Bio::Tree::NodeI")
defined $value not $value->isa("Bio::Tree::NodeI")
Truth table33%1/3
A and not(B)
A= defined $valueB= not $value->isa("Bio::Tree::NodeI")
ABresult
0X0
100
111
263 0 $self->warn("Trying to set the root node to $value which is not a Bio::Tree::NodeI");
264 0 return $self->get_root_node;
265 }
266 388 $self->{'_rootnode'} = $value;
267 }
268 388 return $self->get_root_node;
269 }
270  
271  
272 =head2 total_branch_length
273  
274 Title : total_branch_length
275 Usage : my $size = $tree->total_branch_length
276 Function: Returns the sum of the length of all branches
277 Returns : real
278 Args : none
279  
280 =cut
281  
282 13 ▶sub total_branch_length { shift->subtree_length }
Subroutine total_branch_length: called CC=1 SCAR=0.0
Pod documented
283  
284  
285 =head2 subtree_length
286  
287 Title : subtree_length
288 Usage : my $subtree_size = $tree->subtree_length($internal_node)
289 Function: Returns the sum of the length of all branches in a subtree
290 under the node. Calculates the size of the whole tree
291 without an argument (but only if root node is defined)
292 Returns : real or undef
293 Args : Bio::Tree::NodeI object, defaults to the root node
294  
295 =cut
296  
297 15 ▶sub subtree_length {
Subroutine subtree_length: called CC=5 SCAR=16.2
Pod documented
298 15 my $tree = shift;
299 15 ▶ my $node = shift || $tree->get_root_node;
Condition66%2/3
shift() || $tree->get_root_node
l!l&&r!l&&!r
1140
MC/DC0%0/2
shift() || $tree->get_root_node
shift() $tree->get_root_node
Truth table66%2/3
A || B
A= shift()B= $tree->get_root_node
ABresult
1X1
011
000
300 15 ▶ return unless $node;
Branch: 1 branch
BranchTrueFalseTotal
unless $node 0 15 15
301 15 my $sum = 0;
302 15 for ( $node->get_all_Descendents ) {
303 534 ▶ $sum += $_->branch_length || 0;
Condition100%2/2
$_->branch_length || 0
l!l
5268
MC/DC100%1/1
$_->branch_length || 0
$_->branch_length
Truth table100%2/2
A
A= $_->branch_length
Aresult
11
00
304 }
305 15 return $sum;
306 }
307  
308  
309 =head2 id
310  
311 Title : id
312 Usage : my $id = $tree->id();
313 Function: An id value for the tree
314 Returns : scalar
315 Args : [optional] new value to set
316  
317 =cut
318  
319 61 ▶sub id {
Subroutine id: called CC=2 SCAR=6.9
Pod documented
320 61 my ($self, $val) = @_;
321 61 ▶ if ( defined $val ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val) 55 6 61
322 55 $self->{'_treeid'} = $val;
323 }
324 61 return $self->{'_treeid'};
325 }
326  
327  
328 =head2 score
329  
330 Title : score
331 Usage : $obj->score($newval)
332 Function: Sets the associated score with this tree
333 This is a generic slot which is probably best used
334 for log likelihood or other overall tree score
335 Returns : value of score
336 Args : newvalue (optional)
337  
338 =cut
339  
340 126 ▶sub score {
Subroutine score: called CC=2 SCAR=6.9
Pod documented
341 126 my ($self, $val) = @_;
342 126 ▶ if ( defined $val ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val) 7 119 126
343 7 $self->{'_score'} = $val;
344 }
345 126 return $self->{'_score'};
346 }
347  
348  
349 # decorated interface TreeI Implements this
350  
351 =head2 height
352  
353 Title : height
354 Usage : my $height = $tree->height
355 Function: Gets the height of tree - this LOG_2($number_nodes)
356 WARNING: this is only true for strict binary trees. The TreeIO
357 system is capable of building non-binary trees, for which this
358 method will currently return an incorrect value!!
359 Returns : integer
360 Args : none
361  
362 =head2 number_nodes
363  
364 Title : number_nodes
365 Usage : my $size = $tree->number_nodes
366 Function: Returns the number of nodes in the tree
367 Returns : integer
368 Args : none
369  
370 =head2 as_text
371  
372 Title : as_text
373 Usage : my $tree_as_string = $tree->as_text($format)
374 Function: Returns the tree as a string representation in the
375 desired format, e.g.: 'newick', 'nhx' or 'tabtree' (the default)
376 Returns : scalar string
377 Args : format type as specified by Bio::TreeIO
378 Note : This method loads the Bio::TreeIO::$format module
379 on the fly, and commandeers the _write_tree_Helper
380 routine therein to create the tree string.
381  
382 =cut
383  
384 42 ▶sub as_text {
Subroutine as_text: called CC=4 SCAR=13.9
Pod documented
385 42 my $self = shift;
386 42 ▶ my $format = shift || 'tabtree';
Condition50%1/2
shift() || 'tabtree'
l!l
420
MC/DC0%0/1
shift() || 'tabtree'
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
387 42 ▶ my $params_input = shift || {};
Condition100%2/2
shift() || {}
l!l
537
MC/DC100%1/1
shift() || {}
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
388  
389 42 my $iomod = "Bio::TreeIO::$format";
390 42 $self->_load_module($iomod);
391  
392 42 my $string = '';
393 42 ▶ open my $fh, '>', \$string or $self->throw("Could not write '$string' as file: $!");
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", \$string or $self->throw("Could not write '${string}' as file: $!") 42 0 42
394 42 my $test = $iomod->new( -format => $format, -fh => $fh );
395  
396 # Get the default params for the given IO module.
397 42 $test->set_params($params_input);
398  
399 42 $test->write_tree($self);
400 42 close $fh;
401 42 return $string;
402 }
403  
404  
405 =head2 Methods for associating Tag/Values with a Tree
406  
407 These methods associate tag/value pairs with a Tree
408  
409 =head2 set_tag_value
410  
411 Title : set_tag_value
412 Usage : $tree->set_tag_value($tag,$value)
413 $tree->set_tag_value($tag,@values)
414 Function: Sets a tag value(s) to a tree. Replaces old values.
415 Returns : number of values stored for this tag
416 Args : $tag - tag name
417 $value - value to store for the tag
418  
419 =cut
420  
421 1 ▶sub set_tag_value {
Subroutine set_tag_value: called CC=3 SCAR=11.7
Pod documented
422 1 my ($self, $tag, @values) = @_;
423 1 ▶ if ( ! defined $tag || ! scalar @values ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $tag and scalar @values) 0 1 1
Condition33%1/3
defined $tag and scalar @values
!ll&&!rl&&r
001
MC/DC0%0/2
defined $tag and scalar @values
defined $tag scalar @values
Truth table33%1/3
A and B
A= defined $tagB= scalar @values
ABresult
0X0
100
111
424 0 $self->warn("cannot call set_tag_value with an undefined value");
425 }
426 1 $self->remove_tag ($tag);
427 1 map { push @{$self->{'_tags'}->{$tag}}, $_ } @values;
428 1 return scalar @{$self->{'_tags'}->{$tag}};
429 }
430  
431  
432 =head2 add_tag_value
433  
434 Title : add_tag_value
435 Usage : $tree->add_tag_value($tag,$value)
436 Function: Adds a tag value to a tree
437 Returns : number of values stored for this tag
438 Args : $tag - tag name
439 $value - value to store for the tag
440  
441 =cut
442  
443 31 ▶sub add_tag_value {
Subroutine add_tag_value: called CC=3 SCAR=12.0
Pod documented
444 31 my ($self, $tag, $value) = @_;
445 31 ▶ if ( ! defined $tag || ! defined $value ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $tag and defined $value) 0 31 31
Condition33%1/3
defined $tag and defined $value
!ll&&!rl&&r
0031
MC/DC0%0/2
defined $tag and defined $value
defined $tag defined $value
Truth table33%1/3
A and B
A= defined $tagB= defined $value
ABresult
0X0
100
111
446 0 $self->warn("cannot call add_tag_value with an undefined value");
447 }
448 31 push @{$self->{'_tags'}->{$tag}}, $value;
449 31 return scalar @{$self->{'_tags'}->{$tag}};
450 }
451  
452  
453 =head2 remove_tag
454  
455 Title : remove_tag
456 Usage : $tree->remove_tag($tag)
457 Function: Remove the tag and all values for this tag
458 Returns : boolean representing success (0 if tag does not exist)
459 Args : $tag - tagname to remove
460  
461 =cut
462  
463 3 ▶sub remove_tag {
Subroutine remove_tag: called CC=2 SCAR=6.9
Pod documented
464 3 my ($self, $tag) = @_;
465 3 ▶ if ( exists $self->{'_tags'}->{$tag} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"_tags"}{$tag}) 1 2 3
466 1 $self->{'_tags'}->{$tag} = undef;
467 1 delete $self->{'_tags'}->{$tag};
468 1 return 1;
469 }
470 2 return 0;
471 }
472  
473  
474 =head2 remove_all_tags
475  
476 Title : remove_all_tags
477 Usage : $tree->remove_all_tags()
478 Function: Removes all tags
479 Returns : None
480 Args : None
481  
482 =cut
483  
484 1 ▶sub remove_all_tags {
Subroutine remove_all_tags: called CC=1 SCAR=0.0
Pod documented
485 1 my ($self) = @_;
486 1 $self->{'_tags'} = {};
487 1 return;
488 }
489  
490  
491 =head2 get_all_tags
492  
493 Title : get_all_tags
494 Usage : my @tags = $tree->get_all_tags()
495 Function: Gets all the tag names for this Tree
496 Returns : Array of tagnames
497 Args : None
498  
499 =cut
500  
501 14 ▶sub get_all_tags {
Subroutine get_all_tags: called CC=2 SCAR=6.9
Pod documented
502 14 my ($self) = @_;
503 14 ▶ my @tags = sort keys %{$self->{'_tags'} || {}};
Condition100%2/2
$self->{'_tags'} || {}
l!l
131
MC/DC100%1/1
$self->{'_tags'} || {}
$self->{'_tags'}
Truth table100%2/2
A
A= $self->{'_tags'}
Aresult
11
00
504 14 return @tags;
505 }
506  
507  
508 =head2 get_tag_values
509  
510 Title : get_tag_values
511 Usage : my @values = $tree->get_tag_values($tag)
512 Function: Gets the values for given tag ($tag)
513 Returns : Array of values or empty list if tag does not exist
514 Args : $tag - tag name
515  
516 =cut
517  
518 47 ▶sub get_tag_values {
Subroutine get_tag_values: called CC=4 SCAR=13.9
Pod documented
519 47 my ($self, $tag) = @_;
520 44 ▶ return wantarray ? @{$self->{'_tags'}->{$tag} || []} :
Condition100%2/2
$self->{'_tags'}{$tag} || []
l!l
431
MC/DC100%1/1
$self->{'_tags'}{$tag} || []
$self->{'_tags'}{$tag}
Truth table100%2/2
A
A= $self->{'_tags'}{$tag}
Aresult
11
00
521 47 ▶ (@{$self->{'_tags'}->{$tag} || []})[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 44 3 47
Condition50%1/2
$self->{'_tags'}{$tag} || []
l!l
30
MC/DC0%0/1
$self->{'_tags'}{$tag} || []
$self->{'_tags'}{$tag}
Truth table50%1/2
A
A= $self->{'_tags'}{$tag}
Aresult
11
00
522 }
523  
524  
525 =head2 has_tag
526  
527 Title : has_tag
528 Usage : $tree->has_tag($tag)
529 Function: Boolean test if tag exists in the Tree
530 Returns : Boolean
531 Args : $tag - tagname
532  
533 =cut
534  
535 4 ▶sub has_tag {
Subroutine has_tag: called CC=1 SCAR=0.0
Pod documented
536 4 my ($self, $tag) = @_;
537 4 return exists $self->{'_tags'}->{$tag};
538 }
539  
540  
541 # safe tree clone that doesn't seg fault
542  
543 =head2 clone
544  
545 Title : clone
546 Alias : _clone
547 Usage : $tree_copy = $tree->clone();
548 $subtree_copy = $tree->clone($internal_node);
549 Function: Safe tree clone that doesn't segfault
550 Returns : Bio::Tree::Tree object
551 Args : [optional] $start_node, Bio::Tree::Node object
552  
553 =cut
554  
555 340 ▶sub clone {
Subroutine clone: called CC=5 SCAR=16.2
Pod documented
556 340 my ($self, $parent, $parent_clone) = @_;
557 340 ▶ $parent ||= $self->get_root_node;
Condition66%2/3
$parent ||= $self->get_root_node
l!l&&r!l&&!r
324160
MC/DC0%0/2
$parent ||= $self->get_root_node
$parent $self->get_root_node
Truth table66%2/3
A ||= B
A= $parentB= $self->get_root_node
ABresult
1X1
011
000
558 340 ▶ $parent_clone ||= $self->_clone_node($parent);
Condition66%2/3
$parent_clone ||= $self->_clone_node($parent)
l!l&&r!l&&!r
324160
MC/DC0%0/2
$parent_clone ||= $self->_clone_node($parent)
$parent_clone $self->_clone_node($parent)
Truth table66%2/3
A ||= B
A= $parent_cloneB= $self->_clone_node($parent)
ABresult
1X1
011
000
559  
560 340 foreach my $node ($parent->each_Descendent()) {
561 324 my $child = $self->_clone_node($node);
562 324 $child->ancestor($parent_clone);
563 324 $self->_clone($node, $child);
564 }
565 340 ▶ $parent->ancestor && return;
Branch: 1 branch
BranchTrueFalseTotal
$parent->ancestor and return 324 16 340
566  
567 16 my $tree = $self->new(-root => $parent_clone);
568 16 return $tree;
569 }
570  
571  
572 # -- private internal methods --
573  
574 422 ▶sub cleanup_tree {
Subroutine cleanup_tree: called CC=3 SCAR=11.0
Pod undocumented
575 422 my $self = shift;
576 422 ▶ unless( $self->nodelete ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->nodelete) 420 2 422
577 420 for my $node ($self->get_nodes(-order => 'b', -sortby => 'none')) {
578 7810 $node->node_cleanup;
579 }
580 }
581 422 $self->{'_rootnode'} = undef;
582 }
583  
584 79 1;
« Bio/Search/Hit/BlastPullHit.pm ↑ Summary Bio/Index/BlastTable.pm »