#!/bin/sh


## simple script to execute java with the appropriate options to run snpEff
## Change JAVA_CMD to the location of your java binary if necessary
##
## edeveaud, copied from mauve.sh  (c) 2003 Aaron Darling

JAVA_CMD="java"
SNPEFF_DIR="/opt/gensoft/exe/snpEff/4.3/libexec"
JAVA_ARGS="-jar"
JAVA_OPTS=${SNPEFF_JAVA_OPTS:-${JAVA_OPTS:-"-Xmx6G"}}

prog=$(basename $0)

## check if -c config file is provided

CONF_FILE="/opt/gensoft/exe/snpEff/4.3/share/sample-${prog}.config"
CONF_OPT="-c $CONF_FILE"

CMDLINE="$*"

    
if [ ${prog} = "snpEff" ] || [ ${prog} = "ClinEff" ] ; then 
    while [ "$*" != "" ]
     do
       case $1 in 
         ## allows -h option to be used.
         '-h' | '-c' ) CONF_OPT=''; break ;;
         *    ) shift ;;
       esac 
     done
    
    
    #check if -c option is given, if not abort and display a message
    if [ -n  "$CONF_OPT" ] ; then
       # if config file not provided, force it to be mandatory
       # display message 
       echo "configuration file is mandatory."  1>&2
       echo "copy and edit sample config file to suit your needs," 1>&2
       echo "available here: $CONF_FILE"  1>&2
       exit 1
    fi; 
fi 

$JAVA_CMD $JAVA_OPTS $JAVA_ARGS $SNPEFF_DIR/${prog}.jar $CMDLINE
