#!/bin/sh -e

pkg=proteinortho

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

export OMP_NUM_THREADS=1

cd "${AUTOPKGTEST_TMP}"

mkdir test
cp -a /usr/share/doc/${pkg}/examples/* test
gunzip -r *

proteinortho6.pl -force -project=test_blastp -p=blastp+ test/*.faa
./test/chk_test.pl test_blastp.proteinortho.tsv

proteinortho6.pl -force -project=test_synteny -synteny -singles -p=blastp+ test/*.faa
./test/chk_test.pl test_synteny.proteinortho.tsv
./test/chk_test.pl test_synteny.poff.tsv

proteinortho6.pl  -force -project=test_diamond -p=diamond test/*.faa
./test/chk_test.pl test_diamond.proteinortho.tsv

proteinortho6.pl -force -project=test_diamondmoresensitive -p=diamond -subparaBlast="--more-sensitive" test/*.faa
./test/chk_test.pl test_diamondmoresensitive.proteinortho.tsv

# Not yet packaged?
#proteinortho6 -force -project=test_lastp -p=lastp test/*.faa
#./test/chk_test.pl test_lastp.proteinortho.tsv

# Not yet packaged?
#proteinortho6 -force -project=test_topaz -p=topaz test/*.faa
#./test/chk_test.pl test_topaz.proteinortho.tsv

# Not yet packaged
#proteinortho6 -force -project=test_usearch -p=usearch test/*.faa
#./test/chk_test.pl test_usearch.proteinortho.tsv

# Not yet packaged?
#proteinortho6 -force -project=test_ublast -p=ublast test/*.faa
#./test/chk_test.pl test_ublast.proteinortho.tsv

# Not yet packaged?
#proteinortho6 -force -project=test_rapsearch -p=rapsearch test/*.faa
#./test/chk_test.pl test_rapsearch.proteinortho.tsv

# Not yet packaged?
#proteinortho6 -force -project=test_blatp -p=blatp test/*.faa
#./test/chk_test.pl test_blatp.proteinortho.tsv

# Not yet packaged?
#proteinortho6 -force -project=test_mmseqsp -p=mmseqsp test/*.faa
#./test/chk_test.pl test_blatp.proteinortho.tsv

proteinortho6.pl -force -project=test_blastall -p=blastp test/*.faa
./test/chk_test.pl test_blastall.proteinortho.tsv

proteinortho_clustering -test

# Compare results of 'with lapack' and 'without lapack'
proteinortho_clustering -epsilon 0 test_blastp.blast-graph
perl -lne 'print join "\t", sort split("\t",$_)' remove.graph | sort > test.A
proteinortho_clustering -epsilon 0 -lapack 0 test_blastp.blast-graph
perl -lne 'print join "\t", sort split("\t",$_)' remove.graph | sort > test.B
diff -u test.A test.B

echo "Test okay"
