Author: Daniela Puiu
Date: 2025-09-05
OS: Linux
This set of scripts is designed to remove human reads from input FASTQ.GZ files and classify the remaining microbial reads. The workflow includes:
- Aligning sequence samples to two human reference genomes and removing aligned reads, generating unmapped FASTA files.
- Classifying unmapped reads using KrakenUniq.
- Removing additional human reads identified by KrakenUniq from FASTA and KrakenUniq files.
- Updating the KrakenUniq report.
- Generating a Bracken report.
# check the original configuration file
cat init.sh
export REF1=path/Ref/T2T-chm13v2.0 # T2T-chm13v2.0 human assembly
export REF2=path/Ref/hs38DH # hg38 human assembly
export KRAKENDB=path/krakendb-2023-08-08-MICROBIAL/ # krakenuniq database
export BRAKENDB=path/krakenuniq_db_MICROBIAL_20230808/ # bracken database
export P=8 # number of processors
# get server name(Ex: pathology/sciserver/salz/salz12)
SERVER=`hostname -s`
# copy/edit environment
cp -i init.sh init.$SERVER.sh
nano init.$SERVER.sh
# init environment
. ./init.$SERVER.sh
check_config.sh > check_config.$(date -I).$SERVER.$USER.log
# input:
references: REF1,REF2 (indexed)
sample: FASTQ.gz file(s)
aligner: bowtie2 or minimap2
# output:
unmapped FASTA.gz file(s)
# if using unmated reads
QRY_SEQ_FILE=
# if using mated reads
QRY_SEQ_FILE1=
QRY_SEQ_FILE2=
# unmated vs mated
ls $QRY_SEQ_FILE
ls $QRY_SEQ_FILE1 $QRY_SEQ_FILE2
ALIGNER=bowtie2 # or
ALIGNER=minimap2
# unmated vs mated
$ALIGNER.sh $SAMPLE_ID $QRY_SEQ_FILE $OUT_PREFIX
$ALIGNER.sh $SAMPLE_ID $QRY_SEQ_FILE1 $QRY_SEQ_FILE2 $OUT_PREFIX
ls $OUT_PREFIX.unmapped*.fasta.gz
# input: METADATA file; sample names must be in 1st column
META=metadata.{tab,csv,tsv}
head $META
# input: FASTA/FASTQ[.gz] file(s)
ls fastq/
# run bowtie2
$ALIGNER.all.sh $META
# output: unmapped FASTA.gz and count file
ls $ALIGNER/
# unmated vs mated
krakenuniq.sh $SAMPLE_ID $OUT_PREFIX.unmapped.gz $OUT_PREFIX.unmapped.filtered
krakenuniq.sh $SAMPLE_ID $OUT_PREFIX.unmapped_?.gz $OUT_PREFIX.unmapped.filtered
#check output
ls $OUT_PREFIX.unmapped.filtered*.fasta.gz
krakenuniq.all.sh $META