此代码在STDOUT 上生成 SVG 输出(我没有资格评论是否显示了正确的节点):
use v5.16; # sets strict and warnings
use Bio::Phylo::Forest;
use Bio::Phylo::Treedrawer;
my $string = '(B:6.0,(A:5.0,C:3.0,E:4.0):5.0,D:11.0);';
my $forest
= Bio::Phylo::IO->parse( -format => 'newick', -string => $string )->first;
my $treedrawer = Bio::Phylo::Treedrawer->new(
-width => 800,
-height => 600,
-shape => 'CURVY', # curvogram
-mode => 'PHYLO', # phylogram
-format => 'SVG'
);
$treedrawer->set_scale_options(
-width => '100%',
-major => '10%', # major cross hatch interval
-minor => '2%', # minor cross hatch interval
-label => 'MYA',
);
$treedrawer->set_tree($forest);
$treedrawer->set_format('Svg');
print $treedrawer->draw;
为了生成 PNG 图像,我使用脚本将 SVG 输出定向到文件,并使用 ImageMagick 的 convert 实用程序将其转换为 PNG。它看起来像这样:
也有使用Bio::Phylo::Treedrawer 直接创建PNG 图像的工具。要让Bio::Phylo::Treedrawer 输出 PNG 图像,您可以使用以下命令修改对象的属性:$treedrawer->set_format('Png');
但是在我的系统上,我在使用 PNG 图像格式时收到警告:
WARN Bio::Phylo::Treedrawer::Abstract::_draw_legend [Bio/Phylo/Treedrawer/Abstract.pm: 106] - Bio::Phylo::Treedrawer::Png can't draw a legend。我不认为这是一个错误。该消息可能会更好地表达为:
Bio::Phylo::Treedrawer::Png does not support drawing a legend
如果 Bio::Phylo::Treedrawer 的 SVG 输出优于 Bio::Tree::Tree 的输出,那么您可能只想将其用作数据格式。您可以使用图像编辑器或 perl 模块转换您的输出文件,该模块可以将您的 SVG 数据转换为 PNG 作为脚本的一部分。