Step 2: Read Trimming and Filtering (fastp) - aduckwo4-boop/EPP622-2026-SNPCalling GitHub Wiki

Step 2: Read Trimming and Filtering (fastp)

WARNING: Because these reads are simulated, fastp fails to identify that they need poly-G tail trimming. Turn that on with a flag.

ADVICE: Its easier to compare the reads pre and post trimming if you run multiqc on the results of fastqc of the trimmed files (and do not use the .json files from fastp).

Commands

fastp was used to remove adapter contamination, trim poly-G tails, and filter low-quality sequencing reads. Because the reads were simulated, poly-G trimming was manually enabled. FastQC and MultiQC were then used to compare sequencing quality before and after trimming. Created the directories and linked the raw sequencing files:

mkdir 02_fastp
cd 02_fastp
ln -s ../reads/*gz . 
mkdir fastp_trimmed
mkdir trimmed_fastqc
nano run_fastp.sh

# ln -s: creates symbolic links to the raw sequencing files
# fastp_trimmed: directory for trimmed FASTQ files and fastp reports
# trimmed_fastqc: directory for FastQC and MultiQC results after trimming

Created run_fastp.sh

for R1 in Sample_*_R1.fastq.gz
do
    basename=$(echo "$R1" | sed 's/_R1.fastq.gz//')

    echo "$R1"
    echo "$basename"


    fastp --in1 ${basename}_R1.fastq.gz \
        --out1 fastp_trimmed/${basename}_R1.trimmed.fastq.gz \
        --in2 ${basename}_R2.fastq.gz \
        --out2 fastp_trimmed/${basename}_R2.trimmed.fastq.gz \
        --trim_poly_g \
        --detect_adapter_for_pe \
        --thread 2 \
        --json fastp_trimmed/${basename}.fastp.json \
        --html fastp_trimmed/${basename}.fastp.html
done

# for: loops through each forward read file.
# basename: extracts the sample name by removing the R1 filename suffix.
# echo: prints the current file and sample name.
# fastp: trims and filters paired-end sequencing reads.
# --in1: specifies the input forward read (R1) file.
# --out1: specifies the output trimmed forward read file.
# --in2: specifies the input reverse read (R2) file.
# --out2: specifies the output trimmed reverse read file.
# --trim_poly_g: trims poly G tails.
# --detect_adapter_for_pe: enables adapter detection for paired end reads.
# --thread 2: uses two processing threads.
# --json: generates a JSON report containing trimming statistics.
# --html: generates an HTML report summarizing trimming results.
# done: ends the loop.

Ran FastQC and MultiQC on the trimmed reads:

fastqc fastp_trimmed/*.fastq.gz -o trimmed_fastqc -t 2
multiqc trimmed_fastqc -o trimmed_fastqc -n multiqc_trimmed_report.html

# fastqc: evaluates sequencing quality after trimming.
# fastp_trimmed/*.fastq.gz: selects all trimmed FASTQ files.
# -o trimmed_fastqc: saves FastQC results in the specified directory.
# -t 2: uses two threads for FastQC.
# multiqc: combines the trimmed FastQC reports into one summary.
# trimmed_fastqc: specifies the directory containing FastQC results.
# -o: specifies the MultiQC output directory.
# -n: specifies the MultiQC report filename.

Downloaded the MultiQC report:

scp [email protected]:/lustre/isaac24/proj/UTK0505/aduckwo4/622_test2/02_fastp/trimmed_fastqc/multiqc_trimmed_report.html ~/Downloads/

MultiQC gives a rounded number for total reads and does not report total bases per sample. To find out those numbers use this:

for f in *.fastq.gz; do
  echo -ne "$f\t"
  zcat "$f" | awk 'NR%4==2{r++; b+=length($0)} END{printf "%d\t%d\t%.1f\n", r, b, b/r}'
done | column -t

This gives the total reads, then the total bases, then the average read length for each file.

Results

MultiQC report path and name: /lustre/isaac24/proj/UTK0505/aduckwo4/622_test2/02_fastp/trimmed_fastqc/multiqc_trimmed_report.html

For each sample, report R1 + R2. Use the reference genome size above to calculate coverage.

Sample Reads before Reads after Mean length before Mean length after
A R1:804650 R2:804650 R1:804650 R2:804650 150.0 150.0
B R1:160930 R2:160930 R1:160930 R2:160930 150.0 150.0
C R1:804650 R2:804650 R1:788629 R2:788629 150.0 R1:125.9 R2:125.8
D R1:804650 R2:804650 R1:804650 R2:804650 150.0 150.0