<p>I'm working with a Daphnia data set looking at the 16s gene pulled from the BOLD database. So far I did </p>

<ul>
<li>a multiple sequence alignment and </li>
<li><p>attempted to cluster and plot a dendrogram:</p>

<p>myClustalWAlignment &lt;- DNAStringSet(msa(MySeqString, cluster="nj", gapOpening=30.0,  gapExtension=20.0, maxiters=2, substitutionMatrix="default", type="default", verbose=TRUE))</p></li>
<li><p>Replace full sequence names with Accession numbers for easy identification</p>

<p>names(myClustalWAlignment) &lt;- Daphnia_DF$Accession_number</p></li>
<li><p>Converts the alignment object into a DNAbin class. Some of the results are shown and may be useful for further analysis:</p>

<p>ClustalAlignment_dnaBin &lt;- as.DNAbin(myClustalWAlignment)</p></li>
<li><p>Creating a distance matrix:</p>

<p>distmat &lt;- dist.dna(ClustalAlignment_dnaBin, model = "TN93", as.matrix = TRUE, pairwise.deletion = TRUE)</p></li>
<li><p>clustering the sequences:</p>

<p>Daphnia_Clustered &lt;- IdClusters(distmat,
                      method = "UPGMA",
                      cutoff = 0.01,
                      showPlot = TRUE,
                      type = "both",
                      myXStringSet = NULL,
                      model = MODELS,
                      collapse = 0,
                      processors = NULL,
                      verbose = TRUE)</p></li>
<li><p>checking to see the number of clusters:</p>

<p>length(unique(unlist(Daphnia_Clustered<a href="https://i.sstatic.net/s0dId.png" rel="nofollow noreferrer"><a href="https://i.sstatic.net/s0dId.png" rel="nofollow noreferrer">1</a></a>)))</p></li>
</ul>

<p>output: 80</p>

<p>The problem is that I want a dendrogram showing just the 80 clusters if that's possible. Right now the output of the above clustering is:</p>

<p><a href="https://i.sstatic.net/s0dId.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/s0dId.png" alt="dendrogram"></a></p>

<p>Is there a way to get a smaller number of clusters? Or even being able to plot just the 80 OTU clusters would be great. Is there an easy way of reconstructing the phylogenetic relationship between these clusters?</p>

CC BY-SA 4.0
2018-10-25T06:22:44.353Z
Welcome! Just curious - why don't you want to just make a maximum likelihood or Bayesian tree? Those are very standard approaches and you can just collapse nodes later on to make clusters.
conchoecia
CC BY-SA 4.0
2018-10-25T14:41:04.773Z
Hey, I'm just extremely new r and bioinformatics I guess. I did attempt that and I did come out with a tree structure. However, how would I go on about collapsing the branches, are there any packages you particularly recommend ?
Gurkamal Deol
CC BY-SA 4.0
2018-10-25T15:08:58.060Z
If you need to quickly visualize the tree I would just save the tree file, open it in FigTree, and collapse the nodes. https://www.biostars.org/p/18302/  If you add some info to your question like what the end goals are for this project or this phylogenetic analysis/visualization I think people can get a better answer tailored to the needs of the question.
conchoecia
CC BY-SA 4.0
2018-12-28T21:13:25.720Z
I agree that it is easier to make a subtree in figtree and write the tree in R to the hard-drive.
M__
<phylogenetics><phylogeny><ggplot2><clustering>
How to create a dendrogram of clusters and reconstruct phylogenetic relationship
# How to create a dendrogram of clusters and reconstruct phylogenetic relationship

(Asked by: username_0 on 2018-10-25)

I'm working with a Daphnia data set looking at the 16s gene pulled from the BOLD database. So far I did

* a multiple sequence alignment and
* attempted to cluster and plot a dendrogram:

  myClustalWAlignment <- DNAStringSet(msa(MySeqString, cluster="nj", gapOpening=30.0, gapExtension=20.0, maxiters=2, substitutionMatrix="default", type="default", verbose=TRUE))
* Replace full sequence names with Accession numbers for easy identification

  names(myClustalWAlignment) <- Daphnia\_DF$Accession\_number
* Converts the alignment object into a DNAbin class. Some of the results are shown and may be useful for further analysis:

  ClustalAlignment\_dnaBin <- as.DNAbin(myClustalWAlignment)
* Creating a distance matrix:

  distmat <- dist.dna(ClustalAlignment\_dnaBin, model = "TN93", as.matrix = TRUE, pairwise.deletion = TRUE)
* clustering the sequences:

  Daphnia\_Clustered <- IdClusters(distmat,
  method = "UPGMA",
  cutoff = 0.01,
  showPlot = TRUE,
  type = "both",
  myXStringSet = NULL,
  model = MODELS,
  collapse = 0,
  processors = NULL,
  verbose = TRUE)
* checking to see the number of clusters:

  length(unique(unlist(Daphnia\_Clustered[[1](https://i.sstatic.net/s0dId.png)](https://i.sstatic.net/s0dId.png))))

output: 80

The problem is that I want a dendrogram showing just the 80 clusters if that's possible. Right now the output of the above clustering is:

[![dendrogram](https://i.sstatic.net/s0dId.png)](https://i.sstatic.net/s0dId.png)

Is there a way to get a smaller number of clusters? Or even being able to plot just the 80 OTU clusters would be great. Is there an easy way of reconstructing the phylogenetic relationship between these clusters?

**Tags:** phylogenetics, phylogeny, ggplot2, clustering
> **Comments:**
> **username_1**: Welcome! Just curious - why don't you want to just make a maximum likelihood or Bayesian tree? Those are very standard approaches and you can just collapse nodes later on to make clusters.  
> **username_0**: Hey, I'm just extremely new r and bioinformatics I guess. I did attempt that and I did come out with a tree structure. However, how would I go on about collapsing the branches, are there any packages you particularly recommend ?  
> **username_1**: If you need to quickly visualize the tree I would just save the tree file, open it in FigTree, and collapse the nodes. https://www.biostars.org/p/18302/  If you add some info to your question like what the end goals are for this project or this phylogenetic analysis/visualization I think people can get a better answer tailored to the needs of the question.  
> **username_2**: I agree that it is easier to make a subtree in figtree and write the tree in R to the hard-drive.  

---

## 0 answers

