#!/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=2
#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 --output=slurm-Anne-%j.log


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

module load FastQC/0.11.9-Java-11
cpu=2

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


folder=/scratch/hb-molgen/NGSdata/20250303_022
ext=fastq.gz

# Iterate over each file with the .fastq.gz extension
for file in $folder/*.$ext; do
  if [[ -e "$file" ]]; then         # Check if the file exists to avoid errors when no files match
	name=$(basename $file .$ext)    # Extract the basename without the extension
	echo $name						# use $name for any purpose
	echo $name $(zgrep -c "^+$" $folder/$name.$ext) >> $folder/00.fastq.counts
	fastqc -t $cpu -o $folder -f fastq $folder/$name.$ext
  fi
done

