5 Image.pm - a front-end class to the Phylo library to easily generate tree images.
9 This class provides some simple functions to generate a tree images in PNG format directly from a tree
10 definition file provided in the constructor and can embed the file on any html page using generate_html().
11 The image width and the image height can be set using set_image_width() and set_image_height().
13 A standard set of links is created in the file. There is currently not much control over how the program
14 generates these links. They essentially point to the SGN tree browser, so that the tree can be explored
19 Lukas Mueller (lam87@cornell.edu)
27 use CXGN
::Phylo
::Tree_browser
;
29 package CXGN
::Phylo
::Image
;
35 my $self = bless $args, $class;
37 $self->set_file($hash_ref->{file
});
38 $self->set_file_type($hash_ref->{type
});
39 $self->set_image_width(150);
40 $self->set_image_height(150);
44 =head2 function get_file
59 =head2 function set_file
74 =head2 function get_file_type
86 return $self->{file_type
};
89 =head2 function set_file_type
101 $self->{file_type
}=shift;
113 return $self->{view
};
116 =head2 function get_image_width
126 sub get_image_width
{
128 return $self->{image_width
};
131 =head2 function set_image_width
141 sub set_image_width
{
143 $self->{image_width
}=shift;
146 =head2 function get_image_height
156 sub get_image_height
{
158 return $self->{image_height
};
161 =head2 function set_image_height
171 sub set_image_height
{
173 $self->{image_height
}=shift;
176 =head2 function read_file()
178 Synopsis: $image->read_file($filename);
180 Returns: a newick formatted string
181 Side effects: sets the tree_string property
182 Description: it reads either a tre file or a file with no particular
183 format that contains a newick string. It the file type that
184 is available through get_file_type() to determine what file
185 type the file is. It also looks at the extension: files with a
186 suffix of .tre are assumed to be of tre format.
194 my $tree_file_obj = CXGN
::Phylo
::Tree
->new(file
=> $file, type
=>$type);
195 return $tree_file_obj->get_tree_string();
198 =head2 function get_tree_string
208 sub get_tree_string
{
210 return $self->{tree_string
};
213 =head2 function set_tree_string
223 sub set_tree_string
{
225 $self->{tree_string
}=shift;
231 # read asterids definition file
233 open (F
, "<".$self->get_file()) || die "Can't open file\n";
241 print STDERR
"Newick String: $newick\n";
242 my $parser = CXGN
::Phylo
::Parse_newick
->new($newick);
243 my $tree = $parser->parse();
247 if (!$tree) { exit(-1); }
248 if (!$self->get_view()) {
249 $self->set_view("asterid");
252 # retrieve some key nodes
254 my ($sol) = $tree->search_node_name("Solanaceae");
255 my ($con) = $tree->search_node_name("Convolvulaceae");
256 my ($ros) = $tree->search_node_name("Asterids");
257 my ($mon) = $tree->search_node_name("Monocots");
259 if ($self->get_view() eq "asterid") {
270 if ($self->get_view() eq "solanaceae") {
271 $tree->set_root($sol);
272 $tree->get_layout()->set_image_height($self->get_image_height());
273 $tree->get_layout()->set_image_width($self->get_image_width());
278 my $browser=CXGN
::Phylo
::Tree_browser
->new();
279 my ($tempfile, $temp_url) = $browser->create_temp_file();
280 my $renderer = CXGN
::Phylo
::PNG_tree_renderer
->new($tree);
281 $renderer->get_layout()->set_top_margin(20);
282 $renderer->get_layout()->set_bottom_margin(20);
284 $renderer->render_png($tempfile.".png");
285 my $html_image_map = $renderer->get_html_image_map("map");
289 print "<img src=\"$temp_url.png\" usemap=\"#map\" /> " ;
290 print "$html_image_map";