简体   繁体   中英

Adding new tips randomly to different specific position in a phylogenetic tree

I am building a phylogenetic tree, and now I have several species only identified to genus level only. However, I want to keep them and bind to the tree for futher analysis.

The package I am using now is phytools and following Liam's toturials.

Solution1

Initially, let's assume we have a phylogenetic tree like this.

在此处输入图片说明

Now, I want to add a set of species to the corresponding genus by using the function 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)

The outcome will be like this.

在此处输入图片说明

However, as you guys see here, one name only is binded to one tip.

Solution2

# 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,split=list(node=node,
        bp=tree$edge.length[which(tree$edge[,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))

在此处输入图片说明

Here, one name randomly binded to different tips' position.

In sum, I would like to ask:

For solution 1, how can I do replicate for the binding? I mean that one name/species can be binded to more tips, eg Genus 5_sp3 can be added to Genus 5_sp1 .

For solution 2, how can I do add more than a tip to pre-specified clades.

General question : How can I add new tips randomly repeatly to different clades in a tree?

Does anyone know how to do this or have any experiences for this case? It would be appreciative if anyone could give a solution for this.

Note : The codes and images I used from the Liam's website.

Above codes provided by Liam from his website http://blog.phytools.org/2017/10/adding-tip-at-random-to-pre-specified.html and http://blog.phytools.org/2013/11/new-function-to-add-species-to-genus-in.html

updated Hi guys,

I dont know my answer is correct or not but it seems to go on the right way.

#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

What do you think about my solution? Does it make sense?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM