- 1 Read the file
- 2 Clean and validate
- 3 Filter by length
- 4 Trim adapters
- 5 Quality check a FASTQ file
Quality check a FASTQ file
THE BRIEF
A FASTQ record has four lines: a header starting with @, the sequence, a + line, and a quality string with one character per base. Each character encodes a Phred quality score: its ASCII code minus 33. A score Q means the chance the base is wrong is 10^(-Q/10), so Q20 means a 1 in 100 chance of error.
Your task. For each read, compute the mean quality (the average of its per-base Phred scores) and print the read id (the first word after @), the mean rounded to one decimal place, and PASS if the mean is at least 20, otherwise FAIL.
Input. A FASTQ file (4 lines per record).
Output. One line per read: id mean PASS or id mean FAIL.
GIVEN INPUT
Your code reads this from standard input (input() or sys.stdin), both here and when it is graded.
@read1 good ACGTACGT + IIIIIIII @read2 half bad ACGTACGT + 5555!!!! @read3 poor ACGTACGT + ########
EXPECTED OUTPUT FOR THIS INPUT
read1 40.0 PASS read2 10.0 FAIL read3 2.0 FAIL
SKILLS YOU'LL USE
Stuck? These bank problems practise the same techniques.
Write your code
Check your understanding
A quick self-check, marked right here in your browser. It is not graded or saved.
How many lines does one FASTQ record use?
Header, sequence, the + line and the quality string.
A base has Phred quality 20. What is the probability that the base call is wrong?
Q = -10 log10(P), so Q20 means P = 0.01. Q30 means 1 in 1000.
Why is a high mean quality still not a guarantee that a read is perfect?
Averages smooth out detail: always look at how quality changes along the read as well.
Explain and submit
Explain how you turn a quality string into a mean score and what a pipeline would do with reads that fail.
Your submissions (0)
You can look ahead; come back to finish this stage.