#!/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 info
    USE_DIR_PROJECT="$(ODB-mapper INFO project 2>/dev/null)"
    [[ -d $USE_DIR_PROJECT ]] || {
        echo "error: project dir is not readable $USE_DIR_PROJECT"
        return $EC_FAIL
    }
    echo "Got project dir: $USE_DIR_PROJECT"
    append_slash USE_DIR_PROJECT

    local dirrefs="${USE_DIR_PROJECT}refs"
    [[ -d "$dirrefs" ]] || mkdir "$dirrefs" || return 255

    # 3. download a sample fasta
    download_fasta example.fs || return $EC_FAIL

    local run_label="test_simple"
    local node="1489911"
    # 5. map fasta file against $node
    ODB-mapper MAP "$run_label" "${dirrefs}/example.fs" "$node" || {
        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 $?
