#!/bin/bash
if [ -z "$OSTYPE" ]; then
      if which cygpath 1>/dev/null 2>/dev/null; then
              OSTYPE=cygwin
      fi
fi
mypath=$0
while [ -h "$mypath" ]; do  # Resolve symlinks
        ls=`ls -ld "$mypath"`
        link=`expr "$ls" : '.*-> \(.*\)$'`
        if expr "$link" : '\/' > /dev/null; then
                mypath="$link"
        else
                mypath=`dirname "$mypath"`/"$link"
        fi
done

if expr "$mypath" : '[^\/]' > /dev/null; then
	mypath="`pwd`/$mypath"
fi

case "$OSTYPE" in
cygwin*)
	dir="`dirname $mypath`"
	dir="`cygpath -w $dir`"
        JCHEMHOME="$dir\\..\\.."
        ;;
*)
        dir=`dirname $mypath`
        JCHEMHOME="$dir/../.."
        ;;
esac

cd $JCHEMHOME

echo
echo "This example calculates statistics about the performance of different"
echo "parametrized metrics of two molecular descriptors (pharmacophore"
echo "fingerprints (basic and fuzzy) and chemical fingerprints). These metrics" 
echo "are used in screening a set of molecules against a set of known actives."
echo "The actives are beta2 antagonists of the adrenerg receptor. 900"
echo "molecules from the NCI database are screened."
echo
echo "Input is taken from the directory 'examples/molecules'."
echo 
echo "Results are written into the file" 
echo "examples/output/nci-beta2-adreno-antag-Enrichment.stat."
echo

read -p "Press any key to continue (or Ctrl-C to abort) " -n 1 key
echo

if [ -e examples/output/opt-CF-nci1000-beta2-adreno-antag.xml ]; then
echo

bin/hitstatistics config examples/config/hitstatistics.xml -v -f

echo
echo "Now the output text file"
echo "examples/output/nci-beta2-adreno-antag-Enrichment.stat containing"
echo "statistics about the performance of screening with the parametrized"
echo "metrics is displayed."
echo

read -p "Press any key to continue (or Ctrl-C to abort) " -n 1 key
echo

less examples/output/nci-beta2-adreno-antag-Enrichment.stat;

else

echo
echo "ERROR!!!"
echo "File $JCHEMHOME/examples/output/opt-CF-nci1000-beta2-adreno-antag.xml does not exists."
echo "Before executing this example 'optimizemetrics_example' should be" 
echo "invoked which sets the parametrized metrics."
echo;

fi
