#!/bin/bash
set -e

pkg=plink

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 "247395d4cfd4bef03befd9672a2afe0a  test.emmax.ps" >> checksums

p-link --noweb  --file test --recode12 --output-missing-genotype 0 --transpose --out test

awk '{print $1,$2,$6}' test.ped > test.emmax_phenotypes
sed -i 's/-9$/NA/' test.emmax_phenotypes
sed -i 's/0$/NA/' test.emmax_phenotypes

echo -e "Running Tests"

echo -e "Test 1"

emmax-kin -v -d 10 test

echo -e "Test 2"

emmax -v -d 10 -t test -p test.emmax_phenotypes -k test.BN.kinf -o test.emmax

md5sum --check checksums
echo -e "PASS"

# Clean up
rm -f test.*
