Hi Matthew.

I don't doubt that other members of the list have better suggestions, but it is possible to add a tip in all possible places using bind.tree() in "ape."

For instance, starting with a random unrooted tree with, say, 4 taxa:

tree<-rtree(n=4,rooted=FALSE,br=rep(1,5))
# create a 5th species, here "t5", to add as a "phylo" object
# [I don't think this can be avoided with bind.tree()]
new.tip<-list(edge=matrix(c(2,1),1,2),tip.label="t5",edge.length=1,Nnode=1)
class(new.tip)<-"phylo"
# add the new tip to all edges of the tree
trees<-list(); class(trees)<-"multiPhylo"
for(i in 1:nrow(tree$edge))
trees[[i]]<-bind.tree(tree,new.tip,where=tree$edge[i,2],position=0.5)
# now plot them to see what we have done
plot(trees,type="unrooted",use.edge.length=F)

Of course I would be happy to see a more elegant solution!

Sincerely, Liam

--
Liam J. Revell
University of Massachusetts Boston
web: http://faculty.umb.edu/liam.revell/
email: liam.rev...@umb.edu
blog: http://phytools.blogspot.com

On 4/1/2011 11:02 PM, Matthew Vavrek wrote:
Hello again all,
I got a number of great solutions to my last question about branch and
bound maximum parsimony searches, several of which had definitely not
crossed my mind. However, being stubborn (or is that stupid? Hard to
tell sometimes) I went ahead and have started putting together a branch
and bound style search function for R, just because (I'll try to get it
up on CRAN shortly). It works, however it's not as efficient as I think
it probably could be, probably because the method I use to add new taxa
to the tree involves text searches with grep to create Newick trees. All
that being said, is there any way to take an existing tree (in any
format, such as Newick, but also the edge lists like in an ape 'phylo'
object) and add a taxon at all the possible positions? I know allTrees()
exists, but that would give me all the possibilities, rather than a
restricted set (as I would need for branch and bound).

Thanks again
Matthew

_______________________________________________
R-sig-phylo mailing list
R-sig-phylo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-phylo

_______________________________________________
R-sig-phylo mailing list
R-sig-phylo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-phylo

Reply via email to