Hi, I've banged my head long enough with this one, so I hope someone can help. I am trying to write a routine to permute the structure of a tree. Note, this is different than phyloshuffle() in phylotools, which just shuffles tips -- in contrast, I am trying to permute the structure of the tree. In this case I cannot resample the original data because these trees are manually constructed, yet I want a way or doing some statistics on them. If there is a package doing this that I've missed? I would like to be able to specify a number of iterations (easy) and the routine would repeatedly switch random pairs of clades within the tree (not so easy, apparently). If the routine is run for many iterations, the resulting tree would be completely random. This seems simple, but given the dependencies in the tree, you can't pick just any two nodes; for example, the second node cannot be a descendant of the first node. Also, it seems like I need to test that the two subtrees are structurally ! independent, but I'm not certain exactly what these criteria are. They don't appear to have to be the same distance from the root in all cases. The next problem is how to do this in ape. I'm reasonably familiar with the phylo() object, but obviously since I'm posting this, I haven't been able to make it work. Especially, the bind.tree() step.
Thanks much for any help, Sean ## Tree Permutation ## Note, code does not work correctly! library(ape) library(distory) atree<-read.tree(text="((L1496,L1499),((L1498,L1490),((L1497,L1494),((L1493,L1492),(L1503,(L1502,(L1212,L1501)))))),L1489);") atree<-makeNodeLabel(atree, prefix = "") atree<-compute.brlen(atree,1) n=1 # No. itterations plot.phylo(atree, show.node.label = TRUE) ptree<-atree # a copy to permute for (i in 1:n){ # Pick the first node from the tree a.node<-as.numeric(sample(ptree$node,1)) a.node <- 2 # testing # This creates a subtree to sample the second branch from extract.a<-extract.clade(ptree,node=as.character(a.node)) drop.a.node<-drop.tip(ptree,extract.a$tip.label, trim.internal=F) #trim F to leave a place to attach other subtree plot(extract.a, show.node.label = TRUE) plot(drop.a.node, show.node.label = TRUE) # Pick a node from somewhere ealse in the tree b.node<-as.numeric(sample(drop.a.node$node,1)) b.node <- 5 #testing # This creates a subtree to sample the second branch from extract.b<-extract.clade(drop.a.node,node=as.character(b.node)) drop.b.node<-drop.tip(drop.a.node,extract.b$tip.label, trim.internal=F) plot(extract.b, show.node.label = TRUE) plot(drop.b.node, show.node.label = TRUE) # drop.b.node contains whatever is left after clipping out the two subtrees # now I want to reassemble the tree switching extract.a and extract.b bind.tree.1<-bind.tree(drop.b.node,extract.a,where=b.node) # doesnt work? plot(bind.tree.1, show.node.label = TRUE) bind.tree.2<-bind.tree(bind.tree.1,extract.b,where=a.node) plot(bind.tree.2, show.node.label = TRUE) #copy the results ptree <- bind.tree.2 } #plot the permuted tree plot(ptree, show.node.label = TRUE) #END ************************************* Sean S. Downey, Ph.D. Institute of Archaeology University College London 31-34 Gordon Square London WC1H 0PY s.dow...@ucl.ac.uk http://www.homepages.ucl.ac.uk/~tcrnssd/ UK Cell: +44 (0)7542 41 0077 Belize Cell: +501 636-2939 _______________________________________________ R-sig-phylo mailing list R-sig-phylo@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-phylo