<p>Dear All,
Am I right to use the following script to transform a fastq file (named test.fastq) to a fasta file? THANKS a lot!</p>

<pre><code>#!/usr/bin/perl
use strict;
use Bio::SeqIO;
my $in=Bio::SeqIO-&gt;new(-file=&gt;"test.fastq",-format=&gt;'fastq');
my $out=Bio::SeqIO-&gt;new(-file=&gt;"&gt;test.fasta",-format=&gt;'fasta');
while(my $seq=$in-&gt;next_seq()){
      $out-&gt;write_seq($seq);
}
</code></pre>

<p>The following list shows the time for converting 2 million 100bp sequences in fastq to fasta with different approaches (locale set to "C"):</p>

<pre>
================================================================================================
Real(s)    CPU(s)   Command line
------------------------------------------------------------------------------------------------
  1.8        1.8    seqtk seq -A t.fq > /dev/null
  3.1        3.1    sed -n '1~4s/^@/>/p;2~4p' t.fq > /dev/null
  5.8       12.4    paste - - - - &lt; t.fq | sed 's/^@/>/g'| cut -f1-2 | tr '\t' '\n' > /dev/null
  7.6        7.5    bioawk -c fastx '{print ">"$name"\n"$seq}' t.fq > /dev/null
 11.9       12.9    awk 'NR%4==1||NR%4==2' t.fq | tr "@" ">" > /dev/null
 22.2       22.2    seqret -sequence t.fq -out /dev/null        # 6.4.0
 26.5       25.4    fastq_to_fasta -Q32 -i t.fq -o /dev/null    # 0.0.13
================================================================================================
</pre>

<p>In the list, seqtk, bioawk and seqret work with multi-line fastq; the rest don't. If you just want to use the standard unix tools, rtliu's sed solution is preferred, both short and efficient. It should be noted that file <code>t.fq</code> is put in <code>/dev/shm</code> and the results are written to <code>/dev/null</code>. In real applications, I/O may take more wall-clock time than CPU. In addition, frequently the sequence file is gzip'd. For seqtk, decompression takes more CPU time than parsing fastq.</p>

<p>Additional comments:</p>

<ul>
<li><p>SES observed that seqret was faster than Irsan's command. At my hand, seqret is always slower than most. Is it because of version, locale or something else?</p></li>
<li><p>I have not tried the native bioperl parser. Probably it is much slower. Using bioperl on large fastq is discouraged.</p></li>
<li><p>I do agree 4-line fastq is much more convenient for many people. However, fastq is never "defined" to consist of 4 lines. When it was first introduced at the Sanger Institute for ~1kb capillary reads, it allows multiple lines.</p></li>
<li><p>Tools in many ancient unix distributions (e.g. older AIX) do not work with long lines. I was working with a couple of such unix even in 2005. I guess this is why older outputs/formats, such as fasta, blast and genbank/embl, used short lines. This is not a concern any more nowadays.</p></li>
<li><p>To convert multi-line fastq to 4-line (or multi-line fasta to 2-line fasta): <code>seqtk seq -l0 multi-line.fq &gt; 4-line.fq</code></p></li>
</ul>
