#!/bin/bash
set -e

pkg=dazzdb

export LC_ALL=C.UTF-8
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}"

# Generate a random 1Mbp sequence R.fasta
rangen 1.0 -r2020 > R.fasta
echo "e259b3524f74d97e70ecf97f9078b77e  R.fasta" >> checksums

# Load it into a .dam DB R.dam
fasta2DAM R R.fasta
echo "ab5f001069bd928051b01c42bbf91f5b  .R.bps" >> checksums
echo "89ad93fbaa6e7a645c76ffdf1fb43792  .R.hdr" >> checksums
echo "6a0932e3b471456e3430c87315b7505c  .R.idx" >> checksums
echo "de9ee03fc1bb8cf29c0b1ee6c3e621af  R.dam" >> checksums

# Sample a 20x data sets of the random geneome R
dsimulator R -c20. -r2020 > G.fasta
echo "4382a3340b21340efcc5c878c1e07216  G.fasta" >> checksums

# Create a compressed data base of the reads, G.db
fasta2DB G G.fasta
echo "fa422bad76a2b9119c182be811f389d1  .G.bps" >> checksums


# Split G into 2 parts of size ~ 11MB each
DBsplit -s11 G
echo "25a447c3375b8581314e7c92641b01a2  .G.idx" >> checksums
echo "f6cec403e88918a5c93f265de226ca75  G.db" >> checksums

# Produce a "dust" track on each part
DBdust G.1
echo "4d128adb1b639552ea751f6e1b4d35bb  .G.1.dust.anno" >> checksums
echo "e8dcdd4094198898e51ac431cd3b071b  .G.1.dust.data" >> checksums
DBdust G.2
echo "3957f13eabc099461179b1b5be3393be  .G.2.dust.anno" >> checksums
echo "7ae21880213ececd5411097bc5787386  .G.2.dust.data" >> checksums

#  Create one track for all of the DB
Catrack G dust
echo "99cd6dcb6c6206f4770500ec7e6c0bc3  .G.dust.anno" >> checksums
echo "df77d8ad1ca51e730bb11597d2c8bd93  .G.dust.data" >> checksums

#  Take a look at the statistics for the database
DBstats -mdust G > result
echo "5c5c5f89a9ae055cc06487febc6adb3d  result" >> checksums

md5sum --check checksums
