How to convert FASTQ to FASTA

The following examples show how to convert a FASTQ file to a FASTA file. The commands assume a Unix-based operating system with Perl.

Using commands “cat” and “perl”:
There are many different ways of combining Unix commands to convert FASTQ files to FASTA files. Here is one example:

$ cat file_in.fastq | perl -e '$i=0;while(< >){if(/^@/&&$i==0){s/^@/>/;print;}elsif($i==1){print;$i=-3}$i++;}' > file_out.fasta

Make sure that you remove the space between the brackets at while() in the line above when you copy and paste the command. The content managment system automatically removes empty tags before publishing posts (even in code blocks) and requires this modification.


If you prefer to use a program instead, try the lite version of PRINSEQ ( that is written in Perl and provides an option to convert between different file formats (in addition to many other features):

$ perl -fastq file_in.fastq -out_format 1 -out_good file_out