Answers.Body: <p>A key difference from many examples provided is that they assume that the data provided is in the form of sequences rather than an already aligned sequence alignment.</p>
  <pre><code>library(&quot;Biostrings&quot;)
  library(&quot;seqinr&quot;)
  library(&quot;ape&quot;)
  library(phylogram)
  library(&quot;dendextend&quot;)
  
  
  #read in the data from a format with the aligned sequences (eg msf)
  msf.res &lt;- read.alignment(file = &quot;geneticAlignment.msf&quot;, format = &quot;msf&quot;)
  #dist.alignment and not dna.dist commonly used in tutorials
  msf.res.dist.alignment = dist.alignment(msf.res, matrix = &quot;identity&quot;)
  #perform neighbor joining upon the distance set
  msf.res.dist.alignment.nj = nj(msf.res.dist.alignment)
  #then plot the joined sequences
  plot(msf.res.dist.alignment.nj, main = &quot;Neighbor Joining&quot;)
   
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-08-16T01:04:17.417Z
Answers.LastActivityDate: 2020-08-16T01:04:17.417Z
Answers.UserDisplayName: Vass
Body: <p>I am looking at how to build a <code>phylogenetic tree</code> in <code>R</code> from <strong>aligned</strong> genetic information (dna sequences). There are multiple tutorials on how to go about this task eg <a href="https://yulab-smu.github.io/treedata-book/chapter2.html" rel="nofollow noreferrer">tutorial1</a>, <a href="https://cran.r-project.org/web/packages/ape/ape.pdf" rel="nofollow noreferrer">tutorial2 (&quot;ape&quot; docs)</a>, <a href="http://www.phytools.org/Cordoba2017/ex/2/Intro-to-phylogenies.html" rel="nofollow noreferrer">tutorial3</a>, and there are many more. There appears to be quite a few steps with dependencies from multiple packages: eg. &quot;ape&quot;, &quot;phangorn&quot;, &quot;phytools&quot;, &quot;geiger&quot;. I would like to learn a minimal working example (mwe) for constructing a phylogenetic tree from a basic data-structure holding dna-strings.</p>
  <p>Eg. I have a vector of nucleotide strings, and a separate vector for the 'names' of each string in the vector, how can I construct a phylogenetic tree from this information? (not a fasta file)</p>
  
Tags: <phylogenetics><phylogeny>
Title: Minimal working example for phylogenetic tree construction in R using an alignment of DNA strings and a vector of names?
ThreadText: # Minimal working example for phylogenetic tree construction in R using an alignment of DNA strings and a vector of names?
  
  (Asked by: username_0 on 2020-08-11)
  
  I am looking at how to build a `phylogenetic tree` in `R` from **aligned** genetic information (dna sequences). There are multiple tutorials on how to go about this task eg [tutorial1](https://yulab-smu.github.io/treedata-book/chapter2.html), [tutorial2 ("ape" docs)](https://cran.r-project.org/web/packages/ape/ape.pdf), [tutorial3](http://www.phytools.org/Cordoba2017/ex/2/Intro-to-phylogenies.html), and there are many more. There appears to be quite a few steps with dependencies from multiple packages: eg. "ape", "phangorn", "phytools", "geiger". I would like to learn a minimal working example (mwe) for constructing a phylogenetic tree from a basic data-structure holding dna-strings.
  
  Eg. I have a vector of nucleotide strings, and a separate vector for the 'names' of each string in the vector, how can I construct a phylogenetic tree from this information? (not a fasta file)
  
  **Tags:** phylogenetics, phylogeny
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2020-08-16. Score: 1
  
  A key difference from many examples provided is that they assume that the data provided is in the form of sequences rather than an already aligned sequence alignment.
  
  ```
  library("Biostrings")
  library("seqinr")
  library("ape")
  library(phylogram)
  library("dendextend")
  
  #read in the data from a format with the aligned sequences (eg msf)
  msf.res <- read.alignment(file = "geneticAlignment.msf", format = "msf")
  #dist.alignment and not dna.dist commonly used in tutorials
  msf.res.dist.alignment = dist.alignment(msf.res, matrix = "identity")
  #perform neighbor joining upon the distance set
  msf.res.dist.alignment.nj = nj(msf.res.dist.alignment)
  #then plot the joined sequences
  plot(msf.res.dist.alignment.nj, main = "Neighbor Joining")
   
  
  ```
  
  
  ---
  
  