one-line for fasta to fastq
There are many tools used for converting files from fastq to fasta. But it’s somewhat not so easy when I want do reverse convertion because of the absence of qulity score in fasta file.
I just want do a conversion from fa to fq just for testing something regardless of the quality scores, so it’s possible to do a dummy convertion from fa to fq.
Here is a simple one-line solution without any installation of software.
sample fasta: test.fa.gz
>probe_ac99b173fa
AACCAAACAAAAAGCGAGCACTGAGAGCTAAAGATGAGGAACTATTGCCTGTGTGCAGTATTGACCTTTCGAAAC
>probe_f7bf6328a4
TCTACAGCTTATAATTGCTGCCTTTATTCCTTCTATTGCCCCACTCAATCAAGCATACATTTTGGATTTTATTAG
>probe_810e250078
AAAACTCTACACACAAAAACATCTAGATTAGCCAATGTCACCTATCAATGCTCAACTATATCAACAGGATATGAA
......
......
Solution
zcat test.fa.gz | awk '{if(NR%2==1){sub(/^>/,"@",$0);print $0}else if(NR%2==0){print $0"\n+\n"$0}}'
result:
@probe_ac99b173fa
AACCAAACAAAAAGCGAGCACTGAGAGCTAAAGATGAGGAACTATTGCCTGTGTGCAGTATTGACCTTTCGAAAC
+
AACCAAACAAAAAGCGAGCACTGAGAGCTAAAGATGAGGAACTATTGCCTGTGTGCAGTATTGACCTTTCGAAAC
@probe_f7bf6328a4
TCTACAGCTTATAATTGCTGCCTTTATTCCTTCTATTGCCCCACTCAATCAAGCATACATTTTGGATTTTATTAG
+
TCTACAGCTTATAATTGCTGCCTTTATTCCTTCTATTGCCCCACTCAATCAAGCATACATTTTGGATTTTATTAG
@probe_810e250078
AAAACTCTACACACAAAAACATCTAGATTAGCCAATGTCACCTATCAATGCTCAACTATATCAACAGGATATGAA
+
AAAACTCTACACACAAAAACATCTAGATTAGCCAATGTCACCTATCAATGCTCAACTATATCAACAGGATATGAA
......
......
NOTICE: The quality(4th) row is replaced by sequence(2nd) row just for simplicity, I don’t know whether there will exist problems subsequently. Please make your own decision or modify the code upward.