[Bioperl-l] Unrooting a tree

Felix Schlesinger schlesi at ebi.ac.uk
Tue Jul 10 08:58:00 EDT 2007


>  I don't think there is a function for this yet but it would be a good one
> to have.
> I assume you don't really want to take a shot at writing it though?
> To make this work I think you have to create a new node which contains the
> trifurcation and this node is what the root is set to.

Creating a new root is fine, but what would the (3) children of that
node be? I took a different approach now, where I iterate over all
(indirect) descendents of the root, find the first one which does not
have the root as its direct ancestor and move it up the tree, i.e.

foreach my $d ($root->get_all_Descendents){
  if ($d->ancestor != $root){
    if ($root->add_Descendent($d, 1) == 3){

This will make the old root a trifurcation. It does the right thing
for what I am trying to do, but is not general I believe (it does for
example at the moment not worry about branch length). Also instead of
taking the first, taking the most distant possible subtree of a clade
up to the root might be better.


> On Jul 6, 2007, at 7:24 AM, Felix Schlesinger wrote:
> Hi,
> I am reading a rooted tree in newick format from a string (i.e. a
> bifurcation at the root) and would like to unroot it (i.e. a
> trifurcation at the root). I tried getting a grandchild of the root
> and adding it as a direct child, but that does not seem to work (the
> root still only has two descendents and the tree structure gets messed
> up). Is there a nice way to do this directly in bioperl? Doing it on
> the newick string is possible of course, but not nice.
> Thanks
>   Felix
> _______________________________________________
> Bioperl-l mailing list
> Bioperl-l at lists.open-bio.org
> http://lists.open-bio.org/mailman/listinfo/bioperl-l
> --
> Jason Stajich
> jason at bioperl.org
> http://jason.open-bio.org/

More information about the Bioperl-l mailing list