[Biopython-dev] Rerooting a tree with Bio.Phylo

Peter biopython at maubp.freeserve.co.uk
Wed Mar 24 15:16:51 UTC 2010


On Mon, Mar 22, 2010 at 9:48 PM, Peter <biopython at maubp.freeserve.co.uk> wrote:
>> In Bio.Nexus, would you normally have handled this with the method
>> root_with_outgroup? I intend to port that method to Bio.Phylo once I
>> understand it, but the existing code has been kind of hard for me to figure
>> out.
>
> I've just got a quick answer for you now tonight: I've not used Bio.Nexus
> to try and do this - I'll try to get back to you in more depth tomorrow.

Here is an example using Bio.Nexus.Trees to reroot with an outgroup.

#I have encoded the tree here as a string:
tree_string = """((gi|6273291|gb|AF191665.1|AF191:0.00418,
(gi|6273290|gb|AF191664.1|AF191:0.00189,
gi|6273289|gb|AF191663.1|AF191:0.00145)
:0.00083):0.00770,
(gi|6273287|gb|AF191661.1|AF191:0.00489,
gi|6273286|gb|AF191660.1|AF191:0.00295)
:0.00014, (gi|6273285|gb|AF191659.1|AF191:0.00094,
gi|6273284|gb|AF191658.1|AF191:0.00018)
:0.00125);"""
from Bio.Nexus import Tree
tree = Trees.Tree(tree_string)
print "Old"
print tree
print tree.display()
print
print "New"
#This acts in situ:
tree.root_with_outgroup(["gi|6273289|gb|AF191663.1|AF191"])
print tree
print tree.display()


Old
tree a_tree = ((gi|6273291|gb|AF191665.1|AF191,(gi|6273290|gb|AF191664.1|AF191,gi|6273289|gb|AF191663.1|AF191)),(gi|6273287|gb|AF191661.1|AF191,gi|6273286|gb|AF191660.1|AF191),(gi|6273285|gb|AF191659.1|AF191,gi|6273284|gb|AF191658.1|AF191));
  #                            taxon            prev            succ
 brlen blen (sum)  support              comment
  0                                -            None       [1, 6, 9]
   0.0        0.0        -                    -
  1                                -               0          [2, 3]
0.0077     0.0077        -                    -
  2   gi|6273291|gb|AF191665.1|AF191               1              []
0.00418    0.01188        -                    -
  3                                -               1          [4, 5]
0.00083    0.00853        -                    -
  4   gi|6273290|gb|AF191664.1|AF191               3              []
0.00189    0.01042        -                    -
  5   gi|6273289|gb|AF191663.1|AF191               3              []
0.00145    0.00998        -                    -
  6                                -               0          [7, 8]
0.00014    0.00014        -                    -
  7   gi|6273287|gb|AF191661.1|AF191               6              []
0.00489    0.00503        -                    -
  8   gi|6273286|gb|AF191660.1|AF191               6              []
0.00295    0.00309        -                    -
  9                                -               0        [10, 11]
0.00125    0.00125        -                    -
 10   gi|6273285|gb|AF191659.1|AF191               9              []
0.00094    0.00219        -                    -
 11   gi|6273284|gb|AF191658.1|AF191               9              []
0.00018    0.00143        -                    -

Root:  0
None

New
tree a_tree = (((((gi|6273287|gb|AF191661.1|AF191,gi|6273286|gb|AF191660.1|AF191),(gi|6273285|gb|AF191659.1|AF191,gi|6273284|gb|AF191658.1|AF191)),gi|6273291|gb|AF191665.1|AF191),gi|6273290|gb|AF191664.1|AF191),gi|6273289|gb|AF191663.1|AF191);
  #                            taxon            prev            succ
 brlen blen (sum)  support              comment
  0                                -               1          [6, 9]
0.0077    0.00998        -                    -
  1                                -               3          [0, 2]
0.00083    0.00228        -                    -
  2   gi|6273291|gb|AF191665.1|AF191               1              []
0.00418    0.00646        -                    -
  3                                -              12          [1, 4]
0.00145    0.00145        -                    -
  4   gi|6273290|gb|AF191664.1|AF191               3              []
0.00189    0.00334        -                    -
  5   gi|6273289|gb|AF191663.1|AF191              12              []
   0.0        0.0      0.0                    -
  6                                -               0          [7, 8]
0.00014    0.01012        -                    -
  7   gi|6273287|gb|AF191661.1|AF191               6              []
0.00489    0.01501        -                    -
  8   gi|6273286|gb|AF191660.1|AF191               6              []
0.00295    0.01307        -                    -
  9                                -               0        [10, 11]
0.00125    0.01123        -                    -
 10   gi|6273285|gb|AF191659.1|AF191               9              []
0.00094    0.01217        -                    -
 11   gi|6273284|gb|AF191658.1|AF191               9              []
0.00018    0.01141        -                    -
 12                                -            None          [3, 5]
   0.0        0.0        -                    -

Root:  12
None

Here the root_with_outgroup method acts in situ, and returns the new
root ID number (not applicable to Bio.Phylo). The outgroup argument
seems to be a list of taxon names (here just one).

In my example, the outgroup originally has a branch length of 0.00145.
A new root node was created (here #12) with two children, one with a
branch length of zero (#5, the outgroup) and one with the full length
(#3, branch length 0.00145). Essentially this new root node (#12) and
the outgroup (#5) are now both right at the base of the tree.

There is more than one what to do this though. For example FigTree
seems to introduce a new root node half way along the outgroup branch
(replacing the edge with two edges of half its length). This way the
new root node represents the last common ancestor of the outgroup and
the ingroup (everything else), although putting it at the mid point is
perhaps a little arbitrary.

Peter



More information about the Biopython-dev mailing list