Lesson 5 of 16 · 10 min
The FASTQ format: reads & quality scores
A sequencing machine is a lab instrument that reads DNA, the molecule inside living cells that stores genetic instructions. DNA is written using just four building blocks called nucleotide bases, shortened to the letters A, C, G, and T. When the machine finishes, it hands you a plain text file in a format called FASTQ, and learning to read it is your first real step in bioinformatics.
A read is one short stretch of DNA letters that the machine spelled out in a single go, for example a run of 30 or 150 letters. A FASTQ file is simply a long list of these reads, often millions of them stacked one after another, and every read is stored in exactly four lines, always in the same order.
Four lines per read
Line 1 starts with an @ symbol and holds the read ID, a unique name for that read. Line 2 is the sequence, the actual A, C, G, and T letters. Line 3 is a single + sign that acts as a separator. Line 4 has one quality character for each letter in line 2, telling you how confident the machine was about each base.
head -4 sample.fastq@READ_001 sample read
AGCTAGCTAGCTAGCTAGCTAGCTAGCTAG
+
IIIIIIIIIIIIIIIFFFFFFFF??????5
Here the read is named READ_001, its sequence is 30 letters long, the + line separates sequence from quality, and the last line has exactly 30 quality characters, one per base. Notice how the characters near the end (? and 5) differ from those at the start (I and F), which is the machine warning you that the later bases are less certain.
Quality scores explained
Each base gets a Phred quality score, written Q, defined as Q = -10 * log10(error probability). In plain words, a higher Q means a smaller chance the letter is wrong: Q30 means a 1-in-1000 chance of error, so the machine is 99.9% sure, and Q20 means a 1-in-100 chance, so 99% sure.
Tip: Quality scores are stored as single text characters using Phred+33 encoding, meaning character = chr(Q + 33). That +33 shift turns a plain number into a printable symbol: Q40 becomes the letter I, Q30 becomes ?, and Q20 becomes 5. That is why line 4 looks like random punctuation until you decode it.
Because every read takes up exactly four lines with no exceptions, the number of reads equals the total number of lines divided by 4. This is the fastest sanity check in bioinformatics: if your line count is not evenly divisible by 4, the file is probably truncated or corrupted.
Try it yourself: In a terminal (the text window where you type commands), run wc -l sample.fastq to print the total number of lines, then divide that number by 4 to get the read count. To do the division automatically in one step, run awk 'END{print NR/4}' sample.fastq, which counts the lines (NR) and prints NR divided by 4.