#!/bin/bash
set -e

pkg=kallisto

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

cd "${AUTOPKGTEST_TMP}"/test

# OK
kallisto index -i transcripts.kidx transcripts.fasta.gz
kallisto quant -i transcripts.kidx -b 30 -o kallisto_out --genomebam --gtf transcripts.gtf.gz --chromosomes chrom.txt reads_1.fastq.gz reads_2.fastq.gz

exit 0

# The following command line is wrong but it should not throw Segmentation fault!

 $ LC_ALL=C kallisto quant -i transcripts.kidx -b 30 -o kallisto_out --genomebam --gtf transcripts.gtf.gz transcripts.fasta.gz --chromosomes reads_1.fastq.gz reads_2.fastq.gz

[quant] fragment length distribution will be estimated from the data
[index] k-mer length: 31
[index] number of targets: 14
[index] number of k-mers: 22,118
[index] number of equivalence classes: 20
Warning: could not find chromosomes for 117 transcripts
[quant] running in paired-end mode
[quant] will process pair 1: transcripts.fasta.gz
                             reads_2.fastq.gz
[quant] finding pseudoalignments for the reads ...Segmentation fault
