#!/bin/bash


# =============================================================================================================================================================
# ==                                                          SLURM parameters                                                                               ==
# =============================================================================================================================================================

# Decide how much computer power you need
# The programs used in this script can only be executed on 1 NODE
# You can use a max of 24 task per node. But the lower the number of tasks requested the shorter the queue when submitting a job
#SBATCH --nodes=1			
#SBATCH --ntasks-per-node=4
#SBATCH --mem=8GB

# Choose between long or short queue: A short job will start quickly after submitting, but will be terminated after 30 minutes
# confusing might be that #BACTH is used by SLURM, but a hashtag quotes out the line; ##BATCH means that SLURM will not read this line 
#SBATCH --time=24:00:00
##SBATCH -p short


# Personal stuff; Change this to your personal settings 
#SBATCH --job-name=FastQC
#SBATCH --mail-type=END
#SBATCH --mail-user=youremail@student.rug.nl
#SBATCH --output=slurm-Anne-%j.log


# =============================================================================================================================================================
# ==                                                          Load modules                                                                               ==
# =============================================================================================================================================================

module load FastQC/0.11.9-Java-11
module load Trimmomatic/0.39-Java-11
module load Trim_Galore/0.6.6-GCCcore-9.3.0-Python-3.8.2
cpu=4

# =============================================================================================================================================================
# ==                                                          Functions                                                                               ==
# =============================================================================================================================================================

function my_fastq_readcount {
	# NOTE: not used in this script
	name=$1
	fastq=$2
	echo $name $(zgrep -c "^+$" $datadir/$fastq) >> $resultsdir/00.fastq.counts
}

function my_fastqc {
	name=$1
	fastq=$2
	printf "\n========== FastQC: "$name" ======================================\n"	
	my_mkdir $resultsdir/$name
	fastqc -t $cpu -o $resultsdir/$name -f fastq $datadir/$fastq
}

function trimmomatic {
	name=$1
	fastq=$2
	printf "\n========== Trimmomatic: "$name" ======================================\n"
	#java -jar $EBROOTTRIMMOMATIC/trimmomatic-0.39.jar SE -phred33 -threads $cpu $datadir/$fastq $datadir/$name.$fastq ILLUMINACLIP:/data/pg-molgen/software/trimmomatic/TruSeq3-PE.fa:2:30:10 LEADING:3 TRAILING:3 SLIDINGWINDOW:4:15 MINLEN:36
	java -jar $EBROOTTRIMMOMATIC/trimmomatic-0.39.jar SE -phred33 -threads $cpu $datadir/$fastq $datadir/$name.36.$fastq CROP:36
}




function my_mkdir {
	if [ ! -d $1 ]; then
		mkdir $1 ;
	fi
}


# =============================================================================================================================================================
# ==                                                          Main script                                                                               ==
# =============================================================================================================================================================



datadir=/scratch/hb-molgen/NGSdata/20240926_019
resultsdir=/scratch/p127804/PROJECTS/Douwe/Bifidobacterium_202409_019/results_fastqc

my_mkdir $resultsdir

# below you see: 1) function, 2) name of the sample and 3) the fastq filename

my_fastqc DS019_01 DS019_01_S32_L001_R1_001.fastq.gz
# MM0160
my_fastqc DS019_13 DS019_13_S44_L001_R1_001.fastq.gz
	

