#!/bin/sh -

# This script will start ACT on a UNIX system.  This script should
# be left in the same directory as the rest of the ACT
# distribution, so that the java class files can be found.  If
# necessary a symbolic link can be made to this script from
# /usr/local/bin/ or elsewhere.


# $Header: //tmp/pathsoft/artemis/act,v 1.15 2009-08-10 08:14:46 tjc Exp $

# resolve links - $0 may be a link
PRG=$0
progname=`basename $0`

#PSU_PROD_JAVA_VERSION=1.4.2
#. $PSU_CONFIG_DIR/shell/java_environment.sh

while [ -h "$PRG" ] ; do
  ls=`ls -ld "$PRG"`
  link=`expr "$ls" : '.*-> \(.*\)$'`
  if expr "$link" : '.*/.*' > /dev/null; then
    PRG="$link"
  else
    PRG="`dirname $PRG`/$link"
  fi
done

ACT_HOME=`dirname "$PRG"`/.


CLASSPATH=$ACT_HOME:$ACT_HOME/lib/JacORB.jar:$ACT_HOME/lib/jemAlign.jar:$ACT_HOME/lib/jakarta-regexp-1.2.jar:$ACT_HOME/lib/macos.jar:$ACT_HOME/lib/chado-14-interface.jar:$ACT_HOME/lib/postgresql-8.4-701.jdbc3.jar:$CLASSPATH

# batik jars
CLASSPATH=$CLASSPATH:$ACT_HOME/lib/batik/batik-awt-util.jar:$ACT_HOME/lib/batik/batik-dom.jar:$ACT_HOME/lib/batik/batik-ext.jar:$ACT_HOME/lib/batik/batik-svggen.jar:$ACT_HOME/lib/batik/batik-util.jar:$ACT_HOME/lib/batik/batik-xml.jar

# j2ssh jars
CLASSPATH=$CLASSPATH:$ACT_HOME/lib/j2ssh/commons-logging.jar:$ACT_HOME/lib/j2ssh/j2ssh-core.jar:$ACT_HOME/lib/j2ssh/

# iBatis jars
CLASSPATH=$CLASSPATH:$ACT_HOME/lib/ibatis/ibatis-2.3.4.726.jar:$ACT_HOME/lib/ibatis/:$ACT_HOME/lib/ibatis/log4j-1.2.14.jar:$ACT_HOME/lib/ibatis/cglib-nodep-2.2.jar:$ACT_HOME/lib/retrotranslator-runtime-1.1.0.jar

# picard jars
CLASSPATH=$ACT_HOME/lib/picard/sam.jar:$ACT_HOME/lib/picard/picard.jar:$CLASSPATH

export CLASSPATH

ACT_PROPERTIES="-Dartemis.environment=UNIX"

MEM="-mx500m -ms20m"

if [ "$JVM_FLAGS" = "" ]
then
    FLAGS="$MEM -noverify"
else
    FLAGS="$MEM -noverify $JVM_FLAGS"
fi


# work-around for OSF JVM core dump problem
if [ `uname` = OSF1 ]
then
    FLAGS="$FLAGS -Dsimple_splash_screen=true"
fi


QUIET=no

if [ $# = 0 ]
then
    :
else
    if [ "$1" = "-h" -o "$1" = "--help" -o "$1" = "-help" ]
    then
        cat <<EOF

SYNOPSIS
        Artemis Comparison Tool (ACT): Genome Comparison Tool
USAGE
        $0 [options] <SEQUENCE_1> <COMPARISON_1_2> <SEQUENCE_2> ...
OPTIONS
        SEQUENCE                   An EMBL, GenBank, FASTA, or GFF3 file
        FEATURE                    An Artemis TAB file, or GFF file
        COMPARISON                 A BLAST comparison file in tabular format

        -options FILE              Read a text file of options from FILE
        -debug                     Run using the debugging JVM instead

        -Dblack_belt_mode=?         Keep warning messages to a minimum [true,false]
        -DuserplotX=FILE[,FILE2]    For sequence 'X" open one or more userplots
        -DloguserplotX=FILE[,FILE2] For sequence 'X" open one or more userplots, take log(data)
        -DbamX=FILE[,FILE2,...]     For sequence 'X" open one or more BAM, VCF, or BCF files
        -Dchado="h:p/d?u"           Get ACT to open this CHADO database
        -Dread_only                 Open CHADO database read-only
EXAMPLES
        % act
        % act af063097.embl af063097_v_b132222.crunch b132222.embl
        % act -Dblack_belt_mode=true -Dbam1=MAL_0h.bam -Dbam2=MAL_7h.bam,var.raw.new.bcf 
        % act -Duserplot2=/pathToFile/userPlot

HOMEPAGE
        http://www.sanger.ac.uk/resources/software/act/

EOF
        exit 0
    fi


    while test $# != 0
    do
        case $1 in
        -options) FLAGS="$FLAGS -Dextra_options=$2"; shift ;;
        -D*) FLAGS="$FLAGS $1" ;;
        -fast) FLAGS="$FLAGS -fast" ;;
        -quiet) QUIET=yes ; FLAGS="$FLAGS -Drun_quietly=true" ;;
        -debug) DEBUG=yes ;;
        *) break ;;
        esac
        shift
    done
fi

if [ "$JAVA_VM" = "" ]
then
    if [ "$DEBUG" = yes ]
    then
        JAVA=java_g
    else
        JAVA=java
    fi
else
    JAVA=$JAVA_VM
fi

PLATTMP=`uname`
if [ "$PLATTMP" = "Darwin" ]
then
  FLAGS="$FLAGS -Dapple.laf.useScreenMenuBar=true -Dcom.apple.mrj.application.apple.menu.about.name=ACT"
fi


if [ $QUIET = no ]
then
    echo starting ACT with flags: $FLAGS 1>&2
fi

$JAVA $FLAGS -Djdbc.drivers=org.postgresql.Driver $ACT_PROPERTIES uk.ac.sanger.artemis.components.ActMain $*

