<p>Another 2 tree compare tools: <a href="https://yulab-smu.github.io/treedata-book/chapter2.html" rel="nofollow noreferrer">ggtree</a> and <a href="https://github.com/Don86/baltic3" rel="nofollow noreferrer">blatic 3</a></p>

CC BY-SA 4.0
2020-05-29T01:29:21.753Z
The tree building is usually used IQ-Tree, MrBayes, RAxML, and beast to get a robust maximum likelihood or maximum-credibility tree. This process is time-consuming and computational resource consuming. If I want to use the dendextend to compare the phylogenetic trees which are built by the methods mentioned above rather than in R, can I do it with dendextend?
Biodeer
CC BY-SA 4.0
2020-05-28T01:47:40.920Z
2020-06-02T09:49:55.660Z
2020-06-02T09:49:55.660Z
Biodeer
<p>If you only have to compare two phylogenies (as opposed to more), I would suggest that an alternative to using R would be using iqtree . One of its parameters (-rf) can calculate the Robinson-Foulds metric between two trees.
(you can also use iqtree to calculate the phylogenies in the first place)</p>

<p>It is command-line based, but can be easily installed with conda. Having anaconda installed in general makes bioinformatics work easier, I feel.</p>

<p>Alternatively, differences in trees can be visualized (without numbers) in Dendroscope, or Splitstree. They have different strategies for it. With Dendroscope it is easier to compare side-by-side and, if having precisely the same taxon names, to draw lines between taxa in different trees. Splitstree can accept an input of multiple trees (File>Tools>Load Multiple trees) and build a network (which can be a way to visualize the consensus of the trees).</p>

CC BY-SA 4.0
2020-05-25T11:27:58.957Z
Hi @Laura, SplitsTree is very cool, but by default will not work here because classically it will identify incongruence within the sequence itself (not just between trees). There may be options to disable this (if so please post them), but by default thats what it will attempt.
M__
CC BY-SA 4.0
2020-05-25T13:22:08.527Z
@Michael Thank you for pointing that out. I meant Splitstree starting from trees, not from sequence (File>Tools>Load Multiple trees). I've used it before for visualizing bootstraping results, but technically it should work on fewer trees too?
Laura
CC BY-SA 4.0
2020-05-25T11:01:46.407Z
2020-05-25T13:23:06.547Z
2020-05-25T13:23:06.547Z
Laura
<p><strong>Bootstrapping</strong> I agree correlation is one way in, but the classic way to do this is via bootstrapping, i.e. resampling the alignment with replacement and making a consensus phylogeny of of 100 to 1000 replicates. Values exceeding 75 to 80% define node robustness and you can calculate incongruence from there.</p>

<p><code>Phangorn</code> certainly does bootstrapping, but the efficiency of the algorhithm for maximum likelihood (ML) I don't know (might take a very long time), just think how long one tree takes and times it by 100 (or even 1000).</p>

<p>If you just performed a correlation measure there is a risk the differences are not robust, but if you've got loads of taxa you could bootstrap collapse any value less than the robustness threshold into a polytomy and then perform a correlation method. Its a bit complicated, but it would work.</p>

<p>Bootstrapping parsimony isn't hard nor computationally expensive, bootstrapping maximum likelihood sometimes requires specific efficient algorhithms notably <a href="https://cme.h-its.org/exelixis/web/software/raxml/" rel="nofollow noreferrer"><code>RAxML</code></a>.</p>

<p><strong>Non-R</strong> The other way in is just dump the trees into <a href="https://uni-tuebingen.de/fakultaeten/mathematisch-naturwissenschaftliche-fakultaet/fachbereiche/informatik/lehrstuehle/algorithms-in-bioinformatics/software/dendroscope/" rel="nofollow noreferrer"><code>Dendroscope3</code></a>, okay its not R but will work. Dendroscrope is hard for a non-tree person to read, however it will flag the differences for a specialist. Dendroscope will make a network tree for the topological differences, in this case between methods, i.e. non-bifurcating. You really then usually have to present the differences as a "mirror tree", i.e. parsimony and ML side by side, because usually non-tree people wonder what a Dendroscope output means. Technically there is nothing wrong with describing incongruence via networks.</p>

<p>Basically, the heart-beat is bootstrapping.</p>

<p>Generally speaking parsimony will give the same basic output as ML, except when you have some taxa undergoing rapid evolution against their sister group. This does happen in pathogen evolution and parsimony falls over into a phenomina known as 'long-branch attraction'.</p>

CC BY-SA 4.0
2020-05-25T11:49:58.600Z
The advantage of the correlation measure will be the metrics which provide a more objective evaluation. Michael's recommandation with bootstrapping is really good, especially using collapsed branches.
thomas duge de bernonville
CC BY-SA 4.0
2020-05-25T10:33:18.020Z
2020-05-25T10:38:44.093Z
2020-05-25T10:38:44.093Z
M__
<p>phangorn is a really powerful package for phylogenies. But to compare the trees, I think you may convert them into dendrograms and calculate a correlation measure, such as the Fowlkes-Mallows Index or a distance measure such as Baker’s Gamma Index. These can be easily computed using the <code>dendextend</code> R package (<a href="https://cran.r-project.org/web/packages/dendextend/vignettes/dendextend.html#correlation-measures" rel="nofollow noreferrer">https://cran.r-project.org/web/packages/dendextend/vignettes/dendextend.html#correlation-measures</a>).</p>

CC BY-SA 4.0
2020-05-25T16:10:43.417Z
"I think you may convert them into dendrograms and calculate a correlation measure" so you mean one for  Maximum likelihood and other for maximum parsimony, so can I do it using the Phangorn package? or I have to use something else
kcm
CC BY-SA 4.0
2020-05-25T19:56:31.930Z
Yes, you can build the two trees and then convert them into dendrograms. Be careful, trees should be ultrametric for that.  You can convert them using the `force.ultrametric` function from **phytools** package followed by `as.dendrogram` from **dendextend** package.
thomas duge de bernonville
CC BY-SA 4.0
2020-05-25T21:31:21.077Z
I would let you know what i have done so far..So i have a multi fasta sequence which I did multiple sequence alignment using Muscle then i have an alignment file which i have used so far for distance based methods like NJ etc.The same alignmen file can be used in phytools to build Likelihood and parsimony tree ?
kcm
CC BY-SA 4.0
2020-05-26T04:51:14.637Z
I think you can still use **phangorn** to construct the phylogenies.You just have to read your alignment with the `read.alignment` function of **seqinr** package, then convert it into a `phyDat` object, then calculate a distance with `dist.ml`. From that point, you may construct ML or parsimony trees (https://cran.r-project.org/web/packages/phangorn/vignettes/Trees.pdf). Once you've obtained the trees, convert them into dendrograms and calculate a correlation as described above.
thomas duge de bernonville
CC BY-SA 4.0
2020-05-26T05:38:11.353Z
data <- read.dna("clean_dup_align_fast.fas", format = "fasta")
data
dat <- as.phyDat(data)                                                                                                                      d <- dist.alignment(dat, "identity") this is what i have done and I think as you mentioned Im doing it perhaps right need to see how to construct the ML or MP trees..
kcm
CC BY-SA 4.0
2020-05-26T05:55:13.117Z
the ML and MP part I got in the vignette. How do I convert the trees into  dendrogram? this link https://bioinformatics.stackexchange.com/questions/923/how-to-convert-a-phylogeny-to-a-dendrogram-in-r  so this is what you are suggesting isn;t it?
kcm
CC BY-SA 4.0
2020-05-26T07:13:25.947Z
from your **phyDat** object, you may estimate a distance eg `d<-dist.ml(dat)`, then construct a rooted starting tree with UPGMA, `tr.upgma<-upgma(d)` then from this starting tree construct either ML or MP following the **phangorn** vignette. Once you get the bootstrapped trees, set them as ultrametric `tr.ml.ultra<-force.ultrametric(tr.ml)` and convert them as dendrogram `dd.ml.ultra<-as.dendrogram(tr.ml.ultra)`. Please load the appropriate libraries to do that, and to have a look at the parameters that can be tuned at each step.
thomas duge de bernonville
CC BY-SA 4.0
2020-05-26T11:29:00.417Z
I have updated my question with code and the data file and the error i ran into when Im trying to covert it into dendrogram
kcm
CC BY-SA 4.0
2020-05-26T12:08:54.920Z
I think you should use the UPGMA tree as a starting tree, both for the MP and ML, because I think it produces rooted trees, in contrast to NJ.
thomas duge de bernonville
CC BY-SA 4.0
2020-05-26T12:21:33.523Z
okay let me try that and update you i did try the UPGMA im still getting the same error "Error in ape::as.hclust.phylo(object) : the tree is not rooted
"
kcm
CC BY-SA 4.0
2020-05-26T12:55:46.220Z
Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/108496/discussion-between-thomas-duge-de-bernonville-and-krushnach-chandra).
thomas duge de bernonville
CC BY-SA 4.0
2020-05-25T10:01:46.293Z
2020-05-25T10:01:46.293Z
thomas duge de bernonville
<p>So I want to compare the phylogeny created using two methods for example Maximum likelihood and maximum parsimony.Is there any way to compare the two phylogeny ?</p>

<p>I did read about phangorn but not sure if its the right R library for comparative analysis.</p>

<p>Any suggestion or helped would be highly appreciated </p>

<p>My data <a href="https://drive.google.com/open?id=1ErIpdS99Vu_tsWtvNQCKftzFmpJAUKuu" rel="nofollow noreferrer">file</a></p>

<pre><code>library(phangorn)
library(phytools)
library(dendextend)



data &lt;- read.dna("abhi_seq/clean_dup_align_fast.fas", format = "fasta")
data
dat &lt;- as.phyDat(data)

dm &lt;- dist.ml(dat)
treeUPGMA &lt;- upgma(dm)
treeNJ &lt;- NJ(dm)

layout(matrix(c(1,2), 2, 1), height=c(1,2))
par(mar = c(0,0,2,0)+ 0.1)
plot(treeUPGMA, main="UPGMA")
plot(treeNJ, "phylogram", main="NJ")

dev.off()

parsimony(treeUPGMA, dat)
parsimony(treeNJ,dat)

tr.mp &lt;- optim.parsimony(treeNJ, dat)

#tr.ml = optim.pml(treeNJ, dat)




fit &lt;- pml(treeNJ, dat)
fit &lt;- optim.pml(fit, rearrangement="NNI")




fit.ini &lt;- pml(treeNJ, dat)
fit.ini


fit &lt;- optim.pml(fit.ini, optNni=TRUE, optBf=TRUE, optQ=TRUE, optGamma=TRUE)
fit

tr.ml &lt;- root(fit$tree,1)





tr.mp.ultra&lt;-force.ultrametric(tr.mp)
tr.ml.ultra&lt;-force.ultrametric(tr.ml)

is.ultrametric(tr.mp.ultra)
is.binary.tree(tr.mp.ultra)
is.rooted(tr.mp.ultra)



dd.ml.ultra&lt;-as.dendrogram(tr.mp.ultra)
</code></pre>

<blockquote>
  <p>Error in ape::as.hclust.phylo(object) : the tree is not rooted</p>
</blockquote>

<p>I ran into this error this error which says trees is not rooted </p>

<p><strong>Comparing phylogeny code updated ** <em>Working</em> thanks to ***thomas duge de bernonville*</strong> <a href="https://bioinformatics.stackexchange.com/users/8749/thomas-duge-de-bernonville">thomas</a> for putting codes together and fixing the errors </p>

<pre><code>library(dendextend)
library(seqinr)
library(phytools)
library(phangorn)

a&lt;-read.alignment("abhi_seq/clean_dup_align_fast.fas", format="fasta")
a.phydat&lt;-as.phyDat(a)
dist.a.phydat&lt;-dist.dna(as.DNAbin(a.phydat))
upgma.a&lt;-upgma(dist.a.phydat)
parsimony(upgma.a,a.phydat)
pars.a &lt;- optim.parsimony(upgma.a, a.phydat)
pars.a&lt;-acctran(pars.a, a.phydat)
pars.a.rooted&lt;-root(pars.a, outgroup="AAA64460", resolve.root=T)
pars.a.rooted.dd&lt;-as.dendrogram(force.ultrametric(pars.a.rooted))


mt &lt;- modelTest(a.phydat, tree=upgma.a,multicore = TRUE,mc.cores=10)

#ml.a = pml(upgma.a,a.phydat)
#fitJC &lt;- optim.pml(ml.a, TRUE)
#ml.a.rooted&lt;-root(midpoint(fitJC$tree), outgroup="AAA64460", resolve.root=T)
#ml.a.rooted.dd&lt;-as.dendrogram(force.ultrametric(ml.a.rooted))

#########################################################################

######################################################################33

#mt &lt;- modelTest(dat, tree=tree, multicore=TRUE)
mt[order(mt<span class="math-container">$AICc),]# choose best model from the table according to AICc
bestmodel &lt;- mt$</span>Model[which.min(mt$AICc)]
env = attr(mt, "env")
fitStart = eval(get(bestmodel, env), env)
fit = optim.pml(fitStart, rearrangement = "stochastic",optGamma=TRUE, optInv=TRUE, model="GTR")#tree 
bs=bootstrap.pml(fit, bs=25, optNni=TRUE, multicore=TRUE)

ml.a.rooted&lt;-root(midpoint(fit$tree), outgroup="AAA64460", resolve.root=T)
ml.a.rooted.dd&lt;-as.dendrogram(force.ultrametric(ml.a.rooted))
</code></pre>

<r><phylogenetics><phylogeny><phangorn>
Comparing phylogeny in R
# Comparing phylogeny in R

(Asked by: username_0 on 2020-05-25)

So I want to compare the phylogeny created using two methods for example Maximum likelihood and maximum parsimony.Is there any way to compare the two phylogeny ?
I did read about phangorn but not sure if its the right R library for comparative analysis.
Any suggestion or helped would be highly appreciated 
My data file
library(phangorn)
library(phytools)
library(dendextend)



data <- read.dna("abhi_seq/clean_dup_align_fast.fas", format = "fasta")
data
dat <- as.phyDat(data)

dm <- dist.ml(dat)
treeUPGMA <- upgma(dm)
treeNJ <- NJ(dm)

layout(matrix(c(1,2), 2, 1), height=c(1,2))
par(mar = c(0,0,2,0)+ 0.1)
plot(treeUPGMA, main="UPGMA")
plot(treeNJ, "phylogram", main="NJ")

dev.off()

parsimony(treeUPGMA, dat)
parsimony(treeNJ,dat)

tr.mp <- optim.parsimony(treeNJ, dat)

#tr.ml = optim.pml(treeNJ, dat)




fit <- pml(treeNJ, dat)
fit <- optim.pml(fit, rearrangement="NNI")




fit.ini <- pml(treeNJ, dat)
fit.ini


fit <- optim.pml(fit.ini, optNni=TRUE, optBf=TRUE, optQ=TRUE, optGamma=TRUE)
fit

tr.ml <- root(fit$tree,1)





tr.mp.ultra<-force.ultrametric(tr.mp)
tr.ml.ultra<-force.ultrametric(tr.ml)

is.ultrametric(tr.mp.ultra)
is.binary.tree(tr.mp.ultra)
is.rooted(tr.mp.ultra)



dd.ml.ultra<-as.dendrogram(tr.mp.ultra)


Error in ape::as.hclust.phylo(object) : the tree is not rooted

I ran into this error this error which says trees is not rooted 
Comparing phylogeny code updated ** Working thanks to ***thomas duge de bernonville* thomas for putting codes together and fixing the errors 
library(dendextend)
library(seqinr)
library(phytools)
library(phangorn)

a<-read.alignment("abhi_seq/clean_dup_align_fast.fas", format="fasta")
a.phydat<-as.phyDat(a)
dist.a.phydat<-dist.dna(as.DNAbin(a.phydat))
upgma.a<-upgma(dist.a.phydat)
parsimony(upgma.a,a.phydat)
pars.a <- optim.parsimony(upgma.a, a.phydat)
pars.a<-acctran(pars.a, a.phydat)
pars.a.rooted<-root(pars.a, outgroup="AAA64460", resolve.root=T)
pars.a.rooted.dd<-as.dendrogram(force.ultrametric(pars.a.rooted))


mt <- modelTest(a.phydat, tree=upgma.a,multicore = TRUE,mc.cores=10)

#ml.a = pml(upgma.a,a.phydat)
#fitJC <- optim.pml(ml.a, TRUE)
#ml.a.rooted<-root(midpoint(fitJC$tree), outgroup="AAA64460", resolve.root=T)
#ml.a.rooted.dd<-as.dendrogram(force.ultrametric(ml.a.rooted))

#########################################################################

######################################################################33

#mt <- modelTest(dat, tree=tree, multicore=TRUE)
mt[order(mt$AICc),]# choose best model from the table according to AICc
bestmodel <- mt$Model[which.min(mt$AICc)]
env = attr(mt, "env")
fitStart = eval(get(bestmodel, env), env)
fit = optim.pml(fitStart, rearrangement = "stochastic",optGamma=TRUE, optInv=TRUE, model="GTR")#tree 
bs=bootstrap.pml(fit, bs=25, optNni=TRUE, multicore=TRUE)

ml.a.rooted<-root(midpoint(fit$tree), outgroup="AAA64460", resolve.root=T)
ml.a.rooted.dd<-as.dendrogram(force.ultrametric(ml.a.rooted))

**Tags:** r, phylogenetics, phylogeny, phangorn

---

## 4 answers

### Answer by username_4 on 2020-05-25. Score: 3 | Accepted answer

phangorn is a really powerful package for phylogenies. But to compare the trees, I think you may convert them into dendrograms and calculate a correlation measure, such as the Fowlkes-Mallows Index or a distance measure such as Baker’s Gamma Index. These can be easily computed using the `dendextend` R package (<https://cran.r-project.org/web/packages/dendextend/vignettes/dendextend.html#correlation-measures>).

> **Comments:**
> **username_0**: "I think you may convert them into dendrograms and calculate a correlation measure" so you mean one for  Maximum likelihood and other for maximum parsimony, so can I do it using the Phangorn package? or I have to use something else  
> **username_4**: Yes, you can build the two trees and then convert them into dendrograms. Be careful, trees should be ultrametric for that.  You can convert them using the `force.ultrametric` function from **phytools** package followed by `as.dendrogram` from **dendextend** package.  
> **username_0**: I would let you know what i have done so far..So i have a multi fasta sequence which I did multiple sequence alignment using Muscle then i have an alignment file which i have used so far for distance based methods like NJ etc.The same alignmen file can be used in phytools to build Likelihood and parsimony tree ?  
> **username_4**: I think you can still use **phangorn** to construct the phylogenies.You just have to read your alignment with the `read.alignment` function of **seqinr** package, then convert it into a `phyDat` object, then calculate a distance with `dist.ml`. From that point, you may construct ML or parsimony trees (https://cran.r-project.org/web/packages/phangorn/vignettes/Trees.pdf). Once you've obtained the trees, convert them into dendrograms and calculate a correlation as described above.  
> **username_0**: data <- read.dna("clean_dup_align_fast.fas", format = "fasta") data dat <- as.phyDat(data)                                                                                                                      d <- dist.alignment(dat, "identity") this is what i have done and I think as you mentioned Im doing it perhaps right need to see how to construct the ML or MP trees..  
> **username_0**: the ML and MP part I got in the vignette. How do I convert the trees into  dendrogram? this link https://bioinformatics.stackexchange.com/questions/923/how-to-convert-a-phylogeny-to-a-dendrogram-in-r  so this is what you are suggesting isn;t it?  
> **username_4**: from your **phyDat** object, you may estimate a distance eg `d<-dist.ml(dat)`, then construct a rooted starting tree with UPGMA, `tr.upgma<-upgma(d)` then from this starting tree construct either ML or MP following the **phangorn** vignette. Once you get the bootstrapped trees, set them as ultrametric `tr.ml.ultra<-force.ultrametric(tr.ml)` and convert them as dendrogram `dd.ml.ultra<-as.dendrogram(tr.ml.ultra)`. Please load the appropriate libraries to do that, and to have a look at the parameters that can be tuned at each step.  
> **username_0**: I have updated my question with code and the data file and the error i ran into when Im trying to covert it into dendrogram  
> **username_4**: I think you should use the UPGMA tree as a starting tree, both for the MP and ML, because I think it produces rooted trees, in contrast to NJ.  
> **username_0**: okay let me try that and update you i did try the UPGMA im still getting the same error "Error in ape::as.hclust.phylo(object) : the tree is not rooted "  
> **username_4**: Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/108496/discussion-between-thomas-duge-de-bernonville-and-krushnach-chandra).  

---

### Answer by username_1 on 2020-05-28. Score: 4

Another 2 tree compare tools: [ggtree](https://yulab-smu.github.io/treedata-book/chapter2.html) and [blatic 3](https://github.com/Don86/baltic3)

> **Comments:**
> **username_1**: The tree building is usually used IQ-Tree, MrBayes, RAxML, and beast to get a robust maximum likelihood or maximum-credibility tree. This process is time-consuming and computational resource consuming. If I want to use the dendextend to compare the phylogenetic trees which are built by the methods mentioned above rather than in R, can I do it with dendextend?  

---

### Answer by username_2 on 2020-05-25. Score: 2

If you only have to compare two phylogenies (as opposed to more), I would suggest that an alternative to using R would be using iqtree . One of its parameters (-rf) can calculate the Robinson-Foulds metric between two trees.
(you can also use iqtree to calculate the phylogenies in the first place)

It is command-line based, but can be easily installed with conda. Having anaconda installed in general makes bioinformatics work easier, I feel.

Alternatively, differences in trees can be visualized (without numbers) in Dendroscope, or Splitstree. They have different strategies for it. With Dendroscope it is easier to compare side-by-side and, if having precisely the same taxon names, to draw lines between taxa in different trees. Splitstree can accept an input of multiple trees (File>Tools>Load Multiple trees) and build a network (which can be a way to visualize the consensus of the trees).

> **Comments:**
> **username_3**: Hi @Laura, SplitsTree is very cool, but by default will not work here because classically it will identify incongruence within the sequence itself (not just between trees). There may be options to disable this (if so please post them), but by default thats what it will attempt.  
> **username_2**: @Michael Thank you for pointing that out. I meant Splitstree starting from trees, not from sequence (File>Tools>Load Multiple trees). I've used it before for visualizing bootstraping results, but technically it should work on fewer trees too?  

---

### Answer by username_3 on 2020-05-25. Score: 2

**Bootstrapping** I agree correlation is one way in, but the classic way to do this is via bootstrapping, i.e. resampling the alignment with replacement and making a consensus phylogeny of of 100 to 1000 replicates. Values exceeding 75 to 80% define node robustness and you can calculate incongruence from there.

`Phangorn` certainly does bootstrapping, but the efficiency of the algorhithm for maximum likelihood (ML) I don't know (might take a very long time), just think how long one tree takes and times it by 100 (or even 1000).

If you just performed a correlation measure there is a risk the differences are not robust, but if you've got loads of taxa you could bootstrap collapse any value less than the robustness threshold into a polytomy and then perform a correlation method. Its a bit complicated, but it would work.

Bootstrapping parsimony isn't hard nor computationally expensive, bootstrapping maximum likelihood sometimes requires specific efficient algorhithms notably [`RAxML`](https://cme.h-its.org/exelixis/web/software/raxml/).

**Non-R** The other way in is just dump the trees into [`Dendroscope3`](https://uni-tuebingen.de/fakultaeten/mathematisch-naturwissenschaftliche-fakultaet/fachbereiche/informatik/lehrstuehle/algorithms-in-bioinformatics/software/dendroscope/), okay its not R but will work. Dendroscrope is hard for a non-tree person to read, however it will flag the differences for a specialist. Dendroscope will make a network tree for the topological differences, in this case between methods, i.e. non-bifurcating. You really then usually have to present the differences as a "mirror tree", i.e. parsimony and ML side by side, because usually non-tree people wonder what a Dendroscope output means. Technically there is nothing wrong with describing incongruence via networks.

Basically, the heart-beat is bootstrapping.

Generally speaking parsimony will give the same basic output as ML, except when you have some taxa undergoing rapid evolution against their sister group. This does happen in pathogen evolution and parsimony falls over into a phenomina known as 'long-branch attraction'.

> **Comments:**
> **username_4**: The advantage of the correlation measure will be the metrics which provide a more objective evaluation. Michael's recommandation with bootstrapping is really good, especially using collapsed branches.  

---

