我正在尝试使用bioperl从newick树中删除节点。 树文件包含以下数据:
(((A:5,B:5)90:2,C:4)25:3,d:10);
以下是代码:
use Bio::TreeIO;
use Bio::Tree::TreeFunctionsI;
use strict;
use warnings;
my $input = new Bio::TreeIO(-file => "tree.newick", -format => "newick");
my $tree = $input->next_tree;
my $bool = $tree-> remove_Node('B');
print $bool;
输出:1;
所以remove_Node正在工作,但问题是当我打开树文件时我发现节点仍然存在!... 代码有什么问题?如何从树中删除节点?
提前致谢。
答案 0 :(得分:2)
use strict;
use warnings;
use Bio::TreeIO;
use Bio::Tree::TreeFunctionsI;
my $in = Bio::TreeIO->new( -format => 'newick',
-file => 'tree.newick' );
my $out = Bio::TreeIO->new( -format => 'newick' );
while ( my $tree = $in->next_tree ) {
$tree->remove_Node('B');
$out->write_tree($tree);
}