#!/bin/sh

# Tests scramble compatibility with a simple cramtools.jar cram file.
# Minimal, but potentially useful compatibility test.
# We also add a non-java cram here, but one manually tweaked to stress
# test threading with multi-slice containers.

scramble="${VALGRIND} /usr/bin/scramble ${SCRAMBLE_ARGS}"
compare_sam=$srcdir/compare_sam.pl

for i in `/bin/ls $srcdir/data/*_java.cram` $srcdir/data/9827_rand3.cram
do
    echo "=== testing $i ==="
    ref=`echo $i | sed 's/#.*/.fa/'`
    root=`echo $i | sed 's/\.cram$//;s:.*/::'`
    if [ -e "$ref" -a "$ref" != "$root" ]
    then
	echo "$scramble -t4 -r $ref $i $outdir/$root.scramble.sam"
	$scramble -r $ref $i $outdir/$root.scramble.sam || exit 1
    else
	echo "$scramble -t4 $i $outdir/$root.scramble.sam"
	REF_PATH=/fail $scramble -t4 $i $outdir/$root.scramble.sam || exit 1
    fi

    echo $compare_sam $srcdir/data/${root}.sam $outdir/$root.scramble.sam
    $compare_sam $srcdir/data/${root}.sam $outdir/$root.scramble.sam || exit 1
done
