FASTQ Quality Control

Intermediate Bioinformatics FASTQ Phred Scores Quality Control Parsing
Significance:

Every sequencing run produces FASTQ, and every analysis begins by throwing away the
reads that are not worth analysing. Phred quality scores are encoded as ASCII characters offset by 33,
a compression trick that keeps files small but trips up anyone who has not decoded it before. Filtering
on mean quality is the single most common QC step in existence — it is what tools like fastp and
Trimmomatic do on their first pass.

Statement

You are given FASTQ records and a quality threshold. Each record is exactly four lines:
a header starting with @, the sequence, a separator line starting with +, and a quality string of
the same length as the sequence.

Quality characters use Phred+33 encoding: the score of a character is its ASCII code minus 33.

Count how many records have a mean quality score strictly below the given threshold, and print that
count on one line.

Input — read from standard input
Variable Type Description
threshold
line 1
float The mean quality threshold
0 <= threshold <= 60
fastq
line 2..n
str FASTQ records, four lines each
1 <= records <= 100

These variables are already read for you in the starter code on the right.

Output

str a single integer, the number of records whose mean quality is strictly below the threshold

Sample Cases
Sample 1
Input
30
@r1
ACGT
+
IIII
@r2
ACGT
+
!!!!
Expected Output
1
Read r1 has mean quality 40 and passes; r2 has mean quality 0 and is counted.
Sample 2
Input
20
@only
AAAA
+
5555
Expected Output
0
A single record with mean quality 20, which is not strictly below 20.

Submit also runs your code against 4 hidden test cases. Hidden inputs are never shown — if one fails you'll get its number and a description of the mismatch, not the data.

Constraints
  • The first line is the threshold; everything after it is FASTQ data
  • 1 <= number of records <= 100, each exactly four lines
  • Quality strings use Phred+33 encoding and match their sequence in length
  • Comparison is strictly less than: a record whose mean equals the threshold is not counted
Further Reading
  • ord(c) - 33 converts a quality character to its Phred score.
  • Read all lines first, then step through them four at a time.
  • Use exact floating-point comparison against the threshold — no rounding before comparing.

My Notes
Log in to save personal notes.
Console output will appear here when you click Run Code or Submit...
Expected: threshold (float), fastq (remaining lines)
Next Problem
Locating Restriction Sites