#!/bin/bash

source scripts/nextflow_detached.sh
bcbio=$PWD/scripts/bcbio_nextgen.py
bcbio_prepare_samples=$PWD/scripts/bcbio_prepare_samples.py

common_args="--bcbio $bcbio --bcbio_prepare_samples $bcbio_prepare_samples --bcbio_template $PWD/bcbio/bcbio_template.yaml"

test_exit_status=0

nextflow clean -f

echo "Test case 1: simple trio"
run_nextflow ../pipeline/main.nf --ped_file assets/input_data/ped_files/batch_1.ped  --sample_sheet assets/input_data/sample_sheets/batch_1.tsv $common_args
test_exit_status=$(( $test_exit_status + $? ))
for f in "
    outputs/individuals/000001/merged_fastqs/000001_merged_r1.fastq.gz
    outputs/individuals/000001/merged_fastqs/000001_merged_r2.fastq.gz
    outputs/individuals/000002/merged_fastqs/000002_merged_r1.fastq.gz
    outputs/individuals/000002/merged_fastqs/000002_merged_r2.fastq.gz
    outputs/individuals/000003/merged_fastqs/000003_merged_r1.fastq.gz
    outputs/individuals/000003/merged_fastqs/000003_merged_r2.fastq.gz
    outputs/families/000001/000001.csv
"
do
    ls $f > /dev/null
    test_exit_status=$(( $test_exit_status + $? ))
done

echo "Test case 2: MD5 errors"
run_nextflow ../pipeline/main.nf --ped_file assets/input_data/ped_files/batch_2_md5_errors.ped  --sample_sheet assets/input_data/sample_sheets/batch_2_md5_errors.tsv $common_args
if [ $? == 0 ]
then
    test_exit_status=$(( $test_exit_status + 1 ))
fi

echo "Tests finished with exit status $test_exit_status"
