SLURM Array Examples

From UFRC
Jump to navigation Jump to search


Example 1

This shell portion of a SLURM job script sets input and output directories as variables. Then, it sets a RUN variable to the SLURM task id in a job or to a value of '1' if you are running a quick test before submitting a job. The RUN value is used as an index value to pick a full path to a dataset from the input directory, determine the file name, and remove the specified extension to create a value that may represent a sample name to be used in forming an output path. Finally, the automated command is printed to stdout to be recorded in the job log and executed as a command.

INPUT_DIR=/blue/group/user/project/run/input
OUTPUT_DIR=/blue/group/user/project/run/output

RUN=${SLURM_ARRAY_TASK_ID:-1}

echo "Run: ${RUN}"

module load plink/1.90b3.39

INPUT_PATH=$(ls ${INPUT_DIR}/*.vcf.gz | sed -n ${RUN}p)
INPUT_FILE=$(basename ${INPUT_PATH})
SAMPLE=$(basename ${INPUT_FILE} .vcf.gz)

read -d '' cmd << EOF
plink \
--vcf ${INPUT_PATH} \
--out ${OUTPUT_DIR}/${SAMPLE} \
--allow-no-sex \
--keep-allele-order
EOF
echo ${cmd}

eval ${cmd}