Bio/Tree/Statistics.pm

filter: Statementstmt 95.4% 313 / 328 Branchbran 81.2% 91 / 112 Conditioncond 42.2% 30 / 71 MC/DCmcdc 6.3% 3 / 47 Subroutinesub 96.1% 25 / 26 Podpod 100% 16 / 16 totaltotal 79.6% 478 / 600 CC 105 SCAR 20.5
CC
105
Cov
85%
transfer_bootstrap_expectation
15.1
fitch
12.0
fitch_up
12.0
CRAP 7.8
« Bio/Search/HSP/BlastPullHSP.pm ↑ Summary Bio/Tools/Phylo/Phylip/ProtDist.pm »
1 #
2 # BioPerl module for Bio::Tree::Statistics
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 =head1 NAME
15  
16 Bio::Tree::Statistics - Calculate certain statistics for a Tree
17  
18 =head1 SYNOPSIS
19  
20 use Bio::Tree::Statistics;
21  
22 =head1 DESCRIPTION
23  
24 This should be where Tree statistics are calculated. It was
25 previously where statistics from a Coalescent simulation.
26  
27 It now contains several methods for calculating L<Tree-Trait
28 statistics>.
29  
30 =head1 FEEDBACK
31  
32 =head2 Mailing Lists
33  
34 User feedback is an integral part of the evolution of this and other
35 Bioperl modules. Send your comments and suggestions preferably to
36 the Bioperl mailing list. Your participation is much appreciated.
37  
38 bioperl-l@bioperl.org - General discussion
39 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
40  
41 =head2 Support
42  
43 Please direct usage questions or support issues to the mailing list:
44  
45 I<bioperl-l@bioperl.org>
46  
47 rather than to the module maintainer directly. Many experienced and
48 reponsive experts will be able look at the problem and quickly
49 address it. Please include a thorough description of the problem
50 with code and data examples if at all possible.
51  
52 =head2 Reporting Bugs
53  
54 Report bugs to the Bioperl bug tracking system to help us keep track
55 of the bugs and their resolution. Bug reports can be submitted via
56 the web:
57  
58 https://github.com/bioperl/bioperl-live/issues
59  
60 =head1 AUTHOR - Jason Stajich
61  
62 Email jason AT bioperl.org
63  
64 =head1 CONTRIBUTORS
65  
66 Heikki Lehvaslaiho, heikki at bioperl dot org
67  
68 =head1 APPENDIX
69  
70 The rest of the documentation details each of the object methods.
71 Internal methods are usually preceded with a _
72  
73 =cut
74  
75  
76 # Let the code begin...
77  
78  
79 package Bio::Tree::Statistics;
80 3 $Bio::Tree::Statistics::VERSION = '1.7.8';
81 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
82  
83  
84 3 ▶use base qw(Bio::Root::Root);
Subroutine BEGIN: called CC=1 SCAR=0.0
85  
86 =head2 new
87  
88 Title : new
89 Usage : my $obj = Bio::Tree::Statistics->new();
90 Function: Builds a new Bio::Tree::Statistics object
91 Returns : Bio::Tree::Statistics
92 Args :
93  
94 =head2 assess_bootstrap
95  
96 Title : assess_bootstrap
97 Usage : my $tree_with_bs = $stats->assess_bootstrap(\@bs_trees,$guide_tree);
98 Function: Calculates the bootstrap for internal nodes based on the percentage
99 of times \@bs_trees agree with each internal node
100 Returns : L<Bio::Tree::TreeI>
101 Args : Arrayref of L<Bio::Tree::TreeI>s
102 Guide tree, L<Bio::Tree::TreeI>s
103  
104 =cut
105  
106 1 ▶sub assess_bootstrap{
Subroutine assess_bootstrap: called CC=9 SCAR=22.3
Pod documented
107 1 my ($self,$bs_trees,$guide_tree) = @_;
108 1 my @consensus;
109  
110 1 ▶ if(!defined($bs_trees) || ref($bs_trees) ne 'ARRAY'){
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $bs_trees or ref $bs_trees ne "ARRAY") 0 1 1
Condition33%1/3
not defined $bs_trees or ref $bs_trees ne "ARRAY"
l!l&&r!l&&!r
001
MC/DC0%0/2
not defined $bs_trees or ref $bs_trees ne "ARRAY"
not defined $bs_trees ref $bs_trees ne "ARRAY"
Truth table33%1/3
not(A) or B
A= not defined $bs_treesB= ref $bs_trees ne "ARRAY"
ABresult
1X1
011
000
111 0 die "ERROR: second parameter in assess_bootstrap() must be a list";
112 }
113 1 my $num_bs_trees = scalar(@$bs_trees);
114 1 ▶ if($num_bs_trees < 1){
Branch: 1 branch
BranchTrueFalseTotal
if ($num_bs_trees < 1) 0 1 1
115 0 die "ERROR: no bootstrap trees were passed to assess_bootstrap()";
116 }
117  
118 # internal nodes are defined by their children
119  
120 1 my (%lookup,%internal);
121 1 my $i = 0;
122 1 for my $tree ( $guide_tree, @$bs_trees ) {
123 # Do this as a top down approach, can probably be
124 # improved by caching internal node states, but not going
125 # to worry about it right now.
126  
127 11 my @allnodes = $tree->get_nodes;
128 11 my @internalnodes = grep { ! $_->is_Leaf } @allnodes;
129 11 for my $node ( @internalnodes ) {
130 704 my @tips = sort map { $_->id }
131 165 grep { $_->is_Leaf() } $node->get_all_Descendents;
132 165 my $id = "(".join(",", @tips).")";
133 165 ▶ if( $i == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i == 0) { } 15 150 165
134 15 $internal{$id} = $node->internal_id;
135 } else {
136 150 $lookup{$id}++;
137 }
138 }
139 11 $i++;
140 }
141 #my @save; # unsure why this variable is needed
142 1 for my $l ( keys %lookup ) {
143 47 ▶ if( defined $internal{$l} ) {#&& $lookup{$l} > $min_seen ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $internal{$l}) 13 34 47
144 13 my $intnode = $guide_tree->find_node(-internal_id => $internal{$l});
145 13 $intnode->bootstrap(sprintf("%d",100 * $lookup{$l} / $num_bs_trees));
146 }
147 }
148 1 return $guide_tree;
149 }
150  
151 =head2 transfer_bootstrap_expectation
152  
153 Title : transfer_bootstrap_expectation
154 Usage : my $tree_with_bs = $stats->transfer_bootstrap_expectation(\@bs_trees,$guide_tree);
155 Function: Calculates the Transfer Bootstrap Expectation (TBE) for internal nodes based on
156 the methods outlined in Lemoine et al, Nature, 2018.
157 Currently experimental.
158 Returns : L<Bio::Tree::TreeI>
159 Args : Arrayref of L<Bio::Tree::TreeI>s
160 Guide tree, L<Bio::Tree::TreeI>s
161  
162 =cut
163  
164 1 ▶sub transfer_bootstrap_expectation{
Subroutine transfer_bootstrap_expectation: called CC=15 SCAR=27.1
Pod documented
165 1 my ($self,$bs_trees,$guide_tree) = @_;
166  
167 1 ▶ if(!defined($bs_trees) || ref($bs_trees) ne 'ARRAY'){
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $bs_trees or ref $bs_trees ne "ARRAY") 0 1 1
Condition33%1/3
not defined $bs_trees or ref $bs_trees ne "ARRAY"
l!l&&r!l&&!r
001
MC/DC0%0/2
not defined $bs_trees or ref $bs_trees ne "ARRAY"
not defined $bs_trees ref $bs_trees ne "ARRAY"
Truth table33%1/3
not(A) or B
A= not defined $bs_treesB= ref $bs_trees ne "ARRAY"
ABresult
1X1
011
000
168 0 die "ERROR: second parameter in assess_bootstrap() must be a list";
169 }
170 1 my $num_bs_trees = scalar(@$bs_trees);
171 1 ▶ if($num_bs_trees < 1){
Branch: 1 branch
BranchTrueFalseTotal
if ($num_bs_trees < 1) 0 1 1
172 0 die "ERROR: no bootstrap trees were passed to ".(caller(0))[3];
173 }
174  
175 # internal nodes are defined by their children
176 1 my %internal = ();
177 1 my %leafNameId = ();
178 1 my @idLookup = ();
179 1 my @internalLookup = ();
180 1 my @tree = ($guide_tree, @$bs_trees);
181 1 my $numTrees = scalar(@tree);
182 1 ▶ for(my $i = 0; $i < $numTrees; $i++){ # guide tree's index is $i==0
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $numTrees) 11 1 12
183 # Do this as a top down approach, can probably be
184 # improved by caching internal node states, but not going
185 # to worry about it right now.
186  
187 11 my @allnodes = $tree[$i]->get_nodes;
188 11 my @internalnodes = grep { ! $_->is_Leaf } @allnodes;
189 11 for my $node ( @internalnodes ) {
190 704 my @tips = sort map { $_->id }
191 165 grep { $_->is_Leaf() } $node->get_all_Descendents;
192 165 my $id = join(",", @tips);
193 # Map the concatenated-leaf ID to the internal ID on the guide tree
194 165 ▶ if( $i == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i == 0) 15 150 165
195 15 $internal{$id} = $node->internal_id;
196 15 $leafNameId{$node->internal_id} = $id;
197 }
198  
199 # Record the tips for each tree's internal node
200 # ID lookup (concatenated string of leaf names)
201 165 $idLookup[$i]{$id} = \@tips;
202 # Internal ID lookup
203 165 $internalLookup[$i]{$internal{$id}} = \@tips;
204 }
205 }
206  
207 # Find the average distance from branch b to all
208 # bootstrap trees' branches b*
209 1 my @id = sort keys %internal;
210 1 my $numIds = @id;
211 # Loop through all internal nodes of the guide tree
212 1 ▶ for(my $j=0; $j<$numIds; $j++){
Branch: 1 branch
BranchTrueFalseTotal
if ($j < $numIds) 15 1 16
213 15 my $refNode = $guide_tree->find_node(-internal_id => $internal{$id[$j]});
214 15 my $refNodeId = $refNode->internal_id;
215 15 my $refJoinId = $leafNameId{$refNodeId};
216 15 my $refLeaves = $idLookup[0]{$refJoinId};
217 15 my %refLeafIndex = map{$_=>1} @$refLeaves;
218 #next if(!defined($refLeaves));
219  
220 # For each internal node, start calculating for
221 # an average TBE distance.
222 15 my $nodeTbeTotal = 0;
223
224 # Loop through all bootstrap trees, skipping the 0th
225 # tree which is the guide tree.
226 15 ▶ for(my $i=1;$i<$numTrees;$i++){
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $numTrees) 150 15 165
227  
228 # Find the right branch to bootstrap with. The right
229 # branch will be the one that has the smallest
230 # TBE distance.
231 150 my @bsNode = grep {!$_->is_Leaf} $tree[$i]->get_nodes;
232 150 my $numBsIds = scalar(@bsNode);
233 150 my $minDistance = ~0; # large int
234 150 ▶ for(my $k=0;$k<$numBsIds;$k++){
Branch: 1 branch
BranchTrueFalseTotal
if ($k < $numBsIds) 2250 150 2400
235 9600 my @queryLeaves = sort map { $_->id }
236 2250 grep { $_->is_Leaf() } $bsNode[$k]->get_all_Descendents;
237  
238 2250 my %queryLeafIndex = map{$_=>1} @queryLeaves;
239  
240 # How many moves does it take to go from query to ref?
241 2250 my $dist=0;
242 2250 for my $queryLeaf(@queryLeaves){
243 9600 ▶ if(!$refLeafIndex{$queryLeaf}){
Branch: 1 branch
BranchTrueFalseTotal
unless ($refLeafIndex{$queryLeaf}) 7040 2560 9600
244 7040 $dist++;
245 }
246 }
247 2250 for my $refLeaf(@$refLeaves){
248 9600 ▶ if(!$queryLeafIndex{$refLeaf}){
Branch: 1 branch
BranchTrueFalseTotal
unless ($queryLeafIndex{$refLeaf}) 7040 2560 9600
249 7040 $dist++;
250 }
251 }
252  
253 2250 ▶ if($dist < $minDistance){
Branch: 1 branch
BranchTrueFalseTotal
if ($dist < $minDistance) 612 1638 2250
254 612 $minDistance = $dist;
255 }
256 }
257 150 $nodeTbeTotal += $minDistance;
258 }
259 15 my $avgTbe = $nodeTbeTotal / $numTrees;
260
261 # Calculate the average of all b to b* distances
262 # But it is also 1 - average.
263 15 my $numRefLeaves = scalar(@$refLeaves);
264 15 my $nodeTbe = 1 - $avgTbe/$numRefLeaves;
265 # Round to an integer
266 15 $refNode->bootstrap(sprintf("%0.0f",100 * $nodeTbe));
267 }
268
269 1 return $guide_tree;
270 }
271  
272  
273 =head2 cherries
274  
275 Example : cherries($tree, $node);
276 Description: Count number of paired leaf nodes
277 in a binary tree
278 Returns : integer
279 Exceptions :
280 Args : 1. Bio::Tree::TreeI object
281 2. Bio::Tree::NodeI object within the tree, optional
282  
283 Commonly used statistics assume a binary tree, but this methods
284 returns a value even for trees with polytomies.
285  
286 =cut
287  
288 22 ▶sub cherries ($;$) {
Subroutine cherries: called CC=6 SCAR=18.3
Pod documented
289 22 my $self = shift;
290 22 my $tree = shift;
291 22 ▶ my $node = shift || $tree->get_root_node;
Condition66%2/3
shift() || $tree->get_root_node
l!l&&r!l&&!r
2110
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
292  
293 22 my $cherries = 0;
294 22 my @descs = $node->each_Descendent;
295  
296 22 ▶ if ($descs[0]->is_Leaf and $descs[1]->is_Leaf) {
Branch: 1 branch
BranchTrueFalseTotal
if ($descs[0]->is_Leaf and $descs[1]->is_Leaf) { } 12 10 22
Condition66%2/3
$descs[0]->is_Leaf and $descs[1]->is_Leaf
!ll&&!rl&&r
10012
MC/DC50%1/2
$descs[0]->is_Leaf and $descs[1]->is_Leaf
$descs[0]->is_Leaf $descs[1]->is_Leaf
Truth table66%2/3
A and B
A= $descs[0]->is_LeafB= $descs[1]->is_Leaf
ABresult
0X0
100
111
297 12 ▶ if ($descs[3]) { #polytomy at leaf level
Branch: 1 branch
BranchTrueFalseTotal
if ($descs[3]) { } 0 12 12
298 0 $cherries = 0;
299 } else {
300 12 $cherries = 1;
301 }
302 } else {
303 # recurse
304 10 foreach my $desc (@descs) {
305 20 $cherries += $self->cherries($tree, $desc);
306 }
307 }
308 22 return $cherries;
309 }
310  
311  
312 =head2 Tree-Trait statistics
313  
314 The following methods produce descriptors of trait distribution among
315 leaf nodes within the trees. They require that a trait has been set
316 for each leaf node. The tag methods of Bio::Tree::Node are used to
317 store them as key/value pairs. In this way, one tree can store more
318 than one trait.
319  
320 Trees have method add_traits() to set trait values from a file. See the
321 add_trait() method in L<Bio::Tree::TreeFunctionsI>.
322  
323 =head2 fitch
324  
325 Example : fitch($tree, $key, $node);
326 Description: Calculates Parsimony Score (PS) and internal trait
327 values using the Fitch 1971 parsimony algorithm for
328 the subtree a defined by the (internal) node.
329 Node defaults to the root.
330 Returns : true on success
331 Exceptions : leaf nodes have to have the trait defined
332 Args : 1. Bio::Tree::TreeI object
333 2. trait name string
334 3. Bio::Tree::NodeI object within the tree, optional
335  
336 Runs first L<fitch_up> that calculates parsimony scores and then
337 L<fitch_down> that should resolve most of the trait/character state
338 ambiguities.
339  
340 Fitch, W.M., 1971. Toward defining the course of evolution: minimal
341 change for a specific tree topology. Syst. Zool. 20, 406-416.
342  
343 You can access calculated parsimony values using:
344  
345 $score = $node->->get_tag_values('ps_score');
346  
347 and the trait value with:
348  
349 $traitvalue = $node->->get_tag_values('ps_trait'); # only the first
350 @traitvalues = $node->->get_tag_values('ps_trait');
351  
352 Note that there can be more that one trait value, especially for the
353 root node.
354  
355 =cut
356  
357 0 ▶sub fitch {
Subroutine fitch: not called CC=3 SCAR=24.8
Pod documented
358 0 my $self = shift;
359 0 my $tree = shift;
360 0 ▶ my $key = shift || $self->throw("Trait name is needed");
Condition0%0/3
shift() || $self->throw('Trait name is needed')
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || $self->throw('Trait name is needed')
shift() $self->throw('Trait name is needed')
Truth table0%0/3
A || B
A= shift()B= $self->throw('Trait name is needed')
ABresult
1X1
011
000
361 0 ▶ my $node = shift || $tree->get_root_node;
Condition0%0/3
shift() || $tree->get_root_node
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || $tree->get_root_node
shift() $tree->get_root_node
Truth table0%0/3
A || B
A= shift()B= $tree->get_root_node
ABresult
1X1
011
000
362  
363 0 $self->fitch_up($tree, $key, $node);
364 0 $self->fitch_down($tree, $node);
365 }
366  
367  
368 =head2 ps
369  
370 Example : ps($tree, $key, $node);
371 Description: Calculates Parsimony Score (PS) from Fitch 1971
372 parsimony algorithm for the subtree as defined
373 by the (internal) node.
374 Node defaults to the root.
375 Returns : integer, 1 < PS < n, where n is number of branches
376 Exceptions : leaf nodes have to have the trait defined
377 Args : 1. Bio::Tree::TreeI object
378 2. trait name string
379 3. Bio::Tree::NodeI object within the tree, optional
380  
381 This is the first half of the Fitch algorithm that is enough for
382 calculating the resolved parsimony values. The trait/chararacter
383 states are commonly left in ambiguous state. To resolve them, run
384 L<fitch_down>.
385  
386 =cut
387  
388 2 ▶sub ps { shift->fitch_up(@_) }
Subroutine ps: called CC=1 SCAR=0.0
Pod documented
389  
390  
391 =head2 fitch_up
392  
393 Example : fitch_up($tree, $key, $node);
394 Description: Calculates Parsimony Score (PS) from the Fitch 1971
395 parsimony algorithm for the subtree as defined
396 by the (internal) node.
397 Node defaults to the root.
398 Returns : integer, 1< PS < n, where n is number of branches
399 Exceptions : leaf nodes have to have the trait defined
400 Args : 1. Bio::Tree::TreeI object
401 2. trait name string
402 3. Bio::Tree::NodeI object within the tree, optional
403  
404 This is a more generic name for L<ps> and indicates that it performs
405 the first bottom-up tree traversal that calculates the parsimony score
406 but usually leaves trait/character states ambiguous. If you are
407 interested in internal trait states, running L<fitch_down> should
408 resolve most of the ambiguities.
409  
410 =cut
411  
412 46 ▶sub fitch_up {
Subroutine fitch_up: called CC=11 SCAR=24.8
Pod documented
413 46 my $self = shift;
414 46 my $tree = shift;
415 46 ▶ my $key = shift || $self->throw("Trait name is needed");
Condition33%1/3
shift() || $self->throw('Trait name is needed')
l!l&&r!l&&!r
4600
MC/DC0%0/2
shift() || $self->throw('Trait name is needed')
shift() $self->throw('Trait name is needed')
Truth table33%1/3
A || B
A= shift()B= $self->throw('Trait name is needed')
ABresult
1X1
011
000
416 46 ▶ my $node = shift || $tree->get_root_node;
Condition66%2/3
shift() || $tree->get_root_node
l!l&&r!l&&!r
4510
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
417  
418 46 ▶ if ($node->is_Leaf) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->is_Leaf) 24 22 46
419 24 ▶ $self->throw ("ERROR: ". $node->internal_id. " needs a value for trait $key")
Branch: 1 branch
BranchTrueFalseTotal
unless $node->has_tag($key) 0 24 24
420 unless $node->has_tag($key);
421 24 $node->set_tag_value('ps_trait', $node->get_tag_values($key) );
422 24 $node->set_tag_value('ps_score', 0 );
423 24 return; # end of recursion
424 }
425  
426 22 foreach my $child ($node->each_Descendent) {
427 44 $self->fitch_up($tree, $key, $child);
428 }
429  
430 22 my %intersection;
431 my %union;
432 22 my $score;
433  
434 22 foreach my $child ($node->each_Descendent) {
435 44 foreach my $trait ($child->get_tag_values('ps_trait') ) {
436 48 ▶ $intersection{$trait}++ if $union{$trait};
Branch: 1 branch
BranchTrueFalseTotal
if $union{$trait} 17 31 48
437 48 $union{$trait}++;
438 }
439 44 $score += $child->get_tag_values('ps_score');
440 }
441  
442 22 ▶ if (keys %intersection) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %intersection) { } 17 5 22
443 17 $node->set_tag_value('ps_trait', keys %intersection);
444 17 $node->set_tag_value('ps_score', $score);
445 } else {
446 5 $node->set_tag_value('ps_trait', keys %union);
447 5 $node->set_tag_value('ps_score', $score+1);
448 }
449  
450 22 ▶ if ($self->verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->verbose) 0 22 22
451 0 print "-- node --------------------------\n";
452 0 print "iID: ", $node->internal_id, " (", $node->id, ")\n";
453 0 print "Trait: ", join (', ', $node->get_tag_values('ps_trait') ), "\n";
454 0 print "length :", scalar($node->get_tag_values('ps_score')) , "\n";
455 }
456 22 return scalar $node->get_tag_values('ps_score');
457 }
458  
459  
460 =head2 fitch_down
461  
462 Example : fitch_down($tree, $node);
463 Description: Runs the second pass from Fitch 1971
464 parsimony algorithm to resolve ambiguous
465 trait states left by first pass.
466 by the (internal) node.
467 Node defaults to the root.
468 Returns : true
469 Exceptions : dies unless the trait is defined in all nodes
470 Args : 1. Bio::Tree::TreeI object
471 2. Bio::Tree::NodeI object within the tree, optional
472  
473 Before running this method you should have ran L<fitch_up> (alias to
474 L<ps> ). Note that it is not guaranteed that all states are completely
475 resolved.
476  
477 =cut
478  
479 15 ▶sub fitch_down {
Subroutine fitch_down: called CC=8 SCAR=20.8
Pod documented
480 15 my $self = shift;
481 15 my $tree = shift;
482 15 ▶ my $node = shift || $tree->get_root_node;
Condition66%2/3
shift() || $tree->get_root_node
l!l&&r!l&&!r
1410
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
483  
484 15 my $key = 'ps_trait';
485 15 ▶ $self->throw ("ERROR: ". $node->internal_id. " needs a value for $key")
Branch: 1 branch
BranchTrueFalseTotal
unless $node->has_tag($key) 0 15 15
486 unless $node->has_tag($key);
487  
488 15 my $nodev;
489 15 foreach my $trait ($node->get_tag_values($key) ) {
490 19 $nodev->{$trait}++;
491 }
492  
493 15 foreach my $child ($node->each_Descendent) {
494 30 ▶ next if $child->is_Leaf; # end of recursion
Branch: 1 branch
BranchTrueFalseTotal
if $child->is_Leaf 16 14 30
495  
496 14 my $intersection;
497 14 foreach my $trait ($child->get_tag_values($key) ) {
498 17 ▶ $intersection->{$trait}++ if $nodev->{$trait};
Branch: 1 branch
BranchTrueFalseTotal
if $nodev->{$trait} 14 3 17
499 }
500  
501 14 $self->fitch_down($tree, $child);
502 14 $child->set_tag_value($key, keys %$intersection);
503 }
504 15 return 1; # success
505 }
506  
507  
508 =head2 persistence
509  
510 Example : persistence($tree, $node);
511 Description: Calculates the persistence
512 for node in the subtree defined by the (internal)
513 node. Node defaults to the root.
514 Returns : int, number of generations trait value has to remain same
515 Exceptions : all the nodes need to have the trait defined
516 Args : 1. Bio::Tree::TreeI object
517 2. Bio::Tree::NodeI object within the tree, optional
518  
519 Persistence measures the stability that the trait value has in a
520 tree. It expresses the number of generations the trait value remains
521 the same. All the decendants of the root in the same generation have
522 to share the same value.
523  
524 Depends on Fitch's parsimony score (PS).
525  
526 =cut
527  
528 18 ▶sub _persistence {
Subroutine _persistence: called CC=7 SCAR=19.6
529 18 my $self = shift;
530 18 my $tree = shift;
531 18 my $node = shift;
532 18 ▶ my $value = shift || $self->throw("Value is needed");
Condition33%1/3
shift() || $self->throw('Value is needed')
l!l&&r!l&&!r
1800
MC/DC0%0/2
shift() || $self->throw('Value is needed')
shift() $self->throw('Value is needed')
Truth table33%1/3
A || B
A= shift()B= $self->throw('Value is needed')
ABresult
1X1
011
000
533  
534  
535 18 my $key = 'ps_trait';
536  
537 18 ▶ $self->throw("Node is needed") unless $node->isa('Bio::Tree::NodeI');
Branch: 1 branch
BranchTrueFalseTotal
unless $node->isa("Bio::Tree::NodeI") 0 18 18
538  
539 18 ▶ return 0 unless $node->get_tag_values($key) eq $value; # wrong value
Branch: 1 branch
BranchTrueFalseTotal
unless $node->get_tag_values($key) eq $value 2 16 18
540 16 ▶ return 1 if $node->is_Leaf; # end of recursion
Branch: 1 branch
BranchTrueFalseTotal
if $node->is_Leaf 9 7 16
541  
542 7 my $persistence = 10000000; # an arbitrarily large number
543 7 foreach my $child ($node->each_Descendent) {
544 14 my $pers = $self->_persistence($tree, $child, $value);
545 14 ▶ $persistence = $pers if $pers < $persistence;
Branch: 1 branch
BranchTrueFalseTotal
if $pers < $persistence 7 7 14
546 }
547 7 return $persistence + 1;
548 }
549  
550 4 ▶sub persistence {
Subroutine persistence: called CC=3 SCAR=11.3
Pod documented
551 4 my $self = shift;
552 4 my $tree = shift;
553 4 ▶ my $node = shift || $tree->get_root_node;
Condition33%1/3
shift() || $tree->get_root_node
l!l&&r!l&&!r
400
MC/DC0%0/2
shift() || $tree->get_root_node
shift() $tree->get_root_node
Truth table33%1/3
A || B
A= shift()B= $tree->get_root_node
ABresult
1X1
011
000
554 4 ▶ $self->throw("Node is needed") unless $node->isa('Bio::Tree::NodeI');
Branch: 1 branch
BranchTrueFalseTotal
unless $node->isa("Bio::Tree::NodeI") 0 4 4
555  
556 4 my $key = 'ps_trait';
557 4 my $value = $node->get_tag_values($key);
558  
559 #calculate
560 4 my $persistence = $self->_persistence($tree, $node, $value);
561 4 $node->set_tag_value('persistance', $persistence);
562 4 return $persistence;
563 }
564  
565  
566 =head2 count_subclusters
567  
568 Example : count_clusters($tree, $node);
569 Description: Calculates the number of sub-clusters
570 in the subtree defined by the (internal)
571 node. Node defaults to the root.
572 Returns : int, count
573 Exceptions : all the nodes need to have the trait defined
574 Args : 1. Bio::Tree::TreeI object
575 2. Bio::Tree::NodeI object within the tree, optional
576  
577 Depends on Fitch's parsimony score (PS).
578  
579 =cut
580  
581 22 ▶sub _count_subclusters {
Subroutine _count_subclusters: called CC=6 SCAR=18.0
582 22 my $self = shift;
583 22 my $tree = shift;
584 22 my $node = shift;
585 22 ▶ my $value = shift || $self->throw("Value is needed");
Condition33%1/3
shift() || $self->throw('Value is needed')
l!l&&r!l&&!r
2200
MC/DC0%0/2
shift() || $self->throw('Value is needed')
shift() $self->throw('Value is needed')
Truth table33%1/3
A || B
A= shift()B= $self->throw('Value is needed')
ABresult
1X1
011
000
586  
587 22 my $key = 'ps_trait';
588  
589 22 ▶ $self->throw ("ERROR: ". $node->internal_id. " needs a value for trait $key")
Branch: 1 branch
BranchTrueFalseTotal
unless $node->has_tag($key) 0 22 22
590 unless $node->has_tag($key);
591  
592 22 ▶ if ($node->get_tag_values($key) eq $value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->get_tag_values($key) eq $value) 18 4 22
593 18 ▶ if ($node->get_tag_values('ps_score') == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->get_tag_values('ps_score') == 0) { } 9 9 18
594 9 return 0;
595 } else {
596 9 my $count = 0;
597 9 foreach my $child ($node->each_Descendent) {
598 18 $count += $self->_count_subclusters($tree, $child, $value);
599 }
600 9 return $count;
601 }
602 }
603 4 return 1;
604 }
605  
606 4 ▶sub count_subclusters {
Subroutine count_subclusters: called CC=3 SCAR=11.4
Pod documented
607 4 my $self = shift;
608 4 my $tree = shift;
609 4 ▶ my $node = shift || $tree->get_root_node;
Condition33%1/3
shift() || $tree->get_root_node
l!l&&r!l&&!r
400
MC/DC0%0/2
shift() || $tree->get_root_node
shift() $tree->get_root_node
Truth table33%1/3
A || B
A= shift()B= $tree->get_root_node
ABresult
1X1
011
000
610 4 ▶ $self->throw("Node is needed") unless $node->isa('Bio::Tree::NodeI');
Branch: 1 branch
BranchTrueFalseTotal
unless $node->isa("Bio::Tree::NodeI") 0 4 4
611  
612 4 my $key = 'ps_trait';
613 4 my $value = $node->get_tag_values($key);
614  
615 4 return $self->_count_subclusters($tree, $node, $value);
616 }
617  
618  
619 =head2 count_leaves
620  
621 Example : count_leaves($tree, $node);
622 Description: Calculates the number of leaves with same trait
623 value as root in the subtree defined by the (internal)
624 node. Requires an unbroken line of identical trait values.
625 Node defaults to the root.
626 Returns : int, number of leaves with this trait value
627 Exceptions : all the nodes need to have the trait defined
628 Args : 1. Bio::Tree::TreeI object
629 2. Bio::Tree::NodeI object within the tree, optional
630  
631 Depends on Fitch's parsimony score (PS).
632  
633 =cut
634  
635 204 ▶sub _count_leaves {
Subroutine _count_leaves: called CC=6 SCAR=18.1
636 204 my $self = shift;
637 204 my $tree = shift;
638 204 ▶ my $node = shift || $tree->get_root_node;
Condition33%1/3
shift() || $tree->get_root_node
l!l&&r!l&&!r
20400
MC/DC0%0/2
shift() || $tree->get_root_node
shift() $tree->get_root_node
Truth table33%1/3
A || B
A= shift()B= $tree->get_root_node
ABresult
1X1
011
000
639 204 my $value = shift;
640  
641 204 my $key = 'ps_trait';
642  
643 204 ▶ $self->throw ("ERROR: ". $node->internal_id. " needs a value for trait $key")
Branch: 1 branch
BranchTrueFalseTotal
unless $node->has_tag($key) 0 204 204
644 unless $node->has_tag($key);
645  
646 204 ▶ if ($node->get_tag_values($key) eq $value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->get_tag_values($key) eq $value) 184 20 204
647 #print $node->id, ": ", $node->get_tag_values($key), "\n";
648 184 ▶ return 1 if $node->is_Leaf; # end of recursion
Branch: 1 branch
BranchTrueFalseTotal
if $node->is_Leaf 117 67 184
649  
650 67 my $count = 0;
651 67 foreach my $child ($node->each_Descendent) {
652 134 $count += $self->_count_leaves($tree, $child, $value);
653 }
654 67 return $count;
655 }
656 20 return 0;
657 }
658  
659 6 ▶sub count_leaves {
Subroutine count_leaves: called CC=3 SCAR=11.4
Pod documented
660 6 my $self = shift;
661 6 my $tree = shift;
662 6 ▶ my $node = shift || $tree->get_root_node;
Condition33%1/3
shift() || $tree->get_root_node
l!l&&r!l&&!r
600
MC/DC0%0/2
shift() || $tree->get_root_node
shift() $tree->get_root_node
Truth table33%1/3
A || B
A= shift()B= $tree->get_root_node
ABresult
1X1
011
000
663 6 ▶ $self->throw("Node is needed") unless $node->isa('Bio::Tree::NodeI');
Branch: 1 branch
BranchTrueFalseTotal
unless $node->isa("Bio::Tree::NodeI") 0 6 6
664  
665 6 my $key = 'ps_trait';
666 6 my $value = $node->get_tag_values($key);
667  
668 6 return $self->_count_leaves($tree, $node, $value);
669 }
670  
671  
672 =head2 phylotype_length
673  
674 Example : phylotype_length($tree, $node);
675 Description: Sums up the branch lengths within phylotype
676 excluding the subclusters where the trait values
677 are different
678 Returns : float, length
679 Exceptions : all the nodes need to have the trait defined
680 Args : 1. Bio::Tree::TreeI object
681 2. Bio::Tree::NodeI object within the tree, optional
682  
683 Depends on Fitch's parsimony score (PS).
684  
685 =cut
686  
687 45 ▶sub _phylotype_length {
Subroutine _phylotype_length: called CC=7 SCAR=19.5
688 45 my $self = shift;
689 45 my $tree = shift;
690 45 my $node = shift;
691 45 my $value = shift;
692  
693 45 my $key = 'ps_trait';
694  
695 45 ▶ $self->throw ("ERROR: ". $node->internal_id. " needs a value for trait $key")
Branch: 1 branch
BranchTrueFalseTotal
unless $node->has_tag($key) 0 45 45
696 unless $node->has_tag($key);
697  
698 45 ▶ return 0 if $node->get_tag_values($key) ne $value;
Branch: 1 branch
BranchTrueFalseTotal
if $node->get_tag_values($key) ne $value 5 40 45
699 40 ▶ return $node->branch_length if $node->is_Leaf; # end of recursion
Branch: 1 branch
BranchTrueFalseTotal
if $node->is_Leaf 20 20 40
700  
701 20 my $length = 0;
702 20 foreach my $child ($node->each_Descendent) {
703 40 my $sub_len = $self->_phylotype_length($tree, $child, $value);
704 40 $length += $sub_len;
705 40 ▶ $length += $child->branch_length if not $child->is_Leaf and $sub_len;
Branch: 1 branch
BranchTrueFalseTotal
if not $child->is_Leaf and $sub_len 15 25 40
Condition100%3/3
not $child->is_Leaf and $sub_len
!ll&&!rl&&r
24115
MC/DC100%2/2
not $child->is_Leaf and $sub_len
not $child->is_Leaf $sub_len
Truth table100%3/3
not(A) and B
A= not $child->is_LeafB= $sub_len
ABresult
0X0
100
111
706 }
707 20 return $length;
708 }
709  
710 5 ▶sub phylotype_length {
Subroutine phylotype_length: called CC=2 SCAR=7.1
Pod documented
711 5 my $self = shift;
712 5 my $tree = shift;
713 5 ▶ my $node = shift || $tree->get_root_node;
Condition33%1/3
shift() || $tree->get_root_node
l!l&&r!l&&!r
500
MC/DC0%0/2
shift() || $tree->get_root_node
shift() $tree->get_root_node
Truth table33%1/3
A || B
A= shift()B= $tree->get_root_node
ABresult
1X1
011
000
714  
715 5 my $key = 'ps_trait';
716 5 my $value = $node->get_tag_values($key);
717  
718 5 return $self->_phylotype_length($tree, $node, $value);
719 }
720  
721  
722 =head2 sum_of_leaf_distances
723  
724 Example : sum_of_leaf_distances($tree, $node);
725 Description: Sums up the branch lengths from root to leaf
726 excluding the subclusters where the trait values
727 are different
728 Returns : float, length
729 Exceptions : all the nodes need to have the trait defined
730 Args : 1. Bio::Tree::TreeI object
731 2. Bio::Tree::NodeI object within the tree, optional
732  
733 Depends on Fitch's parsimony score (PS).
734  
735 =cut
736  
737 71 ▶sub _sum_of_leaf_distances {
Subroutine _sum_of_leaf_distances: called CC=5 SCAR=16.1
738 71 my $self = shift;
739 71 my $tree = shift;
740 71 my $node = shift;
741 71 my $value = shift;
742  
743 71 my $key = 'ps_trait';
744  
745 71 ▶ $self->throw ("ERROR: ". $node->internal_id. " needs a value for trait $key")
Branch: 1 branch
BranchTrueFalseTotal
unless $node->has_tag($key) 0 71 71
746 unless $node->has_tag($key);
747 71 ▶ return 0 if $node->get_tag_values($key) ne $value;
Branch: 1 branch
BranchTrueFalseTotal
if $node->get_tag_values($key) ne $value 7 64 71
748 #return $node->branch_length if $node->is_Leaf; # end of recursion
749 64 ▶ return 0 if $node->is_Leaf; # end of recursion
Branch: 1 branch
BranchTrueFalseTotal
if $node->is_Leaf 32 32 64
750  
751 32 my $length = 0;
752 32 foreach my $child ($node->each_Descendent) {
753 64 $length += $self->_count_leaves($tree, $child, $value) * $child->branch_length +
754 $self->_sum_of_leaf_distances($tree, $child, $value);
755 }
756 32 return $length;
757 }
758  
759 7 ▶sub sum_of_leaf_distances {
Subroutine sum_of_leaf_distances: called CC=2 SCAR=7.1
Pod documented
760 7 my $self = shift;
761 7 my $tree = shift;
762 7 ▶ my $node = shift || $tree->get_root_node;
Condition33%1/3
shift() || $tree->get_root_node
l!l&&r!l&&!r
700
MC/DC0%0/2
shift() || $tree->get_root_node
shift() $tree->get_root_node
Truth table33%1/3
A || B
A= shift()B= $tree->get_root_node
ABresult
1X1
011
000
763  
764 7 my $key = 'ps_trait';
765 7 my $value = $node->get_tag_values($key);
766  
767 7 return $self->_sum_of_leaf_distances($tree, $node, $value);
768 }
769  
770  
771 =head2 genetic_diversity
772  
773 Example : genetic_diversity($tree, $node);
774 Description: Diversity is the sum of root to leaf distances
775 within the phylotype normalised by number of leaf
776 nodes
777 Returns : float, value of genetic diversity
778 Exceptions : all the nodes need to have the trait defined
779 Args : 1. Bio::Tree::TreeI object
780 2. Bio::Tree::NodeI object within the tree, optional
781  
782 Depends on Fitch's parsimony score (PS).
783  
784 =cut
785  
786 2 ▶sub genetic_diversity {
Subroutine genetic_diversity: called CC=2 SCAR=7.4
Pod documented
787 2 my $self = shift;
788 2 my $tree = shift;
789 2 ▶ my $node = shift || $tree->get_root_node;
Condition33%1/3
shift() || $tree->get_root_node
l!l&&r!l&&!r
200
MC/DC0%0/2
shift() || $tree->get_root_node
shift() $tree->get_root_node
Truth table33%1/3
A || B
A= shift()B= $tree->get_root_node
ABresult
1X1
011
000
790  
791 2 return $self->sum_of_leaf_distances($tree, $node) /
792 $self->count_leaves($tree, $node);
793 }
794  
795  
796 =head2 statratio
797  
798 Example : statratio($tree, $node);
799 Description: Ratio of the stem length and the genetic diversity of the
800 phylotype L<genetic_diversity>
801 Returns : float, separation score
802 Exceptions : all the nodes need to have the trait defined
803 Args : 1. Bio::Tree::TreeI object
804 2. Bio::Tree::NodeI object within the tree, optional
805  
806 Statratio gives a measure of separation and variability within the phylotype.
807 Larger values identify more rapidly evolving and recent phylotypes.
808  
809 Depends on Fitch's parsimony score (PS).
810  
811 =cut
812  
813 1 ▶sub statratio {
Subroutine statratio: called CC=3 SCAR=11.6
Pod documented
814 1 my $self = shift;
815 1 my $tree = shift;
816 1 ▶ my $node = shift || $tree->get_root_node;
Condition33%1/3
shift() || $tree->get_root_node
l!l&&r!l&&!r
100
MC/DC0%0/2
shift() || $tree->get_root_node
shift() $tree->get_root_node
Truth table33%1/3
A || B
A= shift()B= $tree->get_root_node
ABresult
1X1
011
000
817  
818 1 my $div = $self->genetic_diversity($tree, $node);
819 1 ▶ return 0 if $div == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $div == 0 0 1 1
820 1 return $node->branch_length / $div;
821  
822 }
823  
824  
825 =head2 ai
826  
827 Example : ai($tree, $key, $node);
828 Description: Calculates the Association Index (AI) of Whang et
829 al. 2001 for the subtree defined by the (internal)
830 node. Node defaults to the root.
831 Returns : real
832 Exceptions : leaf nodes have to have the trait defined
833 Args : 1. Bio::Tree::TreeI object
834 2. trait name string
835 3. Bio::Tree::NodeI object within the tree, optional
836  
837 Association index (AI) gives a more fine grained results than PS since
838 the result is a real number. ~0 E<lt>= AI.
839  
840 Wang, T.H., Donaldson, Y.K., Brettle, R.P., Bell, J.E., Simmonds, P.,
841 2001. Identification of shared populations of human immunodeficiency
842 Virus Type 1 infecting microglia and tissue macrophages outside the
843 central nervous system. J. Virol. 75 (23), 11686-11699.
844  
845 =cut
846  
847 20 ▶sub _node_ai {
Subroutine _node_ai: called CC=6 SCAR=17.9
848 20 my $self = shift;
849 20 my $node = shift;
850 20 my $key = shift;
851  
852 20 my $traits;
853 20 my $leaf_count = 0;
854 20 for my $desc ( $node->get_all_Descendents ) {
855 88 ▶ next unless $desc->is_Leaf;
Branch: 1 branch
BranchTrueFalseTotal
unless $desc->is_Leaf 24 64 88
856 64 $leaf_count++;
857 64 ▶ $self->throw ("Node ". $desc->id. " needs a value for trait [$key]")
Branch: 1 branch
BranchTrueFalseTotal
unless $desc->has_tag($key) 0 64 64
858 unless $desc->has_tag($key);
859 64 my $trait = $desc->get_tag_values($key);
860 64 $traits->{$trait}++;
861 }
862 20 my $most_common = 0;
863 20 foreach ( keys %$traits) {
864 28 ▶ $most_common = $traits->{$_} if $traits->{$_} > $most_common;
Branch: 1 branch
BranchTrueFalseTotal
if $traits->{$_} > $most_common 21 7 28
865 }
866 20 return sprintf "%1.6f", (1 - ($most_common/$leaf_count) ) / (2**($leaf_count-1) );
867 }
868  
869 2 ▶sub ai {
Subroutine ai: called CC=6 SCAR=18.4
Pod documented
870 2 my $self = shift;
871 2 my $tree = shift;
872 2 ▶ my $key = shift || $self->throw("Trait name is needed");
Condition33%1/3
shift() || $self->throw('Trait name is needed')
l!l&&r!l&&!r
200
MC/DC0%0/2
shift() || $self->throw('Trait name is needed')
shift() $self->throw('Trait name is needed')
Truth table33%1/3
A || B
A= shift()B= $self->throw('Trait name is needed')
ABresult
1X1
011
000
873 2 ▶ my $start_node = shift || $tree->get_root_node;
Condition66%2/3
shift() || $tree->get_root_node
l!l&&r!l&&!r
110
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
874 2 ▶ return unless $start_node;
Branch: 1 branch
BranchTrueFalseTotal
unless $start_node 0 2 2
875  
876 2 my $sum = 0;
877 2 for my $node ( $start_node->get_all_Descendents ) {
878 44 ▶ next if $node->is_Leaf;
Branch: 1 branch
BranchTrueFalseTotal
if $node->is_Leaf 24 20 44
879 20 $sum += $self->_node_ai($node, $key);
880 }
881 2 return $sum;
882 }
883  
884  
885 =head2 mc
886  
887 Example : mc($tree, $key, $node);
888 Description: Calculates the Monophyletic Clade (MC) size statistics
889 for the subtree a defined by the (internal) node.
890 Node defaults to the root;
891 Returns : hashref with trait values as keys
892 Exceptions : leaf nodes have to have the trait defined
893 Args : 1. Bio::Tree::TreeI object
894 2. trait name string
895 3. Bio::Tree::NodeI object within the tree, optional
896  
897 Monophyletic Clade (MC) size statistics by Salemi at al 2005. It is
898 calculated for each trait value. 1 E<lt>= MC E<lt>= nx, where nx is the
899 number of tips with value x:
900  
901 pick the internal node with maximim value for
902 number of of tips with only trait x
903  
904 MC was defined by Parker et al 2008.
905  
906 Salemi, M., Lamers, S.L., Yu, S., de Oliveira, T., Fitch, W.M., McGrath, M.S.,
907 2005. Phylodynamic analysis of Human Immunodeficiency Virus Type 1 in
908 distinct brain compartments provides a model for the neuropathogenesis of
909 AIDS. J. Virol. 79 (17), 11343-11352.
910  
911 Parker, J., Rambaut A., Pybus O., 2008. Correlating viral phenotypes
912 with phylogeny: Accounting for phylogenetic uncertainty Infection,
913 Genetics and Evolution 8 (2008), 239-246.
914  
915 =cut
916  
917 16 ▶sub _node_mc {
Subroutine _node_mc: called CC=3 SCAR=11.0
918 16 my $self = shift;
919 16 my $node = shift;
920 16 my $key = shift;
921  
922 16 my $traits;
923 16 my $leaf_count = 0;
924 16 for my $node2 ( $node->get_all_Descendents ) {
925 72 ▶ next unless $node2->is_Leaf;
Branch: 1 branch
BranchTrueFalseTotal
unless $node2->is_Leaf 20 52 72
926 52 $leaf_count++;
927 52 my $trait = $node2->get_tag_values($key);
928 52 $traits->{$trait}++;
929 }
930 16 return $traits;
931 }
932  
933 2 ▶sub mc {
Subroutine mc: called CC=10 SCAR=23.2
Pod documented
934 2 my $self = shift;
935 2 my $tree = shift;
936 2 ▶ my $key = shift || die "Trait name is needed";
Condition50%1/2
shift() || die('Trait name is needed')
l!l
20
MC/DC0%0/1
shift() || die('Trait name is needed')
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
937 2 ▶ my $start_node = shift || $tree->get_root_node;
Condition66%2/3
shift() || $tree->get_root_node
l!l&&r!l&&!r
110
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
938 2 ▶ return unless $start_node;
Branch: 1 branch
BranchTrueFalseTotal
unless $start_node 0 2 2
939  
940 2 my $sum; # hashref, keys are trait values
941 my $keys; # hashref, keys are trait values
942 2 foreach my $node ( $start_node->get_all_Descendents ) {
943 36 ▶ next if $node->is_Leaf;
Branch: 1 branch
BranchTrueFalseTotal
if $node->is_Leaf 20 16 36
944 16 my $traits = $self->_node_mc($node, $key);
945 16 ▶ if (scalar keys %$traits == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %$traits == 1) { } 9 7 16
946 9 my ($value) = keys %$traits;
947 3 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
948 $sum->{$value} = $traits->{$value}
949 9 ▶ if $sum->{$value} < $traits->{$value};
Branch: 1 branch
BranchTrueFalseTotal
if $sum->{$value} < $traits->{$value} 5 4 9
950 } else {
951 7 map { $keys->{$_} = 1 } keys %$traits;
952 }
953 }
954 # check for cases where there are no clusters
955 2 foreach my $value (keys %$keys) {
956 2 ▶ $sum->{$value} = 1 unless defined $sum->{$value};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $sum->{$value} 0 2 2
957 }
958 2 return $sum;
959 }
960  
961  
962 3 1;
« Bio/Search/HSP/BlastPullHSP.pm ↑ Summary Bio/Tools/Phylo/Phylip/ProtDist.pm »