#!/bin/bash
#PBS -l walltime=48:00:00
#PBS -l ncpus=16,mem=8gb
#PBS -q sgp
#PBS -N nhss_wes_bcbio
#PBS -j oe

# enable running singletons
if [ -z $PBS_ARRAY_INDEX ]
then
  if [ -z $INDEX ]
  then
    export PBS_ARRAY_INDEX=1
  else
    export PBS_ARRAY_INDEX=$INDEX
  fi
fi

export PATH=$PATH:/home/u027/project/software/bcbio/tools/bin
BCBIO_CONFIG=/scratch/u027/project/analysis/wes_pilot/bcbio-1.1.5_test/config
BCBIO_WORK=/scratch/u027/project/analysis/wes_pilot/bcbio-1.1.5_test/work

# Expects environment variables to be set
# BATCH - nhsswesXXX
# FAMILY_IDS - text file listing family ids

FAMILY_ID=`head -n $PBS_ARRAY_INDEX $FAMILY_IDS | tail -n 1`

CONFIG_FILE=$BCBIO_CONFIG/${BATCH}_${FAMILY_ID}.yaml
mkdir -p $BCBIO_WORK/$FAMILY_ID
cd $BCBIO_WORK/$FAMILY_ID

bcbio_nextgen.py $CONFIG_FILE -n 16 -t local
