Dear R users and phylogeneticists,
I've been manipulating some phylo objects mostly with ape functions but
also with some phangorn functions. I'm a bit confused with some effects
of rerooting and the output of various functions. Any help would be
greatly appreciated!
R code:
## Rerooting seems to fail sometimes:
library(ape)
tree <-
read.tree(text="((((G:1,H:1)g:1,(((A:1,B:1)c:1,(C:1,D:1)d:1)b:1,(E:1,F:1)e:1)a:1)f:1,K:1)h:1,I:1,J:1)i;")
clan <- list(c("G","H"),c("A","B","C","D","E","F"))[[2]]
layout(matrix(c(1,2), 1, 2), width = c(1, 1))
plot(tree,'u');nodelabels()
treeR <- root(tree, outgroup = c("I","J","K"), resolve.root = F)
plot(treeR,'u');nodelabels()
treeR$edge[1]
reorder(treeR)$edge[1]
## the root node of treeR is unchanged and within the requested
## outgroup :-(
plot(tree,'u');nodelabels()
treeR <- root(tree, outgroup = c("G","H"), resolve.root = F) # put the
root elsewhere temporarily
treeR <- root(treeR, outgroup = c("I","J","K"), resolve.root = F)
plot(treeR,'u');nodelabels()
treeR$edge[1]
reorder(treeR)$edge[1]
## the root node of treeR is now at the base of the outgroup as
## expected :-) but an additional rerooting was necessary.
## all.equal.phylo() and therefore unique.phylo() are sensitive to edge
## order in the edge matrix in unrooted trees:
clado1 <-
read.tree(text="((:1,(:1,:1):1):1,:1,((:1,:1):1,((:1,:1):1,:1):1):1);")
clado2 <-
read.tree(text="((:1,(:1,:1):1):1,(:1,:1):1,(:1,((:1,:1):1,:1):1):1);")
plot(clado1,'u');tiplabels();nodelabels()
plot(clado2,'u');tiplabels();nodelabels()
## I would say these are topologically identical
is.rooted(clado1) # FALSE
is.rooted(clado2) # FALSE
## confirm these phylo objects are not rooted
all.equal.phylo(clado1,clado2,use.tip.label=F,use.edge.length=F) # FALSE
## all.equal.phylo thinks they are different . . . .
length(unique(c(clado1,clado2))) # 2
## things are as expected if a root is added in equivalent places:
library(phangorn)
plot(midpoint(clado1),'u');tiplabels();nodelabels()
plot(midpoint(clado2),'u');tiplabels();nodelabels()
## I would say these are topologically identical
## all.equal.phylo agrees this time
all.equal.phylo(unroot(midpoint(clado1)),unroot(midpoint(clado2)),use.tip.label=F,use.edge.length=F)
# TRUE
length(unique(c(midpoint(clado1),midpoint(clado2)))) #1
## if the phylo objects are topologically identical, I would expect
## a Robinson-Foulds distance of 0
RF.dist(clado1,clado2) # 4
RF.dist(reorder(clado1),reorder(clado2)) # 4
RF.dist(reorder(midpoint(clado1)),reorder(midpoint(clado2))) # 6
RF.dist(midpoint(clado1),midpoint(clado2)) # 6
Thanks!
_______________________________________________
R-sig-phylo mailing list
[email protected]
https://stat.ethz.ch/mailman/listinfo/r-sig-phylo