#!/bin/sh
# autopkgtest check: Run sumatra on one single file with three sequences to 
# test alignment against itself. We use a threshold of 0.5 and then a 
# threshold of 0.6, and we check that
# * 3 sequences are read in the file;
# * 3 lines are output with a threshold of 0.5;
# * 1 line is output with a threshold of 1.
# (C) 2020 Pierre Gruet.
# Author: Pierre Gruet <pgtdebian@free.fr>

set -e

WORKDIR=$(mktemp -d)
trap "rm -rf $WORKDIR" 0 INT QUIT ABRT PIPE TERM
cd $WORKDIR
cat <<EOF > input.fasta
>SEQ1
ATGTGATCAATGCTGCTAGCTGCTAGCTGCTACGCACACGTGCATCGCTGCATGCACTGCTGCTGATGCTCAGCTAG
>SEQ2
AGGTATCTCGATCGATCACTCGCATCGTGTGCTAGCTGCTAGCTGCTACGATCGCATCGC
>SEQ3
AGGTATCTCGATCGATCACTCGCATCGTGTGCTAGCTGCTAGCTGCTACGATCGCATCGC
EOF

sumatra -t 0.5 input.fasta 2>&1 | \
  sed -n 's/^3.sequences//p' | \
  wc -l |
  grep -q "1"

if [ $? -ne 0 ]; then
  exit 1
fi

sumatra -t 0.5 input.fasta 2>&1 | \
  sed -n 's/^SEQ.*SEQ//p' | \
  wc -l |
  grep -q "3"

if [ $? -ne 0 ]; then
  exit 1
fi

sumatra -t 0.6 input.fasta 2>&1 | \
  sed -n 's/^SEQ.*SEQ//p' | \
  wc -l |
  grep -q "1"

if [ $? -ne 0 ]; then
  exit 1
fi
