Does anyone know how I can convert a phylip tree format file in text format to a PNG image programmically in perl?
Tree file:
(
B:6.0,
(
A:5.0,
C:3.0,
E:4.0)
:5.0,
D:11.0);
I have tried using the Bio::Tree::Tree
module but it writes incorrect nodes into an SVG file.
This code produces SVG output on
STDOUT
(I'm not qualified to comment on whether the correct nodes are displayed):To produce a PNG image I used the script to direct the SVG output to a file and converted it to PNG with ImageMagick's
convert
utility. It looks like this:There are facilities for directly creating PNG images with
Bio::Phylo::Treedrawer
as well. To haveBio::Phylo::Treedrawer
output PNG images you can modify the object's properties using:$treedrawer->set_format('Png');
However on my system I get a warning when using the PNG image format:
WARN Bio::Phylo::Treedrawer::Abstract::_draw_legend [Bio/Phylo/Treedrawer/Abstract.pm: 106] - Bio::Phylo::Treedrawer::Png can't draw a legend
. I don't think this is a bug. The message would probably be better put as:Bio::Phylo::Treedrawer::Png does not support drawing a legend
If the SVG output from
Bio::Phylo::Treedrawer
is preferable to that ofBio::Tree::Tree
then you may want to just use that as your data format. You can convert your output file with either an image editor or a perl module that can convert your SVG data to PNG as part of the script.