- 1 Read the file
- 2 Clean and validate
- 3 Filter by length
- 4 Trim adapters
- 5 Quality check a FASTQ file
Read the file
THE BRIEF
Sequences are usually stored in FASTA files. Each record starts with a header line beginning with > (the first word after > is the record's id), followed by the sequence, which may be split over several lines.
Your task. Read a FASTA file from standard input. For every record, in order, print its id and its sequence length (the total number of letters, with all the sequence lines joined).
Input. A FASTA file.
Output. One line per record: id length.
GIVEN INPUT
Your code reads this from standard input (input() or sys.stdin), both here and when it is graded.
>seq1 sample from patient A ACGTACGTAC GGTT >seq2 TTGACCA >seq3 low complexity region AAAAAAAAAAAAAAAAAAAA
EXPECTED OUTPUT FOR THIS INPUT
seq1 14 seq2 7 seq3 20
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.
What character starts the header line of every FASTA record?
FASTA headers start with >. (FASTQ headers start with @.)
Why do parsers join all the sequence lines of a record before measuring its length?
Wrapping is only a display convention; the sequence is everything between one header and the next.
Explain and submit
Explain how your code decides where one record ends and the next begins.
Your submissions (0)
You can look ahead; come back to finish this stage.