#!/bin/bash
set -e

pkg=seer

export LC_ALL=C.UTF-8
if [ "${AUTOPKGTEST_TMP}" = "" ] ; then
  AUTOPKGTEST_TMP=$(mktemp -d /tmp/${pkg}-test.XXXXXX)
  # Double quote below to expand the temporary directory variable now versus
  # later is on purpose.
  # shellcheck disable=SC2064
  trap "rm -rf ${AUTOPKGTEST_TMP}" 0 INT QUIT ABRT PIPE TERM
fi

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

cd "${AUTOPKGTEST_TMP}"

gunzip -r *
gzip example_kmers
#do_stuff_to_test_package#
echo -e "\e[93m\e[1mTest 1: Basic Filters\e[0m"
seer -k example_kmers.gz -p subset.pheno
echo -e "\e[92m\e[1mPassed\e[0m"
echo

echo -e "\e[93m\e[1mTest 2: Binary Phenotype Assocation\e[0m"
seer -k example_kmers.gz -p subset.pheno --pval 1 --chisq 1
echo -e "\e[92m\e[1mPassed\e[0m"
echo

echo -e "\e[93m\e[1mTest 3:Print Output\e[0m"
seer -k example_kmers.gz -p subset.pheno --pval 1 --chisq 1 --maf 0.1 --print_samples
echo -e "\e[92m\e[1mPassed\e[0m"
echo

echo -e "\e[93m\e[1mTest 4: Continuous Phenotype Assocation\e[0m"
seer -k example_kmers.gz -p subset.cont.pheno --pval 1 --chisq 1 --maf 0.1
echo -e "\e[92m\e[1mPassed\e[0m"
echo

echo -e "\e[93m\e[1mTest 5: Assocation with Population Structure\e[0m"
seer -k example_kmers.gz -p example.pheno --struct all_structure_new --pval 1 --chisq 1
echo -e "\e[92m\e[1mPassed\e[0m"
echo

echo -e "\e[93m\e[1mTest 6: Assocation with Covariates\e[0m"
seer -k example_kmers.gz -p subset.pheno --covar_file covariates.txt --covar_list 2q,3 --pval 1 --chisq 1
echo -e "\e[92m\e[1mPassed\e[0m"
echo

echo -e "\e[93m\e[1mTest 7: Filter Output\e[0m"
filter_seer -k filter_in.txt --pos_beta
echo -e "\e[92m\e[1mPassed\e[0m"
echo

echo -e "\e[93m\e[1mTest 8: Map k-mers\e[0m"
map_back -k map_in.txt -r assembly_locations.txt --threads 1
echo -e "\e[92m\e[1mPassed\e[0m"
echo
