【问题标题】:Plot phylogenetic trees face to face with links in R用 R 中的链接面对面绘制系统发育树
【发布时间】:2016-05-23 21:15:47
【问题描述】:

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

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

cophyloplot 函数用指定的链接将这些面对面绘制出来。

我无法指定链接。

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

链接应该如下:

如果在tree1 nexus 文件中,序列的尖端标签是 1-40。在tree2 nexus 文件中,提示标签为 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")

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

【问题讨论】:

    标签: r phylogeny


    【解决方案1】:

    要绘制树木,试试这个

    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)
    

    【讨论】:

    • 谢谢!!我收到以下错误:Error in decx[i] &lt;- strwidth(x$tip.label[lsa[x$tip.label == assoc[i, 1]]]) : replacement has length zero 所以我尝试了tree1$tip.label&lt;-(1:40) tree2$tip.label&lt;-(1:26)
    • 当我运行您的代码@lukeA 时,我得到了相同的树,但它不可读,需要扩展。我怎样才能把它扩展成你的样子?
    【解决方案2】:

    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() 从外部文件导入它们。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-13
      • 1970-01-01
      • 2022-11-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多