Thursday, April 19, 2012

Creating Trees

I told Luke Mahler about how I'm interested in practicing analyses in R with my particular group of interest, even though I haven't collected data on more than a few species and I don't have a tree.  He told me creating a tree from previously published studies is easy:  just import the tree into R in newick format! In the geiger package in R, there is a function read.tree that does just that.

The tricky part about doing this is creating the newick-format tree itself.  It involves a lot of parentheses, colons, and parentheses:

exampleTree = read.tree(text = "(((A:1, B:1):1, C:2):1, D:3);")

will give you

Since I was typing out the newick-format tree directly within read.tree, I needed to make sure it went into the text argument instead of the file argument.  As for the newick format itself, the tip names are followed by the immediately subtending branch length:  hence A:1 or D:3.  The nodes also need to be provided with branch lengths, which is the :1 following each clade designated in parentheses. Finally, you can't forget the semi-colon at the end.  It is very easy to get lost in a sea of parentheses, especially for large trees, so inevitably I needed to go back to make changes.  Testing small clades at a time makes this a little easier.

In my particular tree, I had polytomies, which I designated with 0-length internal branches.  So if in the above tree, I actually don't have any information about the interrelationships of A, B, and C, I can use this:

polytomyTree = read.tree(text = "(((A:1, B:1):0, C:1):1, D:2);")

to get


No comments:

Post a Comment