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 2 OF 5

Clean and validate

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

Real files are messy: lowercase letters, stray spaces and unexpected characters. A pipeline first cleans each sequence (makes it uppercase and removes all whitespace) and then validates it.

Your task. For each record in a FASTA file, clean its sequence, then decide whether it is VALID: it must be non-empty and contain only the letters A, C, G, T and N (N means "unknown base"). Print the id followed by VALID or INVALID.

Input. A FASTA file (the sequences may contain lowercase letters, spaces and invalid characters).

Output. One line per record: id VALID or id INVALID.

GIVEN INPUT

Your code reads this from standard input (input() or sys.stdin), both here and when it is graded.

>r1
acgtn acgt
>r2
ACGTXACGT
>r3
AC GT
TTGA
>r4
ACG1T
>r5

EXPECTED OUTPUT FOR THIS INPUT

r1 VALID
r2 INVALID
r3 VALID
r4 INVALID
r5 INVALID

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.

Why convert every sequence to uppercase before checking or counting it?

2.

In a DNA sequence, what does the letter N usually mean?

Explain and submit

Explain why your pipeline cleans a sequence before it validates it, and what would go wrong if the order were reversed.

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.