omics.co.in logo omics.co.in

Module 5: Read Trimming, Adapter Clipping & Quality Filtering with fastp & Trimmomatic

Tested Stacks: GATK 4.6.1 Samtools 1.21 Nextflow 24.10 Seurat v5.1 Python 3.12
Prerequisites: Basic Linux CLI & Sequencing Formats
Module 05 • Preprocessing Track 18 • Practical Transcriptomics Hands-On Code Included

Module 5: Read Trimming, Adapter Clipping & Quality Filtering with fastp & Trimmomatic

Automated adapter detection, sliding-window Phred quality filtering, poly-G tail clipping on two-color chemistry (NovaSeq/NextSeq), low-complexity read filtering, and post-filtering verification.

5. Read Trimming, Adapter Clipping & Filtering with fastp

Residual sequencing adapters, low-quality ends, and two-color optical noise (e.g., NovaSeq poly-G tails where no fluorophore fires) compromise spliced alignment accuracy. fastp is an ultra-fast C++ preprocessor that automatically detects adapters, clips sliding-window low quality bases, trims poly-G, and outputs interactive HTML diagnostics in a single pass.

Automated Batch Preprocessing with fastp

# Loop over all samples and execute fastp trimming
for R1 in 00_raw_data/*_R1.fastq.gz; do
    SAMPLE=$(basename "$R1" _R1.fastq.gz)
    R2="00_raw_data/${SAMPLE}_R2.fastq.gz"

    fastp \
      --in1 "$R1" \
      --in2 "$R2" \
      --out1 "02_trimmed_data/${SAMPLE}_R1.trimmed.fastq.gz" \
      --out2 "02_trimmed_data/${SAMPLE}_R2.trimmed.fastq.gz" \
      --detect_adapter_for_pe \
      --trim_poly_g \
      --cut_front --cut_tail \
      --cut_mean_quality 20 \
      --length_required 36 \
      --thread 8 \
      --html "03_qc_trimmed/${SAMPLE}_fastp.html" \
      --json "03_qc_trimmed/${SAMPLE}_fastp.json"
done

# Generate post-trimming MultiQC report
multiqc 03_qc_trimmed/ -o 03_qc_trimmed/ --title "Post-Trimming MultiQC Report"
⚠️

Common Pitfalls & Troubleshooting Checklist

  • Java Heap Exhaustion (GATK / Picard): If processes terminate with java.lang.OutOfMemoryError, set your environment variable explicitly: export _JAVA_OPTIONS="-Xmx16g -Djava.io.tmpdir=/tmp".
  • Index Timestamp Mismatch: If tools complain that a BAM index is missing or out of date, regenerate with samtools index -@ 4 sample.bam.
  • Conda Channel Conflicts: Avoid ABI incompatibilities between bioconda and conda-forge by setting strict priority: conda config --set channel_priority strict.
  • Chromosome Naming Contamination: Always verify whether reference FASTA headers use chr1 or 1; divergent naming causes silent alignment drops.
Was this guide helpful to your research?
Help us maintain 100% accurate, peer-reviewed bioinformatics standards.
📝 Propose Edit on GitHub ↗