PhyloNetwork/TreeFactoryMulti.pm

filter: Statementstmt 15.7% 14 / 89 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 66.6% 4 / 6 Podpod 100% 2 / 2 totaltotal 15.3% 20 / 130 CC 14 SCAR 41.9
CC
14
Cov
12%
next_network
110.0
new
30.0
BEGIN
1.0
CRAP 66.0
↑ Summary PhyloNetwork/FactoryX.pm »
1 #
2 # Module for Bio::PhyloNetwork::TreeFactoryMulti
3 #
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
5 #
6 # Cared for by Gabriel Cardona <gabriel(dot)cardona(at)uib(dot)es>
7 #
8 # Copyright Gabriel Cardona
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::PhyloNetwork::TreeFactoryMulti - Module to sequentially generate
17 Phylogenetic Trees
18  
19 =head1 SYNOPSIS
20  
21 use strict;
22 use warnings;
23  
24 use Bio::PhyloNetwork;
25 use Bio::PhyloNetwork::TreeFactory;
26  
27 # Will generate sequentially all the 15 binary phylogetic
28 # trees with 4 leaves
29  
30 my $factory=Bio::PhyloNetwork::TreeFactory->new(-numleaves=>4);
31  
32 my @nets;
33  
34 while (my $net=$factory->next_network()) {
35 push @nets,$net;
36 print "".(scalar @nets).": ".$net->eNewick()."\n";
37 }
38  
39 =head1 DESCRIPTION
40  
41 Sequentially builds a (binary) phylogenetic tree each time
42 next_network is called.
43  
44 =head1 AUTHOR
45  
46 Gabriel Cardona, gabriel(dot)cardona(at)uib(dot)es
47  
48 =head1 SEE ALSO
49  
50 L<Bio::PhyloNetwork>
51  
52 =head1 APPENDIX
53  
54 The rest of the documentation details each of the object methods.
55  
56 =cut
57  
58 package Bio::PhyloNetwork::TreeFactoryMulti;
59 1 $Bio::PhyloNetwork::TreeFactoryMulti::VERSION = '1.7.3';
60 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
61 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
62  
63 1 ▶use base qw(Bio::Root::Root);
Subroutine BEGIN: called CC=1 SCAR=0.0
64  
65 1 ▶use Bio::PhyloNetwork;
Subroutine BEGIN: called CC=1 SCAR=0.0
66  
67 =head2 new
68  
69 Title : new
70 Usage : my $factory = new Bio::PhyloNetwork::TreeFactory();
71 Function: Creates a new Bio::PhyloNetwork::TreeFactory
72 Returns : Bio::PhyloNetwork::RandomFactory
73 Args : -numleaves => integer
74 OR
75 -leaves => reference to an array (of leaves names)
76  
77 Returns a Bio::PhyloNetwork::TreeFactory object. Such an object will
78 sequentially create binary phylogenetic trees
79 each time next_network is called.
80  
81 If the parameter -leaves=E<gt>\@leaves is given, then the set of leaves of
82 these networks will be @leaves. If it is given the parameter
83 -numleaves=E<gt>$numleaves, then the set of leaves will be "l1"..."l$numleaves".
84  
85 =cut
86  
87 0 ▶sub new {
Subroutine new: not called CC=5 SCAR=34.0
Pod documented
88 0 my ($pkg,@args)=@_;
89  
90 0 my $self=$pkg->SUPER::new(@args);
91  
92 0 my ($leavesR,$numleaves,$numhybrids)=
93 $self->_rearrange([qw(LEAVES
94 NUMLEAVES
95 NUMHYBRIDS)],@args);
96  
97 0 my @leaves;
98 0 ▶ if ((! defined $leavesR) && (defined $numleaves)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $leavesR and defined $numleaves) 0 0 0
Condition0%0/3
not defined $leavesR and defined $numleaves
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $leavesR and defined $numleaves
not defined $leavesR defined $numleaves
Truth table0%0/3
not(A) and B
A= not defined $leavesRB= defined $numleaves
ABresult
0X0
100
111
99 0 @leaves=map {"l$_"} (1..$numleaves);
100 0 $leavesR=\@leaves;
101 }
102 0 ▶ if (! defined $leavesR) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $leavesR) 0 0 0
103 0 $self->throw("No leaves set neither numleaves given");
104 }
105 0 @leaves=@$leavesR;
106 0 $self->{leaves}=$leavesR;
107  
108 0 $numleaves=@leaves;
109 0 $self->{numleaves}=$numleaves;
110 0 ▶ if ($numleaves > 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($numleaves > 2) 0 0 0
111 0 my @leavesparent=@leaves;
112 0 my $newleaf=pop @leavesparent;
113 0 $self->{newleaf}=$newleaf;
114 $self->{parent}=
115 0 new($pkg,-leaves=>\@leavesparent);
116 0 my $oldnet=$self->{parent}->next_network();
117 0 $self->{oldnet}=$oldnet;
118 0 my @candidates=$oldnet->nodes();
119 0 $self->{candidates}=\@candidates;
120 0 my @candidatesbis=$oldnet->internal_nodes();
121 0 $self->{candidatesbis}=\@candidatesbis;
122 0 $self->{processbis}=0;
123 }
124 0 $self->{index}=0;
125  
126 0 bless($self,$pkg);
127 }
128  
129 =head2 next_network
130  
131 Title : next_network
132 Usage : my $net=$factory->next_network()
133 Function: returns a tree
134 Returns : Bio::PhyloNetwork
135 Args : none
136  
137 =cut
138  
139 0 ▶sub next_network {
Subroutine next_network: not called CC=10 SCAR=47.0
Pod documented
140 0 my ($self)=@_;
141  
142 0 my $n=$self->{numleaves};
143 0 ▶ if ($self->{numleaves} == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'numleaves'} == 2) { } 0 0 0
144 0 ▶ if ($self->{index} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'index'} == 0) { } 0 0 0
145 0 my $graph=Graph::Directed->new();
146 0 $graph->add_edges("t0",$self->{leaves}->[0],"t0",$self->{leaves}->[1]);
147 0 my $net=Bio::PhyloNetwork->new(-graph=>$graph);
148 0 $self->{index}++;
149 0 return $net;
150 }
151 else {
152 0 return 0;
153 }
154 }
155 else {
156 0 ▶ if (($self->{index} == (scalar @{$self->{candidatesbis}})) && $self->{processbis}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"index"} == scalar @{$self->{"candidatesbis"};} and $self->{"processbis"}) 0 0 0
Condition0%0/3
$self->{"index"} == scalar @{$self->{"candidatesbis"};} and $self->{"processbis"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"index"} == scalar @{$self->{"candidatesbis"};} and $self->{"processbis"}
$self->{"index"} == scalar @{$self->{"candidatesbis"};} $self->{"processbis"}
Truth table0%0/3
A and B
A= $self->{"index"} == scalar @{$self->{"candidatesbis"};}B= $self->{"processbis"}
ABresult
0X0
100
111
157 ) {
158 0 my $oldnet=$self->{parent}->next_network();
159 0 ▶ if (! $oldnet) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($oldnet) 0 0 0
160 0 return 0;
161 }
162 0 $self->{oldnet}=$oldnet;
163 0 my @candidates=$oldnet->nodes();
164 0 $self->{candidates}=\@candidates;
165 0 my @candidatesbis=$oldnet->internal_nodes();
166 0 $self->{candidatesbis}=\@candidatesbis;
167 0 $self->{processbis}=0;
168 0 $self->{index}=0;
169 0 my $n1=scalar @candidates;
170 0 my $n2=scalar @candidatesbis;
171 0 print $oldnet->eNewick()."(".$self->{numleaves}.")($n1,$n2):\n";
172 }
173 0 ▶ if (($self->{index} == (scalar @{$self->{candidates}})) && $self->{processbis}==0
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"index"} == scalar @{$self->{"candidates"};} and $self->{"processbis"} == 0) 0 0 0
Condition0%0/3
$self->{"index"} == scalar @{$self->{"candidates"};} and $self->{"processbis"} == 0
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"index"} == scalar @{$self->{"candidates"};} and $self->{"processbis"} == 0
$self->{"index"} == scalar @{$self->{"candidates"};} $self->{"processbis"} == 0
Truth table0%0/3
A and B
A= $self->{"index"} == scalar @{$self->{"candidates"};}B= $self->{"processbis"} == 0
ABresult
0X0
100
111
174 ) {
175 0 $self->{processbis}=1;
176 0 $self->{index}=0;
177 0 print "--\n";
178 }
179 0 ▶ if ($self->{processbis}==0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'processbis'} == 0) { } 0 0 0
180 0 my $graph=$self->{oldnet}->{graph}->copy();
181 0 my $u=$self->{candidates}->[$self->{index}];
182 0 foreach my $w ($graph->predecessors($u)) {
183 0 $graph->delete_edge($w,$u);
184 0 $graph->add_edge($w,"t$n");
185 }
186 0 $graph->add_edge("t$n",$u);
187 0 $graph->add_edge("t$n",$self->{newleaf});
188 0 my $net=Bio::PhyloNetwork->new(-graph=>$graph);
189 0 $self->{index}++;
190 0 return $net;
191 } else {
192 0 my $graph=$self->{oldnet}->{graph}->copy();
193 0 my $u=$self->{candidatesbis}->[$self->{index}];
194 # print "<<$u\n";
195 0 $graph->add_edge($u,$self->{newleaf});
196 0 my $net=Bio::PhyloNetwork->new(-graph=>$graph);
197 0 $self->{index}++;
198 0 return $net;
199 }
200 }
201 }
202  
203 1 1;
↑ Summary PhyloNetwork/FactoryX.pm »