<commit_before><commit_msg>Initial commit<commit_after>#!/bin/bash

# FIXME reimplement in python

# http://redsymbol.net/articles/unofficial-bash-strict-mode/
set -euo pipefail

MYNAME=$(basename $(readlink -f $0))
KEEP_TMP=1

toaddr() {
    if [ $(whoami) == 'userrig' ]; then
        echo "<EMAIL>";
    else
        echo "$(whoami)<EMAIL>";
    fi
}

usage() {
    echo "$MYNAME: run pipeline tests"
    echo " -d: Run dry-run tests"
    echo " -r: Run real-run tests"
}
skip_dry_runs=1
skip_real_runs=1
while getopts "dr" opt; do
    case $opt in
        d)
            skip_dry_runs=0
            ;;
        r)
            skip_real_runs=0
            ;;
        \?)
            usage
            exit 1
            ;;
    esac
done


# readlink resolves links and makes path absolute
test -z "$RPD_ROOT" && exit 1
NA12878_DIR=$RPD_ROOT/testing/data/illumina-platinum-NA12878
#R1_1M=ERR091571_1_split000001_1M-only.fastq.gz
#R2_1M=ERR091571_2_split000001_1M-only.fastq.gz
R1_1K=$NA12878_DIR/ERR091571_1_split000001_1konly.fastq.gz
R2_1K=$NA12878_DIR/ERR091571_2_split000001_1konly.fastq.gz
SAMPLE_1K=NA12878-1K

for f in $R1_1K $R2_1K; do
    if [ ! -e $f ]; then
        echo "FATAL: non existant file $f" 1>&2
        exit 1
    fi
done


cd $(dirname $0)
pipeline=$(pwd | sed -e 's,.*/,,')
commit=$(git describe --always --dirty)
test -e Snakefile || exit 1


test_outdir_base=/mnt/projects/rpd/testing/output/${pipeline}/${pipeline}-commit-${commit}
log=$(mktemp)
COMPLETE_MSG="*** All tests completed ***"
echo "Logging to $log"
echo "Check log if the following final message is not printed: \"$COMPLETE_MSG\""


# dryruns
#
if [ $skip_dry_runs -ne 1 ]; then
    echo "Dryrun: $SAMPLE_1K" | tee -a $log
    odir=$(mktemp -d ${test_outdir_base}-dryrun-$SAMPLE_1K.XXXXXXXXXX) && rmdir $odir
    ./variant-calling-lofreq.py -1 $R1_1K -2 $R2_1K -s $SAMPLE_1K -d -o $odir --no-run >> $log 2>&1
    pushd $odir >> $log
    EXTRA_SNAKEMAKE_ARGS="--dryrun" bash run.sh >> $log 2>&1
    popd >> $log
    test $KEEP_TMP -eq  1 || rm -rf $odir
else
    echo "Dryruns tests skipped"
fi


# real runs
#
if [ $skip_real_runs -ne 1 ]; then
    echo "Real run: $SAMPLE_1K" | tee -a $log
    odir=$(mktemp -d ${test_outdir_base}-realrun-$SAMPLE_1K.XXXXXXXXXX) && rmdir $odir
    ./variant-calling-lofreq.py -1 $R1_1K -2 $R2_1K -s $SAMPLE_1K -d -o $odir >> $log 2>&1
    #pushd $odir >> $log
    #EXTRA_SNAKEMAKE_ARGS="--notemp" bash run.sh >> $log 2>&1
    #EXTRA_SNAKEMAKE_ARGS="--notemp" 
    #bash run.sh >> $log 2>&1
    #popd >> $log
    echo "Started job in $odir. You will receive an email"
    test $KEEP_TMP -eq  1 || rm -rf $odir       
else
    echo "Real-run test skipped"
fi


echo
echo "$COMPLETE_MSG"

{'fraction_non_alphanumeric': 0.14575645756457564, 'fraction_numerical': 0.05166051660516605, 'mean_word_length': 2.8673323823109844, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1533485', 'n_tokens_mistral': 1193, 'n_tokens_neox': 1114, 'n_words': 263}