#!/bin/sh
# autopkgtest check: build and run concavity with default test data,
# taken from concavity's readme
# Author: Tatiana Malygina <merlettaia@gmail.com>

set -e

pkg=concavity

if [ "$AUTOPKGTEST_TMP" = "" ] ; then
  AUTOPKGTEST_TMP=$(mktemp -d /tmp/${pkg}-test.XXXXXX)
  trap "rm -rf $AUTOPKGTEST_TMP" 0 INT QUIT ABRT PIPE TERM
fi

cd $AUTOPKGTEST_TMP
# Does not work
# cp -R "${0%/*}/../../examples" $AUTOPKGTEST_TMP[<0;60;11M
# use examples out of package which also helps users to reproduce the test as example
cp -a /usr/share/doc/${pkg}/examples/* .
find . -type f -name "*.gz" -exec gunzip \{\} \;
for lnk in `find . -type l -name "*.gz"` ; do
    ln -s `basename $(readlink $lnk) .gz` `echo $lnk | sed 's/\.gz$//'`
    rm $lnk
done

# This very basic test is if we have no other option for testing
# concavity --help
test_id=test1
echo "Run ${test_id}"
concavity -conservation conservation_data/1G6C 1G6C.pdb $test_id
echo "Run: OK, checking output files..."
# After running concavity several files should appear in working directory - check them:
[ -s 1G6C_A_${test_id}.scores ]
[ -s 1G6C_B_${test_id}.scores ]
[ -s 1G6C_C_${test_id}.scores ]
[ -s 1G6C_D_${test_id}.scores ]
[ -s 1G6C_${test_id}_residue.pdb ]
[ -s 1G6C_${test_id}.dx ]
[ -s 1G6C_${test_id}.pml ]
echo "Results: OK"

test_id=cc-pocketfinder_search_blur
echo "Run ${test_id}"
#Another simple test with non-default parameters (as suggested in readme.txt):
concavity -conservation conservation_data/1G6C -grid_method pocketfinder \
-extraction_method search -res_map_method blur 1G6C.pdb ${test_id}
echo "Run: OK, checking output files..."
# After running concavity several files should appear in working directory - check them:
[ -s 1G6C_A_${test_id}.scores ]
[ -s 1G6C_B_${test_id}.scores ]
[ -s 1G6C_C_${test_id}.scores ]
[ -s 1G6C_D_${test_id}.scores ]
[ -s 1G6C_${test_id}_residue.pdb ]
[ -s 1G6C_${test_id}.dx ]
[ -s 1G6C_${test_id}.pml ]
echo "Results: OK"
