#!/bin/sh -e

pkg=gemma

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}/example/* $AUTOPKGTEST_TMP

cd $AUTOPKGTEST_TMP

ls *.gz | grep -v "geno.txt.gz" | xargs gunzip

# Test copied from upstream example/demo.txt file
gemma -g mouse_hs1940.geno.txt.gz -p mouse_hs1940.pheno.txt \
      -a mouse_hs1940.anno.txt -gk -o mouse_hs1940

hostarch=$(dpkg-architecture -qDEB_HOST_ARCH)

# Ignore single test on armhf (see bug #972553)
if [ "$hostarch" = "armhf" ] ; then
  echo "Do only one test for $hostarch to reduce test time (see bug #985004)"
  exit 0
fi

gemma -g mouse_hs1940.geno.txt.gz -p mouse_hs1940.pheno.txt -n 1 \
      -a mouse_hs1940.anno.txt -k ./output/mouse_hs1940.cXX.txt -lmm \
      -o mouse_hs1940_CD8_lmm

gemma -g mouse_hs1940.geno.txt.gz -p mouse_hs1940.pheno.txt \
      -n 1 6 -a mouse_hs1940.anno.txt -k ./output/mouse_hs1940.cXX.txt \
      -lmm -o mouse_hs1940_CD8MCH_lmm

gemma -g mouse_hs1940.geno.txt.gz -p mouse_hs1940.pheno.txt \
      -n 1 6 -a mouse_hs1940.anno.txt -k ./output/mouse_hs1940.cXX.txt \
      -predict -o mouse_hs1940_CD8MCH_prdt

gemma -g mouse_hs1940.geno.txt.gz -p ./output/mouse_hs1940_CD8MCH_prdt.prdt.txt \
      -n 1 2 -a mouse_hs1940.anno.txt -k ./output/mouse_hs1940.cXX.txt -lmm \
      -o mouse_hs1940_CD8MCH_prdt_lmm

gemma -g mouse_hs1940.geno.txt.gz -p mouse_hs1940.pheno.txt -n 4 \
      -a mouse_hs1940.anno.txt -bslmm -o mouse_hs1940_CD8_bslmm_cc1 -w 1000 -s 10000 -seed 1

gemma -g mouse_hs1940.geno.txt.gz -p mouse_hs1940.pheno.txt -n 4 \
      -a mouse_hs1940.anno.txt -bslmm 3 -o mouse_hs1940_CD8_bslmm_cc3 -w 1000 -s 10000 -seed 1

gemma -g mouse_hs1940.geno.txt.gz -p mouse_hs1940.pheno.txt -n 2 \
      -a mouse_hs1940.anno.txt -gk 1 -o mouse_hs1940_CD8_train

gemma -g mouse_hs1940.geno.txt.gz -p mouse_hs1940.pheno.txt -n 2 \
      -epm ./output/mouse_hs1940_CD8_bslmm_cc1.param.txt \
      -emu ./output/mouse_hs1940_CD8_bslmm_cc1.log.txt \
      -ebv ./output/mouse_hs1940_CD8_bslmm_cc1.bv.txt \
      -k ./output/mouse_hs1940_CD8_train.cXX.txt -predict -o mouse_hs1940_CD8_prdt_k

gemma -g mouse_hs1940.geno.txt.gz -p mouse_hs1940.pheno.txt -n 2 \
      -epm ./output/mouse_hs1940_CD8_bslmm_cc1.param.txt \
      -emu ./output/mouse_hs1940_CD8_bslmm_cc1.log.txt -predict -o mouse_hs1940_CD8_prdt

gemma -g mouse_hs1940.geno.txt.gz -p mouse_hs1940.pheno.txt -n 4 \
      -epm ./output/mouse_hs1940_CD8_bslmm_cc1.param.txt \
      -emu ./output/mouse_hs1940_CD8_bslmm_cc1.log.txt -predict -o mouse_hs1940_CD8_prdt_cc1

gemma -g mouse_hs1940.geno.txt.gz -p mouse_hs1940.pheno.txt -n 4 \
      -epm ./output/mouse_hs1940_CD8_bslmm_cc3.param.txt \
      -emu ./output/mouse_hs1940_CD8_bslmm_cc3.log.txt -predict 2 -o mouse_hs1940_CD8_prdt_cc3
