Skip to content

Instantly share code, notes, and snippets.

@stephenturner
Created November 12, 2010 20:01
Show Gist options
  • Save stephenturner/674591 to your computer and use it in GitHub Desktop.
Save stephenturner/674591 to your computer and use it in GitHub Desktop.
impute_1000genomes.pbs
#!/bin/bash
#PBS -M youremailaddress@domain.com
#PBS -m abe
#PBS -S /bin/bash
#PBS -l nodes=1:ppn=1
#PBS -W x=NODESET:FIRSTOF:FEATURE:opteron:x86
#PBS -l walltime=96:00:00
#PBS -l cput=96:00:00
#PBS -l pmem=3000mb
#PBS -l mem=3000mb
#PBS -j oe
# Otto Valladares, Jacki Buros
# Version 1.0.pbs
# Created 2010-09-24
# Purpose :
# Prepare environment variables for 1000-genomes imputation
# Run 1000-genomes imputation per ADGC-organized pipeline
#set current working directory
cd $PBS_O_WORKDIR
# prefix used for file naming within this study (no spaces)
export prefix=$PREFIX
# settings for this run
export chr=$CHR
if [ -z $GRP ]
then
# if no group is specified run step1 impute
step=1
script="impute_step1.sh"
else
# group exists so will run step2 impute script
export grp=`printf "%02d" $GRP`
step=2
script="impute_step2.sh"
fi
# operating directories (note : files copied to OUTDIR at completion)
SRCDIR="$(pwd)"
OUTDIR="$(pwd)"
ERRDIR="$OUTDIR/error_${prefix}_chr${chr}_step${step}_grp${grp}_${JOB_ID}"
# executables
export MACHBIN="/home/bin/mach1" #CHANGE
export PLINKBIN="/usr/local/plink/plink" #CHANGE
export GAWKBIN="/usr/bin/gawk" #CHANGE
export TARBIN="/bin/tar" #CHANGE
# 1000 genomes files that you downloaded and used tar -zxvf to extract
export REFHAPS="/scratch/username/impute/1000genomes/hap"
export REFSNPS="/scratch/username/impute/snps"
# ** NOTE : scratch dir is working directory where file manipulations / etc can take place.
# This directory will be created & deleted during the operation of the script
# For some clusters, this is ideally located on a node to reduce I/O, but it can be anywhere.
SCRATCHDIR="~/scratch/${prefix}_chr${chr}_step${step}_grp${grp}_${JOB_ID}"
# tar files created / sourced
# s0file is supposed to exist before running
export s0file="${prefix}_chr${chr}_step0.tar.gz"
export s1file="${prefix}_chr${chr}_step1.tar.gz"
export s2file="${prefix}_chr${chr}_grp${grp}_step2.tar.gz"
# naming conventions used for files in step1 and step2 tarfiles
export s1out="${prefix}_chr${chr}_step1"
export s2out="${prefix}_1000genomes_chr${chr}_grp${grp}"
# error codes indicating success/failure and whether to copy files to $OUTDIR or $ERRDIR
export OK=0
export ERR_DELETE_FILES=1
export ERR_COPY_FILES=2
echo "=========================================================="
echo "Starting on : $(date)"
echo "Running on node : $(hostname)"
echo "Current directory : $(pwd)"
echo "Current job ID : $JOB_ID"
echo "Current job name : $JOB_NAME"
echo " __ environment variables __"
echo "Scratch dir : $SCRATCHDIR"
echo "Study prefix : $prefix"
echo "scriptfile : $script"
echo "=========================================================="
# create scratch directory
mkdir -p ${SCRATCHDIR}
if [ -d ${SCRATCHDIR} ]; then
cd ${SCRATCHDIR}
else
echo "scratchdir ${SCRATCHDIR} does not exist. Exiting"
exit
fi
# copy source files to scratch directory
cp -a --dereference ${SRCDIR}/${script} .
cp -a --dereference ${SRCDIR}/${s0file} .
if [[ $step -eq 2 ]] ; then
cp -a --dereference ${SRCDIR}/${s1file} .
fi
# run imputation script -- note : requires script & tar files in working directory
source ${script}
rc=$?
# clean up files
if [[ $rc -eq $OK ]] ; then
# create & copy tar file
if [[ $step -eq 1 ]] ; then
$TARBIN cfz ${s1file} ${s1out}.*
mv ${s1file} ${OUTDIR}
rc=$?
elif [[ $step -eq 2 ]] ; then
$TARBIN cfz ${s2file} ${s2out}.*
mv ${s2file} ${OUTDIR}
rc=$?
fi
# Clean up scratch dir
if [[ $rc -eq 0 ]] ; then
echo "=========================================================="
echo "Finished on : $(date)"
echo "=========================================================="
cd ${OUTDIR}
rm -rf ${SCRATCHDIR}
exit
else
echo "Unable to copy resulting tar file to $OUTDIR."
echo "Please ssh to $(hostname) and"
echo "look at the content of ${SCRATCHDIR}"
exit
fi
elif [[ $rc -eq $ERR_DELETE_FILES ]] ; then
echo "=========================================================="
echo "Script exited with errors; scratch dir deleted."
echo "Finished on : $(date)"
echo "=========================================================="
cd ${OUTDIR}
rm -rf ${SCRATCHDIR}
exit
elif [[ $rc -eq $ERR_COPY_FILES ]] ; then
echo "=========================================================="
echo "Script exited with errors; copying source files to ${ERRDIR}."
echo "Finished on : $(date)"
echo "=========================================================="
mkdir -p ${ERRDIR}
if [ -d ${ERRDIR} ]; then
mv * ${ERRDIR}
else
echo "Unable to copy resulting files to $ERRDIR."
echo "Please ssh to $(hostname) and"
echo "look at the content of ${SCRATCHDIR}"
exit
fi
cd ${OUTDIR}
rm -rf ${SCRATCHDIR}
exit
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment