Sequence Data QC Pipeline
0 of 5 stages done
  1. 1 Read the file
  2. 2 Clean and validate
  3. 3 Filter by length
  4. 4 Trim adapters
  5. 5 Quality check a FASTQ file
STAGE 5 OF 5

Quality check a FASTQ file

Code not passed yet Explanation needed Self-check
You are browsing as a guest: read the stage and run code freely. To be graded and save your progress, sign in or create an account →

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

.ipynb
Shift + Enter runs a cell. Your notebook runs and is saved in this browser only; nothing is sent to us until you submit in step 3.

Check your understanding

A quick self-check, marked right here in your browser. It is not graded or saved.

1.

How many lines does one FASTQ record use?

2.

A base has Phred quality 20. What is the probability that the base call is wrong?

3.

Why is a high mean quality still not a guarantee that a read is perfect?

Explain and submit

Explain how you turn a quality string into a mean score and what a pipeline would do with reads that fail.

Submitting sends the code in your solution cell and this explanation. The code is checked on our server against the given input and hidden tests. The stage is complete when the code passes and the explanation has at least 25 words.

You can look ahead; come back to finish this stage.