PhyloNetwork/TreeFactoryX.pm

filter: Statementstmt 17.0% 14 / 82 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 50.0% 4 / 8 Podpod 50.0% 2 / 4 totaltotal 17.3% 20 / 115 CC 11 SCAR 31.5
CC
11
Cov
14%
next_network_new
42.0
new
30.0
next_network_repeated
6.0
CRAP 23.3
« PhyloNetwork/FactoryX.pm ↑ Summary PhyloNetwork.pm »
1 #
2 # Module for Bio::PhyloNetwork::TreeFactoryX
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::TreeFactoryX - 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::TreeFactoryX;
59 2 $Bio::PhyloNetwork::TreeFactoryX::VERSION = '1.7.3';
60 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
61 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
62  
63 2 ▶use base qw(Bio::Root::Root);
Subroutine BEGIN: called CC=1 SCAR=0.0
64  
65 2 ▶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_new();
117 0 $self->{oldnet}=$oldnet;
118 0 my @candidates=$oldnet->nodes();
119 0 $self->{candidates}=\@candidates;
120 }
121 0 $self->{index}=0;
122 0 $self->{found}=[];
123 0 $self->{thrown}=0;
124 0 bless($self,$pkg);
125 }
126  
127 =head2 next_network
128  
129 Title : next_network
130 Usage : my $net=$factory->next_network()
131 Function: returns a tree
132 Returns : Bio::PhyloNetwork
133 Args : none
134  
135 =cut
136  
137 0 ▶sub next_network_new {
Subroutine next_network_new: not called CC=6 SCAR=37.4
Pod undocumented
138 0 my ($self)=@_;
139  
140 0 my $n=$self->{numleaves};
141 0 ▶ if ($self->{numleaves} == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'numleaves'} == 2) { } 0 0 0
142 0 ▶ if ($self->{index} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'index'} == 0) { } 0 0 0
143 0 my $graph=Graph::Directed->new();
144 0 $graph->add_edges("t0",$self->{leaves}->[0],"t0",$self->{leaves}->[1]);
145 0 my $net=Bio::PhyloNetwork->new(-graph=>$graph);
146 0 $self->{index}++;
147 0 $self->{found}=[$net];
148 0 return $net;
149 }
150 else {
151 0 return 0;
152 }
153 }
154 else {
155 0 ▶ if ($self->{index} == (scalar @{$self->{candidates}})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"index"} == scalar @{$self->{"candidates"};}) 0 0 0
156 0 my $oldnet=$self->{parent}->next_network_new();
157 0 ▶ if (! $oldnet) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($oldnet) 0 0 0
158 0 return 0;
159 }
160 0 $self->{oldnet}=$oldnet;
161 0 my @candidates=$oldnet->nodes();
162 0 $self->{candidates}=\@candidates;
163 0 $self->{index}=0;
164 }
165 0 my $graph=$self->{oldnet}->{graph}->copy();
166 0 my $u=$self->{candidates}->[$self->{index}];
167 0 foreach my $w ($graph->predecessors($u)) {
168 0 $graph->delete_edge($w,$u);
169 0 $graph->add_edge($w,"t$n");
170 }
171 0 $graph->add_edge("t$n",$u);
172 0 $graph->add_edge("t$n",$self->{newleaf});
173 0 my $net=Bio::PhyloNetwork->new(-graph=>$graph);
174 0 $self->{index}++;
175 0 my @found=@{$self->{found}};
176 0 push @found,$net;
177 0 $self->{found}=\@found;
178 0 return $net;
179 }
180 }
181  
182 0 ▶sub next_network_repeated {
Subroutine next_network_repeated: not called CC=2 SCAR=17.9
Pod undocumented
183 0 my ($self)=@_;
184  
185 0 ▶ return 0 if ($self->{thrown} >= (scalar @{$self->{found}}));
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"thrown"} >= scalar @{$self->{"found"};} 0 0 0
186 0 $self->{thrown}=$self->{thrown}+1;
187 0 return $self->{found}->[$self->{thrown}-1];
188 }
189  
190 0 ▶sub next_network {
Subroutine next_network: not called CC=1 SCAR=6.9
Pod documented
191 0 my ($self)=@_;
192 0 return $self->next_network_new();
193 }
194  
195 2 1;
« PhyloNetwork/FactoryX.pm ↑ Summary PhyloNetwork.pm »