#!/bin/bash
set -e

pkg=trinculo

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

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

cd "${AUTOPKGTEST_TMP}"

echo "1. Testing frequentist association (plink)..."
trinculo multinom --bfile genotypes --pheno phenos.txt --phenoname Pheno --basepheno Control
echo "PASSED"
echo "2. Testing frequentist association (dosage)..."
trinculo multinom --dosage genotypes.dose --pheno phenos.txt --phenoname Pheno --basepheno Control 
echo "PASSED"
echo "3. Testing frequentist association (covariates)..."
trinculo multinom --bfile genotypes --pheno phenos.txt --phenoname Pheno --basepheno Control --covar pcs.txt 
echo "PASSED"
echo "4. Testing frequentist association (conditioning)..."
echo "SNP1" > condfile[1]
trinculo multinom --bfile genotypes --pheno phenos.txt --phenoname Pheno --basepheno Control --covar pcs.txt --condition condfile[1] 
echo "PASSED"
echo "5. Testing Bayesian association..."
trinculo multinom --bfile genotypes --pheno phenos.txt --phenoname Pheno --basepheno Control --covar pcs.txt --normalize --defaultprior 
echo "PASSED"
echo "6. Testing Bayesian association (prior file)..."
trinculo multinom --bfile genotypes --pheno phenos.txt --phenoname Pheno --basepheno Control --covar pcs.txt --normalize --priors priors.txt 
echo "PASSED"
echo "7. Testing Bayesian model selection..."
trinculo multinom --bfile genotypes --pheno phenos.txt --phenoname Pheno --basepheno Control --covar pcs.txt --normalize --defaultprior --select 
echo "PASSED"
echo "8. Testing Bayesian model selection (empirical prior)..."
trinculo multinom --bfile genotypes --pheno phenos.txt --phenoname Pheno --basepheno Control --covar pcs.txt --normalize --empiricalprior --select 
echo "PASSED"
echo "9. Testing ordinal regression..."
trinculo ordinal --bfile genotypes --pheno phenos.txt --phenoname Order --covar pcs.txt
echo "PASSED"
