如何对multiPhylo类列表循环执行phytools包物种添加函数
系统发育树批量添加物种循环操作问题与解决
问题描述
我删除了此前表述不清的旧问题,本次想请教如何对列表中的元素循环执行函数。以下是我使用phytools包编写的示例代码:
# 一组系统发育树 List <- list(tree1= pbtree(n=3, tip.label = c("Pycnonotus_simplex", "Pycnonotus_brunneus", "Blythipicus_rubiginosus")), tree2 = pbtree(n=3, tip.label = c("Blythipicus_rubiginosus", "Pycnonotus_erythropthalmos", "Orthotomus_atrogularis"))) class(List) <- "multiPhylo" # 待添加的物种向量 spp <- c("Pycnonotus_sp.02", "Pycnonotus_sp.08")
我计划通过add.species.to.genus函数将spp中的物种随机添加到树中,单棵树的实现代码如下:
for (i in 1:length(spp)){ tree1 <- add.species.to.genus(tree1, spp [i], where = "random") }
解决方法(更新)
我已经自行解决了该问题:使用add.species.to.genus函数会导致树的边长精度受限,搭配force.ultrametric函数即可解决,实现代码如下:
for (i in 1:length(List)){ tree[[i]] <- List[[i]] for (j in 1:length(spp)){ tree[[i]] <- force.ultrametric(tree[[i]]) tree[[i]] <- add.species.to.genus(tree[[i]], spp[j], where = "random") } }
内容的提问来源于stack exchange,提问作者Anh
相关产品推荐
相关产品推荐

