FASTA to FASTQ

Turn FASTA records into FASTQ, with the scores from a QUAL file or one fixed value.

FASTQ

How do you convert FASTA to FASTQ?

A FASTQ record is four lines: an identifier line starting with @, the sequence, a separator line holding a single +, and a quality string with exactly one character per base. A FASTA record has only the first two of those, and it carries no quality information at all. The conversion therefore rewrites >name as @name, puts the sequence on one line, adds the + line, and fills the fourth line with one repeated character that stands for the quality value you choose. If you still have the qualities, in a .qual file beside the FASTA, paste it into the QUAL box and the real scores are written instead.

Without a QUAL file the quality string is a placeholder, not a measurement. It says nothing about how the sequence was determined. Use that conversion only to feed a tool that insists on FASTQ input, such as an aligner, a read simulator or a trimming pipeline, and never to report base quality. Going the other way, from real reads to sequences, is lossless: use theFASTQ to FASTA converter.

What do the quality characters mean?

A Phred quality value Q is the probability P that the base is wrong, on a log scale, and each value is stored as one printable character:

Q = −10 × log₁₀ P     character = ASCII(Q + offset)

The offset is 33 for Phred+33 and 64 for Phred+64. With the default Q40 and Phred+33 the character is ASCII 73, the capital letter I.

QError probabilityAccuracyPhred+33Phred+64
01 in 10 %!@
101 in 1090 %+J
201 in 10099 %5T
301 in 1,00099.9 %?^
401 in 10,00099.99 %Ih

Phred+33 can hold Q0 to Q93, Phred+64 only Q0 to Q62, because the character must stay inside the printable ASCII range 33 to 126. Values outside the range are reduced to the highest one the encoding can write, and the tool says so.

Using a QUAL file instead of a made-up value

Sequencing platforms that predate FASTQ, 454 and capillary Sanger above all, wrote the bases and the qualities into two files: a FASTA file and a .qual file with the same records, each one a > header followed by the Phred scores of that read as plain numbers separated by spaces or line breaks. Paste that file into the QUAL file box and the real scores are used; leave it empty and the fixed value above it fills every base, as before.

>read1 control spike-in
40 40 40 38 38 38 35 35 35 32 32 30 30 30 28 28 25 20

Records are matched by name, the first word after the > in each header, so the two files may be in any order. Three things are checked before anything is written:

  • Length. A record whose sequence and quality string differ in length is left out and named, with both counts, rather than written as a FASTQ record no parser will accept.
  • Names. A sequence with no QUAL record of its own falls back to the fixed value and is named, and QUAL records that match no sequence are counted.
  • Range. Scores outside what the encoding can hold, Q0 to Q93 for Phred+33 and Q0 to Q62 for Phred+64, are brought inside it and counted.

Worked example

The example loads two sequences of 18 and 16 bases and the matching QUAL records. With Phred+33 the first record comes out as

@read1 control spike-in
ATCGATCGATCGTTTAAA
+
IIIGGGDDDAA???==:5

Eighteen bases, eighteen quality characters: I is Q40 at the start of the read and5 is Q20 at the end, the quality slide every real read has. Across both records the mean is Q32.2, from Q20 to Q40. Empty the QUAL box and the same record comes back with eighteen copies of I, the fixed Q40 placeholder. Either way the two lines are the same length, which is the first rule a FASTQ parser checks.

Frequently asked questions

Can you really convert FASTA to FASTQ?

Only in the bookkeeping sense, unless you have the qualities in a separate file. A FASTA file holds no quality information, so on its own the conversion invents one quality value and repeats it for every base: a valid FASTQ file that tools will accept, with a quality line that carries no measurement. Add the matching .qual file and the real Phred scores are written instead, which is a lossless conversion.

What is a QUAL file and how do I merge it with my FASTA?

A .qual file is the other half of the old two-file format used by 454 and Sanger sequencing: the same records as the FASTA file, in the same order, but with the Phred score of every base written out as a number instead of the base itself. Paste it into the QUAL box and each record is matched to its sequence by name, the first word of the header, then the numbers are encoded as Phred+33 or Phred+64 characters. If a sequence and its scores differ in length that record is left out and named, because the FASTQ would otherwise be invalid.

Which quality value should I choose?

Q40 is the usual placeholder: it means one expected error in 10,000 bases, which tells downstream tools to trust the bases. Some pipelines prefer Q30 (one error in 1,000) so that the reads are not treated as better than real data. If a tool filters on quality, pick a value above its threshold.

What is the difference between Phred+33 and Phred+64?

They are two ways of writing the same number as a character. Phred+33 (Sanger and Illumina 1.8 or later) adds 33 to the quality value, so Q40 is the character I. Phred+64 (Illumina 1.3 to 1.7 and Solexa) adds 64, so Q40 is the character h. Phred+33 is the modern standard and the default here.

Why is the header line the same as in my FASTA file?

FASTQ uses @ instead of > to start a record, so the description after the marker is kept as it is. The separator line is a bare +, which is the compact form; repeating the identifier after the + is allowed but doubles the file size for no benefit.

What happens to sequences without a header?

Plain sequence pasted without a > line becomes one record named sequence. Line breaks, digits and spaces inside a sequence are removed, because a FASTQ record needs the whole sequence on one line so that it lines up with the quality string.