4
$\begingroup$

I want to convert my phylogeny into a dendrogram so I can use it with dendextend in R to produce a tanglegram. I have made some progress but I keep encountering errors, see below:

library(ape)
library(dendextend)

Tree <- rtree(10, rooted=F)

Tree <- read.tree(file="clipboard", text=NULL) 
# test <- as.dendrogram(Tree) 
## Error in ape::as.hclust.phylo(object) : the tree is not ultrametric

Tree.ultra <- chronos(Tree)  
# test <- as.dendrogram(Tree.ultra) 
## Error in ape::as.hclust.phylo(object) : the tree is not rooted

Tree.ultra$root.edge <- 0
# test <- as.dendrogram(Tree.ultra) 
## Error in ape::as.hclust.phylo(object) : the tree is not binary

This thread seems to be the closest to answering my issues but the workflow is different and Im not sure how to address this binary issue. I have tried using as.hclust, as.hclust.phylo and hclust.

$\endgroup$
5
  • 1
    $\begingroup$ Please edit your question and give us a minimal reproducible example. Something that lets us test your code (and ours) and make sure our answers would work for you. A simple version of the tree you are using, for example, or even a way to generate random data that are similar to what you're working with. $\endgroup$
    – terdon
    Commented Jun 27, 2017 at 16:30
  • $\begingroup$ Its not really clear to me (and maybe it is just me) what you mean? A dendrogram and a phylogeny are synonyms. Unless theres some suble difference I'm not aware of, so I'll let others enlighten me if thats the case. $\endgroup$
    – Joe Healey
    Commented Jun 27, 2017 at 18:22
  • $\begingroup$ Ive added a small example which incurs the same errors. @JoeHealey. Depends whom you ask about dendrogram vs phylogeny. Many say they are synonyms but classically a dendrogram is seen as a simple graphical representation of hierarchy vs phylogeny which is based on more sound and substantial, evidence and data. $\endgroup$
    – AudileF
    Commented Jun 27, 2017 at 18:58
  • $\begingroup$ If dendrogram is the same as cladogram than it contains just a tree topology, phylogeny is more general term, it frequently contains branch lengths corresponding to mutation rate * time. See this post. $\endgroup$ Commented Jun 27, 2017 at 19:11
  • $\begingroup$ I was googling and it seems that dendrogram is a term used for visualisation of hierarchical clustering, which could be analogous to NJ-tree, but then it is not just a topology. If you mean cladogram, can you use this word? $\endgroup$ Commented Jun 28, 2017 at 14:53

2 Answers 2

2
$\begingroup$

For your example to work you should replace the rtree function with the rcoal function, see example below.

library(ape)  
library(dendextend)   
Tree <- rtree(10, rooted=F)
is.ultrametric(Tree) 
[1] FALSE 
is.binary.tree(Tree) 
[1] TRUE

Tree_rcoal <- rcoal(10, rooted=F) 
is.ultrametric(Tree_rcoal) 
[1] TRUE
is.binary.tree(Tree_rcoal) 
[1] TRUE

Tree_rcoal2 <- rcoal(10, rooted=F)

tanglegram(Tree_rcoal, Tree_rcoal2)

To make use of a file in newick format, you can try to convert with the chronos function.

s <- "owls(((Strix_aluco:4.2,Asio_otus:4.2):3.1,Athene_noctua:7.3):6.3,Tyto_alba:13.5);"
cat(s, file = "ex.tre", sep = "\n")
tree.owls <- read.tree("ex.tre")
is.ultrametric(tree.owls)
[1] FALSE
dendrogram <- chronos(tree.owls)

Setting initial dates...
Fitting in progress... get a first set of estimates
         Penalised log-lik = -24.04992 
Optimising rates... dates... -24.04992 
Optimising rates... dates... -24.04908 

Done.
is.ultrametric(dendrogram)
[1] TRUE
$\endgroup$
2
  • $\begingroup$ Hi b.nota. Thats all well and good but I have an actual newick file I need convert to a dendrogram. rtree was to give an example for troubleshooting. Thanks though. $\endgroup$
    – AudileF
    Commented Jun 27, 2017 at 20:09
  • 1
    $\begingroup$ Yes, I understand. But you didn't mention any newick file in your original post. Check [link] stackoverflow.com/questions/7445684/… this post from years ago, I think the chronos function might be helpful in your case. $\endgroup$
    – benn
    Commented Jun 27, 2017 at 21:15
1
$\begingroup$

After searching high and low I have found an answer from this thread

Workflow goes like:

library(DECIPHER)
dend1 <- ReadDendrogram(file="clipboard") 

# Alternatively to load from existing environment 
Tree$node.label <- NULL # Need to remove node labels
dend1 <- ReadDendrogram(textConnection(write.tree(Tree))) 

This object can then be used in the dendextend package and tanglegram function.

$\endgroup$
7
  • $\begingroup$ Does that give different results than the chronos function? $\endgroup$
    – benn
    Commented Jun 28, 2017 at 10:01
  • 1
    $\begingroup$ Contrary to what you say, you can read a character string from within R by passing a textConnection to ReadDendrogram. $\endgroup$ Commented Jun 28, 2017 at 11:05
  • $\begingroup$ Thanks @KonradRudolph I was not aware of that. Im only a novice to be honest. Ill change my answer above to include this. $\endgroup$
    – AudileF
    Commented Jun 28, 2017 at 11:17
  • $\begingroup$ Hi @KonradRudolph I have been trying the text connect as so:` dend1 <- ReadDendrogram(textConnection(Tree))` but I get an error. Error in textConnection(Tree) : invalid 'text' argument $\endgroup$
    – AudileF
    Commented Jun 29, 2017 at 8:08
  • 1
    $\begingroup$ @AudileF not sure if you've figured it out already but what you should have done is dend1 <- ReadDendrogram(textConnection(write.tree(Tree))) $\endgroup$
    – august
    Commented Sep 30, 2017 at 17:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.