Created
October 14, 2011 22:05
-
-
Save sckott/1288492 to your computer and use it in GitHub Desktop.
Simulate a tree with an outgroup on a long branch.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Code from Liam Revell, and put up here by Scott Chamberlain | |
require(phytools); require(geiger) # load packages | |
ntaxa1<-20; ntaxa2<-2 # number of taxa in each clade | |
total.height<-10 # total tree height (may need to be adjusted) | |
# simulate subtree 1 | |
tr1<-birthdeath.tree(b=1,d=0,taxa.stop=ntaxa1) | |
tr1$tip.label<-1:ntaxa1; tr1$root.edge<-0 | |
# simulate subtree 2 | |
tr2<-birthdeath.tree(b=1,d=0,taxa.stop=ntaxa2) | |
tr2$tip.label<-1:ntaxa2+ntaxa1; tr2$root.edge<-0 | |
# compute tree heights, so that the whole thing can be ultrametric | |
height1<-max(nodeHeights(tr1)) | |
height2<-max(nodeHeights(tr2)) | |
# create the basal split | |
tr3<-list(Nnode=1,edge=matrix(c(3,1,3,2),2,2,byrow=T),edge.length=c(total.height-height1,total.height-height2),tip.label=c("tr1","tr2")) | |
class(tr3)<-"phylo" | |
# attach the two subtrees one by one | |
tr3$tip.label[tr3$tip.label=="tr1"]<-"NA" | |
tr3<-paste.tree(tr3,tr1) | |
tr3$tip.label[tr3$tip.label=="tr2"]<-"NA" | |
tr3<-paste.tree(tr3,tr2) | |
# plot the full tree | |
plot(tr3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment