将PHYLIP文本文件转换为PNG图像

时间:2014-12-18 11:25:43

标签: perl tree bioinformatics scientific-computing bioperl

有没有人知道如何在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文件。

1 个答案:

答案 0 :(得分:4)

此代码在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。它看起来像这样:

<code>Bio::Phylo::Treedrawer</code> output

还可以使用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作为脚本的一部分。