2 # Module for Bio::PhyloNetwork::TreeFactory
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::TreeFactory - 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
::TreeFactory
;
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;
129 Usage : my $net=$factory->next_network()
130 Function: returns a tree
131 Returns : Bio::PhyloNetwork
139 my $n=$self->{numleaves
};
140 if ($self->{numleaves
} == 2) {
141 if ($self->{index} == 0) {
142 my $graph=Graph
::Directed
->new();
143 $graph->add_edges("t0",$self->{leaves
}->[0],"t0",$self->{leaves
}->[1]);
144 my $net=Bio
::PhyloNetwork
->new(-graph
=>$graph);
153 if ($self->{index} == (scalar @
{$self->{candidates
}})) {
154 my $oldnet=$self->{parent
}->next_network();
158 $self->{oldnet
}=$oldnet;
159 my @candidates=$oldnet->nodes();
160 $self->{candidates
}=\
@candidates;
163 my $graph=$self->{oldnet
}->{graph
}->copy();
164 my $u=$self->{candidates
}->[$self->{index}];
165 foreach my $w ($graph->predecessors($u)) {
166 $graph->delete_edge($w,$u);
167 $graph->add_edge($w,"t$n");
169 $graph->add_edge("t$n",$u);
170 $graph->add_edge("t$n",$self->{newleaf
});
171 my $net=Bio
::PhyloNetwork
->new(-graph
=>$graph);