Answers.Body: <p>You require a consensus phylogeny. </p>
  
  <p>This is available in RAxML, PAUP, the old Phylip package and possibly the stats companion to Beast, Tracer. I'd need to dig up the code for RAxML and PAUP. The easiest is Consense <a href="http://evolution.genetics.washington.edu/phylip/doc/consense.html" rel="nofollow noreferrer">here</a> because you just download it and input the sequence. NOTE their is possibly a format difference (RAxML and Consense use Phylip format), I suspect you've got nexus, or Newick format. </p>
  
  <p>Beast is likely to have its own consensus formating OR the Beast companion  "Tracer" may have this (I can't remember). Tracer is <a href="https://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=1&amp;cad=rja&amp;uact=8&amp;ved=2ahUKEwis-s2llqXgAhWkSRUIHYimDR0QFjAAegQICRAB&amp;url=http%3A%2F%2Ftree.bio.ed.ac.uk%2Fsoftware%2Ftracer%2F&amp;usg=AOvVaw372z_FAnVlQErSu7tFxUF2" rel="nofollow noreferrer">here</a> and would be cool if it did consensus phylogeny because there will be no conversion problems (it doesn't use Phylip format). The alternative would be to use PAUP (no conversion problems), which is currently in a state of flux from various stages of freeware and updates. PAUP is contained within the Genious package, which is available as a 1 month free-ware.</p>
  
  <p>Have a look and let me know: because if you want to use RAxML or Consense you'll likely need to remind me of the Beast output, if it is what I think it is a format conversion app is needed.  The calculation is easy, its easy to script a conversion program, but I think tree formating will be an issue.</p>
  
  <p>You could use Ape, within R, but as you have gathered there are alot of other solutions. There are more recent, impressive, solutions as stand-alones which I've not used yet.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-02-06T15:49:53.163Z
Answers.Text: Many thanks for your answer! However, I already have a consensus tree and I am now trying to get the other most represented topologies from my BEAST output.
Answers.UserDisplayName: jvddorpe
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-02-06T16:12:51.380Z
Answers.Text: Ok. As far as I'm aware that program has not been written, at least a couple of years ago it wasn't, not sure about this now. Using R "ape" is your best bet. On this question I definitely can't help.
Answers.UserDisplayName: M__
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-02-05T17:08:41.107Z
Answers.LastActivityDate: 2019-02-06T00:37:14.450Z
Answers.LastEditDate: 2019-02-06T00:37:14.450Z
Answers.UserDisplayName: M__
Answers.Body: <p>I finally managed to do it in <a href="https://stackoverflow.com/questions/54523725/compare-list-of-complex-structures?noredirect=1#comment95877920_54523725">R</a>. Here is my code: </p>
  
  <pre><code>install.packages('devtools')
  library(devtools)
  install_github('santiagosnchez/rBt')
  library(rBt)
  
  beast_output &lt;- read.annot.beast('beast_output.trees')
  beast_output_rooted &lt;- root.multiPhylo(beast_output, c('taxon_A', 'taxon_B'))
  unique_topologies &lt;- unique.multiPhylo(beast_output_rooted)
  
  count &lt;- function(item, list) {
    total = 0
    for (i in 1:length(list)) {
      if (all.equal.phylo(item, list[[i]], use.edge.length = FALSE)) {
        total = total + 1
      }
    }
    return(total)
  }
  
  result &lt;- data.frame(unique_topology = rep(0, length(unique_topologies)),
                       count = rep(0, length(unique_topologies)))
  for (i in 1:length(unique_topologies)) {
    result[i, ] &lt;- c(i, count(unique_topologies[[i]], beast_output_rooted))
  }
  
  result<span class="math-container">$percentage &lt;- ((result$</span>count/length(beast_output_rooted))*100)
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-02-11T13:46:42.020Z
Answers.Text: This is fantastics, thanks for posting back
Answers.UserDisplayName: M__
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-02-07T12:03:07.163Z
Answers.LastActivityDate: 2019-02-07T12:03:07.163Z
Answers.UserDisplayName: jvddorpe
Body: <p>I have a nexus formatted <a href="http://beast.community/" rel="noreferrer">BEAST</a> output containing 20,000 phylogenetic trees of seven taxa. Is there any way to get the percentage of each unique phylogenetic tree contained in this output?</p>
  
  <p>I already made an unsuccessful attempt with <a href="https://stackoverflow.com/questions/54523725/compare-list-of-complex-structures">R</a>.  </p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-02-05T10:36:25.827Z
Comments.Text: If the phylogenetic trees can be represented as strings then it is basically just string matching. Anyway, I think your question would be more suited for [bioinformatics.se] as it is mostly about the programming aspect.
Comments.UserDisplayName: WYSIWYG
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-02-05T15:51:18.177Z
Comments.Text: Could you explain what is a "unique phylogenetic tree"? Perhaps if you upload an image it would be clearer what do you mean.
Comments.UserDisplayName: llrs
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-02-06T15:45:53.307Z
Comments.Text: @llrs When I mention a 'unique phylogenetic tree', I am referring to the [topology](https://www.ebi.ac.uk/training/online/course/introduction-phylogenetics/what-phylogeny/aspects-phylogenies/topology) of the tree. I would like to extract all the unique topologies from my BEAST output, and calculate how many times each of these topologies appears in my BEAST output. This would allow me to establish a percentage for each topology. The idea is to know which topologies are the most represented in addition to the consensus tree.
Comments.UserDisplayName: jvddorpe
Tags: <r><phylogenetics><phylogeny><beast>
Title: Calculate the percentage of each unique phylogenetic tree in a BEAST output
ThreadText: # Calculate the percentage of each unique phylogenetic tree in a BEAST output
  
  (Asked by: username_0 on 2019-02-05)
  
  I have a nexus formatted [BEAST](http://beast.community/) output containing 20,000 phylogenetic trees of seven taxa. Is there any way to get the percentage of each unique phylogenetic tree contained in this output?
  
  I already made an unsuccessful attempt with [R](https://stackoverflow.com/questions/54523725/compare-list-of-complex-structures).
  
  **Tags:** r, phylogenetics, phylogeny, beast
  
  > **Comments:**
  > **username_1**: If the phylogenetic trees can be represented as strings then it is basically just string matching. Anyway, I think your question would be more suited for [bioinformatics.se] as it is mostly about the programming aspect.  
  > **username_2**: Could you explain what is a "unique phylogenetic tree"? Perhaps if you upload an image it would be clearer what do you mean.  
  > **username_0**: @username_2 When I mention a 'unique phylogenetic tree', I am referring to the [topology](https://www.ebi.ac.uk/training/online/course/introduction-phylogenetics/what-phylogeny/aspects-phylogenies/topology) of the tree. I would like to extract all the unique topologies from my BEAST output, and calculate how many times each of these topologies appears in my BEAST output. This would allow me to establish a percentage for each topology. The idea is to know which topologies are the most represented in addition to the consensus tree.  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_0 on 2019-02-07. Score: 4 | Accepted answer
  
  I finally managed to do it in [R](https://stackoverflow.com/questions/54523725/compare-list-of-complex-structures?noredirect=1#comment95877920_54523725). Here is my code:
  
  ```
  install.packages('devtools')
  library(devtools)
  install_github('santiagosnchez/rBt')
  library(rBt)
  
  beast_output <- read.annot.beast('beast_output.trees')
  beast_output_rooted <- root.multiPhylo(beast_output, c('taxon_A', 'taxon_B'))
  unique_topologies <- unique.multiPhylo(beast_output_rooted)
  
  count <- function(item, list) {
    total = 0
    for (i in 1:length(list)) {
      if (all.equal.phylo(item, list[[i]], use.edge.length = FALSE)) {
        total = total + 1
      }
    }
    return(total)
  }
  
  result <- data.frame(unique_topology = rep(0, length(unique_topologies)),
                       count = rep(0, length(unique_topologies)))
  for (i in 1:length(unique_topologies)) {
    result[i, ] <- c(i, count(unique_topologies[[i]], beast_output_rooted))
  }
  
  result$percentage <- ((result$count/length(beast_output_rooted))*100)
  
  ```
  
  > **Comments:**
  > **username_3**: This is fantastics, thanks for posting back  
  
  ---
  
  ### Answer by username_3 on 2019-02-05. Score: 2
  
  You require a consensus phylogeny.
  
  This is available in RAxML, PAUP, the old Phylip package and possibly the stats companion to Beast, Tracer. I'd need to dig up the code for RAxML and PAUP. The easiest is Consense [here](http://evolution.genetics.washington.edu/phylip/doc/consense.html) because you just download it and input the sequence. NOTE their is possibly a format difference (RAxML and Consense use Phylip format), I suspect you've got nexus, or Newick format.
  
  Beast is likely to have its own consensus formating OR the Beast companion "Tracer" may have this (I can't remember). Tracer is [here](https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=2ahUKEwis-s2llqXgAhWkSRUIHYimDR0QFjAAegQICRAB&url=http%3A%2F%2Ftree.bio.ed.ac.uk%2Fsoftware%2Ftracer%2F&usg=AOvVaw372z_FAnVlQErSu7tFxUF2) and would be cool if it did consensus phylogeny because there will be no conversion problems (it doesn't use Phylip format). The alternative would be to use PAUP (no conversion problems), which is currently in a state of flux from various stages of freeware and updates. PAUP is contained within the Genious package, which is available as a 1 month free-ware.
  
  Have a look and let me know: because if you want to use RAxML or Consense you'll likely need to remind me of the Beast output, if it is what I think it is a format conversion app is needed. The calculation is easy, its easy to script a conversion program, but I think tree formating will be an issue.
  
  You could use Ape, within R, but as you have gathered there are alot of other solutions. There are more recent, impressive, solutions as stand-alones which I've not used yet.
  
  > **Comments:**
  > **username_0**: Many thanks for your answer! However, I already have a consensus tree and I am now trying to get the other most represented topologies from my BEAST output.  
  > **username_3**: Ok. As far as I'm aware that program has not been written, at least a couple of years ago it wasn't, not sure about this now. Using R "ape" is your best bet. On this question I definitely can't help.  
  
  ---
  
  