#!/bin/bash
##################################################################################
#Andy Rampersaud, 02.16.16
#This script would be used to summarize UCSC_BigWig statistics 
#Way to run script:
#Usage: 
#./UCSC_BigWig_Summary.sh
##################################################################################
#---------------------------------------------------------------------------------
#Source the setup file to initialize variables
source ../00_Setup_Pipeline/01_Pipeline_Setup.sh
#---------------------------------------------------------------------------------
#Check that each variable prints a value to the terminal:
echo "-----------------------"
echo "Start of variable list:"
echo "-----------------------"
echo "Dataset_DIR:"
echo ${Dataset_DIR}
echo "Sample_Labels_DIR:"
echo ${Sample_Labels_DIR}
echo "STRAND_RULE:"
echo ${STRAND_RULE}
echo "BU_User:"
echo ${BU_User}
echo "VM_DIR_public_html:"
echo ${VM_DIR_public_html}
echo "SCRIPT_DIR:"
echo ${SCRIPT_DIR}
echo "TIME_LIMIT:"
echo ${TIME_LIMIT}
echo "-----------------------"
echo "End of variable list"
echo "-----------------------"
#---------------------------------------------------------------------------------
##################################################################################
INPUT_DIR=$(pwd)
cd $INPUT_DIR
################################################
#A text file (Sample_Labels.txt) is needed to run this script
SCRIPT_DIR=$(pwd)
cp $Sample_Labels_DIR/Sample_Labels.txt $SCRIPT_DIR
################################################
#The text file is formatted like the following:
#----------------------------------------------
#Sample_DIR	Sample_ID	Description
#Sample_Waxman-TP17	G83_M1	Male 8wk-pool 1
#Sample_Waxman-TP18	G83_M2	Male 8wk-pool 2
#Sample_Waxman-TP19	G83_M3	Female 8wk-pool 1
#Sample_Waxman-TP20	G83_M4	Female 8wk-pool 2	
#----------------------------------------------
#The 1st column: The Sample_DIR name
#The 2nd column: Waxman Lab Sample_ID 
#The 3rd column: Sample's description 
################################################
#Text file has a header line to ignore:
tail -n +2 Sample_Labels.txt > Sample_Labels.temp
#Use a while loop to run jobs
while IFS=$'\t' read -r -a myArray
do
#---------------------------
##Check that text file is read in properly:
#echo 'Sample_DIR:'
Sample_DIR=${myArray[0]}
#echo 'Sample_ID:'
Sample_ID=${myArray[1]}
#echo $Sample_ID
#echo 'Description:'
Description=${myArray[2]}
#echo $Description
#---------------------------
echo
echo $Sample_ID
#Copy over BAM and *.bw files:
scp ${Dataset_DIR}/${Sample_ID}/fastq/tophat2/$Sample_ID'_primary_unique.bam' ${BU_User}@waxmanlabvm.bu.edu:${VM_DIR_public_html}
scp ${Dataset_DIR}/${Sample_ID}/fastq/tophat2/$Sample_ID'_primary_unique.bam.bai' ${BU_User}@waxmanlabvm.bu.edu:${VM_DIR_public_html}
scp ${Dataset_DIR}/${Sample_ID}/fastq/tophat2/UCSC_BigWig/*'.bw' ${BU_User}@waxmanlabvm.bu.edu:${VM_DIR_public_html}
done < Sample_Labels.temp
cd $INPUT_DIR
#Remove the temp file:
rm Sample_Labels.temp
##################################################################################
#waxmanlabvm:
#If you want the number of files in a dir (check that all files transferred over)
#ls -1 | wc -l
#Remember to unzip bigWig files on waxmanlabvm
#cd /home/aramp10/public_html/G110
#gzip -d *.gz
##################################################################################
