FASTA to FASTQ
Turn FASTA records into FASTQ, with the scores from a QUAL file or one fixed value.
Turn FASTA records into FASTQ, with the scores from a QUAL file or one fixed value.
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.
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:
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.
| Q | Error probability | Accuracy | Phred+33 | Phred+64 |
|---|---|---|---|---|
| 0 | 1 in 1 | 0 % | ! | @ |
| 10 | 1 in 10 | 90 % | + | J |
| 20 | 1 in 100 | 99 % | 5 | T |
| 30 | 1 in 1,000 | 99.9 % | ? | ^ |
| 40 | 1 in 10,000 | 99.99 % | I | h |
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.
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:
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.
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.
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.
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.
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.
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.
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.