to_newick(-nodelabels=>1) generates "fake" nodenames

16 views
Skip to first unread message

Yan Wong

unread,
Jul 3, 2014, 9:25:06 AM7/3/14
to bio-...@googlegroups.com
Using Bio::Phylo from github, when I write out a tree using $tree->to_newick(-nodelabels=>1), for a tree with (some) blank node names, I get a tree with nodes labelled "Node1", Node2" etc. E.g. the code below outputs 

,,test,A,B,C,D,

(((A,B)test,C)Node5,D)Node4;


Are there any switches to to_newick() I can give which suppress this, and just output unnamed nodes?

#!/usr/bin/perl
use Bio::Phylo::IO 'parse_tree';
my $tree = parse_tree(
'-format' => 'newick',
'-handle' => \*DATA,
);

$tree->visit(sub{print shift->get_name.",";});

print "\n".$tree->to_newick(-nodelabels=>1)."\n";

__DATA__
(((A,B)test,C),D); 

Rutger Vos

unread,
Jul 3, 2014, 11:45:47 AM7/3/14
to bio-...@googlegroups.com
Set the node labels with $node->set_generic( 'name' => $name ), then serialize with $tree->to_newick( -nodelabels => 1, -tipnames => 'name' ), as per the documentation:

http://search.cpan.org/dist/Bio-Phylo/lib/Bio/Phylo/Unparsers/Newick.pm


--
You received this message because you are subscribed to the Google Groups "bio-phylo" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bio-phylo+...@googlegroups.com.
To post to this group, send email to bio-...@googlegroups.com.
Visit this group at http://groups.google.com/group/bio-phylo.
For more options, visit https://groups.google.com/d/optout.

Yan Wong

unread,
Jul 3, 2014, 1:48:31 PM7/3/14
to bio-...@googlegroups.com


On Thursday, 3 July 2014 16:45:47 UTC+1, Rutger Vos wrote:

So sorry, but I'm being dense. I did indeed read the docs before posting, but they seem to suggest that to_newick(-nodelabels=>1) will by default take nodelabels from $node->get_name(). Yet in my example, there are two nodes for which get_name() == "", but which are printed with the names "Node4" and "Node5". If it's not too much trouble (and I realise I've been taking up your time here), could you post a quick code snippet which results in the output string being

"(((A,B)test,C),D);"

(i.e. the same as the input string, without the originally unnamed nodes being given new names)?
 

Rutger Vos

unread,
Jul 10, 2014, 11:16:43 AM7/10/14
to bio-...@googlegroups.com
Hi Yan,

sorry about the slow response. I have altered the behaviour of to_newick a bit because I was also bothered by the default to return autogenerated names. If you do another update from github you should now get the expected behaviour for to_newick( -nodelabels => 1 )

Best wishes,

Rutger

On Thu, Jul 3, 2014 at 7:48 PM, Yan Wong <hyan...@googlemail.com> wrote:
(((A,B)test,C),D);


Reply all
Reply to author
Forward
0 new messages