#!/bin/sh -e

pkg=prottest

# Trivial test
prottest -h

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

# enable MPI run as root to pass test also when called as root
export OMPI_MCA_rmaps_base_oversubscribe=1
export OMPI_ALLOW_RUN_AS_ROOT=1
export OMPI_ALLOW_RUN_AS_ROOT_CONFIRM=1


cd $AUTOPKGTEST_TMP

cp -a /usr/share/doc/${pkg}/examples/* .

# Run simulations with demo models
# Unfortunately there are issues with the Debian packaged phyml as described here
#   https://github.com/ddarriba/prottest3/issues/12
#
# Model optimization exception: there was an error while executing there was an error parsing PhyML stats file: Stats file does not exist. Please check if PhyML is working.
# Model................................ : FLU+I+G+F
#   Number of parameters............... : 74 (21 + 53 branch length estimates)
# 
# ************************************************************
# Date   :  Sun Feb 21 14:44:46 UTC 2021
# Runtime:  0h:02:29
# 
# 
# Lk not initialized

# For the moment we'll leave the trivial test
#prottest -i COX2_PF0016/alignment -t COX2_PF0016/tree -S 0 -all-distributions -F -AIC -BIC -tc 0.5
#prottest -i Ribosomal_L5_PF00673/alignment -t Ribosomal_L5_PF00673/tree -S 0 -all-distributions -F -AIC -BIC -tc 0.5

echo "PASS"
