#!/bin/bash
set -e

pkg=cdbfasta

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 /usr/share/doc/${pkg}/examples/* -a "${AUTOPKGTEST_TMP}"

cd "${AUTOPKGTEST_TMP}"
gunzip -r *

# Just for debugging
set -x

# Create the index file for a multi-FASTA
cdbfasta ebola.fasta

# Pull records based on the index file
cdbyank -a "Cote_d'Ivoire_ebolavirus,_complete_genome" ebola.fasta.cidx

# Retrieve specific sequence ranges
cdbyank -a "Cote_d'Ivoire_ebolavirus,_complete_genome 32 112" -R ebola.fasta.cidx

# Test the compression
cdbfasta ebola.fasta -z ebola.cdbz
