Convert fastq to fasta format with awk

If you need to convert illumina reads in fastq format to fasta format, try using awk. If the reads are compressed, you can extract with zcat, then pipe the output to an awk one-liner:

zcat myReads.fastq.gz | awk 'BEGIN{P=1}{if(P==1||P==2){gsub(/^[@]/,">");print}; if(P==4)P=0; P++}' > myReads.fasta

Otherwise if they aren’t compressed, you can just use awk:

awk 'BEGIN{P=1}{if(P==1||P==2){gsub(/^[@]/,">");print}; if(P==4)P=0; P++}' myreads.fastq > myReads.fasta
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s