Hi Sam,
Sam Brown wrote on 06/10/2009 01:37:
Dear all
To prepare for SH tests between optimised and "expected" trees, I've been
attempting to do tree manipulations in R. Pruning is easy with the dual functions of
extract.clade() and drop.tip(), however grafting the clade into a different place using
bind.tree() is proving much more difficult.
What seems to be happening is that during the tree binding process, some tips are becoming nodes and vice versa.
Any help is much appreciated!
Thank you!
Sam
Some code:
library(ape)
data(bird.orders)
phy<-bird.orders
node<-43 #Node with taxa of interest
(Columbiformes:Passeriformes)
site<-21 #Where above group is expected to be
(In a clade with Struthioniformes:Anseriformes)
j<-allDesc(node) #See function definition below
grp<-extract.clade(phy, node)
rest<-drop.tip(phy, j)
tr<-bind.tree(rest, grp, where=site)
You can solve this by setting the root.edge of 'grp':
grp$root.edge <- 0 # or any value you want
or use the 'root.edge' option of extract.clade (see the help page).
I've fixed bind.tree() to avoid this problem.
Emmanuel
plot(tr) #Should get an error: "Error in
plot.phylo(tr) : NA/NaN/Inf in foreign function call (arg 6)"
write.tree(tr) #Can see Upupiformes as sister to
NODE11, among others.
where:
allDesc<-function(node){
N<-length(phy$tip.label)
index<-which(phy$edge[,1]==node)
desc<-phy$edge[index,2]
taxa<-desc[desc<=N]
desc<-desc[desc>N]
while(length(desc)>=1){
ind<-NULL
for(i in 1:length(desc)){
ind<-c(ind,which(phy$edge[,1]==desc[i]))
}
desc<-phy$edge[ind,2]
taxa<-c(taxa,desc[desc<=N])
desc<-desc[desc>N]
}
taxa
}
_________________________________________________________________
Facebook.
k-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-nz:SI_SB_2:092010
[[alternative HTML version deleted]]
_______________________________________________
R-sig-phylo mailing list
R-sig-phylo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-phylo
--
Emmanuel Paradis
IRD, Montpellier, France
ph: +33 (0)4 67 16 64 47
fax: +33 (0)4 67 16 64 40
http://ape.mpl.ird.fr/
_______________________________________________
R-sig-phylo mailing list
R-sig-phylo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-phylo