- 1 Read the file
- 2 Clean and validate
- 3 Filter by length
- 4 Trim adapters
- 5 Quality check a FASTQ file
Clean and validate
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
Check your understanding
A quick self-check, marked right here in your browser. It is not graded or saved.
Why convert every sequence to uppercase before checking or counting it?
Normalising first prevents a whole class of silent bugs.
In a DNA sequence, what does the letter N usually mean?
N marks a position where the sequencer could not decide which base it saw.
Explain and submit
Explain why your pipeline cleans a sequence before it validates it, and what would go wrong if the order were reversed.
Your submissions (0)
You can look ahead; come back to finish this stage.