有谁知道如何在 perl 中以编程方式将文本格式的phylip 树格式文件转换为 PNG 图像?
树文件:
(
B:6.0,
(
A:5.0,
C:3.0,
E:4.0)
:5.0,
D:11.0);
我曾尝试使用该Bio::Tree::Tree
模块,但它会将不正确的节点写入 SVG 文件。
有谁知道如何在 perl 中以编程方式将文本格式的phylip 树格式文件转换为 PNG 图像?
树文件:
(
B:6.0,
(
A:5.0,
C:3.0,
E:4.0)
:5.0,
D:11.0);
我曾尝试使用该Bio::Tree::Tree
模块,但它会将不正确的节点写入 SVG 文件。
此代码在以下位置生成 SVG 输出STDOUT
(我没有资格评论是否显示了正确的节点):
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。它看起来像这样:
也有直接创建PNG图像的工具Bio::Phylo::Treedrawer
。要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
如果 SVG 输出比 SVG 输出Bio::Phylo::Treedrawer
更可取,Bio::Tree::Tree
那么您可能只想将其用作数据格式。您可以使用图像编辑器或 perl 模块转换您的输出文件,该模块可以将您的 SVG 数据转换为 PNG 作为脚本的一部分。