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

Trim adapters

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

During sequencing, short synthetic adapter sequences are attached to the DNA fragments. If a read is shorter than the fragment the machine runs through into the adapter, so the read ends with adapter sequence that is not part of the organism's DNA. Left in, it can mislead alignment and assembly.

Your task. The first line is the adapter sequence. Every following line is one read. For each read, find the first occurrence of the adapter and remove it together with everything after it, keeping only what came before. If the adapter does not occur, the read is unchanged. If nothing is left after trimming, print EMPTY.

Input. An adapter line, then one read per line.

Output. One line per read: the trimmed read, or EMPTY.

GIVEN INPUT

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

AGATCGGAAG
ACGTACGTAGATCGGAAGTTTT
GGGGCCCC
AGATCGGAAGACGT
TTAGATCGGAAGAGATCGGAAG

EXPECTED OUTPUT FOR THIS INPUT

ACGTACGT
GGGGCCCC
EMPTY
TT

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 is an adapter sequence?

2.

Why must adapters be removed before aligning reads to a genome?

Explain and submit

Explain how your code finds the adapter in a read and why it removes everything after the first match as well as the adapter itself.

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.