首页 > 解决方案 > 将化石尖端添加到树上

问题描述

我很难尝试将几个化石提示添加到 100 个系统发育时间树中。

这是我想做的图:

化石尖端案例

我想为包含在单个关联文件中的 100 棵树执行此操作。

先感谢您。

编辑:

好的,我想出了怎么做。这是示例的代码:

library(phytools)

tree <- read.tree(text = '(A:20,(B1:5,B2:5):15);')
plot(tree)

nodelabels()
edgelabels()

case1 <- bind.tip(tree, tip.label="Fossil tip 1", where=which(tree$tip.label=="A"), position = 10, edge.length=10)
plot(case1)

case2 <- bind.tip(tree, tip.label="Fossil tip 2", where=5, position=0.5*tree$edge.length[2], edge.length=0.5*tree$edge.length[2]+tree$edge.length[3])
plot(case2)

case3 <- bind.tip(tree, tip.label="Fossil tip 3", where=5, position=0.5*tree$edge.length[2], edge.length=(0.5*tree$edge.length[2]+tree$edge.length[3])-10)
plot(case3)

这是我的数据的代码:

library(phytools)

mammif <- read.nexus(file.choose()) #100 phyogenetic time trees
tree <- mammif$tree_7736 #for the first tree
plot(tree)

nodelabels()
edgelabels()

case1 <- bind.tip(tree, tip.label="Fossil tip 1", where=which(tree$tip.label=="Tupaia_belangeri"), position = 30, edge.length=30)
plot(case1)

case2 <- bind.tip(tree, tip.label="Fossil tip 2", where=36, position=0.5*tree$edge.length[21], edge.length=0.5*tree$edge.length[21]+tree$edge.length[22])
plot(case2)

case3 <- bind.tip(tree, tip.label="Fossil tip 3", where=33, position=0.5*tree$edge.length[13], edge.length=(0.5*tree$edge.length[13]+tree$edge.length[14])-10)
plot(case3)

该代码适用于第一棵树。我想为其余的树循环它,但问题是节点和边缘可以在树之间改变。我认为指定进化枝的分类群而不是节点和通向分类单元的边缘而不是边缘编号会更容易。任何的想法?

标签: rphylogeny

解决方案


这是查找某些提示的最近共同祖先(MRCA)并将(化石)分支绑定到该节点的一般方法。我将用一些随机树来展示这一点,但是如果您在使用真实数据时遇到问题,请回信。

library(ape)
library(phytools)

首先我们生成一些随机的超度量树。

set.seed(1)
random_trees <-
  replicate(n = 4,
            expr = rcoal(n = 5, rooted = TRUE),
            simplify = FALSE)

# plot
par(mfrow=c(2,2))
lapply(random_trees, plot.phylo)

在此处输入图像描述

然后我们添加一个任意长度的根边。这是必需的phytools::bind.tip(它是 的包装器ape::bind.tree)。根据您的真实树木,您可能无需担心根分支的长度。

random_trees <-
  lapply(seq_along(random_trees), function(i) {
    random_trees[[i]]$root.edge <- 0.2;
    return(random_trees[[i]])})

lapply(random_trees, "[[", "root.edge")

然后,假设我们想在分支上添加一个化石节点,代表提示 t1 和 t2 的 MRCA。我们可以循环遍历树以找到想要的节点(t1 和 t2 的 MRCA)。这里的拓扑可以不同,我们想要的只是目标节点。

target_taxa <- paste0("t", 1:2)

target_mrcas <-
  lapply(random_trees, function(x)
    getMRCA(x, tip = target_taxa))

在最后一关中,我们在树木上循环并将我们的化石绑定到所需的分支

trees_with_fossil <-
  lapply(seq_along(random_trees), function(i)
    phytools::bind.tip(
      tree = random_trees[[i]],
      tip.label = "fossil",
      edge.length = 0.1,
      where = target_mrcas[[i]],
      position = 0.02
    ))

阴谋:

lapply(trees_with_fossil, plot.phylo)

在此处输入图像描述


推荐阅读