2 # Module for Bio::PhyloNetwork::TreeFactoryMulti
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
6 # Cared for by Gabriel Cardona <gabriel(dot)cardona(at)uib(dot)es>
8 # Copyright Gabriel Cardona
10 # You may distribute this module under the same terms as perl itself
12 # POD documentation - main docs before the code
16 Bio::PhyloNetwork::TreeFactoryMulti - Module to sequentially generate
24 use Bio::PhyloNetwork;
25 use Bio::PhyloNetwork::TreeFactory;
27 # Will generate sequentially all the 15 binary phylogetic
30 my $factory=Bio::PhyloNetwork::TreeFactory->new(-numleaves=>4);
34 while (my $net=$factory->next_network()) {
36 print "".(scalar @nets).": ".$net->eNewick()."\n";
41 Sequentially builds a (binary) phylogenetic tree each time
42 next_network is called.
46 Gabriel Cardona, gabriel(dot)cardona(at)uib(dot)es
54 The rest of the documentation details each of the object methods.
58 package Bio
::PhyloNetwork
::TreeFactoryMulti
;
63 use base
qw(Bio::Root::Root);
65 use Bio
::PhyloNetwork
;
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
75 -leaves => reference to an array (of leaves names)
77 Returns a Bio::PhyloNetwork::TreeFactory object. Such an object will
78 sequentially create binary phylogenetic trees
79 each time next_network is called.
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".
90 my $self=$pkg->SUPER::new
(@args);
92 my ($leavesR,$numleaves,$numhybrids)=
93 $self->_rearrange([qw(LEAVES
98 if ((! defined $leavesR) && (defined $numleaves)) {
99 @leaves=map {"l$_"} (1..$numleaves);
102 if (! defined $leavesR) {
103 $self->throw("No leaves set neither numleaves given");
106 $self->{leaves
}=$leavesR;
109 $self->{numleaves
}=$numleaves;
110 if ($numleaves > 2) {
111 my @leavesparent=@leaves;
112 my $newleaf=pop @leavesparent;
113 $self->{newleaf
}=$newleaf;
115 new
($pkg,-leaves
=>\
@leavesparent);
116 my $oldnet=$self->{parent
}->next_network();
117 $self->{oldnet
}=$oldnet;
118 my @candidates=$oldnet->nodes();
119 $self->{candidates
}=\
@candidates;
120 my @candidatesbis=$oldnet->internal_nodes();
121 $self->{candidatesbis
}=\
@candidatesbis;
122 $self->{processbis
}=0;
132 Usage : my $net=$factory->next_network()
133 Function: returns a tree
134 Returns : Bio::PhyloNetwork
142 my $n=$self->{numleaves
};
143 if ($self->{numleaves
} == 2) {
144 if ($self->{index} == 0) {
145 my $graph=Graph
::Directed
->new();
146 $graph->add_edges("t0",$self->{leaves
}->[0],"t0",$self->{leaves
}->[1]);
147 my $net=Bio
::PhyloNetwork
->new(-graph
=>$graph);
156 if (($self->{index} == (scalar @
{$self->{candidatesbis
}})) && $self->{processbis
}
158 my $oldnet=$self->{parent
}->next_network();
162 $self->{oldnet
}=$oldnet;
163 my @candidates=$oldnet->nodes();
164 $self->{candidates
}=\
@candidates;
165 my @candidatesbis=$oldnet->internal_nodes();
166 $self->{candidatesbis
}=\
@candidatesbis;
167 $self->{processbis
}=0;
169 my $n1=scalar @candidates;
170 my $n2=scalar @candidatesbis;
171 print $oldnet->eNewick()."(".$self->{numleaves
}.")($n1,$n2):\n";
173 if (($self->{index} == (scalar @
{$self->{candidates
}})) && $self->{processbis
}==0
175 $self->{processbis
}=1;
179 if ($self->{processbis
}==0) {
180 my $graph=$self->{oldnet
}->{graph
}->copy();
181 my $u=$self->{candidates
}->[$self->{index}];
182 foreach my $w ($graph->predecessors($u)) {
183 $graph->delete_edge($w,$u);
184 $graph->add_edge($w,"t$n");
186 $graph->add_edge("t$n",$u);
187 $graph->add_edge("t$n",$self->{newleaf
});
188 my $net=Bio
::PhyloNetwork
->new(-graph
=>$graph);
192 my $graph=$self->{oldnet
}->{graph
}->copy();
193 my $u=$self->{candidatesbis
}->[$self->{index}];
195 $graph->add_edge($u,$self->{newleaf
});
196 my $net=Bio
::PhyloNetwork
->new(-graph
=>$graph);