#!/bin/bash
# Created by the Melbourne Bioinformatics job script generator for SLURM
# Thu Aug 17 2017 15:07:06 GMT+1000 (AEST)


# Maximum number of tasks/CPU cores used by the job:
##SBATCH --ntasks=1

# The name of the job:
#SBATCH --job-name=“angsd”

## The amount of memory in megabytes per process in the job:
#SBATCH --mem=8gb

# Use this email address:
##SBATCH --mail-user=samia.elfekih@csiro.au

# The maximum running time of the job in days-hours:mins:sec
#SBATCH --time=2:0:0


# check that the script is launched with sbatch
if [ "x$SLURM_JOB_ID" == "x" ]; then
   echo "You need to submit your job to the queuing system with sbatch"
   exit 1
fi

if [ "x$SLURM_ARRAY_TASK_ID" == "x" ]; then
   echo You need to submit your job as a job array
   exit 1
fi

# Run the job from the directory where it was launched (default)

# The modules to load:
module load bwa


# The job command(s):

fq=$(sed -n ${SLURM_ARRAY_TASK_ID}p fq.txt)

if [[ -z $fq ]]; then
   echo SLURM_ARRAY_TASK_ID is out of range
   exit 1
fi

sam=${fq%_out.fq}.sam

bwa mem MEAM1_scaffold_v1.1.fa $fq > $sam
