[Bioperl-l] Convert newick to nexus format
Jason Stajich
jason at bioperl.org
Mon Feb 5 19:43:09 UTC 2007
please cc the mailing list when asking a question or followup.
Sorry I don't know what you are doing wrong - you didn't resend your
code so I don't know if you still have a typo.
This code works fine for me
use Bio::TreeIO;
use strict;
my ($filein,$fileout) = @ARGV;
my ($format,$oformat) = qw(newick nexus);
my $in = Bio::TreeIO->new(-file => $filein, -format => $format);
my $out= Bio::TreeIO->new(-format => $oformat, -file => ">$fileout");
while( my $t = $in->next_tree ) {
$out->write_tree($t);
}
On Feb 5, 2007, at 11:24 AM, Neha Nahar wrote:
> Thank you very much for the reply.
>
> I fixed the code as per your suggestion,but now am getting a
> different error:
>
> $ ./nexus.pl mrp-input.txt nexus.out
> newickfile=mrp-input.txt, nexusfile=nexus.out
>
> ------------- EXCEPTION -------------
> MSG: Cannot call method write_tree on Bio::TreeIO object must use a
> subclass
> STACK Bio::TreeIO::nexus::write_tree /usr/lib/perl5/vendor_perl/
> 5.8.8/Bio/TreeIO/nexus.pm:170
> STACK toplevel ./nexus.pl:23
>
> --------------------------------------
>
> Please help me out with this script.
>
> Thank you.
> Regards,
> Neha
>
>
>
>
> Jason Stajich <jason at bioperl.org> wrote: you want to write the TREE
> out not the TREE WRITER.
>
>
> $treeout->write_tree($tree)
>
> not
> $treeout->write_tree($treeout);
>
> On Feb 5, 2007, at 9:59 AM, Neha Nahar wrote:
>
> Hello everyone,
>
>
> I am trying to convert newick tree to nexus format.
> Using the script (refered from and email from George dated Wed Sep
> 22 11:52:47 EDT 2004) :
>
>
> /*------------------------------------------------------------*/
>
>
> $ cat nexus.pl
> #!/usr/bin/perl -w
>
>
> use Bio::TreeIO;
>
>
> ($NEWICKFILE, $NEXUSFILE) = @ARGV;
> print "newickfile=$NEWICKFILE, nexusfile=$NEXUSFILE\n";
> my $treeio = new Bio::TreeIO(-format => 'newick', -file =>
> "$NEWICKFILE");
> my $treeout = new Bio::TreeIO(-format => 'nexus', -file => ">
> $NEXUSFILE");
> while(my $tree = $treeio->next_tree) {
> $treeout->write_tree($treeout);
> }
>
>
> exit 0;
>
>
>
>
> /*------------------------------------------------------------*/
>
>
> Running the script through command line:
> Gives the following error:
>
>
> $ ./nexus.pl mrp-input.txt nexus.out
> newickfile=mrp-input.txt, nexusfile=nexus.out
>
>
> ------------- EXCEPTION -------------
> MSG: Cannot call method write_tree on Bio::TreeIO object must use a
> subclass
> STACK Bio::TreeIO::nexus::write_tree /usr/lib/perl5/vendor_perl/
> 5.8.8/Bio/TreeIO/nexus.pm:170
> STACK toplevel ./nexus.pl:23
>
>
> --------------------------------------
>
>
>
>
> Using bioperl-1.5.2_101.tar.gz module from http://search.cpan.org/
> ~sendu/bioperl/Bio/TreeIO.pm
>
>
> Questions:-
>
>
> 1. Please let me know if I am using the correct version.
> If not, please point me to the latest one.
>
>
> 2. Provided that the version I am using is the right one, please
> let me know what is wrong with the script.
>
>
> Thank you.
> Regards,
> Neha.
>
>
>
>
>
>
>
>
>
>
> -Neha Nahar
> " Work for cause and not for applause, live to express and not to
> impress !"
>
>
> ---------------------------------
> Here’s a new way to find what you're looking for - Yahoo! Answers
>
>
> --
> Jason Stajich
> Miller Research Fellow
> University of California, Berkeley
> lab: 510.642.8441
>
> http://pmb.berkeley.edu/~taylor/people/js.html
> http://fungalgenomes.org/
>
>
>
>
>
>
> -Neha Nahar
> " Work for cause and not for applause, live to express and not to
> impress !"
>
> ---------------------------------
> Here’s a new way to find what you're looking for - Yahoo! Answers
--
Jason Stajich
Miller Research Fellow
University of California, Berkeley
lab: 510.642.8441
http://pmb.berkeley.edu/~taylor/people/js.html
http://fungalgenomes.org/
More information about the Bioperl-l
mailing list