Posted on 2005-08-08 21:10:36-07 by stiffler
SVG Problem
Hello,
I am trying to use the following code to produce a SVG tree.
use Bio::Phylo::Parsers; use Bio::Phylo::Unparsers; my $newick = new Bio::Phylo::Parsers; my $trees = $newick->parse(-file => '/tmp/blasthits-3.dnd', '-format' => 'Newick'); my $svg = new Bio::Phylo::Unparsers; my $string = $svg->unparse(-phylo => $trees->first, -format => 'Svg', -mode => 'clado);
But the following error occurs:
Can't call method "calc_max_nodes_to_tips" on an undefined value at /usr/lib/perl5/site_perl/5.8.6/Bio/Phylo/Unparsers/Svg.pm line 320.

Nicholas
Direct Responses: 858 | Write a response
Posted on 2005-08-09 00:05:21-07 by rvosa in response to 854
Re: SVG Problem
Hi Stiffler,

I can see some minor issues with the code you're posting here (e.g. no closing single quote after 'clado'), but none of those can explain what you're having. Perhaps you can email me directly with the tree that's giving you trouble as an attachment?

Cheers,

Rutger
Direct Responses: 861 | Write a response
Posted on 2005-08-09 12:53:05-07 by rvosa in response to 858
Re: SVG Problem
I have uploaded Bio::Phylo version 0.03. Note that this upload *should* not solve the issues you're having (but please install it anyway) - but it might?

In any case, using the following code:
use Bio::Phylo::Parsers; use Bio::Phylo::Unparsers; my $newick = new Bio::Phylo::Parsers; my $trees = $newick->parse( -file => 'testfile.dnd', -format => 'Newick' ); my $svg = new Bio::Phylo::Unparsers; my $string = $svg->unparse( -phylo => $trees->first, -format => 'Svg', -mode => 'clado' ); print $string;

And the following tree description, saved as "testfile.dnd":
(((A,B,E),C),D);

...yields what I'd except. Perhaps you could email me the tree that is giving you trouble?

Best wishes,
Rutger
Direct Responses: 863 | Write a response
Posted on 2005-08-09 19:35:46-07 by stiffler in response to 861
Re: SVG Problem
The test file works fine, but I am still getting the error when using my tree:
( ( ( Os02g02540.1:0.23511, Os04g49570.1:0.22758) :0.00968, ( ( ( Os02g54640.1:0.30160, ( ( Os09g25960.1:0.29752, ( At2g24720.1:0.28523, ( ( At2g29100.1:0.12365, At2g29110.1:0.11997) :0.03891, At2g29120.1:0.16002) :0.11473) :0.02503) :0.01096, Os09g26160.1:0.32038) :0.00132) :0.10441, At2g32400.1:0.29685) :0.02124, ( Os07g01310.1:0.21698, Os07g33790.1:0.21789) :0.03423) :0.00954) :0.00883, ( At1g42540.1:0.21601, At3g51480.1:0.22696) :0.01379, ( At2g17260.1:0.11501, ( At4g35290.1:0.00000, At4g35290.2:0.00000) :0.10429) :0.13006);

By the way, the trees look really nice. This is exactly what I have been looking for. Will it be able to utilize the branch lenghts? Also, it would be nice if I could specify a url for the leaf nodes.
Nicholas
Direct Responses: 864 | Write a response
Posted on 2005-08-09 20:35:55-07 by rvosa in response to 863
Re: SVG Problem
Hi Nicholas,

the package works under the assumption that newick formatted tree files contain multiple trees, one tree per line. It gets confused by the line feeds in your tree description. Do a search and replace on the line feeds and try again. For example, you can while(<>) through the tree, chomp off the line breaks and concatenate them all into $chomped_string, and then parse and unparse like this:
my $parser = new Bio::Phylo::Parsers; my $tree = $parser->parse(-format => 'newick', -string => $chomped_string)->first; my $unparser = new Bio::Phylo::Unparsers; # NOTE: -mode => 'phylo' yields phylograms, so with branch lengths my $svg = $unparser->unparse(-format => 'svg', -mode => 'phylo', -phylo => $tree);
W.r.t. your request for URLs: SVG allows for that, but there's currently no option to include them into graphs produced by Bio::Phylo. Good idea though, will try to implement that.

Hope this helps,

Rutger
Direct Responses: Write a response
Perl Weekly newsletter
A free weekly newsletter for people who are busy to read all the blogs. click here to check it out.