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