Phylogenetic Tree - how to create a branch by species matrix?

时间秒杀一切 提交于 2019-12-06 13:23:37

I am unaware of any built-in function that does this. I wrote a helper function that can calculate this from the edge data stored in the tree object.

branchNodeAdjacency <- function(x) {
    m <- matrix(0, ncol=nt, nrow=nrow(x$edge))
    from <- x$edge[,1]
    to <- x$edge[,2]
    g <- seq_along(x$tip.label)
    while (any(!is.na(g))) {
        i <- match(g, to)
        m[cbind(i, seq_along(i))] <- 1
        g <- from[i]
    }
    rownames(m) <- paste0("B", seq.int(nrow(m)))
    colnames(m) <- x$tip.label
    m
}

branchNodeAdjacency(ex.tree)
#    A B C D E
# B1 1 0 0 0 0
# B2 0 1 1 1 1
# B3 0 1 1 0 0
# B4 0 1 0 0 0
# B5 0 0 1 0 0
# B6 0 0 0 1 1
# B7 0 0 0 1 0
# B8 0 0 0 0 1

The idea is we keep track of which leaf node values are represented by each internal node.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!