问题描述
我正在构建系统发育树,现在我有几个物种仅鉴定到属级。但是,我想保留它们并绑定到树以供进一步分析。
我现在使用的软件包是 phytools
并遵循 Liam 的教程。
解决方案 1
最初,让我们假设我们有一个这样的系统发育树。
现在,我想使用函数 add.species.to.genus
将一组物种添加到相应的属中。
#add a set of species in a vector
species <- c("Genus1_sp2","Genus2_sp3","Genus3_sp2","Genus4_sp7","Genus4_sp8","Genus5_sp3")
for(i in 1:length(species)) tree<-add.species.to.genus(tree,species[i],where="random")
plottree(tree)
结果会是这样。
解决方案 2
# get a pseudo-tree
tree<-pbtree(n=26,tip.label=LETTERS)
plottree(tree)
nodelabels()
#set a node we want to add a tip randomly
node<-45
tt<-splitTree(tree,split=list(node=node,bp=tree$edge.length[which(tree$edge[,2]==node)]))
tt[[2]]<-add.random(tt[[2]],tips="tip to add")
new.tree<-paste.tree(tt[[1]],tt[[2]])
plottree(new.tree)
#replicate times
foo<-function(tree,node){
tt<-splitTree(tree,2]==node)]))
tt[[2]]<-add.random(tt[[2]],tips="tip to add")
paste.tree(tt[[1]],tt[[2]])
}
new.trees<-replicate(9,foo(tree,node),simplify=FALSE)
class(new.trees)<-"multiPhylo"
# add colour
nulo<-sapply(new.trees,function(x) plot(paintSubTree(x,45,"2"),colors=setNames(c("black","blue"),1:2),fsize=0.6))
总而言之,我想问:
对于解决方案 1,我如何为绑定进行复制?我的意思是一个名称/物种可以绑定到更多提示,例如Genus 5_sp3
可以添加到 Genus 5_sp1
。
有没有人知道如何做到这一点或对此案有任何经验? 如果有人可以为此提供解决方案,将不胜感激。
注意:
我在 Liam 的网站上使用的 codes
和 images
。
Liam 从他的网站 http://blog.phytools.org/2017/10/adding-tip-at-random-to-pre-specified.html 和 http://blog.phytools.org/2013/11/new-function-to-add-species-to-genus-in.html
提供的上述代码解决方法
更新 大家好,
我不知道我的答案是否正确,但它似乎是正确的。
#I find the node of clade that I want to add.
node = 193
tt <- list()
class(tt) <- "multiPhylo"
fun<-function(sample_1,node){
tt<-splitTree(sample_1,split=list(node=node,bp=sample_1$edge.length[which(sample_1$edge[,2]==node)]))
tt[[2]]<-add.random(tt[[2]],tips = "Pycnonotus sp.01")
paste.tree(tt[[1]],tt[[2]])
}
new.trees<-replicate(20,fun(sample_1,node),simplify=FALSE)
plotTree(new.trees[[1]])
# Then,I will use the saving tree for the next round of adding another species.
#sp2
node1 = 194
tt1 <- lapply(seq_along(new.trees),function(i)
splitTree(new.trees[[i]],split = list(node = node1,bp = new.trees[[i]]$edge.length[which(new.trees[[i]]$edge[,2]==node1)])))
new.trees.1 <- list()
new.trees.1 <- lapply(seq_along(tt1),function(i){
tt1[[i]][[2]] <- add.random(tt1[[i]][[2]],tips = "Pycnonotus sp.02");
new.trees.1[[i]] <- paste.tree(tt1[[i]][[1]],tt1[[i]][[2]])})
# I would like to do the same thing for adding more species
你觉得我的解决方案怎么样?有意义吗?