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

export ODBMAPPER_WORK="$(pwd)/work"
DIR_INSTALL_LOCAL="$(pwd)/local"

IGNORE_CHECK_ENV=1
testfun() {
    # set path
    local path="$DIR_INSTALL_LOCAL/bin"
    [[ $PATH == *"$path:"* ]] || PATH="$path:$PATH"
    
    # get project directory
    USE_DIR_PROJECT="$(ODB-mapper CONFIG project 2>/dev/null)"
    [[ -d $USE_DIR_PROJECT ]] || {
        echo "error: project dir is not readable $USE_DIR_PROJECT"
        return $EC_FAIL
    }
    append_slash USE_DIR_PROJECT
    echo ">>> Got project dir: $USE_DIR_PROJECT"

    # setup environment
    echo ">>> Setup environment in project dir"
    ODB-mapper SETUP || return $EC_FAIL

    # 3. download a sample fasta
    echo ">>> Download fasta file"
    download_fasta example.fs || return $EC_FAIL

    local dirrefs=${USE_DIR_PROJECT}/refs
    local run_label="test_simple"
    local node="1489911"
    echo ">>> Run mapping with label <$run_label>"
    # 5. map fasta file against $node
    ODB-mapper MAP "$run_label" "${dirrefs}/example.fs" "$node" subsample="no" || {
        echo "error: failed running orthologer"
        return $EC_FAIL
    }
    
    # results
    check_map_result_files "$run_label" || return $EC_FAIL
    
    # compare with reference
    local fclus="$USE_DIR_PROJECT/Cluster/${run_label}.og"
    local fref="$USE_DIR_PROJECT/../../../../proj_map/Cluster/test_simple.og"
    
    # compare with reference
    cmp_with_ref "$fclus" "file:$fref"
    return $?
}
run_test
exit $?
