#!/bin/tcsh
#
# Script: CV1_BatchScript.csh
# Usage:  Submitting batch R jobs to the LSF on NCSU HPC.
# Author: Anna R. Rogers, adapted from NCSU HPC example for submitting multiple R jobs to cluster
#
# To run, type: ./GxE_BatchSub.csh [#i] [#model] [#cv_method] [#outdir]
# Script must have execute permission, i.e. 
# 	chmod u+x CV1_BatchScript.csh

module load R

if ($#argv != 4) then 
	echo "Usage: You need to feed 3 arguments to this program which are"
	echo "The number of folds to run the model on and"
	echo "The type of model to be run, and"
	echo "The type of cross validation to execute, and"
	echo "The output directory, for example,"
	echo "./GxE_BatchSub.csh 10 'Full_GxE_Dim_Reduction' 'CV1' 'outdir/'"
	exit 1
endif

# Specify the number of jobs to submit
set folds = $1
echo "folds = $folds"
set model = $2
echo "Running $model model"
set cv_method = $3
echo "Using $cv_method for cross validation"
set outdir = $4
echo "output will be directed to $outdir"

#Initialize the loop counter for the outer loop
set i = 1

while ($i <= $folds)

	echo "Submit job fold = $i"
	bsub -n 1 -W 1440 -R "rusage[mem=70000]" -oo $outdir/out.cv1.i=$i.$model -eo $outdir/err.cv1.i=$i.$model "Rscript GxE_Integration.R --i $i --model $model --cv_method $cv_method --outdir $outdir"
	@ i++

end
