[Bioperl-l] reading and writing tree
Peter Menzel
pmenzel at googlemail.com
Mon Mar 30 13:56:02 UTC 2009
Hi,
using the TreeIO class, I try to read a tree from a newick file,
delete some nodes, and write the tree using write_tree().
Besides that I cannot write to files, that don't exist already, it's
also not possible to write to existing files.
The following error message is written:
Filehandle GEN1 opened only for input at
/usr/share/perl5/Bio/Root/IO.pm line 421.
So apparently somehow a file handle is associated with the tree, since
different TreeIO objects are used.
Is there a workaround for this problem?
The actual code I run:
#!/usr/bin/perl -w
use strict;
use Bio::TreeIO;
my $filename = shift @ARGV;
# parse in newick/new hampshire format
my $input = new Bio::TreeIO(-file => $filename,
-format => "newick");
my $tree = $input->next_tree;
foreach my $nodename (@ARGV) {
my @nodes = $tree->find_node(-id => $nodename);
if(@nodes > 0) {
foreach my $n (@nodes) {
$tree->remove_Node($n);
}
}
}
$input->close();
#write tree to new file
my $output = new Bio::TreeIO(-file => $filename.".new", -format => "newick");
$output->write_tree($tree);
kind regards, Peter
More information about the Bioperl-l
mailing list