与 R 中的链接面对面绘制系统发育树

Plot phylogenetic trees face to face with links in R

我想使用 ape 包在 R 中绘制两个彼此相对的系统发育图。一棵树有40个节点,一棵树有26个节点:

library(ape)
tree1 <- rtree(40)
tree2 <- rtree(26)

cophyloplot 函数将这些与指定链接面对面绘制。

我在指定链接时遇到问题。

请注意,在我实际的 nexus 树文件中,提示标签是文本(如果需要,我不确定如何将它们更改为数字...)。

链接应该如下:

如果在tree1nexus文件中,序列的tip labels是1-40。在tree2 nexus 文件中,tip 标签是1-26。那么链接应该是:

a <- c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40)
b <- c(14,1,4,1,9,12,2,10,6,3,13,5,14,15,18,19,19,7,14,9,10,11,25,22,21,16,23,24,26,17,1,12,12,21,15,16,21,8,20,21) 
association <- cbind(a, b)

(即 tree1 中的序列 1 与 tree2 中的序列 14 链接)

所以,我用这样的东西来绘制树:

cophyloplot(tree1, tree2, assoc=association,length.line=4, space=28, gap=10, rotate=TRUE)

并计算距离矩阵:

dist.topo(tree1, tree2, method = "PH85")

我不太确定哪里出错了。任何帮助,将不胜感激!

要绘制树木,试试这个

library(ape)
set.seed(1)

# create trees
tree1 <- rtree(40)
tree2 <- rtree(26)

# modify tip labels
tree1$tip.label <- sub("t", "", tree1$tip.label, fixed = T)
tree2$tip.label <- sub("t", "", tree2$tip.label, fixed = T)

# create associations matrix 
a <- as.character(c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40))
b <- as.character(c(14,1,4,1,9,12,2,10,6,3,13,5,14,15,18,19,19,7,14,9,10,11,25,22,21,16,23,24,26,17,1,12,12,21,15,16,21,8,20,21)) 
association <- cbind(a, b)

# plot
cophyloplot(tree1, tree2, assoc = association, length.line = 4, space = 28, gap = 3)

cophyloplot 函数不需要提示标签索引。人们可以用他们的名字来指代分类单元。请注意,lukeA 的答案将关联中的数字存储为 character。将它们转换为与提示标签相对应的文本并绘制​​两棵树显示相同的结果。

association <- apply(association, 2, function(x) sub("^","t", x))

head(association)
#      a    b    
# [1,] "t1" "t14"
# [2,] "t2" "t1" 
# [3,] "t3" "t4" 
# [4,] "t4" "t1" 
# [5,] "t5" "t9" 

cophyloplot(tree1, tree2, assoc=association, length.line=4, space=28, gap=3)

关联在矩阵中的排列顺序无关紧要。最佳做法是使用 read.table().

从外部文件导入它们