#!/bin/bash
source ../test_common.sh
set_test_name "${BASH_SOURCE[0]}"

testfun() {
    [[ -f orthologer.sh ]] || { echo "error: setup_test.sh not executed"; return 255; }

    # check setup
    ./orthologer.sh -xp >& /dev/null || { echo "error: failed check - run ./orthologer.sh -xp to see details"; return 255; }
    
    # 3. download a sample fasta
    download_fasta example.fs || return 255

    # make sure that full pipeline is run
    ./orthologer.sh -r all || return 255

    # check existance of result
    local fsource='Cluster/test.og'
    [[ -f ${fsource} ]] || { echo "error: missing source cluster file ${fsource}"; return 255; }

    local label="test_localmap"

    # map example.fs to this orthology (label 'test')
    ./orthomapper.sh map $label refs/example.fs local:test

    local fbase="Cluster/${label}.og"
    [[ -f ${fbase} ]] || { echo "error: missing result file ${fbase}"; return 255; }

    # compare with reference
    cmp_with_ref "$fbase" "proj_prot/ref_${label}.og"
    return $?
}
run_test
exit $?
