Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion R/utilities.R
Original file line number Diff line number Diff line change
Expand Up @@ -1695,14 +1695,28 @@ bind.tip<-function(tree,tip.label,edge.length=NULL,where=NULL,position=0,interac
} else pp<-position
if(is.null(edge.length)&&is.ultrametric(tree)){
H<-nodeHeights(tree)
if(where==(Ntip(tree)+1)) edge.length<-max(H)
if(where==(Ntip(tree)+1)){
edge.length<-max(H)
# if adding tip as outgroup that diverged before ingroup MRCA, need to take into account new root height
if(position>0){
edge.length<-edge.length+position
}
}
else edge.length<-max(H)-H[tree$edge[,2]==where,2]+position
}
tip<-list(edge=matrix(c(2,1),1,2),
tip.label=tip.label,
edge.length=edge.length,
Nnode=1)
class(tip)<-"phylo"
# if attaching tip creates new root, add root edge to attach to
if(where==(Ntip(tree)+1)&&position>0){
if(is.null(tree$root.edge)){
tree$root.edge<-position
pp<-position
where<-"root"
}
}
obj<-bind.tree(tree,tip,where=where,position=pp)
if(where<=Ntip(tree)&&position==0){
nn<-obj$edge[which(obj$edge[,2]==which(obj$tip.label==tip$tip.label)),1]
Expand Down