This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Root-To-Tip Tree Labeling

Hi,

I am to label a tree with #1 in all the nodes, from root to the leaf.

Example:

(((Sp1  #1 , Sp2)  #1,  Sp3) #1 ,(Sp4,Sp5));   for Sp1
(((Sp1, Sp2  #1 )  #1 , Sp 3) #1 ,(Sp4,Sp5));  for Sp2
(((Sp1, Sp2), Sp3 #1 ) #1 ,(Sp4,Sp5));         for Sp3
(((Sp1, Sp2), Sp3),(Sp4#1,Sp5) #1 );           for Sp4
(((Sp1, Sp2), Sp3),(Sp4,Sp5 #1)#1);            for Sp5

In my real data i will have from 20 to 39 species, and this for many genes, so is impractical to do it manually, does anyone knows any software or script to do it?

Thanks in advance,

João Paulo

paml phylogenetics

2 answers

You could do this with the R library APE:

tr <- rtree(15, br=NULL)
tr$node.label <- rep("#1", Nnode(tr))
write.tree(tr)

 ## [1] "((((t14,t7)#1,t6)#1,(t2,t12)#1)#1,(((((t1,t9)#1,t5)#1,t4)#1,t15)#1,((t10,t13)#1,(t8,(t11,t3)#1)#1)#1)#1)#1;"

But I'm not sure you need to? Isn't the node-labeling format only used if you want o compare ka/ks among different branch sets? I;m not sure why you'd set all branches to one set

EDIT

OK, so a didn't quite get the question. If you want to label every node that is ancestral to a given tip you you make use of the Ancestors function in the library phangorn. An example

library(phangorn)
library(ape)

label_lineage <- function(tr, taxon_name){
     lineage <- Ancestors(tr, which(tr$tip.label == taxon_name)) - Ntip(tr) 
     tr$node.label <- ifelse(1:Nnode(tr) %in% lineage, "#1", "")
     return(tr)
}

set.seed(123)
tr <- rtree(15, br=NULL)
write.tree(label_lineage(tr, "t14"))

    ##[1] "((((t7,t14)#1,(t6,t9))#1,t15)#1,(((t2,(((t12,t10),t1),((t8,t5),t4))),t3),(t13,t11)))#1;"

#check it makes sense
plot(label_lineage(tr, "t14"), show.node.label=TRUE)
#a more interesting one
plot(label_lineage(tr, "t12"), show.node.label=TRUE)

(I'm still not clear that there is a biological reason to want to do this, but at least you can run it now!)

Thanks, worked perfectly.

I want to test the selective pressure in all lineages but trying to reduce the effect of the low divergence problem. In my set of genes i detected ~10-20 genes under selection in spefific terminal branches, but in humam only 2, i supose is the low divergence time with the chimp, since only the branch that point is tested, and will also turn impossible the presence of branches with dS=0. The free-ratio should be avoid since has too much parameters to consider. So i decided to try like this.

Do you think is an incorrect approach? I am learning...

Thanks,

Jp

Hi David,

Thank you for your reply. Yes the purpose is test selection among branches. I have done the terminal branch test for all the genes but in some species (low time of divergence e.g. Human-Chimp) i am seeing a few problem, such as no dN, or inflated rates. So instead of testing only the terminal branch i wanted to included the ancestral branches that lead to the leaf.

Picking your example tree:

((((t14 #1,t7)#1,t6)#1,(t2,t12))#1,(((((t1,t9),t5),t4),t15),((t10,t13),(t8,(t11,t3)))))#1; this for t14

Sorry to not have explained properly in the first post.

Thank you in advance

On Q and A sites like biostar, the "answer" section is really only for answers to the orignal question. Comments and clarifications should be either added as a comment under the answer you are replying to, or, and probably better, as an edit to the your question. You should delete this, and do one of those.

Log in to answer this question.