#!/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=ReadCount
#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
cpu=4

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

function my_fastq_readcount {
	name=$1
	fastq=$2
	echo $name $(zgrep -c "^+$" $datadir/$fastq) >> $resultsdir/00.fastq.counts
}

function my_fastqc {
	# NOTE: not used in this script
	name=$1
	fastq=$2
	printf "\n========== FastQC: "$name" ======================================\n"	
	my_mkdir $resultsdir/$name
	fastqc -t $cpu -o $resultsdir/$name -f fastq $datadir/$fastq
}

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


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


datadir=/data/pg-molgen/rnaseq/20221212_007/fastq
resultsdir=/data/p127804/PROJECTS/wilfried/20221212_007/results
my_mkdir $resultsdir

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


my_fastq_readcount WM007_01 5A_S32_L001_R1_001.fastq.gz
my_fastq_readcount WM007_02 5B_S33_L001_R1_001.fastq.gz
my_fastq_readcount WM007_03 5C_S34_L001_R1_001.fastq.gz
my_fastq_readcount WM007_04 5D_S35_L001_R1_001.fastq.gz
my_fastq_readcount WM007_05 5E_S36_L001_R1_001.fastq.gz
my_fastq_readcount WM007_06 5F_S37_L001_R1_001.fastq.gz
my_fastq_readcount WM007_07 5G_S38_L001_R1_001.fastq.gz
my_fastq_readcount WM007_08 5H_S39_L001_R1_001.fastq.gz
my_fastq_readcount WM007_09 6A_S40_L001_R1_001.fastq.gz
my_fastq_readcount WM007_10 6B_S41_L001_R1_001.fastq.gz
my_fastq_readcount WM007_11 6C_S42_L001_R1_001.fastq.gz
my_fastq_readcount WM007_12 6D_S43_L001_R1_001.fastq.gz
my_fastq_readcount RP007_01 6E_S44_L001_R1_001.fastq.gz
my_fastq_readcount RP007_02 6F_S45_L001_R1_001.fastq.gz
my_fastq_readcount RP007_03 6G_S46_L001_R1_001.fastq.gz
my_fastq_readcount RP007_04 6H_S47_L001_R1_001.fastq.gz


