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

Read the 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

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

.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.

What character starts the header line of every FASTA record?

2.

Why do parsers join all the sequence lines of a record before measuring its length?

Explain and submit

Explain how your code decides where one record ends and the next begins.

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 20 words.

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