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: when you switch it on, 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. Other widely used tools are Trimmomatic and cutadapt (often run through Trim Galore); fastp is a popular all-in-one choice and the one we use here.

▶ 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). Two defaults are worth knowing. For adapters, fastp finds them on its own for paired-end data (by overlapping the two mates) and tries to auto-detect them for single-end data, which can miss them. For quality, by default it only throws away whole reads that are mostly low quality; it does not trim bad bases off the ends unless you ask. So for our single-end example we name the adapter and switch on 3' quality trimming. The -h and -j options save its HTML and JSON reports.

!fastp -i reads.fastq -o reads.trimmed.fastq \
      --adapter_sequence AGATCGGAAGAGCACACGTCTGAACTCCAGTCA \
      --cut_right \
      -h fastp.html -j fastp.json

--adapter_sequence is the standard Illumina adapter (the one planted in our reads). --cut_right slides a small window along each read and cuts it off where the quality drops too low.

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

Two quick checks. The read count tells you whether any reads were dropped (with these settings almost none are, because few become too short). The quality numbers from fastp's JSON report show the real change: the share of bases at Q20 or better goes up after trimming. In our test, about 900 of the 3,000 reads had adapter trimmed, and Q20 rose from about 91% to about 99%.

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

import json
r = json.load(open("fastp.json"))
print("Q20 before:", round(r["summary"]["before_filtering"]["q20_rate"], 3))
print("Q20 after: ", round(r["summary"]["after_filtering"]["q20_rate"], 3))
print("reads with adapter trimmed:", r["adapter_cutting"]["adapter_trimmed_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 deliberately gentle. 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 -h fastp_pe.html -j fastp_pe.json. The capital -I and -O are the second read of each pair.

Try it here: trim real reads in your browser

The practice data is simulated: a 10,000-base chromosome called chr1 and 1,780 reads of 100 bases, built so the results are small, fast and checkable. Press Run on each box; a real Linux terminal opens at the bottom of the page. No install, no account. The Colab boxes above start with !; in this terminal you type the same commands without it.

fastp -i reads.fastq -o reads.trimmed.fastq \
      --adapter_sequence AGATCGGAAGAGCACACGTCTGAACTCCAGTCA \
      --cut_right \
      -h fastp.html -j fastp.json
echo "Before: $(( $(wc -l < reads.fastq)/4 )) reads"
echo "After:  $(( $(wc -l < reads.trimmed.fastq)/4 )) reads"
grep -A2 '"adapter_cutting"' fastp.json

What you should see

1,780 reads before and after (none were short enough to drop), and 135 reads with adapter trimmed: the reads whose DNA fragment was shorter than 100 bases ran into the adapter.

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.
Besides fastp, which trimming tools are widely used and cited?
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.

Sources & further reading

  1. Chen S, Zhou Y, Chen Y, Gu J. fastp: an ultra-fast all-in-one FASTQ preprocessor. Bioinformatics 34: i884-i890, 2018. doi:10.1093/bioinformatics/bty560
  2. Chen S. Ultrafast one-pass FASTQ data preprocessing, quality control, and deduplication using fastp. iMeta 2: e107, 2023. doi:10.1002/imt2.107
  3. Williams CR, Baccarella A, Parrish JZ, Kim CC. Trimming of sequence reads alters RNA-Seq gene expression estimates. BMC Bioinformatics 17: 103, 2016. (why not to over-trim) doi:10.1186/s12859-016-0956-2

Last reviewed: October 2026.

Next in Track 2

Read alignment: BWA, HISAT2, STAR →

Practice terminal powered by sandbox.bio (runs in your browser; your commands stay on your computer).