text: user1402: I am trying to convert DNAbin files to fasta format. Rationale: I want to use the fasta file to calculate non-synonymous/synonymous mutation rate. 
  my_dnabin1 is a DNAbin file of 55 samples and I am using the following code to convert it into a fasta file. 
  dnabin_to_fasta <- lapply(my_dnabin1, function(x) as.character(x[1:length(x)]))
  This generates a list of 55 samples which looks like:
  $SS.11.01
  [1] "t" "t" "a" "c" "c" "t" "a" "a" "a" "a" "a" "g" "c" "c" "g" "c" "t" "t" "c" "c" "c" "t" "c" "c" "a" "a"
   [27] "c" "c" "c" "t" "a" "g" "a" "a" "g" "c" "a" "a" "a" "c" "c" "t" "t" "t" "c" "a" "a" "c" "c" "c" "c" "a"
  $SS.11.02
  [1] "t" "t" "a" "c" "c" "t" "a" "a" "a" "a" "a" "g" "c" "c" "g" "c" "t" "t" "c" "c" "c" "t" "c" "c" "a" "a"
   [27] "c" "c" "c" "t" "a" "g" "a" "a" "g" "c" "a" "a" "a" "c" "c" "t" "t" "t" "c" "a" "a" "c" "c" "c" "c" "a"
  and so on...
  However, I want a fasta formatted file as the output that may look something like:
  >SS.11.01 ttacctga
  >SS.11.02 ttacctga
  
  user73: The following should work:
  cat(file="out.fa", paste(paste0(">",names(dnabin_to_fasta)),
            sapply(dnabin_to_fasta, paste, collapse=""), sep="\n"), sep="\n");
  
  A bit of explanation, starting from the middle outwards:
  
  Collapse the letter arrays inside dnabin_to_fasta into single strings
  Append ">" to the front of the names of each sequence
  Concatenate the results of steps 1 & 2 together, separating with a line break
  Write each concatenated string to a file, separating by a line break
  
  
original_text: 1402: <p>I am trying to convert DNAbin files to fasta format. Rationale: I want to use the fasta file to calculate non-synonymous/synonymous mutation rate. </p>
  
  <p><code>my_dnabin1</code> is a DNAbin file of 55 samples and I am using the following code to convert it into a fasta file. </p>
  
  <p><code>dnabin_to_fasta &lt;- lapply(my_dnabin1, function(x) as.character(x[1:length(x)]))</code>
  This generates a list of 55 samples which looks like:</p>
  
  <p>$SS.11.01</p>
  
  <p>[1] "t" "t" "a" "c" "c" "t" "a" "a" "a" "a" "a" "g" "c" "c" "g" "c" "t" "t" "c" "c" "c" "t" "c" "c" "a" "a"
   [27] "c" "c" "c" "t" "a" "g" "a" "a" "g" "c" "a" "a" "a" "c" "c" "t" "t" "t" "c" "a" "a" "c" "c" "c" "c" "a"</p>
  
  <p>$SS.11.02</p>
  
  <p>[1] "t" "t" "a" "c" "c" "t" "a" "a" "a" "a" "a" "g" "c" "c" "g" "c" "t" "t" "c" "c" "c" "t" "c" "c" "a" "a"
   [27] "c" "c" "c" "t" "a" "g" "a" "a" "g" "c" "a" "a" "a" "c" "c" "t" "t" "t" "c" "a" "a" "c" "c" "c" "c" "a"</p>
  
  <p>and so on...</p>
  
  <p>However, I want a fasta formatted file as the output that may look something like:</p>
  
  <p><code>&gt;SS.11.01 ttacctga</code></p>
  
  <p><code>&gt;SS.11.02 ttacctga</code></p>
   73: <p>The following should work:</p>
  
  <pre><code>cat(file="out.fa", paste(paste0("&gt;",names(dnabin_to_fasta)),
            sapply(dnabin_to_fasta, paste, collapse=""), sep="\n"), sep="\n");
  </code></pre>
  
  <p>A bit of explanation, starting from the middle outwards:</p>
  
  <ol>
  <li>Collapse the letter arrays inside dnabin_to_fasta into single strings</li>
  <li>Append ">" to the front of the names of each sequence</li>
  <li>Concatenate the results of steps 1 &amp; 2 together, separating with a line break</li>
  <li>Write each concatenated string to a file, separating by a line break</li>
  </ol>
  