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

# set root work dir
export ODBMAPPER_WORK=$(pwd)
    
IGNORE_CHECK_ENV=1
testfun() {
    local odbmapper="$DIR_ORTHOLOGER/bin/ODB-mapper.sh"
    [[ -f "$odbmapper" ]] || { echo "error: missing odbmapper command $odbmapper"; return 255; }
    
    # get info
    echo ">>> Get project directory"
    USE_DIR_PROJECT=$($odbmapper INFO project)
    append_slash USE_DIR_PROJECT
    echo ">>> Got project directory $USE_DIR_PROJECT"
    
    USE_API_URL=$($odbmapper INFO apiurl)
    local dirrefs="${USE_DIR_PROJECT}refs"
    [[ -d "$dirrefs" ]] || mkdir "$dirrefs" || return 255
    
    # 3. download a sample fasta
    echo ">>> download example.fs"
    download_fasta example.fs || return $EC_FAIL

    local run_label="test_simple"
    local node="1489911"
    
    # 5. map fasta file against $node
    export DIR_PROJECT=$USE_DIR_PROJECT
    echo ">>> run mapper"
    $odbmapper MAP "$run_label" "${dirrefs}/example.fs" "$node" || { echo "error: failed running orthologer"; return $EC_FAIL; }

    local fclus=$($odbmapper RESULT "$run_label" what=cls)
    
    # results
    echo ">>> get results"
    check_map_result_files "$run_label" || return $EC_FAIL

    echo ">>> compare with ref"
    local fref="$DIR_PROJECT/../../../proj_map/Cluster/test_simple.og"
    # compare with reference
    cmp_with_ref "$fclus" "file:$fref"
    return $?
}
run_test
exit $?

