【问题标题】:Converting PHYLIP text file to a PNG image将 PHYLIP 文本文件转换为 PNG 图像
【发布时间】:2014-12-18 11:25:42
【问题描述】:

有谁知道我如何在 perl 中以编程方式将文本格式的 phylip tree format 文件转换为 PNG 图像?

树文件:

(  
B:6.0,  
(  
A:5.0,  
C:3.0,  
E:4.0)  
:5.0,  
D:11.0);    

我曾尝试使用 Bio::Tree::Tree 模块,但它会将不正确的节点写入 SVG 文件。

【问题讨论】:

  • 你能使用下面描述的模块吗?生成的 SVG 输出是否符合您的预期?
  • 当您尝试下面的代码时,在尝试使用 PNG 之前使用 SVG 输出 :-) 对于 PNG,我建议直接从脚本内部写入文件句柄。

标签: perl tree bioinformatics scientific-computing bioperl


【解决方案1】:

此代码在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 作为脚本的一部分。

【讨论】:

  • 它说,全局符号“$tree”在第 25 行需要明确的包名。
  • @Nari2 错字... ->set_tree 方法应该在 $forest 上调用而不是 $tree
  • 我不仅错过了那个错字,我还错过了一个事实,即我可以说我没有看到 $forest 因为$tree :-)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-06-11
  • 2011-09-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多