#!/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/20232410_012/WilfriedMeijer
resultsdir=/scratch/p127804/PROJECTS/Wilfried/202310_012/fastqc


my_mkdir $resultsdir

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

my_fastqc WM012_32 WM012_32_S50_R1_001.fastq.gz
my_fastqc WM012_38 WM012_38_S51_R1_001.fastq.gz
my_fastqc WM012_46 WM012_46_S52_R1_001.fastq.gz
my_fastqc WM012_48 WM012_48_S53_R1_001.fastq.gz
my_fastqc WM012_51 WM012_51_S54_R1_001.fastq.gz
my_fastqc WM012_53 WM012_53_S55_R1_001.fastq.gz
my_fastqc WM012_63 WM012_63_S56_R1_001.fastq.gz
my_fastqc WM012_64 WM012_64_S57_R1_001.fastq.gz
my_fastqc WM012_65 WM012_65_S58_R1_001.fastq.gz
my_fastqc WM012_66 WM012_66_S59_R1_001.fastq.gz
my_fastqc WM012_67 WM012_67_S60_R1_001.fastq.gz
my_fastqc WM012_68 WM012_68_S61_R1_001.fastq.gz
my_fastqc WM012_69 WM012_69_S62_R1_001.fastq.gz
my_fastqc WM012_70 WM012_70_S63_R1_001.fastq.gz
my_fastqc WM012_71 WM012_71_S64_R1_001.fastq.gz
my_fastqc WM012_72 WM012_72_S65_R1_001.fastq.gz




#trimmomatic JV_27A_T4 JV_27A_T4_S59_R1_001.fastq.gz



