Jason Stajich | 21 Jun 00:17 2013
Picon

Re: Converting newick to nexus

There is an option if you see the docs for Bio::TreeIO::nexus

-header    => boolean  default is true
                         print/do not print #NEXUS header

You can set it to 0 after writing the first tree.

$out->header(0);

Perhaps this should be the default for the module - after writing a tree, set the header to 0....

Jason
On Jun 20, 2013, at 1:30 AM, soungalo <soungalo <at> walla.com> wrote:

> Dear mailing list members,
> Could you please help me with this somewhat trivial task ?
> I'm trying to convert a multi-tree newick format file to nexus format, using
> the TreeIO module. I used the following code:
> 
> ################
> #!/usr/bin/perl -w
> use strict;
> use Bio::TreeIO;
> my $usage = "script.pl INFILE OUTFILE\n";
> my $infile = shift or die $usage;
> my $outfile = shift or die $usage;
> 
> my ($filein,$fileout) =  <at> ARGV;
> my ($format,$oformat) = qw(newick nexus);
> my $in = Bio::TreeIO->new(-file => $infile, -format => $format);
> my $out= Bio::TreeIO->new(-format => $oformat, -file => ">$outfile");
> 
> while( my $t = $in->next_tree ) {
> 	$out->write_tree($t);
           $out->header(0);
> }
> ################
> 
> However, results are coming out a bit weird, since the nexus translation,
> header etc are repeated for every tree in the file, instead of creating a
> single trees block containing all trees.
> Could you please explain how to change this code in order to perform the
> conversion properly, or suggest a different way of doing this ?
> Any help will be appreciated. Thank you! 
> 
> 
> 
> --
> View this message in context: http://bioperl.996286.n3.nabble.com/Converting-newick-to-nexus-tp17013.html
> Sent from the Bioperl-L mailing list archive at Nabble.com.
> _______________________________________________
> Bioperl-l mailing list
> Bioperl-l <at> lists.open-bio.org
> http://lists.open-bio.org/mailman/listinfo/bioperl-l

Jason Stajich
jason.stajich <at> gmail.com
jason <at> bioperl.org

Gmane