[Bioperl-l] reading and writing tree

Mark A. Jensen maj at fortinbras.us
Mon Mar 30 16:16:22 UTC 2009


Hi Peter--

do

my $output = new Bio::TreeIO(-file => ">${filename}.new", -format => "newick");

(just like writing to files using open() )

Should fix it-
cheers, MAJ

----- Original Message ----- 
From: "Peter Menzel" <pmenzel at googlemail.com>
To: <bioperl-l at lists.open-bio.org>
Sent: Monday, March 30, 2009 9:56 AM
Subject: [Bioperl-l] reading and writing tree


> 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
> _______________________________________________
> Bioperl-l mailing list
> Bioperl-l at lists.open-bio.org
> http://lists.open-bio.org/mailman/listinfo/bioperl-l
> 
>



More information about the Bioperl-l mailing list