Hi Liam,
Yes bind.tree() is the function to use here. Two notes below:
On Sat, 02 Apr 2011 00:03:51 -0400 "Liam J. Revell"
<liam.rev...@umb.edu> wrote:
Of course, we could generalize my preceding suggestion with the
following function:
add.everywhere<-function(tree,tip.name){
tree<-unroot(tree)
tree$edge.length<-rep(1,nrow(tree$edge))
new.tip<-list(edge=matrix(c(2,1),1,2),tip.label=tip.name,
edge.length=1,Nnode=1)
To be safe with other functions in ape, you'd better set 'edge' and
'Nnode' as integers, eg:
new.tip<-list(edge=matrix(c(2L,1L),1,2),tip.label=tip.name,
edge.length=1,Nnode=1L)
Or you can do:
new.tip <- compute.brlen(stree(1, tip.label = tip.name), 1)
and the next line is not needed.
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)
Indeed, 'position' cannot be used if the trees have no branch length:
this has the side-effect that a node cannot be added to the 'x' tree;
'y' can only be grafted to an existing node of 'x'. I'll try fix that,
so you won't have to set and then delete branch lengths.
Cheers,
Emmanuel
trees[[i]]$edge.length<-NULL
}
return(trees)
}
Try it:
tree<-read.tree(text="((George,Paul),(Ringo,John));")
trees<-add.everywhere(tree,"Pete_Best")
plot(trees,type="unrooted")
--
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:33 PM, Liam J. Revell wrote:
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
_______________________________________________
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