Skip to content

Instantly share code, notes, and snippets.

@andersgs
Last active April 4, 2018 06:09
Show Gist options
  • Save andersgs/4aa1c19f7cd8a2db49a26f06efe7492d to your computer and use it in GitHub Desktop.
Save andersgs/4aa1c19f7cd8a2db49a26f06efe7492d to your computer and use it in GitHub Desktop.
Stacks: process_radtags on SLURM
#!/bin/bash
#SBATCH --time=06:00:00
#SBATCH --mem=16G
#SBATCH [email protected]
#SBATCH --mail-type=BEGIN
#SBATCH --mail-type=END
#SBATCH --mail-type=FAIL
#SBATCH --mail-type=REQUEUE
#SBATCH --mail-type=ALL
module load singularity/2.4
MAPPING_FILE=$1
LINE=$(sed -n "${SLURM_ARRAY_TASK_ID}p" $MAPPING_FILE)
echo $LINE | while read SAMPLE READS BARCODES PAIRED ENZYME
do
OUTDIR=/path/to/samples/${SAMPLE}
mkdir -p ${OUTDIR}
if [ "${PAIRED}" = "TRUE" ];
then
PAIRED="--paired"
else
PAIRED=""
fi
bash process_reads.sh --reads ${READS} --barcodes ${BARCODES} --enzyme ${ENZYME} --output ${OUTDIR} ${PAIRED}
module load singularity/2.4
IMAGES=<path/to/singularity/images>
STACKS=stacks.img
PAIRED=''
USAGE="USAGE:\n\trun_process_radtags.sh --reads path/to/reads [--paired] --output path/to/output --barcodes path/to/barcodes --enzyme enzyme"
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-r|--reads)
READS="$2"
echo "Found READS."
shift
shift
;;
-o|--output)
OUTPUT="$2"
echo "Found OUTPUT."
shift
shift
;;
-b|--barcodes)
BARCODES="$2"
echo "Found BARCODES."
shift
shift
;;
-e|--enzyme)
ENZYME="$2"
echo "Found ENZYME."
shift
shift
;;
-p|--paired)
PAIRED='--paired'
echo "Found PAIRED."
shift
;;
esac
done
ERROR=0
if [[ -z "${READS}" ]]
then
echo "Please supply path to reads (-r | --reads)."
ERROR=1
fi
if [[ -z "${OUTPUT}" ]]
then
echo "Please supply path to output (-o | --output)."
ERROR=1
fi
if [[ -z "${BARCODES}" ]]
then
echo "Please supply path to barcodes file (-b | --barcodes)."
ERROR=1
fi
if [[ -z "${ENZYME}" ]]
then
echo "Please supply the enzyme used (-e | --enzyme)."
ERROR=1
fi
if [[ "${ERROR}" -ne "0" ]]
then
echo -e ${USAGE}
exit 1
fi
echo "Successfully parsed variables."
echo "Starting run..."
START=$(date +%s.%N)
singularity run --bind /project/6005977 --bind /scratch/andersgs ${IMAGES}/${STACKS} process_radtags -p ${READS} ${PAIRED} -o ${OUTPUT} -b ${BARCODES} -e ${ENZYME} -r -c -q
END=$(date +%s.%N)
DIFF=$(echo "($END - $START)/60" | bc)
echo "Program took ${DIFF} minutes to complete."
@andersgs
Copy link
Author

andersgs commented Apr 4, 2018

INSTRUCTIONS

Before you start, you need to prepare a TSV file where each line is a different library, and has five fields in the following order:
SAMPLE: A unique sample name (with no spaces or /)
READS: the full path to the FASTQ files
BARCODES: the full path to the Barcode file
PAIRED: TRUE or FALSE if the library is paired-end
ENZYME: The name of the enzyme used (e.g., SbfI)

A line in the file might look like this:

Lib1\t/home/user/reads/lib1\t/home/user/barcodes/lib1.txt\tTRUE\tSbfI
  1. Create a folder to store the Singularity images
  2. Download the Stacks singularity image: singularity pull --name "stacks.img" phgenomics-singularity/stacks
  3. Edit process_radtags.sh to make sure the path to the Singularity images is correct
  4. Edit the last line of jobarray_process_radtags.sh to make sure the path to process_radtags.sh is correct AND line 18 to make sure it points to an existing folder to store the output.
  5. Submit the job to SLURM queue with the following:
    sbatch --array 1-<number of libraries> jobarray_process_radtags.sh </path/to/mapping_file>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment