Bio/Tree/RandomFactory.pm

filter: Statementstmt 69.8% 118 / 169 Branchbran 51.7% 29 / 56 Conditioncond 32.2% 10 / 31 MC/DCmcdc 0.0% 0 / 20 Subroutinesub 82.3% 14 / 17 Podpod 66.6% 8 / 12 totaltotal 58.6% 179 / 305 CC 44 SCAR 27.6
CC
44
Cov
61%
rand_birthdeath_backwards_tree
56.0
new
22.1
next_tree
14.8
CRAP 15.8
« Bio/Tools/Analysis/SimpleAnalysisBase.pm ↑ Summary Bio/SearchIO/blasttable.pm »
1 #
2 # BioPerl module for Bio::Tree::RandomFactory
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::RandomFactory - TreeFactory for generating Random Trees
17  
18 =head1 SYNOPSIS
19  
20 use Bio::Tree::RandomFactory
21 my @taxonnames;
22 my $factory = Bio::Tree::RandomFactory->new( -taxa => \@taxonnames,
23 -maxcount => 10);
24  
25 # or for anonymous samples
26  
27 my $factory = Bio::Tree::RandomFactory->new( -num_taxa => 6,
28 -maxcount => 50);
29  
30  
31 my $tree = $factory->next_tree;
32  
33 =head1 DESCRIPTION
34  
35 Builds a random tree every time next_tree is called or up to -maxcount times.
36  
37 This module was originally written for Coalescent simulations see
38 L<Bio::PopGen::Simulation::Coalescent>. I've left the next_tree
39 method intact although it is not generating random trees in the
40 phylogenetic sense. I would be happy for someone to provide
41 alternative implementations which can be used here. As written it
42 will generate random topologies but the branch lengths are built from
43 assumptions in the coalescent and are not appropriate for phylogenetic
44 analyses.
45  
46 This algorithm is based on the make_tree algorithm from Richard Hudson 1990.
47  
48 Hudson, R. R. 1990. Gene genealogies and the coalescent
49 process. Pp. 1-44 in D. Futuyma and J. Antonovics, eds. Oxford
50 surveys in evolutionary biology. Vol. 7. Oxford University
51 Press, New York
52  
53 Sanderson, M ...
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-AT-bioperl.org
88  
89 =head1 CONTRIBUTORS
90  
91 Matthew Hahn, E<lt>matthew.hahn@duke.eduE<gt>
92 Mike Sanderson
93  
94 =head1 APPENDIX
95  
96 The rest of the documentation details each of the object methods.
97 Internal methods are usually preceded with a _
98  
99 =cut
100  
101  
102 # Let the code begin...
103  
104  
105 package Bio::Tree::RandomFactory;
106 2 $Bio::Tree::RandomFactory::VERSION = '1.7.8';
107 2 ▶use vars qw($PRECISION_DIGITS $DefaultNodeType %Defaults);
Subroutine BEGIN: called CC=1 SCAR=0.0
108 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
109  
110 2 $PRECISION_DIGITS = 3; # Precision for the branchlength
111 2 $DefaultNodeType = 'Bio::Tree::Node';
112 2 %Defaults = ('YuleRate' => 1.0, # as set by Sanderson in Rates
113 'Speciation' => 1.0, #
114 'DefaultTreeMethod' => 'yule',
115 );
116  
117 2 ▶use Bio::Tools::RandomDistFunctions;
Subroutine BEGIN: called CC=1 SCAR=0.0
118 2 ▶use Bio::Tree::Tree;
Subroutine BEGIN: called CC=1 SCAR=0.0
119  
120 2 ▶use base qw(Bio::Root::Root Bio::Factory::TreeFactoryI);
Subroutine BEGIN: called CC=1 SCAR=0.0
121  
122 =head2 new
123  
124 Title : new
125 Usage : my $factory = Bio::Tree::RandomFactory->new(-samples => \@samples,
126 -maxcount=> $N);
127 Function: Initializes a Bio::Tree::RandomFactory object
128 Returns : Bio::Tree::RandomFactory
129 Args : -nodetype => Type of Nodes to create [default Bio::Tree::Node]
130 -maxcount => [optional] Maximum num trees to create
131 -randtype => Type of random trees so far support
132 - yule/backward_yule/BY [default]
133 - forward_yule/FY
134 - birthdeath_forward/BDF
135 - birthdeath_backwards/BDB
136  
137  
138 ONE of the following must be specified
139 -taxa => $arrayref of taxa names
140 -num_taxa => integer indicating number of taxa in the tree
141  
142 =cut
143  
144 1 ▶sub new{
Subroutine new: called CC=12 SCAR=31.0
Pod documented
145 1 my ($class,@args) = @_;
146 1 my $self = $class->SUPER::new(@args);
147
148 1 $self->{'_treecounter'} = 0;
149 1 $self->{'_maxcount'} = 0;
150 1 my ($nodetype,$randtype,
151 $maxcount, $samps,$samplesize,
152 $taxa, $num_taxa) = $self->_rearrange([qw(NODETYPE
153 RANDTYPE
154 MAXCOUNT
155 SAMPLES
156 SAMPLE_SIZE
157 TAXA
158 NUM_TAXA)],
159 @args);
160 1 my @taxa;
161 1 ▶ $nodetype ||= $DefaultNodeType;
Condition33%1/3
$nodetype ||= $Bio::Tree::RandomFactory::DefaultNodeType
l!l&&r!l&&!r
010
MC/DC0%0/2
$nodetype ||= $Bio::Tree::RandomFactory::DefaultNodeType
$nodetype $Bio::Tree::RandomFactory::DefaultNodeType
Truth table33%1/3
A ||= B
A= $nodetypeB= $Bio::Tree::RandomFactory::DefaultNodeType
ABresult
1X1
011
000
162 1 $self->nodetype($nodetype);
163 1 ▶ $taxa = $samps if defined $samps && ! defined $taxa;
Branch: 1 branch
BranchTrueFalseTotal
if defined $samps and not defined $taxa 0 1 1
Condition33%1/3
defined $samps and not defined $taxa
!ll&&!rl&&r
100
MC/DC0%0/2
defined $samps and not defined $taxa
defined $samps not defined $taxa
Truth table33%1/3
A and not(B)
A= defined $sampsB= not defined $taxa
ABresult
0X0
100
111
164 1 ▶ $num_taxa = $samplesize if $samplesize && ! $num_taxa;
Branch: 1 branch
BranchTrueFalseTotal
if $samplesize and not $num_taxa 1 0 1
Condition33%1/3
$samplesize and not $num_taxa
!ll&&!rl&&r
001
MC/DC0%0/2
$samplesize and not $num_taxa
$samplesize not $num_taxa
Truth table33%1/3
A and not(B)
A= $samplesizeB= not $num_taxa
ABresult
0X0
100
111
165 1 ▶ if( ! defined $taxa ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $taxa) { } 1 0 1
166 1 ▶ if( ! defined $num_taxa || $num_taxa <= 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $num_taxa or $num_taxa <= 0) 0 1 1
Condition33%1/3
not defined $num_taxa or $num_taxa <= 0
l!l&&r!l&&!r
001
MC/DC0%0/2
not defined $num_taxa or $num_taxa <= 0
not defined $num_taxa $num_taxa <= 0
Truth table33%1/3
not(A) or B
A= not defined $num_taxaB= $num_taxa <= 0
ABresult
1X1
011
000
167 0 $self->throw("Must specify a valid num_taxa if parameter -TAXA is not specified");
168 }
169 1 foreach ( 1..$num_taxa ) { push @taxa, "Taxon$_"; }
170 } else {
171 0 ▶ if( ref($taxa) !~ /ARRAY/i ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref($taxa) =~ /ARRAY/i) 0 0 0
172 0 $self->throw("Must specify a valid ARRAY reference to the parameter -TAXA, did you forget a leading '\\'? for $taxa");
173 }
174 0 @taxa = @$taxa;
175 }
176
177 1 $self->taxa(\@taxa);
178 1 ▶ defined $maxcount && $self->maxcount($maxcount);
Branch: 1 branch
BranchTrueFalseTotal
defined $maxcount and $self->maxcount($maxcount) 0 1 1
179 1 $self->{'_count'} = 0;
180 1 return $self;
181 }
182  
183 =head2 next_tree
184  
185 Title : next_tree
186 Usage : my $tree = $factory->next_tree
187 Function: Returns a random tree based on the initialized number of nodes
188 NOTE: if maxcount is not specified on initialization or
189 set to a valid integer, subsequent calls to next_tree will
190 continue to return random trees and never return undef
191  
192 Returns : Bio::Tree::TreeI object
193 Args : none
194  
195 =cut
196  
197  
198 1 ▶sub next_tree{
Subroutine next_tree: called CC=11 SCAR=27.0
Pod documented
199 1 my ($self,%options) = @_;
200 return if $self->maxcount &&
201 1 ▶ $self->{'_count'}++ >= $self->maxcount;
Branch: 1 branch
BranchTrueFalseTotal
if $self->maxcount and $self->{"_count"}++ >= $self->maxcount 0 1 1
Condition33%1/3
$self->maxcount and $self->{"_count"}++ >= $self->maxcount
!ll&&!rl&&r
100
MC/DC0%0/2
$self->maxcount and $self->{"_count"}++ >= $self->maxcount
$self->maxcount $self->{"_count"}++ >= $self->maxcount
Truth table33%1/3
A and B
A= $self->maxcountB= $self->{"_count"}++ >= $self->maxcount
ABresult
0X0
100
111
202 1 ▶ my $rand_type = $options{'randtype'} || $self->random_tree_method;
Condition33%1/3
$options{'randtype'} || $self->random_tree_method
l!l&&r!l&&!r
010
MC/DC0%0/2
$options{'randtype'} || $self->random_tree_method
$options{'randtype'} $self->random_tree_method
Truth table33%1/3
A || B
A= $options{'randtype'}B= $self->random_tree_method
ABresult
1X1
011
000
203 1 my $nodetype = $self->nodetype;
204 1 my $treearray;
205  
206 1 ▶ if( $rand_type =~ /(birthdeath_forward|birth|BDF)/i ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($rand_type =~ /(birthdeath_forward|birth|BDF)/i) { } 0 1 1
elsif ($rand_type =~ /(birthdeath_backward|BDB)/i) { } 0 1 1
elsif ($rand_type =~ /(BY|backwards_yule)/i or $rand_type =~ /^yule/i) { } 1 0 1
207  
208 } elsif ( $rand_type =~ /(birthdeath_backward|BDB)/i ) {
209 0 $treearray = $self->rand_birthdeath_backwards_tree;
210 ▶ } elsif( $rand_type =~ /(BY|backwards_yule)/i ||
Condition33%1/3
$rand_type =~ /(BY|backwards_yule)/i or $rand_type =~ /^yule/i
l!l&&r!l&&!r
010
MC/DC0%0/2
$rand_type =~ /(BY|backwards_yule)/i or $rand_type =~ /^yule/i
$rand_type =~ /(BY|backwards_yule)/i $rand_type =~ /^yule/i
Truth table33%1/3
A or B
A= $rand_type =~ /(BY|backwards_yule)/iB= $rand_type =~ /^yule/i
ABresult
1X1
011
000
211 $rand_type =~ /^yule/i ) {
212 1 my $speciation = $options{'speciation'}; # can be undef
213 1 $treearray = $self->rand_yule_c_tree($speciation);
214 } else {
215 0 $self->warn("unrecognized random type $rand_type");
216 }
217
218 1 my @nodes = ();
219 1 foreach my $n ( @$treearray ) {
220 9 for my $k ( qw(desc1 desc2) ) {
221 18 ▶ next unless defined $n->{$k};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $n->{$k} 10 8 18
222 8 push @{$n->{'descendents'}}, $nodes[$n->{$k}];
223 }
224 push @nodes,
225 $nodetype->new(-id => $n->{'nodenum'},
226 -branch_length => $n->{'time'},
227 9 -descendents => $n->{'descendents'},
228 );
229 }
230 1 my $T = Bio::Tree::Tree->new(-root => pop @nodes );
231 1 return $T;
232 }
233  
234  
235 =head2 maxcount
236  
237 Title : maxcount
238 Usage : $obj->maxcount($newval)
239 Function:
240 Returns : Maxcount value
241 Args : newvalue (optional)
242  
243  
244 =cut
245  
246 1 ▶sub maxcount{
Subroutine maxcount: called CC=3 SCAR=16.7
Pod documented
247 1 my ($self,$value) = @_;
248 1 ▶ if( defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 0 1 1
249 0 ▶ if( $value =~ /^(\d+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value =~ /^(\d+)/) { } 0 0 0
250 0 $self->{'_maxcount'} = $1;
251 } else {
252 0 $self->warn("Must specify a valid Positive integer to maxcount");
253 0 $self->{'_maxcount'} = 0;
254 }
255 }
256 1 return $self->{'_maxcount'};
257 }
258  
259  
260 =head2 reset_tree_count
261  
262 Title : reset_tree_count
263 Usage : $factory->reset_tree_count;
264 Function: Reset the tree counter
265 Returns : none
266 Args : none
267  
268  
269 =cut
270  
271 0 ▶sub reset_count{
Subroutine reset_count: not called CC=1 SCAR=6.9
Pod undocumented
272 0 shift->{'_count'} = 0;
273 }
274  
275 =head2 taxa
276  
277 Title : taxa
278 Usage : $obj->taxa($newval)
279 Function: Set the leaf node names
280 Returns : value of taxa
281 Args : Arrayref of Taxon names
282  
283  
284 =cut
285  
286 2 ▶sub taxa {
Subroutine taxa: called CC=3 SCAR=11.4
Pod documented
287 2 my ($self,$value) = @_;
288 2 ▶ if( defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 1 1 2
289 1 ▶ if( ref($value) !~ /ARRAY/i ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref($value) =~ /ARRAY/i) 0 1 1
290 0 $self->warn("Must specify a valid array ref to the method 'taxa'");
291 0 $value = [];
292 }
293 1 $self->{'_taxa'} = $value;
294 1 $self->{'_num_taxa'} = scalar @$value;
295 }
296 2 return $self->{'_taxa'};
297  
298 }
299  
300 =head2 num_taxa
301  
302 Title : num_taxa
303 Usage : $obj->num_taxa($newval)
304 Function: Get the number of Taxa
305 Returns : value of num_taxa
306 Args : none
307  
308  
309 =cut
310  
311 1 ▶sub num_taxa {
Subroutine num_taxa: called CC=1 SCAR=0.0
Pod documented
312 1 my ($self) = @_;
313 1 return $self->{'_num_taxa'};
314 }
315  
316 # alias old methods
317 2 *num_samples = \&num_taxa;
318 2 *samples = \&taxa;
319  
320 =head2 random
321  
322 Title : random
323 Usage : my $rfloat = $node->random($size)
324 Function: Generates a random number between 0 and $size
325 This is abstracted so that someone can override and provide their
326 own special RNG. This is expected to be a uniform RNG.
327 Returns : Floating point random
328 Args : $maximum size for random number (defaults to 1)
329  
330  
331 =cut
332  
333 4 ▶sub random{
Subroutine random: called CC=1 SCAR=0.0
Pod documented
334 4 my ($self,$max) = @_;
335 4 return rand($max);
336 }
337  
338  
339 =head2 random_tree_method
340  
341 Title : random_tree_method
342 Usage : $obj->random_tree_method($newval)
343 Function:
344 Example :
345 Returns : value of random_tree_method (a scalar)
346 Args : on set, new value (a scalar or undef, optional)
347  
348  
349 =cut
350  
351 1 ▶sub random_tree_method{
Subroutine random_tree_method: called CC=3 SCAR=12.5
Pod documented
352 1 my $self = shift;
353  
354 1 ▶ return $self->{'random_tree_method'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 1 1
355 1 ▶ return $self->{'random_tree_method'} || $Defaults{'DefaultTreeMethod'};
Condition33%1/3
$self->{'random_tree_method'} || $Bio::Tree::RandomFactory::Defaults{'DefaultTreeMethod'}
l!l&&r!l&&!r
010
MC/DC0%0/2
$self->{'random_tree_method'} || $Bio::Tree::RandomFactory::Defaults{'DefaultTreeMethod'}
$self->{'random_tree_method'} $Bio::Tree::RandomFactory::Defaults{'DefaultTreeMethod'}
Truth table33%1/3
A || B
A= $self->{'random_tree_method'}B= $Bio::Tree::RandomFactory::Defaults{'DefaultTreeMethod'}
ABresult
1X1
011
000
356 }
357  
358 =head2 nodetype
359  
360 Title : nodetype
361 Usage : $obj->nodetype($newval)
362 Function:
363 Example :
364 Returns : value of nodetype (a scalar)
365 Args : on set, new value (a scalar or undef, optional)
366  
367  
368 =cut
369  
370 3 ▶sub nodetype{
Subroutine nodetype: called CC=4 SCAR=14.5
Pod documented
371 3 my ($self,$value) = @_;
372 3 ▶ if( defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 1 2 3
373 1 eval "require $value";
374 0 ▶ if( $@ ) { $self->throw("$@: Unrecognized Node type for ".ref($self).
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 1 1
375 "'$value'");}
376
377 1 my $a = bless {},$value;
378 1 ▶ unless( $a->isa('Bio::Tree::NodeI') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($a->isa("Bio::Tree::NodeI")) 0 1 1
379 0 $self->throw("Must provide a valid Bio::Tree::NodeI or child class to SeqFactory Not $value");
380 }
381 1 $self->{'nodetype'} = $value;
382 }
383 3 return $self->{'nodetype'};
384 }
385  
386  
387 # The assignment of times are based on Mike Sanderson's r8s code
388 # The topology assignment code is based on Richard Hudson's
389 # make_trees
390  
391  
392 1 ▶sub rand_yule_c_tree {
Subroutine rand_yule_c_tree: called CC=8 SCAR=20.8
Pod undocumented
393 1 my ($self,$speciation) = @_;
394 1 ▶ $speciation ||= $Defaults{'Speciation'};
Condition33%1/3
$speciation ||= $Bio::Tree::RandomFactory::Defaults{"Speciation"}
l!l&&r!l&&!r
010
MC/DC0%0/2
$speciation ||= $Bio::Tree::RandomFactory::Defaults{"Speciation"}
$speciation $Bio::Tree::RandomFactory::Defaults{"Speciation"}
Truth table33%1/3
A ||= B
A= $speciationB= $Bio::Tree::RandomFactory::Defaults{"Speciation"}
ABresult
1X1
011
000
395 1 my $n_taxa = $self->num_taxa;
396 1 ▶ my $taxa = $self->taxa || [];
Condition50%1/2
$self->taxa || []
l!l
10
MC/DC0%0/1
$self->taxa || []
$self->taxa
Truth table50%1/2
A
A= $self->taxa
Aresult
11
00
397 1 my $nodetype = $self->nodetype;
398
399 1 my $randfuncs = Bio::Tools::RandomDistFunctions->new();
400 1 my $rate = $Defaults{'YuleRate'};
401 1 my (@tree,@list,@times,$i,$in);
402 1 my $max = 2 * $n_taxa - 1;
403 1 ▶ for($in=0;$in < $max; $in++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in < $max) 9 1 10
404 9 push @tree, { 'nodenum' => "Node$in" };
405 }
406 # setup leaf nodes
407 1 ▶ for($in=0;$in < $n_taxa;$in++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in < $n_taxa) 5 1 6
408 5 $tree[$in]->{'time'} = 0;
409 5 $tree[$in]->{'desc1'} = undef;
410 5 $tree[$in]->{'desc2'} = undef;
411 5 ▶ if( my $r = $taxa->[$in] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $r = $taxa->[$in]) 5 0 5
412 5 $tree[$in]->{'nodenum'} = $r;
413 }
414 5 push @list, $in;
415 }
416
417 1 ▶ for( $i = 0; $i < $n_taxa - 1; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $n_taxa - 1) 4 1 5
418 # draw random interval times
419 4 push @times, $randfuncs->rand_birth_distribution($speciation);
420 }
421 # sort smallest to largest
422 1 @times = sort {$a <=> $b} @times;
423 # topology generation
424 1 ▶ for ($in = $n_taxa; $in > 1; $in-- ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in > 1) 4 1 5
425 4 my $time = shift @times;
426
427 4 my $pick = int $self->random($in);
428 4 my $nodeindex = $list[$pick];
429 4 $tree[$list[$pick]]->{'time'} = $time;
430 4 my $swap = 2 * $n_taxa - $in;
431 4 $tree[$swap]->{'desc1'} = $nodeindex;
432 4 $list[$pick] = $list[$in-1];
433
434 4 $pick = int rand($in - 1);
435 4 $nodeindex = $list[$pick];
436 4 $tree[$list[$pick]]->{'time'} = $time;
437 4 $tree[$swap]->{'desc2'} = $nodeindex;
438 4 $list[$pick] = $swap;
439 }
440 1 $tree[-1]->{'time'} = shift @times;
441 1 return \@tree;
442 }
443  
444  
445  
446 0 ▶sub rand_birthdeath_backwards_tree {
Subroutine rand_birthdeath_backwards_tree: not called CC=7 SCAR=40.3
Pod undocumented
447 0 my ($self) = @_;
448 0 my $n_taxa = $self->num_taxa;
449 0 ▶ my $taxa = $self->taxa || [];
Condition0%0/2
$self->taxa || []
l!l
00
MC/DC0%0/1
$self->taxa || []
$self->taxa
Truth table0%0/2
A
A= $self->taxa
Aresult
11
00
450
451 0 my $randfuncs = Bio::Tools::RandomDistFunctions->new();
452 0 my $rate = $Defaults{'YuleRate'};
453 0 my (@tree,@list,@times,$i,$in);
454 0 my $max = 2 * $n_taxa - 1;
455 0 ▶ for($in=0;$in < $max; $in++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in < $max) 0 0 0
456 0 push @tree, { 'nodenum' => "Node$in" };
457 }
458 # setup leaf nodes
459 0 ▶ for($in=0;$in < $n_taxa;$in++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in < $n_taxa) 0 0 0
460 0 $tree[$in]->{'time'} = 0;
461 0 $tree[$in]->{'desc1'} = undef;
462 0 $tree[$in]->{'desc2'} = undef;
463 0 ▶ if( my $r = $taxa->[$in] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $r = $taxa->[$in]) 0 0 0
464 # deal with pre-labeled nodes
465 0 $tree[$in]->{'nodenum'} = $r;
466 }
467 0 push @list, $in;
468 }
469 0 my ($time) = (0);
470  
471 # topology generation
472 0 ▶ for ($in = $n_taxa; $in > 1; $in-- ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in > 1) 0 0 0
473 0 my $pick = int $self->random($in);
474 0 my $nodeindex = $list[$pick];
475 0 my $swap = 2 * $n_taxa - $in;
476 0 $time += $randfuncs->rand_geometric_distribution($n_taxa * $rate);;
477 0 $tree[$list[$pick]]->{'time'} = $time;
478 0 $tree[$swap]->{'desc1'} = $nodeindex;
479 0 $list[$pick] = $list[$in-1];
480
481 0 $pick = int rand($in - 1);
482 0 $nodeindex = $list[$pick];
483 0 $tree[$list[$pick]]->{'time'} = $time;
484 0 $tree[$swap]->{'desc2'} = $nodeindex;
485 0 $list[$pick] = $swap;
486 }
487 0 my $root = $tree[-1];
488 0 $time += $randfuncs->rand_geometric_distribution($n_taxa * $rate);;
489 0 $root->{'time'} = $time;
490  
491 # Normalize times by the root node...
492 0 for my $node ( @tree ) {
493 0 $node->{'time'} /= $root->{'time'};
494 }
495 0 return \@tree;
496 }
497  
498  
499 # The assignment of times are based on Mike Sanderson's r8s code
500 # The topology assignment code is based on Richard Hudson's
501 # make_trees
502  
503 0 ▶sub rand_birth_death_tree {
Subroutine rand_birth_death_tree: not called CC=1 SCAR=0.0
Pod undocumented
504 # Still need to finish
505 # my ($self,$spec_rate,$extinct_rate,$char_rate) = @_;
506 # my $n_taxa = $self->num_taxa;
507 # my $dt = 0.1 / $n_taxa;
508 # my @tree;
509 # my $max = 3 * $n_taxa - 1;
510 # # setup leaf nodes
511
512 # for($in=0;$in < $size;$in++) {
513 # push @tree, { 'nodenum' => $taxa->[$in] || "Node$in",
514 # 'time' => 0,
515 # 'desc1' => undef,
516 # 'desc2' => undef,
517 # };
518 # }
519 # my $time = $dt;
520 # my $idx = 0;
521 # while( $n_taxa > 1 ) {
522 # if ( event($dt * $spec_rate, $n_taxa) ) {
523 # my $pick = int $self->random($n_taxa);
524 # my $pick2 = int $self->random($n_taxa);
525 # while( $pick2 == $pick ) {
526 # $pick2 = int $self->random($n_taxa);
527 # }
528 # to finish....
529
530 # $tree[$swap]->{'desc1'} = $nodeindex;
531 # }
532 # }
533  
534
535  
536 # $list[$pick] = $list[$in-1];
537
538 # $pick = int rand($in - 1);
539 # $nodeindex = $list[$pick];
540 # $tree[$swap]->{'desc2'} = $nodeindex;
541 # $list[$pick] = $swap;
542 # $tree[$swap]->{'time'} = $times[$ix++];
543 # }
544 }
545  
546  
547 2 1;
« Bio/Tools/Analysis/SimpleAnalysisBase.pm ↑ Summary Bio/SearchIO/blasttable.pm »