#!/bin/sh
# autopkgtest check: Run sumaclust on two different chains with two different 
# thresholds: 0.9 and 0.8. The first run must result in 2 clusters, the second 
# one must result in 1 cluster.
# (C) 2020 Pierre Gruet.
# Author: Pierre Gruet <pgt@debian.org>

set -e

WORKDIR=$(mktemp -d)
trap "rm -rf $WORKDIR" 0 INT QUIT ABRT PIPE TERM
cd $WORKDIR
cat <<EOF > inputTwoDifferent.fasta
>SEQ_TEST1
CCAGATCTAGCTAGCTAGCTACAGCATCGACATCAGCACTCAGCACTCAG
>SEQ_TEST2
CCAGATGATCTAGCTAGCTAGCTACAGCATTTGAACATCAGCACTGGATCAG
EOF

sumaclust -t 0.9 inputTwoDifferent.fasta 2>&1 | \
  sed -n '/clusters/ s/.*Done : 100 \% *//p' | \
  sed -n 's/ clusters.*//p' | \
  grep -q "2"

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

sumaclust -t 0.8 inputTwoDifferent.fasta 2>&1 | \
  sed -n '/clusters/ s/.*Done : 100 \% *//p' | \
  sed -n 's/ clusters.*//p' | \
  grep -q "1"

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

