Trimming and Filtering Reads

FastQC told you what was wrong with your reads. Trimming fixes it: snip off leftover adapters and low-quality ends, drop reads that are too short to be useful, and send only clean, trustworthy sequence into alignment. We'll do it with one fast tool, fastp.

🟡 Intermediate ⏱️ ~45 min 💻 Command line 🌐 Runs free in Colab

Before you start

  • You've done Quality Control with FastQC, so you know what a bad read looks like.
  • Comfortable with a few command-line lines. A free Google account to run the notebook.
  • Any term new? The Glossary has it.

Learning objectives

By the end of this lesson you will be able to: explain what trimming and filtering do to raw reads, run fastp to remove adapters and low-quality bases in one command, and confirm the cleaned reads improved before passing them on to alignment.

What "trimming" actually does

Trimming is housekeeping for reads. It does three jobs:

  • Adapter trimming: when a DNA fragment is shorter than the read, the machine reads past the real sequence into the adapter. That adapter is not biology, so it is cut off.
  • Quality trimming: the low-quality bases that pile up at the 3' end of reads are trimmed away, so you do not align unreliable letters.
  • Length filtering: if a read becomes too short after trimming (or was always bad), it is dropped entirely.

The result is a new FASTQ file with cleaner reads, ready for alignment.

Decode the jargonfastp

fastp is a single, fast tool that does adapter trimming, quality trimming, and filtering in one step. It even auto-detects the adapter sequence for you and writes its own before-and-after quality report, so you can see exactly what it cleaned. Older alternatives you'll see in papers are Trimmomatic and cutadapt; fastp is the modern, beginner-friendly default.

▶ Run it in Google Colab

Colab is a free Linux machine in your browser, so fastp runs with nothing to install on your computer.

Open the notebook in Colab →

1Install fastp and get some reads

Install the tool, then make an example FASTQ. The notebook builds reads that have both a quality drop at the end and adapter contamination in some reads, so there is something real to clean.

!apt-get -qq install -y fastp
!fastp --version

2Trim with one command

The core command takes an input file (-i) and writes a cleaned output file (-o). By default fastp auto-detects adapters and trims low-quality bases. The -h and -j options save its HTML and JSON reports. One caveat: adapter auto-detection is most reliable for paired-end data (it uses the overlap between mates). For single-end reads it is weaker, so if the report shows reads are still under-trimmed, pass the adapter explicitly with --adapter_sequence.

!fastp -i reads.fastq -o reads.trimmed.fastq -h fastp.html -j fastp.json

As it runs, fastp prints a summary: how many reads went in, how many passed the filters, how many had adapters trimmed, and the quality before and after. That summary is your before-and-after QC.

3Confirm it worked

A quick count shows that some reads were dropped (the ones too short or too poor to keep), and fastp's report shows the adapter content gone and the average quality up.

!echo "Before: $(( $(wc -l < reads.fastq)/4 )) reads"
!echo "After:  $(( $(wc -l < reads.trimmed.fastq)/4 )) reads"

Open fastp.html (download it from the Colab file browser on the left) to see the full before-and-after graphs. This is the loop you repeat in real projects: QC, trim, QC again, until the reads are clean.

⚠️ Do not over-trim

It is tempting to crank the settings up and cut aggressively, but over-trimming throws away good data and can bias your results. fastp's defaults are sensible for most data. Trim to fix real problems you saw in QC, not to chase a perfect-looking report.

Where the cleaned reads go next

Your reads.trimmed.fastq is now ready for the heart of the workflow: alignment, where each read is matched to its place in a reference genome. That is the next lesson.

🔶 Level up: paired-end trimming

Most real sequencing is paired-end (two files, R1 and R2). fastp handles both at once and keeps the pairs in sync: fastp -i R1.fastq -I R2.fastq -o R1.trimmed.fastq -O R2.trimmed.fastq. The capital -I and -O are the second read of each pair.

Check your understanding

Why must adapter sequence be trimmed before alignment?
Adapter is artificial sequence added in the lab, not part of the genome. If you leave it on, the aligner tries to match non-biological letters and either fails or maps reads to the wrong place. Removing it gives clean, biological sequence to align.
After trimming you have fewer reads than you started with. Is that a problem?
Usually no. Trimming drops reads that became too short or were too low-quality to trust. Losing a modest fraction is normal and healthy; it means you kept only reliable reads. Losing most of your reads, though, points to a deeper problem worth investigating.
What does fastp do that you would otherwise need several tools for?
It detects and trims adapters, trims low-quality bases, filters short reads, and produces a before-and-after QC report, all in one fast command. That is why it has become the go-to first step.
Which older trimming tools will you still see cited in papers, before fastp became the default?
Trimmomatic and cutadapt are the older alternatives you will meet in the literature. fastp is the modern, beginner-friendly default that bundles their jobs into one command.
Why is aggressively over-trimming your reads a bad idea?
Over-trimming discards good sequence and can bias downstream results. fastp's defaults are sensible for most data; trim to fix real problems you saw in QC, not to chase a perfect-looking report.
Next in Track 2

Read alignment: BWA, HISAT2, STAR →