#!/bin/sh

# Author: Lance Lin <LQi254@protonmail.com>
# Date: 08 March 2022
# File: run-mlagan-test
# Purpose: run a unit test for the mlagan binary
#
# Details:
# Use a publicly accessible .fasta file format example. There are others, but they quite large (>30MB).
# Compare it with the included sample.fasta file in the lagan package.

set -e

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

# This is needed for lagan to run
export LAGAN_DIR=/usr/lib/lagan

echo "run-mlagan-test: generating sample data"

# FASTA format file from "UT Southwestern Medical Center"
# URL: http://prodata.swmed.edu/promals/info/fasta_format_file_example.htm
# Website title: Fasta format file example
# Date accessed: 18 February 2022
cat <<EOF > testfile.fasta
>seq0
FQTWEEFSRAAEKLYLADPMKVRVVLKYRHVDGNLCIKVTDDLVCLVYRTDQAQDVKKIEKF
>seq1
KYRTWEEFTRAAEKLYQADPMKVRVVLKYRHCDGNLCIKVTDDVVCLLYRTDQAQDVKKIEKFHSQLMRLME LKVTDNKECLKFKTDQAQEAKKMEKLNNIFFTLM
>seq2
EEYQTWEEFARAAEKLYLTDPMKVRVVLKYRHCDGNLCMKVTDDAVCLQYKTDQAQDVKKVEKLHGK
>seq3
MYQVWEEFSRAVEKLYLTDPMKVRVVLKYRHCDGNLCIKVTDNSVCLQYKTDQAQDVK
>seq4
EEFSRAVEKLYLTDPMKVRVVLKYRHCDGNLCIKVTDNSVVSYEMRLFGVQKDNFALEHSLL
>seq5
SWEEFAKAAEVLYLEDPMKCRMCTKYRHVDHKLVVKLTDNHTVLKYVTDMAQDVKKIEKLTTLLMR
>seq6
FTNWEEFAKAAERLHSANPEKCRFVTKYNHTKGELVLKLTDDVVCLQYSTNQLQDVKKLEKLSSTLLRSI
>seq7
SWEEFVERSVQLFRGDPNATRYVMKYRHCEGKLVLKVTDDRECLKFKTDQAQDAKKMEKLNNIFF
>seq8
SWDEFVDRSVQLFRADPESTRYVMKYRHCDGKLVLKVTDNKECLKFKTDQAQEAKKMEKLNNIFFTLM
>seq9
KNWEDFEIAAENMYMANPQNCRYTMKYVHSKGHILLKMSDNVKCVQYRAENMPDLKK
>seq10
FDSWDEFVSKSVELFRNHPDTTRYVVKYRHCEGKLVLKVTDNHECLKFKTDQAQDAKKMEK
EOF

# This is sample.fasta from the lagan package
cat <<EOF > sample.fasta
>sample1
GGCATGTCCAGAAAATCCAAGTGCCTCTTCCTCTTGATCTTCTCCAACGATGTCCAGA
AAATCCAAGTGCCTCATTCCTCTTGATCTTCTCCAGGCATGTCCAGAAAATCCAAGTG
CCTCTTCCTCTCTGATCTTCTCCTCGGTTGGTCCAGAAAATCCAAGTGCCTCTTCCTC
TTGATCTTCTCCAGAAATGTCCAGAAAATCCAAGTAGCCTCTTCCTCTTGATCGGCTC
CAGAAATGTCCAGAAAAATCCAAGTGCCTCTTCCTCTTGATCGGCTCCATAAATGTCC
AGAAAATCCAACGTGCCTCTTCCTCTTGATCGGCTCCAGAAATGTCCAGAAATATCCA
AGTGCCTCTTCCTCTTGATCGGCTCCTTA
>sample2
CGATCCCAAATCCAAGTGCCTCAGAGTCTACTTGATCTTCAATTCAGATCCCAAATCC
AAGTGCCTCAGAGTCTACTTGAATCTTCTATCGGGTCCCAAATCCAAGTGCCTCAGAG
TCTACTTGATCTTCTCTCTCGATCCCATATCCAAGTGCCTCCTAGAGTCTACTTGATC
TTCTCGATAACCAAAATCCAAGTGCCTCAGAGTCTACTTCACTCTTCTCGACTAACCC
AAATCCAAGTGCCTCAGATGAGTCTACTTCCTCTTCTCATAACTCAAATCCAAGTGCC
TCAGAGTCTAACTTCCTCTTCTCGAATAACCCAAATCCAAGTGCCTCAGAGTGTCTAC
TTCCTCTTCTCG
>sample3
TACCCAAATCCAAGTGCCTCAGCGTCTAATAAAACAAGTCTTGATCTTCAACTCCTCC
CAAATCCAAGTGCAACCTCAGCCGCTAATAAAAAGTCTTGATCTTCTCGCGTCCGGCA
AATCCAAGTGCCTCAGCGCTAATAAAAAGTCTTGATCTTCTCGGGAGTCCCAAATCCA
AGTGCCTCAGCGCTAATAAAAAGTCTTGATCTTCTCGGAGGAACAACAAATCCAAGTG
CCTCAAGCGCTAATAAAAAGTCCCGATCTTCTCGTGACAATACAAATCCAAGTGCCTC
AGCGCTAATAAAAAGTCCCGATCTTCTCCCGTGTAAACAAATCCAAGTGCCTCAGCGC
TAATAAAAAGTCCCGATCTTCTCTGGTAACACAACAAATCCAAGTCACGCCTCAGATA
CGCTAATAAAAAGTCCCGATCTTCTC
EOF

echo "run-mlagan-test: generating md5 sums for verification"
echo "b7bdc0c6522f86c7c50a62ff7d27c2e9  output.txt" >> checksums

echo "run-mlagan-test: running mlagan"
mlagan sample.fasta testfile.fasta > output.txt

echo "run-mlagan-test: verifying md5 checksums"
md5sum --check checksums
