2 # Module for Bio::PhyloNetwork::GraphViz
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::GraphViz - Interface between PhyloNetwork and GraphViz
20 use Bio::PhyloNetwork;
21 use Bio::PhyloNetwork::GraphViz;
23 my $net=Bio::PhyloNetwork->new(
24 -eNewick=>'((H1,(H1,(H2,l))),H2)t0; (some long label)H1; ("quoted label")H2;'
27 my $gv=Bio::PhyloNetwork::GraphViz->new(-net=>$net,-short_labels=>1);
29 foreach my $u ($net->nodes()) {
30 print "$u:".$gv->nodePN_to_nodeGV->{$u}."\n";
41 This is a module to create GraphViz objects representing phylogenetic networks.
45 Gabriel Cardona, gabriel(dot)cardona(at)uib(dot)es
49 L<Bio::PhyloNetwork>, L<GraphViz>
53 The rest of the documentation details each of the object methods.
57 package Bio
::PhyloNetwork
::GraphViz
;
62 use base
qw(Bio::Root::Root GraphViz);
64 use Bio
::PhyloNetwork
;
69 Usage : my $graphv = new Bio::PhyloNetwork::GraphViz();
70 Function: Creates a new Bio::PhyloNetwork::GraphViz object
71 Returns : Bio::PhyloNetwork::GraphViz
72 Args : -net => Bio::PhyloNetwork object
73 -short_labels => boolean (optional)
75 Returns a Bio::PhyloNetwork::GraphViz object, which is an extension of
76 a GraphViz object. The GraphViz object is a representation of the
77 phylogenetic network given. The extra information the created object
78 holds is a hash table with keys the nodes of the PhyloNetwork object
79 and values the nodes of the GraphViz object. If the optional argument
80 -short_labels=E<gt>1 is given, the labels of the nodes in GraphViz are
81 shortened to a maximum of 3 letters.
88 my $self=$pkg->SUPER::new
(@args);
90 my ($net,$short_labels)=
91 $self->_rearrange([qw(NET
92 SHORT_LABELS)],@args);
93 if (! defined $short_labels) {
96 my $gv=GraphViz
->new();
97 my $nodePN_to_nodeGV={};
98 my @nodes=$net->nodes();
99 foreach my $node (@nodes) {
100 # my $namenode=generate_name($node);
101 # $names->{$node}=$namenode;
103 my $labelnodeint=$net->{labels
}->{$node};
105 my $labelnode=($short_labels ? find_short_label
($labelnodeint) : find_label
($labelnodeint));
107 $gv->add_node(#$namenode,
109 shape
=>($net->is_tree_node($node) ?
'circle' : 'box'));
110 $nodePN_to_nodeGV->{$node}=$nodeGV;
112 my @edges=$net->edges();
113 foreach my $edge (@edges) {
114 my $node1=$edge->[0];
115 # my $namenode1=generate_name($node1);
116 my $node2=$edge->[1];
117 # my $namenode2=generate_name($node2);
118 $gv->add_edge($nodePN_to_nodeGV->{$node1},$nodePN_to_nodeGV->{$node2});
121 $self->{nodePN_to_nodeGV
}=$nodePN_to_nodeGV;
127 # if ($var =~ /\D/) {
128 # print "$var contains a number.\b";
134 sub find_short_label
{
136 return substr(find_label
($str),0,3);
141 $str =~ tr/A-Za-z0-9//cd;
145 =head2 nodePN_to_nodeGV
147 Title : nodePN_to_nodeGV
148 Usage : my $hashR=$graphv->nodePN_to_nodeGV()
149 Function: returns (a reference to) a hash holding the translation between
150 nodes of the Bio::PhyloNetwork object and nodes of the GraphViz
152 Returns : reference to hash
157 sub nodePN_to_nodeGV
{
159 return $self->{nodePN_to_nodeGV
};