The following R code read a newick file with multiple trees, and calculate the topological distance between all pairs.
require(ape)
help(package=ape)
trees = read.tree("treesall.nwk") #list of 10
trees[[1]]
trees[[2]]
dist.topo( trees[[1]], trees[[10]])
d.tree = matrix( nrow=10, ncol=10 )
for ( i in 1:10 ) {
for (j in i:10) {
print ( c(i, j))
d.tree[i,j] = dist.topo( trees[[i]], trees[[j]] )
}
}
d.tree
An output from the 10 tree for Bacillus essential genes are:
> d.tree
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,] 0 2 2 4 6 2 4 4 4 4
[2,] NA 0 4 6 6 4 2 6 6 6
[3,] NA NA 0 2 4 4 6 6 6 6
[4,] NA NA NA 0 2 4 6 6 6 8
[5,] NA NA NA NA 0 6 6 8 8 10
[6,] NA NA NA NA NA 0 2 4 4 6
[7,] NA NA NA NA NA NA 0 6 6 8
[8,] NA NA NA NA NA NA NA 0 2 8
[9,] NA NA NA NA NA NA NA NA 0 8
[10,] NA NA NA NA NA NA NA NA NA 0
No comments:
Post a Comment