#!/bin/bash
#PBS -l walltime=01:00:00
#PBS -l ncpus=1,mem=2gb
#PBS -q uv2000
#PBS -N gather_aff_probands
#PBS -j oe



### folder structure for the downstream analysis - created by NHS_WES_trio_setup.sh ###
BASE=/scratch/u035/u035/shared/trio_whole_exome/analysis
WORK_DIR=${BASE}/${PROJECT_ID}
NHS_DIR=${WORK_DIR}/${PLATE_ID}_${VERSION_N}_results


echo "PLATE_ID = ${PLATE_ID}"           # the PCR plate ID of the batch being currently processed,              	e.g. 16862
echo "PROJECT_ID = ${PROJECT_ID}"       # this the the folder (${BASE}/${PROJECT_ID}) where the downstream analysis will be done
echo "FAMILY_ID = ${FAMILY_ID}"         # the family ID of this family with affected probands
echo "VERSION_N = ${VERSION_N}"         # the version of the alignment and genotyping analysis
echo "JOB_ID = ${JOB_ID}"		# the numerical part of the Job id generated by EPCC when running process_NHS_WES_aff_probands.sh for this family


# check if ${NHS_DIR} already exists - if not, exits and asks to run the standard trio-based analysis first
if [ ! -d "${NHS_DIR}" ]; then
  echo "${NHS_DIR} does not exist - need to run standard trio-based analysis first!!!!"
  exit
fi



# create the family folder for the shared results for this family
FAM_DIR=${NHS_DIR}/${PLATE_ID}_${FAMILY_ID}_shared
if [ -d "${FAM_DIR}" ]; then
  echo "${FAM_DIR} already exists - delete if you want to overwrite!!!!"
  exit
fi
mkdir ${FAM_DIR}


# copy the LOG file
cp ${WORK_DIR}/LOG/go_aff_proband.o${JOB_ID} ${FAM_DIR}

# copy the G2P family html report
cp ${WORK_DIR}/G2P/${PLATE_ID}_${FAMILY_ID}_LOG_DIR/${PLATE_ID}_${FAMILY_ID}.report.html ${FAM_DIR}

# copy all the DECIPHER files for bulk upload
cp ${WORK_DIR}/DECIPHER/*_${FAMILY_ID}_DEC_FLT.csv ${FAM_DIR}
cp ${WORK_DIR}/DECIPHER/*_${FAMILY_ID}_DECIPHER_v10.xlsx ${FAM_DIR}


# copy the variant snapshots
cp ${WORK_DIR}/DECIPHER/IGV/${PLATE_ID}_${FAMILY_ID}/*.png ${FAM_DIR}

# copy proband coverage file
cp ${WORK_DIR}/COV/*_${FAMILY_ID}.DD15.COV.txt ${FAM_DIR}


echo ""
echo ""
echo "OK: Results for ${FAMILY_ID} are stored in ${FAM_DIR}"

