#!/usr/bin/env bash

# vep v0.4.2
# 
# This wrapper script is auto-generated by viash 0.9.4 and is thus a derivative
# work thereof. This software comes with ABSOLUTELY NO WARRANTY from Data
# Intuitive.
# 
# The component may contain files which fall under a different license. The
# authors of this component should specify the license in the header of such
# files, or include a separate license file detailing the licenses of all included
# files.
# 
# Component authors:
#  * Robrecht Cannoodt (author, maintainer)

set -e

if [ -z "$VIASH_TEMP" ]; then
  VIASH_TEMP=${VIASH_TEMP:-$VIASH_TMPDIR}
  VIASH_TEMP=${VIASH_TEMP:-$VIASH_TEMPDIR}
  VIASH_TEMP=${VIASH_TEMP:-$VIASH_TMP}
  VIASH_TEMP=${VIASH_TEMP:-$TMPDIR}
  VIASH_TEMP=${VIASH_TEMP:-$TMP}
  VIASH_TEMP=${VIASH_TEMP:-$TEMPDIR}
  VIASH_TEMP=${VIASH_TEMP:-$TEMP}
  VIASH_TEMP=${VIASH_TEMP:-/tmp}
fi

# define helper functions
# ViashQuote: put quotes around non flag values
# $1     : unquoted string
# return : possibly quoted string
# examples:
#   ViashQuote --foo      # returns --foo
#   ViashQuote bar        # returns 'bar'
#   Viashquote --foo=bar  # returns --foo='bar'
function ViashQuote {
  if [[ "$1" =~ ^-+[a-zA-Z0-9_\-]+=.+$ ]]; then
    echo "$1" | sed "s#=\(.*\)#='\1'#"
  elif [[ "$1" =~ ^-+[a-zA-Z0-9_\-]+$ ]]; then
    echo "$1"
  else
    echo "'$1'"
  fi
}
# ViashRemoveFlags: Remove leading flag
# $1     : string with a possible leading flag
# return : string without possible leading flag
# examples:
#   ViashRemoveFlags --foo=bar  # returns bar
function ViashRemoveFlags {
  echo "$1" | sed 's/^--*[a-zA-Z0-9_\-]*=//'
}
# ViashSourceDir: return the path of a bash file, following symlinks
# usage   : ViashSourceDir ${BASH_SOURCE[0]}
# $1      : Should always be set to ${BASH_SOURCE[0]}
# returns : The absolute path of the bash file
function ViashSourceDir {
  local source="$1"
  while [ -h "$source" ]; do
    local dir="$( cd -P "$( dirname "$source" )" >/dev/null 2>&1 && pwd )"
    source="$(readlink "$source")"
    [[ $source != /* ]] && source="$dir/$source"
  done
  cd -P "$( dirname "$source" )" >/dev/null 2>&1 && pwd
}
# ViashFindTargetDir: return the path of the '.build.yaml' file, following symlinks
# usage   : ViashFindTargetDir 'ScriptPath'
# $1      : The location from where to start the upward search
# returns : The absolute path of the '.build.yaml' file
function ViashFindTargetDir {
  local source="$1"
  while [[ "$source" != "" && ! -e "$source/.build.yaml" ]]; do
    source=${source%/*}
  done
  echo $source
}
# see https://en.wikipedia.org/wiki/Syslog#Severity_level
VIASH_LOGCODE_EMERGENCY=0
VIASH_LOGCODE_ALERT=1
VIASH_LOGCODE_CRITICAL=2
VIASH_LOGCODE_ERROR=3
VIASH_LOGCODE_WARNING=4
VIASH_LOGCODE_NOTICE=5
VIASH_LOGCODE_INFO=6
VIASH_LOGCODE_DEBUG=7
VIASH_VERBOSITY=$VIASH_LOGCODE_NOTICE

# ViashLog: Log events depending on the verbosity level
# usage: ViashLog 1 alert Oh no something went wrong!
# $1: required verbosity level
# $2: display tag
# $3+: messages to display
# stdout: Your input, prepended by '[$2] '.
function ViashLog {
  local required_level="$1"
  local display_tag="$2"
  shift 2
  if [ $VIASH_VERBOSITY -ge $required_level ]; then
    >&2 echo "[$display_tag]" "$@"
  fi
}

# ViashEmergency: log events when the system is unstable
# usage: ViashEmergency Oh no something went wrong.
# stdout: Your input, prepended by '[emergency] '.
function ViashEmergency {
  ViashLog $VIASH_LOGCODE_EMERGENCY emergency "$@"
}

# ViashAlert: log events when actions must be taken immediately (e.g. corrupted system database)
# usage: ViashAlert Oh no something went wrong.
# stdout: Your input, prepended by '[alert] '.
function ViashAlert {
  ViashLog $VIASH_LOGCODE_ALERT alert "$@"
}

# ViashCritical: log events when a critical condition occurs
# usage: ViashCritical Oh no something went wrong.
# stdout: Your input, prepended by '[critical] '.
function ViashCritical {
  ViashLog $VIASH_LOGCODE_CRITICAL critical "$@"
}

# ViashError: log events when an error condition occurs
# usage: ViashError Oh no something went wrong.
# stdout: Your input, prepended by '[error] '.
function ViashError {
  ViashLog $VIASH_LOGCODE_ERROR error "$@"
}

# ViashWarning: log potentially abnormal events
# usage: ViashWarning Something may have gone wrong.
# stdout: Your input, prepended by '[warning] '.
function ViashWarning {
  ViashLog $VIASH_LOGCODE_WARNING warning "$@"
}

# ViashNotice: log significant but normal events
# usage: ViashNotice This just happened.
# stdout: Your input, prepended by '[notice] '.
function ViashNotice {
  ViashLog $VIASH_LOGCODE_NOTICE notice "$@"
}

# ViashInfo: log normal events
# usage: ViashInfo This just happened.
# stdout: Your input, prepended by '[info] '.
function ViashInfo {
  ViashLog $VIASH_LOGCODE_INFO info "$@"
}

# ViashDebug: log all events, for debugging purposes
# usage: ViashDebug This just happened.
# stdout: Your input, prepended by '[debug] '.
function ViashDebug {
  ViashLog $VIASH_LOGCODE_DEBUG debug "$@"
}

# find source folder of this component
VIASH_META_RESOURCES_DIR=`ViashSourceDir ${BASH_SOURCE[0]}`

# find the root of the built components & dependencies
VIASH_TARGET_DIR=`ViashFindTargetDir $VIASH_META_RESOURCES_DIR`

# define meta fields
VIASH_META_NAME="vep"
VIASH_META_FUNCTIONALITY_NAME="vep"
VIASH_META_EXECUTABLE="$VIASH_META_RESOURCES_DIR/$VIASH_META_NAME"
VIASH_META_CONFIG="$VIASH_META_RESOURCES_DIR/.config.vsh.yaml"
VIASH_META_TEMP_DIR="$VIASH_TEMP"



# initialise variables
VIASH_MODE='run'
VIASH_ENGINE_ID='docker'

######## Helper functions for setting up Docker images for viash ########
# expects: ViashDockerBuild

# ViashDockerInstallationCheck: check whether Docker is installed correctly
#
# examples:
#   ViashDockerInstallationCheck
function ViashDockerInstallationCheck {
  ViashDebug "Checking whether Docker is installed"
  if [ ! command -v docker &> /dev/null ]; then
    ViashCritical "Docker doesn't seem to be installed. See 'https://docs.docker.com/get-docker/' for instructions."
    exit 1
  fi

  ViashDebug "Checking whether the Docker daemon is running"
  local save=$-; set +e
  local docker_version=$(docker version --format '{{.Client.APIVersion}}' 2> /dev/null)
  local out=$?
  [[ $save =~ e ]] && set -e
  if [ $out -ne 0 ]; then
    ViashCritical "Docker daemon does not seem to be running. Try one of the following:"
    ViashCritical "- Try running 'dockerd' in the command line"
    ViashCritical "- See https://docs.docker.com/config/daemon/"
    exit 1
  fi
}

# ViashDockerRemoteTagCheck: check whether a Docker image is available 
# on a remote. Assumes `docker login` has been performed, if relevant.
#
# $1                  : image identifier with format `[registry/]image[:tag]`
# exit code $?        : whether or not the image was found
# examples:
#   ViashDockerRemoteTagCheck python:latest
#   echo $?                                     # returns '0'
#   ViashDockerRemoteTagCheck sdaizudceahifu
#   echo $?                                     # returns '1'
function ViashDockerRemoteTagCheck {
  docker manifest inspect $1 > /dev/null 2> /dev/null
}

# ViashDockerLocalTagCheck: check whether a Docker image is available locally
#
# $1                  : image identifier with format `[registry/]image[:tag]`
# exit code $?        : whether or not the image was found
# examples:
#   docker pull python:latest
#   ViashDockerLocalTagCheck python:latest
#   echo $?                                     # returns '0'
#   ViashDockerLocalTagCheck sdaizudceahifu
#   echo $?                                     # returns '1'
function ViashDockerLocalTagCheck {
  [ -n "$(docker images -q $1)" ]
}

# ViashDockerPull: pull a Docker image
#
# $1                  : image identifier with format `[registry/]image[:tag]`
# exit code $?        : whether or not the image was found
# examples:
#   ViashDockerPull python:latest
#   echo $?                                     # returns '0'
#   ViashDockerPull sdaizudceahifu
#   echo $?                                     # returns '1'
function ViashDockerPull {
  ViashNotice "Checking if Docker image is available at '$1'"
  if [ $VIASH_VERBOSITY -ge $VIASH_LOGCODE_INFO ]; then
    docker pull $1 && return 0 || return 1
  else
    local save=$-; set +e
    docker pull $1 2> /dev/null > /dev/null
    local out=$?
    [[ $save =~ e ]] && set -e
    if [ $out -ne 0 ]; then
      ViashWarning "Could not pull from '$1'. Docker image doesn't exist or is not accessible."
    fi
    return $out
  fi
}

# ViashDockerPush: push a Docker image
#
# $1                  : image identifier with format `[registry/]image[:tag]`
# exit code $?        : whether or not the image was found
# examples:
#   ViashDockerPush python:latest
#   echo $?                                     # returns '0'
#   ViashDockerPush sdaizudceahifu
#   echo $?                                     # returns '1'
function ViashDockerPush {
  ViashNotice "Pushing image to '$1'"
  local save=$-; set +e
  local out
  if [ $VIASH_VERBOSITY -ge $VIASH_LOGCODE_INFO ]; then
    docker push $1
    out=$?
  else
    docker push $1 2> /dev/null > /dev/null
    out=$?
  fi
  [[ $save =~ e ]] && set -e
  if [ $out -eq 0 ]; then
    ViashNotice "Container '$1' push succeeded."
  else
    ViashError "Container '$1' push errored. You might not be logged in or have the necessary permissions."
  fi
  return $out
}

# ViashDockerPullElseBuild: pull a Docker image, else build it
#
# $1                  : image identifier with format `[registry/]image[:tag]`
# ViashDockerBuild    : a Bash function which builds a docker image, takes image identifier as argument.
# examples:
#   ViashDockerPullElseBuild mynewcomponent
function ViashDockerPullElseBuild {
  local save=$-; set +e
  ViashDockerPull $1
  local out=$?
  [[ $save =~ e ]] && set -e
  if [ $out -ne 0 ]; then
    ViashDockerBuild $@
  fi
}

# ViashDockerSetup: create a Docker image, according to specified docker setup strategy
#
# $1          : image identifier with format `[registry/]image[:tag]`
# $2          : docker setup strategy, see DockerSetupStrategy.scala
# examples:
#   ViashDockerSetup mynewcomponent alwaysbuild
function ViashDockerSetup {
  local image_id="$1"
  local setup_strategy="$2"
  if [ "$setup_strategy" == "alwaysbuild" -o "$setup_strategy" == "build" -o "$setup_strategy" == "b" ]; then
    ViashDockerBuild $image_id --no-cache $(ViashDockerBuildArgs "$engine_id")
  elif [ "$setup_strategy" == "alwayspull" -o "$setup_strategy" == "pull" -o "$setup_strategy" == "p" ]; then
    ViashDockerPull $image_id
  elif [ "$setup_strategy" == "alwayspullelsebuild" -o "$setup_strategy" == "pullelsebuild" ]; then
    ViashDockerPullElseBuild $image_id --no-cache $(ViashDockerBuildArgs "$engine_id")
  elif [ "$setup_strategy" == "alwayspullelsecachedbuild" -o "$setup_strategy" == "pullelsecachedbuild" ]; then
    ViashDockerPullElseBuild $image_id $(ViashDockerBuildArgs "$engine_id")
  elif [ "$setup_strategy" == "alwayscachedbuild" -o "$setup_strategy" == "cachedbuild" -o "$setup_strategy" == "cb" ]; then
    ViashDockerBuild $image_id $(ViashDockerBuildArgs "$engine_id")
  elif [[ "$setup_strategy" =~ ^ifneedbe ]]; then
    local save=$-; set +e
    ViashDockerLocalTagCheck $image_id
    local outCheck=$?
    [[ $save =~ e ]] && set -e
    if [ $outCheck -eq 0 ]; then
      ViashInfo "Image $image_id already exists"
    elif [ "$setup_strategy" == "ifneedbebuild" ]; then
      ViashDockerBuild $image_id --no-cache $(ViashDockerBuildArgs "$engine_id")
    elif [ "$setup_strategy" == "ifneedbecachedbuild" ]; then
      ViashDockerBuild $image_id $(ViashDockerBuildArgs "$engine_id")
    elif [ "$setup_strategy" == "ifneedbepull" ]; then
      ViashDockerPull $image_id
    elif [ "$setup_strategy" == "ifneedbepullelsebuild" ]; then
      ViashDockerPullElseBuild $image_id --no-cache $(ViashDockerBuildArgs "$engine_id")
    elif [ "$setup_strategy" == "ifneedbepullelsecachedbuild" ]; then
      ViashDockerPullElseBuild $image_id $(ViashDockerBuildArgs "$engine_id")
    else
      ViashError "Unrecognised Docker strategy: $setup_strategy"
      exit 1
    fi
  elif [ "$setup_strategy" == "push" -o "$setup_strategy" == "forcepush" -o "$setup_strategy" == "alwayspush" ]; then
    ViashDockerPush "$image_id"
  elif [ "$setup_strategy" == "pushifnotpresent" -o "$setup_strategy" == "gentlepush" -o "$setup_strategy" == "maybepush" ]; then
    local save=$-; set +e
    ViashDockerRemoteTagCheck $image_id
    local outCheck=$?
    [[ $save =~ e ]] && set -e
    if [ $outCheck -eq 0 ]; then
      ViashNotice "Container '$image_id' exists, doing nothing."
    else
      ViashNotice "Container '$image_id' does not yet exist."
      ViashDockerPush "$image_id"
    fi
  elif [ "$setup_strategy" == "donothing" -o "$setup_strategy" == "meh" ]; then
    ViashNotice "Skipping setup."
  else
    ViashError "Unrecognised Docker strategy: $setup_strategy"
    exit 1
  fi
}

# ViashDockerCheckCommands: Check whether a docker container has the required commands
#
# $1                  : image identifier with format `[registry/]image[:tag]`
# $@                  : commands to verify being present
# examples:
#   ViashDockerCheckCommands bash:4.0 bash ps foo
function ViashDockerCheckCommands {
  local image_id="$1"
  shift 1
  local commands="$@"
  local save=$-; set +e
  local missing # mark 'missing' as local in advance, otherwise the exit code of the command will be missing and always be '0'
  missing=$(docker run --rm --entrypoint=sh "$image_id" -c "for command in $commands; do command -v \$command >/dev/null 2>&1; if [ \$? -ne 0 ]; then echo \$command; exit 1; fi; done")
  local outCheck=$?
  [[ $save =~ e ]] && set -e
  if [ $outCheck -ne 0 ]; then
  	ViashError "Docker container '$image_id' does not contain command '$missing'."
  	exit 1
  fi
}

# ViashDockerBuild: build a docker image
# $1                               : image identifier with format `[registry/]image[:tag]`
# $...                             : additional arguments to pass to docker build
# $VIASH_META_TEMP_DIR             : temporary directory to store dockerfile & optional resources in
# $VIASH_META_NAME                 : name of the component
# $VIASH_META_RESOURCES_DIR        : directory containing the resources
# $VIASH_VERBOSITY                 : verbosity level
# exit code $?                     : whether or not the image was built successfully
function ViashDockerBuild {
  local image_id="$1"
  shift 1

  # create temporary directory to store dockerfile & optional resources in
  local tmpdir=$(mktemp -d "$VIASH_META_TEMP_DIR/dockerbuild-$VIASH_META_NAME-XXXXXX")
  local dockerfile="$tmpdir/Dockerfile"
  function clean_up {
    rm -rf "$tmpdir"
  }
  trap clean_up EXIT

  # store dockerfile and resources
  ViashDockerfile "$VIASH_ENGINE_ID" > "$dockerfile"

  # generate the build command
  local docker_build_cmd="docker build -t '$image_id' $@ '$VIASH_META_RESOURCES_DIR' -f '$dockerfile'"

  # build the container
  ViashNotice "Building container '$image_id' with Dockerfile"
  ViashInfo "$docker_build_cmd"
  local save=$-; set +e
  if [ $VIASH_VERBOSITY -ge $VIASH_LOGCODE_INFO ]; then
    eval $docker_build_cmd
  else
    eval $docker_build_cmd &> "$tmpdir/docker_build.log"
  fi

  # check exit code
  local out=$?
  [[ $save =~ e ]] && set -e
  if [ $out -ne 0 ]; then
    ViashError "Error occurred while building container '$image_id'"
    if [ $VIASH_VERBOSITY -lt $VIASH_LOGCODE_INFO ]; then
      ViashError "Transcript: --------------------------------"
      cat "$tmpdir/docker_build.log"
      ViashError "End of transcript --------------------------"
    fi
    exit 1
  fi
}

######## End of helper functions for setting up Docker images for viash ########

# ViashDockerFile: print the dockerfile to stdout
# $1    : engine identifier
# return : dockerfile required to run this component
# examples:
#   ViashDockerFile
function ViashDockerfile {
  local engine_id="$1"

  if [[ "$engine_id" == "docker" ]]; then
    cat << 'VIASHDOCKER'
FROM quay.io/biocontainers/ensembl-vep:115.2--pl5321h2a3209d_1
ENTRYPOINT []
RUN vep --help | head -1 | sed 's/.*Variant Effect Predictor.*/vep: 115.2/' > /var/software_versions.txt
LABEL org.opencontainers.image.authors="Robrecht Cannoodt"
LABEL org.opencontainers.image.description="Companion container for running component ensembl_vep vep"
LABEL org.opencontainers.image.created="2025-11-20T08:44:55Z"
LABEL org.opencontainers.image.source="https://github.com/Ensembl/ensembl-vep"
LABEL org.opencontainers.image.revision="02b470d967226478af69c37eae2b1256be1b78fd"
LABEL org.opencontainers.image.version="v0.4.2"

VIASHDOCKER
  fi
}

# ViashDockerBuildArgs: return the arguments to pass to docker build
# $1    : engine identifier
# return : arguments to pass to docker build
function ViashDockerBuildArgs {
  local engine_id="$1"

  if [[ "$engine_id" == "docker" ]]; then
    echo ""
  fi
}

# ViashAbsolutePath: generate absolute path from relative path
# borrowed from https://stackoverflow.com/a/21951256
# $1     : relative filename
# return : absolute path
# examples:
#   ViashAbsolutePath some_file.txt   # returns /path/to/some_file.txt
#   ViashAbsolutePath /foo/bar/..     # returns /foo
function ViashAbsolutePath {
  local thePath
  local parr
  local outp
  local len
  if [[ ! "$1" =~ ^/ ]]; then
    thePath="$PWD/$1"
  else
    thePath="$1"
  fi
  echo "$thePath" | (
    IFS=/
    read -a parr
    declare -a outp
    for i in "${parr[@]}"; do
      case "$i" in
      ''|.) continue ;;
      ..)
        len=${#outp[@]}
        if ((len==0)); then
          continue
        else
          unset outp[$((len-1))]
        fi
        ;;
      *)
        len=${#outp[@]}
        outp[$len]="$i"
      ;;
      esac
    done
    echo /"${outp[*]}"
  )
}
# ViashDockerAutodetectMount: auto configuring docker mounts from parameters
# $1                             : The parameter value
# returns                        : New parameter
# $VIASH_DIRECTORY_MOUNTS        : Added another parameter to be passed to docker
# $VIASH_DOCKER_AUTOMOUNT_PREFIX : The prefix to be used for the automounts
# examples:
#   ViashDockerAutodetectMount /path/to/bar      # returns '/viash_automount/path/to/bar'
#   ViashDockerAutodetectMountArg /path/to/bar   # returns '--volume="/path/to:/viash_automount/path/to"'
function ViashDockerAutodetectMount {
  local abs_path=$(ViashAbsolutePath "$1")
  local mount_source
  local base_name
  if [ -d "$abs_path" ]; then
    mount_source="$abs_path"
    base_name=""
  else
    mount_source=`dirname "$abs_path"`
    base_name=`basename "$abs_path"`
  fi
  local mount_target="$VIASH_DOCKER_AUTOMOUNT_PREFIX$mount_source"
  if [ -z "$base_name" ]; then
    echo "$mount_target"
  else
    echo "$mount_target/$base_name"
  fi
}
function ViashDockerAutodetectMountArg {
  local abs_path=$(ViashAbsolutePath "$1")
  local mount_source
  local base_name
  if [ -d "$abs_path" ]; then
    mount_source="$abs_path"
    base_name=""
  else
    mount_source=`dirname "$abs_path"`
    base_name=`basename "$abs_path"`
  fi
  local mount_target="$VIASH_DOCKER_AUTOMOUNT_PREFIX$mount_source"
  ViashDebug "ViashDockerAutodetectMountArg $1 -> $mount_source -> $mount_target"
  echo "--volume=\"$mount_source:$mount_target\""
}
function ViashDockerStripAutomount {
  local abs_path=$(ViashAbsolutePath "$1")
  echo "${abs_path#$VIASH_DOCKER_AUTOMOUNT_PREFIX}"
}
# initialise variables
VIASH_DIRECTORY_MOUNTS=()

# configure default docker automount prefix if it is unset
if [ -z "${VIASH_DOCKER_AUTOMOUNT_PREFIX+x}" ]; then
  VIASH_DOCKER_AUTOMOUNT_PREFIX="/viash_automount"
fi

# initialise docker variables
VIASH_DOCKER_RUN_ARGS=(-i --rm)


# ViashHelp: Display helpful explanation about this executable
function ViashHelp {
  echo "vep v0.4.2"
  echo ""
  echo "Variant Effect Predictor (VEP) determines the effect of variants on genes,"
  echo "transcripts, and protein sequences."
  echo ""
  echo "VEP annotates variants with:"
  echo "- Consequence types (missense, nonsense, splice site, etc.)"
  echo "- Gene and transcript information"
  echo "- Protein effect predictions (SIFT, PolyPhen)"
  echo "- Population frequencies and clinical significance"
  echo "- Conservation scores and regulatory features"
  echo ""
  echo "See the [VEP"
  echo "documentation](http://www.ensembl.org/info/docs/tools/vep/script/index.html) for"
  echo "comprehensive usage."
  echo ""
  echo "Inputs:"
  echo "    -i, --input_file"
  echo "        type: file, required parameter, file must exist"
  echo "        example: variants.vcf"
  echo "        Input variant file for annotation."
  echo "        **Formats:** VCF, VEP, variant_identifier, HGVS, ID, region, SPDI"
  echo "        **Compression:** Supports gzip (.gz) and bgzip compressed files"
  echo ""
  echo "    --format"
  echo "        type: string"
  echo "        default: vcf"
  echo "        choices: [ vcf, variant_identifier, hgvs, id, region, spdi, vep ]"
  echo "        Input file format."
  echo ""
  echo "Outputs:"
  echo "    -o, --output_file"
  echo "        type: file, required parameter, output, file must exist"
  echo "        example: annotated_variants.txt"
  echo "        Output annotated variants to file."
  echo "        **Compression:** Automatically compress if filename ends with .gz"
  echo ""
  echo "    --vcf"
  echo "        type: boolean_true"
  echo "        Output results in VCF format."
  echo "        **Default:** Tab-delimited text format"
  echo "        **VCF mode:** Adds INFO field with VEP annotations"
  echo ""
  echo "Reference Data:"
  echo "    --species"
  echo "        type: string"
  echo "        default: homo_sapiens"
  echo "        example: homo_sapiens"
  echo "        Species for annotation."
  echo ""
  echo "    --assembly"
  echo "        type: string"
  echo "        example: GRCh38"
  echo "        Genome assembly version."
  echo ""
  echo "    --cache"
  echo "        type: boolean_true"
  echo "        Use cache files for annotation (recommended)."
  echo "        **Performance:** Much faster than database queries"
  echo "        **Location:** Specify with --dir or use default ~/.vep/"
  echo ""
  echo "    --dir"
  echo "        type: file, file must exist"
  echo "        default: /root/.vep"
  echo "        example: /data/vep_cache"
  echo "        Directory containing cache files."
  echo ""
  echo "    --cache_version"
  echo "        type: integer"
  echo "        example: 115"
  echo "        Use specific cache version."
  echo ""
  echo "    --offline"
  echo "        type: boolean_true"
  echo "        Enable offline mode (no database connections)."
  echo "        **Requires:** Cache files and FASTA files"
  echo "        **Use case:** Isolated environments or reproducible runs"
  echo ""
  echo "Annotation Options:"
  echo "    --everything"
  echo "        type: boolean_true"
  echo "        Shortcut to switch on commonly used options."
  echo "        **Includes:** --sift, --polyphen, --ccds, --hgvs, --symbol,"
  echo "        --numbers, --domains, --regulatory, --canonical, --protein,"
  echo "        --biotype, --uniprot, --tsl, --appris, --gene_phenotype,"
  echo "        --af, --af_1kg, --af_esp, --af_gnomad, --max_af, --pubmed,"
  echo "        --variant_class, --mane"
  echo ""
  echo "    --canonical"
  echo "        type: boolean_true"
  echo "        Add canonical transcript flag to output."
  echo "        **Canonical:** Transcript selected as representative for each gene"
  echo ""
  echo "    --ccds"
  echo "        type: boolean_true"
  echo "        Add CCDS transcript identifiers."
  echo ""
  echo "    --protein"
  echo "        type: boolean_true"
  echo "        Add Ensembl protein identifiers."
  echo ""
  echo "    --symbol"
  echo "        type: boolean_true"
  echo "        Add gene symbol (e.g., HGNC)."
  echo ""
  echo "    --hgvs"
  echo "        type: boolean_true"
  echo "        Add HGVS nomenclature for variants."
  echo ""
  echo "    --sift"
  echo "        type: string"
  echo "        choices: [ p, s, b ]"
  echo "        Add SIFT prediction and/or score."
  echo ""
  echo "    --polyphen"
  echo "        type: string"
  echo "        choices: [ p, s, b ]"
  echo "        Add PolyPhen prediction and/or score."
  echo ""
  echo "Frequency Options:"
  echo "    --af"
  echo "        type: boolean_true"
  echo "        Add global allele frequency from 1000 Genomes."
  echo ""
  echo "    --af_1kg"
  echo "        type: boolean_true"
  echo "        Add continental allele frequencies from 1000 Genomes."
  echo ""
  echo "    --af_gnomad"
  echo "        type: boolean_true"
  echo "        Add allele frequencies from gnomAD exomes collections."
  echo ""
  echo "    --max_af"
  echo "        type: boolean_true"
  echo "        Add maximum observed allele frequency across populations."
  echo ""
  echo "Filtering Options:"
  echo "    --pick"
  echo "        type: boolean_true"
  echo "        Pick one consequence annotation per variant."
  echo "        **Selection:** Most severe consequence per gene"
  echo "        **Output:** Single annotation line per variant"
  echo ""
  echo "    --pick_allele"
  echo "        type: boolean_true"
  echo "        Pick one consequence annotation per allele."
  echo ""
  echo "    --flag_pick"
  echo "        type: boolean_true"
  echo "        Flag picked consequence with PICK=1."
  echo ""
  echo "    --per_gene"
  echo "        type: boolean_true"
  echo "        Use one consequence annotation per gene."
  echo ""
  echo "    --pick_order"
  echo "        type: string"
  echo "        example: canonical,appris,tsl,biotype,ccds,rank,length"
  echo "        Customize annotation selection criteria order."
  echo ""
  echo "Output Filtering:"
  echo "    --most_severe"
  echo "        type: boolean_true"
  echo "        Output only most severe consequence per variant."
  echo ""
  echo "    --summary"
  echo "        type: boolean_true"
  echo "        Output only summary of consequences for each variant."
  echo ""
  echo "    --filter_common"
  echo "        type: boolean_true"
  echo "        Shortcut to exclude common variants (frequency > 0.01)."
  echo ""
  echo "Advanced Options:"
  echo "    --buffer_size"
  echo "        type: integer"
  echo "        default: 5000"
  echo "        Number of variants to read at once."
  echo ""
  echo "    --no_check_variants_order"
  echo "        type: boolean_true"
  echo "        Permit variants not ordered by position."
  echo ""
  echo "    --allow_non_variant"
  echo "        type: boolean_true"
  echo "        Allow non-variant VCF lines through analysis."
  echo ""
  echo "Viash built in Computational Requirements:"
  echo "    ---cpus=INT"
  echo "        Number of CPUs to use"
  echo "    ---memory=STRING"
  echo "        Amount of memory to use. Examples: 4GB, 3MiB."
  echo ""
  echo "Viash built in Docker:"
  echo "    ---setup=STRATEGY"
  echo "        Setup the docker container. Options are: alwaysbuild, alwayscachedbuild, ifneedbebuild, ifneedbecachedbuild, alwayspull, alwayspullelsebuild, alwayspullelsecachedbuild, ifneedbepull, ifneedbepullelsebuild, ifneedbepullelsecachedbuild, push, pushifnotpresent, donothing."
  echo "        Default: ifneedbepullelsecachedbuild"
  echo "    ---dockerfile"
  echo "        Print the dockerfile to stdout."
  echo "    ---docker_run_args=ARG"
  echo "        Provide runtime arguments to Docker. See the documentation on \`docker run\` for more information."
  echo "    ---docker_image_id"
  echo "        Print the docker image id to stdout."
  echo "    ---debug"
  echo "        Enter the docker container for debugging purposes."
  echo ""
  echo "Viash built in Engines:"
  echo "    ---engine=ENGINE_ID"
  echo "        Specify the engine to use. Options are: docker, native."
  echo "        Default: docker"
}

# initialise array
VIASH_POSITIONAL_ARGS=''

while [[ $# -gt 0 ]]; do
    case "$1" in
        -h|--help)
            ViashHelp
            exit
            ;;
        ---v|---verbose)
            let "VIASH_VERBOSITY=VIASH_VERBOSITY+1"
            shift 1
            ;;
        ---verbosity)
            VIASH_VERBOSITY="$2"
            shift 2
            ;;
        ---verbosity=*)
            VIASH_VERBOSITY="$(ViashRemoveFlags "$1")"
            shift 1
            ;;
        --version)
            echo "vep v0.4.2"
            exit
            ;;
        --input_file)
            [ -n "$VIASH_PAR_INPUT_FILE" ] && ViashError Bad arguments for option \'--input_file\': \'$VIASH_PAR_INPUT_FILE\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_INPUT_FILE="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --input_file. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --input_file=*)
            [ -n "$VIASH_PAR_INPUT_FILE" ] && ViashError Bad arguments for option \'--input_file=*\': \'$VIASH_PAR_INPUT_FILE\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_INPUT_FILE=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        -i)
            [ -n "$VIASH_PAR_INPUT_FILE" ] && ViashError Bad arguments for option \'-i\': \'$VIASH_PAR_INPUT_FILE\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_INPUT_FILE="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to -i. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --format)
            [ -n "$VIASH_PAR_FORMAT" ] && ViashError Bad arguments for option \'--format\': \'$VIASH_PAR_FORMAT\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_FORMAT="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --format. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --format=*)
            [ -n "$VIASH_PAR_FORMAT" ] && ViashError Bad arguments for option \'--format=*\': \'$VIASH_PAR_FORMAT\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_FORMAT=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --output_file)
            [ -n "$VIASH_PAR_OUTPUT_FILE" ] && ViashError Bad arguments for option \'--output_file\': \'$VIASH_PAR_OUTPUT_FILE\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_OUTPUT_FILE="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --output_file. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --output_file=*)
            [ -n "$VIASH_PAR_OUTPUT_FILE" ] && ViashError Bad arguments for option \'--output_file=*\': \'$VIASH_PAR_OUTPUT_FILE\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_OUTPUT_FILE=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        -o)
            [ -n "$VIASH_PAR_OUTPUT_FILE" ] && ViashError Bad arguments for option \'-o\': \'$VIASH_PAR_OUTPUT_FILE\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_OUTPUT_FILE="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to -o. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --vcf)
            [ -n "$VIASH_PAR_VCF" ] && ViashError Bad arguments for option \'--vcf\': \'$VIASH_PAR_VCF\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_VCF=true
            shift 1
            ;;
        --species)
            [ -n "$VIASH_PAR_SPECIES" ] && ViashError Bad arguments for option \'--species\': \'$VIASH_PAR_SPECIES\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_SPECIES="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --species. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --species=*)
            [ -n "$VIASH_PAR_SPECIES" ] && ViashError Bad arguments for option \'--species=*\': \'$VIASH_PAR_SPECIES\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_SPECIES=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --assembly)
            [ -n "$VIASH_PAR_ASSEMBLY" ] && ViashError Bad arguments for option \'--assembly\': \'$VIASH_PAR_ASSEMBLY\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_ASSEMBLY="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --assembly. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --assembly=*)
            [ -n "$VIASH_PAR_ASSEMBLY" ] && ViashError Bad arguments for option \'--assembly=*\': \'$VIASH_PAR_ASSEMBLY\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_ASSEMBLY=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --cache)
            [ -n "$VIASH_PAR_CACHE" ] && ViashError Bad arguments for option \'--cache\': \'$VIASH_PAR_CACHE\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_CACHE=true
            shift 1
            ;;
        --dir)
            [ -n "$VIASH_PAR_DIR" ] && ViashError Bad arguments for option \'--dir\': \'$VIASH_PAR_DIR\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_DIR="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --dir. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --dir=*)
            [ -n "$VIASH_PAR_DIR" ] && ViashError Bad arguments for option \'--dir=*\': \'$VIASH_PAR_DIR\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_DIR=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --cache_version)
            [ -n "$VIASH_PAR_CACHE_VERSION" ] && ViashError Bad arguments for option \'--cache_version\': \'$VIASH_PAR_CACHE_VERSION\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_CACHE_VERSION="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --cache_version. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --cache_version=*)
            [ -n "$VIASH_PAR_CACHE_VERSION" ] && ViashError Bad arguments for option \'--cache_version=*\': \'$VIASH_PAR_CACHE_VERSION\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_CACHE_VERSION=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --offline)
            [ -n "$VIASH_PAR_OFFLINE" ] && ViashError Bad arguments for option \'--offline\': \'$VIASH_PAR_OFFLINE\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_OFFLINE=true
            shift 1
            ;;
        --everything)
            [ -n "$VIASH_PAR_EVERYTHING" ] && ViashError Bad arguments for option \'--everything\': \'$VIASH_PAR_EVERYTHING\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_EVERYTHING=true
            shift 1
            ;;
        --canonical)
            [ -n "$VIASH_PAR_CANONICAL" ] && ViashError Bad arguments for option \'--canonical\': \'$VIASH_PAR_CANONICAL\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_CANONICAL=true
            shift 1
            ;;
        --ccds)
            [ -n "$VIASH_PAR_CCDS" ] && ViashError Bad arguments for option \'--ccds\': \'$VIASH_PAR_CCDS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_CCDS=true
            shift 1
            ;;
        --protein)
            [ -n "$VIASH_PAR_PROTEIN" ] && ViashError Bad arguments for option \'--protein\': \'$VIASH_PAR_PROTEIN\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_PROTEIN=true
            shift 1
            ;;
        --symbol)
            [ -n "$VIASH_PAR_SYMBOL" ] && ViashError Bad arguments for option \'--symbol\': \'$VIASH_PAR_SYMBOL\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_SYMBOL=true
            shift 1
            ;;
        --hgvs)
            [ -n "$VIASH_PAR_HGVS" ] && ViashError Bad arguments for option \'--hgvs\': \'$VIASH_PAR_HGVS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_HGVS=true
            shift 1
            ;;
        --sift)
            [ -n "$VIASH_PAR_SIFT" ] && ViashError Bad arguments for option \'--sift\': \'$VIASH_PAR_SIFT\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_SIFT="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --sift. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --sift=*)
            [ -n "$VIASH_PAR_SIFT" ] && ViashError Bad arguments for option \'--sift=*\': \'$VIASH_PAR_SIFT\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_SIFT=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --polyphen)
            [ -n "$VIASH_PAR_POLYPHEN" ] && ViashError Bad arguments for option \'--polyphen\': \'$VIASH_PAR_POLYPHEN\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_POLYPHEN="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --polyphen. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --polyphen=*)
            [ -n "$VIASH_PAR_POLYPHEN" ] && ViashError Bad arguments for option \'--polyphen=*\': \'$VIASH_PAR_POLYPHEN\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_POLYPHEN=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --af)
            [ -n "$VIASH_PAR_AF" ] && ViashError Bad arguments for option \'--af\': \'$VIASH_PAR_AF\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_AF=true
            shift 1
            ;;
        --af_1kg)
            [ -n "$VIASH_PAR_AF_1KG" ] && ViashError Bad arguments for option \'--af_1kg\': \'$VIASH_PAR_AF_1KG\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_AF_1KG=true
            shift 1
            ;;
        --af_gnomad)
            [ -n "$VIASH_PAR_AF_GNOMAD" ] && ViashError Bad arguments for option \'--af_gnomad\': \'$VIASH_PAR_AF_GNOMAD\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_AF_GNOMAD=true
            shift 1
            ;;
        --max_af)
            [ -n "$VIASH_PAR_MAX_AF" ] && ViashError Bad arguments for option \'--max_af\': \'$VIASH_PAR_MAX_AF\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_MAX_AF=true
            shift 1
            ;;
        --pick)
            [ -n "$VIASH_PAR_PICK" ] && ViashError Bad arguments for option \'--pick\': \'$VIASH_PAR_PICK\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_PICK=true
            shift 1
            ;;
        --pick_allele)
            [ -n "$VIASH_PAR_PICK_ALLELE" ] && ViashError Bad arguments for option \'--pick_allele\': \'$VIASH_PAR_PICK_ALLELE\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_PICK_ALLELE=true
            shift 1
            ;;
        --flag_pick)
            [ -n "$VIASH_PAR_FLAG_PICK" ] && ViashError Bad arguments for option \'--flag_pick\': \'$VIASH_PAR_FLAG_PICK\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_FLAG_PICK=true
            shift 1
            ;;
        --per_gene)
            [ -n "$VIASH_PAR_PER_GENE" ] && ViashError Bad arguments for option \'--per_gene\': \'$VIASH_PAR_PER_GENE\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_PER_GENE=true
            shift 1
            ;;
        --pick_order)
            [ -n "$VIASH_PAR_PICK_ORDER" ] && ViashError Bad arguments for option \'--pick_order\': \'$VIASH_PAR_PICK_ORDER\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_PICK_ORDER="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --pick_order. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --pick_order=*)
            [ -n "$VIASH_PAR_PICK_ORDER" ] && ViashError Bad arguments for option \'--pick_order=*\': \'$VIASH_PAR_PICK_ORDER\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_PICK_ORDER=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --most_severe)
            [ -n "$VIASH_PAR_MOST_SEVERE" ] && ViashError Bad arguments for option \'--most_severe\': \'$VIASH_PAR_MOST_SEVERE\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_MOST_SEVERE=true
            shift 1
            ;;
        --summary)
            [ -n "$VIASH_PAR_SUMMARY" ] && ViashError Bad arguments for option \'--summary\': \'$VIASH_PAR_SUMMARY\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_SUMMARY=true
            shift 1
            ;;
        --filter_common)
            [ -n "$VIASH_PAR_FILTER_COMMON" ] && ViashError Bad arguments for option \'--filter_common\': \'$VIASH_PAR_FILTER_COMMON\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_FILTER_COMMON=true
            shift 1
            ;;
        --buffer_size)
            [ -n "$VIASH_PAR_BUFFER_SIZE" ] && ViashError Bad arguments for option \'--buffer_size\': \'$VIASH_PAR_BUFFER_SIZE\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_BUFFER_SIZE="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --buffer_size. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --buffer_size=*)
            [ -n "$VIASH_PAR_BUFFER_SIZE" ] && ViashError Bad arguments for option \'--buffer_size=*\': \'$VIASH_PAR_BUFFER_SIZE\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_BUFFER_SIZE=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --no_check_variants_order)
            [ -n "$VIASH_PAR_NO_CHECK_VARIANTS_ORDER" ] && ViashError Bad arguments for option \'--no_check_variants_order\': \'$VIASH_PAR_NO_CHECK_VARIANTS_ORDER\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_NO_CHECK_VARIANTS_ORDER=true
            shift 1
            ;;
        --allow_non_variant)
            [ -n "$VIASH_PAR_ALLOW_NON_VARIANT" ] && ViashError Bad arguments for option \'--allow_non_variant\': \'$VIASH_PAR_ALLOW_NON_VARIANT\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_ALLOW_NON_VARIANT=true
            shift 1
            ;;
        ---engine)
            VIASH_ENGINE_ID="$2"
            shift 2
            ;;
        ---engine=*)
            VIASH_ENGINE_ID="$(ViashRemoveFlags "$1")"
            shift 1
            ;;
        ---setup)
            VIASH_MODE='setup'
            VIASH_SETUP_STRATEGY="$2"
            shift 2
            ;;
        ---setup=*)
            VIASH_MODE='setup'
            VIASH_SETUP_STRATEGY="$(ViashRemoveFlags "$1")"
            shift 1
            ;;
        ---dockerfile)
            VIASH_MODE='dockerfile'
            shift 1
            ;;
        ---docker_run_args)
            VIASH_DOCKER_RUN_ARGS+=("$2")
            shift 2
            ;;
        ---docker_run_args=*)
            VIASH_DOCKER_RUN_ARGS+=("$(ViashRemoveFlags "$1")")
            shift 1
            ;;
        ---docker_image_id)
            VIASH_MODE='docker_image_id'
            shift 1
            ;;
        ---debug)
            VIASH_MODE='debug'
            shift 1
            ;;
        ---cpus)
            [ -n "$VIASH_META_CPUS" ] && ViashError Bad arguments for option \'---cpus\': \'$VIASH_META_CPUS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_META_CPUS="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to ---cpus. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        ---cpus=*)
            [ -n "$VIASH_META_CPUS" ] && ViashError Bad arguments for option \'---cpus=*\': \'$VIASH_META_CPUS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_META_CPUS=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        ---memory)
            [ -n "$VIASH_META_MEMORY" ] && ViashError Bad arguments for option \'---memory\': \'$VIASH_META_MEMORY\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_META_MEMORY="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to ---memory. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        ---memory=*)
            [ -n "$VIASH_META_MEMORY" ] && ViashError Bad arguments for option \'---memory=*\': \'$VIASH_META_MEMORY\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_META_MEMORY=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        *)  # positional arg or unknown option
            # since the positional args will be eval'd, can we always quote, instead of using ViashQuote
            VIASH_POSITIONAL_ARGS="$VIASH_POSITIONAL_ARGS '$1'"
            [[ $1 == -* ]] && ViashWarning $1 looks like a parameter but is not a defined parameter and will instead be treated as a positional argument. Use "--help" to get more information on the parameters.
            shift # past argument
            ;;
    esac
done

# parse positional parameters
eval set -- $VIASH_POSITIONAL_ARGS


if   [ "$VIASH_ENGINE_ID" == "native" ]  ; then
  VIASH_ENGINE_TYPE='native'
elif   [ "$VIASH_ENGINE_ID" == "docker" ]  ; then
  VIASH_ENGINE_TYPE='docker'
else
  ViashError "Engine '$VIASH_ENGINE_ID' is not recognized. Options are: docker, native."
  exit 1
fi

if [[ "$VIASH_ENGINE_TYPE" == "docker" ]]; then
  # check if docker is installed properly
  ViashDockerInstallationCheck

  # determine docker image id
  if [[ "$VIASH_ENGINE_ID" == 'docker' ]]; then
    VIASH_DOCKER_IMAGE_ID='images.viash-hub.com/vsh/biobox/ensembl_vep/vep:v0.4.2'
  fi

  # print dockerfile
  if [ "$VIASH_MODE" == "dockerfile" ]; then
    ViashDockerfile "$VIASH_ENGINE_ID"
    exit 0

  elif [ "$VIASH_MODE" == "docker_image_id" ]; then
    echo "$VIASH_DOCKER_IMAGE_ID"
    exit 0
  
  # enter docker container
  elif [[ "$VIASH_MODE" == "debug" ]]; then
    VIASH_CMD="docker run --entrypoint=bash ${VIASH_DOCKER_RUN_ARGS[@]} -v '$(pwd)':/pwd --workdir /pwd -t $VIASH_DOCKER_IMAGE_ID"
    ViashNotice "+ $VIASH_CMD"
    eval $VIASH_CMD
    exit 

  # build docker image
  elif [ "$VIASH_MODE" == "setup" ]; then
    ViashDockerSetup "$VIASH_DOCKER_IMAGE_ID" "$VIASH_SETUP_STRATEGY"
    ViashDockerCheckCommands "$VIASH_DOCKER_IMAGE_ID" 'vep' 'ps' 'bash'
    exit 0
  fi

  # check if docker image exists
  ViashDockerSetup "$VIASH_DOCKER_IMAGE_ID" ifneedbepullelsecachedbuild
  ViashDockerCheckCommands "$VIASH_DOCKER_IMAGE_ID" 'vep' 'ps' 'bash'
fi

# setting computational defaults

# helper function for parsing memory strings
function ViashMemoryAsBytes {
  local memory=`echo "$1" | tr '[:upper:]' '[:lower:]' | tr -d '[:space:]'`
  local memory_regex='^([0-9]+)([kmgtp]i?b?|b)$'
  if [[ $memory =~ $memory_regex ]]; then
    local number=${memory/[^0-9]*/}
    local symbol=${memory/*[0-9]/}
    
    case $symbol in
      b)      memory_b=$number ;;
      kb|k)   memory_b=$(( $number * 1000 )) ;;
      mb|m)   memory_b=$(( $number * 1000 * 1000 )) ;;
      gb|g)   memory_b=$(( $number * 1000 * 1000 * 1000 )) ;;
      tb|t)   memory_b=$(( $number * 1000 * 1000 * 1000 * 1000 )) ;;
      pb|p)   memory_b=$(( $number * 1000 * 1000 * 1000 * 1000 * 1000 )) ;;
      kib|ki)   memory_b=$(( $number * 1024 )) ;;
      mib|mi)   memory_b=$(( $number * 1024 * 1024 )) ;;
      gib|gi)   memory_b=$(( $number * 1024 * 1024 * 1024 )) ;;
      tib|ti)   memory_b=$(( $number * 1024 * 1024 * 1024 * 1024 )) ;;
      pib|pi)   memory_b=$(( $number * 1024 * 1024 * 1024 * 1024 * 1024 )) ;;
    esac
    echo "$memory_b"
  fi
}
# compute memory in different units
if [ ! -z ${VIASH_META_MEMORY+x} ]; then
  VIASH_META_MEMORY_B=`ViashMemoryAsBytes $VIASH_META_MEMORY`
  # do not define other variables if memory_b is an empty string
  if [ ! -z "$VIASH_META_MEMORY_B" ]; then
    VIASH_META_MEMORY_KB=$(( ($VIASH_META_MEMORY_B+999) / 1000 ))
    VIASH_META_MEMORY_MB=$(( ($VIASH_META_MEMORY_KB+999) / 1000 ))
    VIASH_META_MEMORY_GB=$(( ($VIASH_META_MEMORY_MB+999) / 1000 ))
    VIASH_META_MEMORY_TB=$(( ($VIASH_META_MEMORY_GB+999) / 1000 ))
    VIASH_META_MEMORY_PB=$(( ($VIASH_META_MEMORY_TB+999) / 1000 ))
    VIASH_META_MEMORY_KIB=$(( ($VIASH_META_MEMORY_B+1023) / 1024 ))
    VIASH_META_MEMORY_MIB=$(( ($VIASH_META_MEMORY_KIB+1023) / 1024 ))
    VIASH_META_MEMORY_GIB=$(( ($VIASH_META_MEMORY_MIB+1023) / 1024 ))
    VIASH_META_MEMORY_TIB=$(( ($VIASH_META_MEMORY_GIB+1023) / 1024 ))
    VIASH_META_MEMORY_PIB=$(( ($VIASH_META_MEMORY_TIB+1023) / 1024 ))
  else
    # unset memory if string is empty
    unset $VIASH_META_MEMORY_B
  fi
fi
# unset nproc if string is empty
if [ -z "$VIASH_META_CPUS" ]; then
  unset $VIASH_META_CPUS
fi


# check whether required parameters exist
if [ -z ${VIASH_PAR_INPUT_FILE+x} ]; then
  ViashError '--input_file' is a required argument. Use "--help" to get more information on the parameters.
  exit 1
fi
if [ -z ${VIASH_PAR_OUTPUT_FILE+x} ]; then
  ViashError '--output_file' is a required argument. Use "--help" to get more information on the parameters.
  exit 1
fi
if [ -z ${VIASH_META_NAME+x} ]; then
  ViashError 'name' is a required argument. Use "--help" to get more information on the parameters.
  exit 1
fi
if [ -z ${VIASH_META_FUNCTIONALITY_NAME+x} ]; then
  ViashError 'functionality_name' is a required argument. Use "--help" to get more information on the parameters.
  exit 1
fi
if [ -z ${VIASH_META_RESOURCES_DIR+x} ]; then
  ViashError 'resources_dir' is a required argument. Use "--help" to get more information on the parameters.
  exit 1
fi
if [ -z ${VIASH_META_EXECUTABLE+x} ]; then
  ViashError 'executable' is a required argument. Use "--help" to get more information on the parameters.
  exit 1
fi
if [ -z ${VIASH_META_CONFIG+x} ]; then
  ViashError 'config' is a required argument. Use "--help" to get more information on the parameters.
  exit 1
fi
if [ -z ${VIASH_META_TEMP_DIR+x} ]; then
  ViashError 'temp_dir' is a required argument. Use "--help" to get more information on the parameters.
  exit 1
fi

# filling in defaults
if [ -z ${VIASH_PAR_FORMAT+x} ]; then
  VIASH_PAR_FORMAT="vcf"
fi
if [ -z ${VIASH_PAR_VCF+x} ]; then
  VIASH_PAR_VCF="false"
fi
if [ -z ${VIASH_PAR_SPECIES+x} ]; then
  VIASH_PAR_SPECIES="homo_sapiens"
fi
if [ -z ${VIASH_PAR_CACHE+x} ]; then
  VIASH_PAR_CACHE="false"
fi
if [ -z ${VIASH_PAR_DIR+x} ]; then
  VIASH_PAR_DIR="/root/.vep"
fi
if [ -z ${VIASH_PAR_OFFLINE+x} ]; then
  VIASH_PAR_OFFLINE="false"
fi
if [ -z ${VIASH_PAR_EVERYTHING+x} ]; then
  VIASH_PAR_EVERYTHING="false"
fi
if [ -z ${VIASH_PAR_CANONICAL+x} ]; then
  VIASH_PAR_CANONICAL="false"
fi
if [ -z ${VIASH_PAR_CCDS+x} ]; then
  VIASH_PAR_CCDS="false"
fi
if [ -z ${VIASH_PAR_PROTEIN+x} ]; then
  VIASH_PAR_PROTEIN="false"
fi
if [ -z ${VIASH_PAR_SYMBOL+x} ]; then
  VIASH_PAR_SYMBOL="false"
fi
if [ -z ${VIASH_PAR_HGVS+x} ]; then
  VIASH_PAR_HGVS="false"
fi
if [ -z ${VIASH_PAR_AF+x} ]; then
  VIASH_PAR_AF="false"
fi
if [ -z ${VIASH_PAR_AF_1KG+x} ]; then
  VIASH_PAR_AF_1KG="false"
fi
if [ -z ${VIASH_PAR_AF_GNOMAD+x} ]; then
  VIASH_PAR_AF_GNOMAD="false"
fi
if [ -z ${VIASH_PAR_MAX_AF+x} ]; then
  VIASH_PAR_MAX_AF="false"
fi
if [ -z ${VIASH_PAR_PICK+x} ]; then
  VIASH_PAR_PICK="false"
fi
if [ -z ${VIASH_PAR_PICK_ALLELE+x} ]; then
  VIASH_PAR_PICK_ALLELE="false"
fi
if [ -z ${VIASH_PAR_FLAG_PICK+x} ]; then
  VIASH_PAR_FLAG_PICK="false"
fi
if [ -z ${VIASH_PAR_PER_GENE+x} ]; then
  VIASH_PAR_PER_GENE="false"
fi
if [ -z ${VIASH_PAR_MOST_SEVERE+x} ]; then
  VIASH_PAR_MOST_SEVERE="false"
fi
if [ -z ${VIASH_PAR_SUMMARY+x} ]; then
  VIASH_PAR_SUMMARY="false"
fi
if [ -z ${VIASH_PAR_FILTER_COMMON+x} ]; then
  VIASH_PAR_FILTER_COMMON="false"
fi
if [ -z ${VIASH_PAR_BUFFER_SIZE+x} ]; then
  VIASH_PAR_BUFFER_SIZE="5000"
fi
if [ -z ${VIASH_PAR_NO_CHECK_VARIANTS_ORDER+x} ]; then
  VIASH_PAR_NO_CHECK_VARIANTS_ORDER="false"
fi
if [ -z ${VIASH_PAR_ALLOW_NON_VARIANT+x} ]; then
  VIASH_PAR_ALLOW_NON_VARIANT="false"
fi

# check whether required files exist
if [ ! -z "$VIASH_PAR_INPUT_FILE" ] && [ ! -e "$VIASH_PAR_INPUT_FILE" ]; then
  ViashError "Input file '$VIASH_PAR_INPUT_FILE' does not exist."
  exit 1
fi
if [ ! -z "$VIASH_PAR_DIR" ] && [ ! -e "$VIASH_PAR_DIR" ]; then
  ViashError "Input file '$VIASH_PAR_DIR' does not exist."
  exit 1
fi

# check whether parameters values are of the right type
if [[ -n "$VIASH_PAR_VCF" ]]; then
  if ! [[ "$VIASH_PAR_VCF" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--vcf' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_CACHE" ]]; then
  if ! [[ "$VIASH_PAR_CACHE" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--cache' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_CACHE_VERSION" ]]; then
  if ! [[ "$VIASH_PAR_CACHE_VERSION" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError '--cache_version' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_OFFLINE" ]]; then
  if ! [[ "$VIASH_PAR_OFFLINE" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--offline' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_EVERYTHING" ]]; then
  if ! [[ "$VIASH_PAR_EVERYTHING" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--everything' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_CANONICAL" ]]; then
  if ! [[ "$VIASH_PAR_CANONICAL" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--canonical' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_CCDS" ]]; then
  if ! [[ "$VIASH_PAR_CCDS" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--ccds' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_PROTEIN" ]]; then
  if ! [[ "$VIASH_PAR_PROTEIN" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--protein' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_SYMBOL" ]]; then
  if ! [[ "$VIASH_PAR_SYMBOL" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--symbol' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_HGVS" ]]; then
  if ! [[ "$VIASH_PAR_HGVS" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--hgvs' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_AF" ]]; then
  if ! [[ "$VIASH_PAR_AF" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--af' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_AF_1KG" ]]; then
  if ! [[ "$VIASH_PAR_AF_1KG" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--af_1kg' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_AF_GNOMAD" ]]; then
  if ! [[ "$VIASH_PAR_AF_GNOMAD" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--af_gnomad' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_MAX_AF" ]]; then
  if ! [[ "$VIASH_PAR_MAX_AF" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--max_af' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_PICK" ]]; then
  if ! [[ "$VIASH_PAR_PICK" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--pick' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_PICK_ALLELE" ]]; then
  if ! [[ "$VIASH_PAR_PICK_ALLELE" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--pick_allele' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_FLAG_PICK" ]]; then
  if ! [[ "$VIASH_PAR_FLAG_PICK" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--flag_pick' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_PER_GENE" ]]; then
  if ! [[ "$VIASH_PAR_PER_GENE" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--per_gene' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_MOST_SEVERE" ]]; then
  if ! [[ "$VIASH_PAR_MOST_SEVERE" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--most_severe' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_SUMMARY" ]]; then
  if ! [[ "$VIASH_PAR_SUMMARY" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--summary' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_FILTER_COMMON" ]]; then
  if ! [[ "$VIASH_PAR_FILTER_COMMON" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--filter_common' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_BUFFER_SIZE" ]]; then
  if ! [[ "$VIASH_PAR_BUFFER_SIZE" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError '--buffer_size' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_NO_CHECK_VARIANTS_ORDER" ]]; then
  if ! [[ "$VIASH_PAR_NO_CHECK_VARIANTS_ORDER" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--no_check_variants_order' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_ALLOW_NON_VARIANT" ]]; then
  if ! [[ "$VIASH_PAR_ALLOW_NON_VARIANT" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--allow_non_variant' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_META_CPUS" ]]; then
  if ! [[ "$VIASH_META_CPUS" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError 'cpus' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_META_MEMORY_B" ]]; then
  if ! [[ "$VIASH_META_MEMORY_B" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError 'memory_b' has to be a long. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_META_MEMORY_KB" ]]; then
  if ! [[ "$VIASH_META_MEMORY_KB" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError 'memory_kb' has to be a long. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_META_MEMORY_MB" ]]; then
  if ! [[ "$VIASH_META_MEMORY_MB" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError 'memory_mb' has to be a long. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_META_MEMORY_GB" ]]; then
  if ! [[ "$VIASH_META_MEMORY_GB" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError 'memory_gb' has to be a long. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_META_MEMORY_TB" ]]; then
  if ! [[ "$VIASH_META_MEMORY_TB" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError 'memory_tb' has to be a long. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_META_MEMORY_PB" ]]; then
  if ! [[ "$VIASH_META_MEMORY_PB" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError 'memory_pb' has to be a long. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_META_MEMORY_KIB" ]]; then
  if ! [[ "$VIASH_META_MEMORY_KIB" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError 'memory_kib' has to be a long. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_META_MEMORY_MIB" ]]; then
  if ! [[ "$VIASH_META_MEMORY_MIB" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError 'memory_mib' has to be a long. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_META_MEMORY_GIB" ]]; then
  if ! [[ "$VIASH_META_MEMORY_GIB" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError 'memory_gib' has to be a long. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_META_MEMORY_TIB" ]]; then
  if ! [[ "$VIASH_META_MEMORY_TIB" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError 'memory_tib' has to be a long. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_META_MEMORY_PIB" ]]; then
  if ! [[ "$VIASH_META_MEMORY_PIB" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError 'memory_pib' has to be a long. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi

# check whether value is belongs to a set of choices
if [ ! -z "$VIASH_PAR_FORMAT" ]; then
  VIASH_PAR_FORMAT_CHOICES=("vcf;variant_identifier;hgvs;id;region;spdi;vep")
  IFS=';'
  set -f
  if ! [[ ";${VIASH_PAR_FORMAT_CHOICES[*]};" =~ ";$VIASH_PAR_FORMAT;" ]]; then
    ViashError '--format' specified value of \'$VIASH_PAR_FORMAT\' is not in the list of allowed values. Use "--help" to get more information on the parameters.
    exit 1
  fi
  set +f
  unset IFS
fi

if [ ! -z "$VIASH_PAR_SIFT" ]; then
  VIASH_PAR_SIFT_CHOICES=("p;s;b")
  IFS=';'
  set -f
  if ! [[ ";${VIASH_PAR_SIFT_CHOICES[*]};" =~ ";$VIASH_PAR_SIFT;" ]]; then
    ViashError '--sift' specified value of \'$VIASH_PAR_SIFT\' is not in the list of allowed values. Use "--help" to get more information on the parameters.
    exit 1
  fi
  set +f
  unset IFS
fi

if [ ! -z "$VIASH_PAR_POLYPHEN" ]; then
  VIASH_PAR_POLYPHEN_CHOICES=("p;s;b")
  IFS=';'
  set -f
  if ! [[ ";${VIASH_PAR_POLYPHEN_CHOICES[*]};" =~ ";$VIASH_PAR_POLYPHEN;" ]]; then
    ViashError '--polyphen' specified value of \'$VIASH_PAR_POLYPHEN\' is not in the list of allowed values. Use "--help" to get more information on the parameters.
    exit 1
  fi
  set +f
  unset IFS
fi

# create parent directories of output files, if so desired
if [ ! -z "$VIASH_PAR_OUTPUT_FILE" ] && [ ! -d "$(dirname "$VIASH_PAR_OUTPUT_FILE")" ]; then
  mkdir -p "$(dirname "$VIASH_PAR_OUTPUT_FILE")"
fi

if  [ "$VIASH_ENGINE_ID" == "native" ]  ; then
  if [ "$VIASH_MODE" == "run" ]; then
    VIASH_CMD="bash"
  else
    ViashError "Engine '$VIASH_ENGINE_ID' does not support mode '$VIASH_MODE'."
    exit 1
  fi
fi

if [[ "$VIASH_ENGINE_TYPE" == "docker" ]]; then
  # detect volumes from file arguments
  VIASH_CHOWN_VARS=()
if [ ! -z "$VIASH_PAR_INPUT_FILE" ]; then
  VIASH_DIRECTORY_MOUNTS+=( "$(ViashDockerAutodetectMountArg "$VIASH_PAR_INPUT_FILE")" )
  VIASH_PAR_INPUT_FILE=$(ViashDockerAutodetectMount "$VIASH_PAR_INPUT_FILE")
fi
if [ ! -z "$VIASH_PAR_OUTPUT_FILE" ]; then
  VIASH_DIRECTORY_MOUNTS+=( "$(ViashDockerAutodetectMountArg "$VIASH_PAR_OUTPUT_FILE")" )
  VIASH_PAR_OUTPUT_FILE=$(ViashDockerAutodetectMount "$VIASH_PAR_OUTPUT_FILE")
  VIASH_CHOWN_VARS+=( "$VIASH_PAR_OUTPUT_FILE" )
fi
if [ ! -z "$VIASH_PAR_DIR" ]; then
  VIASH_DIRECTORY_MOUNTS+=( "$(ViashDockerAutodetectMountArg "$VIASH_PAR_DIR")" )
  VIASH_PAR_DIR=$(ViashDockerAutodetectMount "$VIASH_PAR_DIR")
fi
if [ ! -z "$VIASH_META_RESOURCES_DIR" ]; then
  VIASH_DIRECTORY_MOUNTS+=( "$(ViashDockerAutodetectMountArg "$VIASH_META_RESOURCES_DIR")" )
  VIASH_META_RESOURCES_DIR=$(ViashDockerAutodetectMount "$VIASH_META_RESOURCES_DIR")
fi
if [ ! -z "$VIASH_META_EXECUTABLE" ]; then
  VIASH_DIRECTORY_MOUNTS+=( "$(ViashDockerAutodetectMountArg "$VIASH_META_EXECUTABLE")" )
  VIASH_META_EXECUTABLE=$(ViashDockerAutodetectMount "$VIASH_META_EXECUTABLE")
fi
if [ ! -z "$VIASH_META_CONFIG" ]; then
  VIASH_DIRECTORY_MOUNTS+=( "$(ViashDockerAutodetectMountArg "$VIASH_META_CONFIG")" )
  VIASH_META_CONFIG=$(ViashDockerAutodetectMount "$VIASH_META_CONFIG")
fi
if [ ! -z "$VIASH_META_TEMP_DIR" ]; then
  VIASH_DIRECTORY_MOUNTS+=( "$(ViashDockerAutodetectMountArg "$VIASH_META_TEMP_DIR")" )
  VIASH_META_TEMP_DIR=$(ViashDockerAutodetectMount "$VIASH_META_TEMP_DIR")
fi
  
  # get unique mounts
  VIASH_UNIQUE_MOUNTS=($(for val in "${VIASH_DIRECTORY_MOUNTS[@]}"; do echo "$val"; done | sort -u))
fi

if [[ "$VIASH_ENGINE_TYPE" == "docker" ]]; then
  # change file ownership
  function ViashPerformChown {
    if (( ${#VIASH_CHOWN_VARS[@]} )); then
      set +e
      VIASH_CMD="docker run --entrypoint=bash --rm ${VIASH_UNIQUE_MOUNTS[@]} $VIASH_DOCKER_IMAGE_ID -c 'chown $(id -u):$(id -g) --silent --recursive ${VIASH_CHOWN_VARS[@]}'"
      ViashDebug "+ $VIASH_CMD"
      eval $VIASH_CMD
      set -e
    fi
  }
  trap ViashPerformChown EXIT
fi

if [[ "$VIASH_ENGINE_TYPE" == "docker" ]]; then
  # helper function for filling in extra docker args
  if [ ! -z "$VIASH_META_MEMORY_B" ]; then
    VIASH_DOCKER_RUN_ARGS+=("--memory=${VIASH_META_MEMORY_B}")
  fi
  if [ ! -z "$VIASH_META_CPUS" ]; then
    VIASH_DOCKER_RUN_ARGS+=("--cpus=${VIASH_META_CPUS}")
  fi
fi

if [[ "$VIASH_ENGINE_TYPE" == "docker" ]]; then
  VIASH_CMD="docker run --entrypoint=bash ${VIASH_DOCKER_RUN_ARGS[@]} ${VIASH_UNIQUE_MOUNTS[@]} $VIASH_DOCKER_IMAGE_ID"
fi


# set dependency paths


ViashDebug "Running command: $(echo $VIASH_CMD)"
cat << VIASHEOF | eval $VIASH_CMD
set -e
tempscript=\$(mktemp "$VIASH_META_TEMP_DIR/viash-run-vep-XXXXXX").sh
function clean_up {
  rm "\$tempscript"
}
function interrupt {
  echo -e "\nCTRL-C Pressed..."
  exit 1
}
trap clean_up EXIT
trap interrupt INT SIGINT
cat > "\$tempscript" << 'VIASHMAIN'
#!/bin/bash

## VIASH START
# The following code has been auto-generated by Viash.
$( if [ ! -z ${VIASH_PAR_INPUT_FILE+x} ]; then echo "${VIASH_PAR_INPUT_FILE}" | sed "s#'#'\"'\"'#g;s#.*#par_input_file='&'#" ; else echo "# par_input_file="; fi )
$( if [ ! -z ${VIASH_PAR_FORMAT+x} ]; then echo "${VIASH_PAR_FORMAT}" | sed "s#'#'\"'\"'#g;s#.*#par_format='&'#" ; else echo "# par_format="; fi )
$( if [ ! -z ${VIASH_PAR_OUTPUT_FILE+x} ]; then echo "${VIASH_PAR_OUTPUT_FILE}" | sed "s#'#'\"'\"'#g;s#.*#par_output_file='&'#" ; else echo "# par_output_file="; fi )
$( if [ ! -z ${VIASH_PAR_VCF+x} ]; then echo "${VIASH_PAR_VCF}" | sed "s#'#'\"'\"'#g;s#.*#par_vcf='&'#" ; else echo "# par_vcf="; fi )
$( if [ ! -z ${VIASH_PAR_SPECIES+x} ]; then echo "${VIASH_PAR_SPECIES}" | sed "s#'#'\"'\"'#g;s#.*#par_species='&'#" ; else echo "# par_species="; fi )
$( if [ ! -z ${VIASH_PAR_ASSEMBLY+x} ]; then echo "${VIASH_PAR_ASSEMBLY}" | sed "s#'#'\"'\"'#g;s#.*#par_assembly='&'#" ; else echo "# par_assembly="; fi )
$( if [ ! -z ${VIASH_PAR_CACHE+x} ]; then echo "${VIASH_PAR_CACHE}" | sed "s#'#'\"'\"'#g;s#.*#par_cache='&'#" ; else echo "# par_cache="; fi )
$( if [ ! -z ${VIASH_PAR_DIR+x} ]; then echo "${VIASH_PAR_DIR}" | sed "s#'#'\"'\"'#g;s#.*#par_dir='&'#" ; else echo "# par_dir="; fi )
$( if [ ! -z ${VIASH_PAR_CACHE_VERSION+x} ]; then echo "${VIASH_PAR_CACHE_VERSION}" | sed "s#'#'\"'\"'#g;s#.*#par_cache_version='&'#" ; else echo "# par_cache_version="; fi )
$( if [ ! -z ${VIASH_PAR_OFFLINE+x} ]; then echo "${VIASH_PAR_OFFLINE}" | sed "s#'#'\"'\"'#g;s#.*#par_offline='&'#" ; else echo "# par_offline="; fi )
$( if [ ! -z ${VIASH_PAR_EVERYTHING+x} ]; then echo "${VIASH_PAR_EVERYTHING}" | sed "s#'#'\"'\"'#g;s#.*#par_everything='&'#" ; else echo "# par_everything="; fi )
$( if [ ! -z ${VIASH_PAR_CANONICAL+x} ]; then echo "${VIASH_PAR_CANONICAL}" | sed "s#'#'\"'\"'#g;s#.*#par_canonical='&'#" ; else echo "# par_canonical="; fi )
$( if [ ! -z ${VIASH_PAR_CCDS+x} ]; then echo "${VIASH_PAR_CCDS}" | sed "s#'#'\"'\"'#g;s#.*#par_ccds='&'#" ; else echo "# par_ccds="; fi )
$( if [ ! -z ${VIASH_PAR_PROTEIN+x} ]; then echo "${VIASH_PAR_PROTEIN}" | sed "s#'#'\"'\"'#g;s#.*#par_protein='&'#" ; else echo "# par_protein="; fi )
$( if [ ! -z ${VIASH_PAR_SYMBOL+x} ]; then echo "${VIASH_PAR_SYMBOL}" | sed "s#'#'\"'\"'#g;s#.*#par_symbol='&'#" ; else echo "# par_symbol="; fi )
$( if [ ! -z ${VIASH_PAR_HGVS+x} ]; then echo "${VIASH_PAR_HGVS}" | sed "s#'#'\"'\"'#g;s#.*#par_hgvs='&'#" ; else echo "# par_hgvs="; fi )
$( if [ ! -z ${VIASH_PAR_SIFT+x} ]; then echo "${VIASH_PAR_SIFT}" | sed "s#'#'\"'\"'#g;s#.*#par_sift='&'#" ; else echo "# par_sift="; fi )
$( if [ ! -z ${VIASH_PAR_POLYPHEN+x} ]; then echo "${VIASH_PAR_POLYPHEN}" | sed "s#'#'\"'\"'#g;s#.*#par_polyphen='&'#" ; else echo "# par_polyphen="; fi )
$( if [ ! -z ${VIASH_PAR_AF+x} ]; then echo "${VIASH_PAR_AF}" | sed "s#'#'\"'\"'#g;s#.*#par_af='&'#" ; else echo "# par_af="; fi )
$( if [ ! -z ${VIASH_PAR_AF_1KG+x} ]; then echo "${VIASH_PAR_AF_1KG}" | sed "s#'#'\"'\"'#g;s#.*#par_af_1kg='&'#" ; else echo "# par_af_1kg="; fi )
$( if [ ! -z ${VIASH_PAR_AF_GNOMAD+x} ]; then echo "${VIASH_PAR_AF_GNOMAD}" | sed "s#'#'\"'\"'#g;s#.*#par_af_gnomad='&'#" ; else echo "# par_af_gnomad="; fi )
$( if [ ! -z ${VIASH_PAR_MAX_AF+x} ]; then echo "${VIASH_PAR_MAX_AF}" | sed "s#'#'\"'\"'#g;s#.*#par_max_af='&'#" ; else echo "# par_max_af="; fi )
$( if [ ! -z ${VIASH_PAR_PICK+x} ]; then echo "${VIASH_PAR_PICK}" | sed "s#'#'\"'\"'#g;s#.*#par_pick='&'#" ; else echo "# par_pick="; fi )
$( if [ ! -z ${VIASH_PAR_PICK_ALLELE+x} ]; then echo "${VIASH_PAR_PICK_ALLELE}" | sed "s#'#'\"'\"'#g;s#.*#par_pick_allele='&'#" ; else echo "# par_pick_allele="; fi )
$( if [ ! -z ${VIASH_PAR_FLAG_PICK+x} ]; then echo "${VIASH_PAR_FLAG_PICK}" | sed "s#'#'\"'\"'#g;s#.*#par_flag_pick='&'#" ; else echo "# par_flag_pick="; fi )
$( if [ ! -z ${VIASH_PAR_PER_GENE+x} ]; then echo "${VIASH_PAR_PER_GENE}" | sed "s#'#'\"'\"'#g;s#.*#par_per_gene='&'#" ; else echo "# par_per_gene="; fi )
$( if [ ! -z ${VIASH_PAR_PICK_ORDER+x} ]; then echo "${VIASH_PAR_PICK_ORDER}" | sed "s#'#'\"'\"'#g;s#.*#par_pick_order='&'#" ; else echo "# par_pick_order="; fi )
$( if [ ! -z ${VIASH_PAR_MOST_SEVERE+x} ]; then echo "${VIASH_PAR_MOST_SEVERE}" | sed "s#'#'\"'\"'#g;s#.*#par_most_severe='&'#" ; else echo "# par_most_severe="; fi )
$( if [ ! -z ${VIASH_PAR_SUMMARY+x} ]; then echo "${VIASH_PAR_SUMMARY}" | sed "s#'#'\"'\"'#g;s#.*#par_summary='&'#" ; else echo "# par_summary="; fi )
$( if [ ! -z ${VIASH_PAR_FILTER_COMMON+x} ]; then echo "${VIASH_PAR_FILTER_COMMON}" | sed "s#'#'\"'\"'#g;s#.*#par_filter_common='&'#" ; else echo "# par_filter_common="; fi )
$( if [ ! -z ${VIASH_PAR_BUFFER_SIZE+x} ]; then echo "${VIASH_PAR_BUFFER_SIZE}" | sed "s#'#'\"'\"'#g;s#.*#par_buffer_size='&'#" ; else echo "# par_buffer_size="; fi )
$( if [ ! -z ${VIASH_PAR_NO_CHECK_VARIANTS_ORDER+x} ]; then echo "${VIASH_PAR_NO_CHECK_VARIANTS_ORDER}" | sed "s#'#'\"'\"'#g;s#.*#par_no_check_variants_order='&'#" ; else echo "# par_no_check_variants_order="; fi )
$( if [ ! -z ${VIASH_PAR_ALLOW_NON_VARIANT+x} ]; then echo "${VIASH_PAR_ALLOW_NON_VARIANT}" | sed "s#'#'\"'\"'#g;s#.*#par_allow_non_variant='&'#" ; else echo "# par_allow_non_variant="; fi )
$( if [ ! -z ${VIASH_META_NAME+x} ]; then echo "${VIASH_META_NAME}" | sed "s#'#'\"'\"'#g;s#.*#meta_name='&'#" ; else echo "# meta_name="; fi )
$( if [ ! -z ${VIASH_META_FUNCTIONALITY_NAME+x} ]; then echo "${VIASH_META_FUNCTIONALITY_NAME}" | sed "s#'#'\"'\"'#g;s#.*#meta_functionality_name='&'#" ; else echo "# meta_functionality_name="; fi )
$( if [ ! -z ${VIASH_META_RESOURCES_DIR+x} ]; then echo "${VIASH_META_RESOURCES_DIR}" | sed "s#'#'\"'\"'#g;s#.*#meta_resources_dir='&'#" ; else echo "# meta_resources_dir="; fi )
$( if [ ! -z ${VIASH_META_EXECUTABLE+x} ]; then echo "${VIASH_META_EXECUTABLE}" | sed "s#'#'\"'\"'#g;s#.*#meta_executable='&'#" ; else echo "# meta_executable="; fi )
$( if [ ! -z ${VIASH_META_CONFIG+x} ]; then echo "${VIASH_META_CONFIG}" | sed "s#'#'\"'\"'#g;s#.*#meta_config='&'#" ; else echo "# meta_config="; fi )
$( if [ ! -z ${VIASH_META_TEMP_DIR+x} ]; then echo "${VIASH_META_TEMP_DIR}" | sed "s#'#'\"'\"'#g;s#.*#meta_temp_dir='&'#" ; else echo "# meta_temp_dir="; fi )
$( if [ ! -z ${VIASH_META_CPUS+x} ]; then echo "${VIASH_META_CPUS}" | sed "s#'#'\"'\"'#g;s#.*#meta_cpus='&'#" ; else echo "# meta_cpus="; fi )
$( if [ ! -z ${VIASH_META_MEMORY_B+x} ]; then echo "${VIASH_META_MEMORY_B}" | sed "s#'#'\"'\"'#g;s#.*#meta_memory_b='&'#" ; else echo "# meta_memory_b="; fi )
$( if [ ! -z ${VIASH_META_MEMORY_KB+x} ]; then echo "${VIASH_META_MEMORY_KB}" | sed "s#'#'\"'\"'#g;s#.*#meta_memory_kb='&'#" ; else echo "# meta_memory_kb="; fi )
$( if [ ! -z ${VIASH_META_MEMORY_MB+x} ]; then echo "${VIASH_META_MEMORY_MB}" | sed "s#'#'\"'\"'#g;s#.*#meta_memory_mb='&'#" ; else echo "# meta_memory_mb="; fi )
$( if [ ! -z ${VIASH_META_MEMORY_GB+x} ]; then echo "${VIASH_META_MEMORY_GB}" | sed "s#'#'\"'\"'#g;s#.*#meta_memory_gb='&'#" ; else echo "# meta_memory_gb="; fi )
$( if [ ! -z ${VIASH_META_MEMORY_TB+x} ]; then echo "${VIASH_META_MEMORY_TB}" | sed "s#'#'\"'\"'#g;s#.*#meta_memory_tb='&'#" ; else echo "# meta_memory_tb="; fi )
$( if [ ! -z ${VIASH_META_MEMORY_PB+x} ]; then echo "${VIASH_META_MEMORY_PB}" | sed "s#'#'\"'\"'#g;s#.*#meta_memory_pb='&'#" ; else echo "# meta_memory_pb="; fi )
$( if [ ! -z ${VIASH_META_MEMORY_KIB+x} ]; then echo "${VIASH_META_MEMORY_KIB}" | sed "s#'#'\"'\"'#g;s#.*#meta_memory_kib='&'#" ; else echo "# meta_memory_kib="; fi )
$( if [ ! -z ${VIASH_META_MEMORY_MIB+x} ]; then echo "${VIASH_META_MEMORY_MIB}" | sed "s#'#'\"'\"'#g;s#.*#meta_memory_mib='&'#" ; else echo "# meta_memory_mib="; fi )
$( if [ ! -z ${VIASH_META_MEMORY_GIB+x} ]; then echo "${VIASH_META_MEMORY_GIB}" | sed "s#'#'\"'\"'#g;s#.*#meta_memory_gib='&'#" ; else echo "# meta_memory_gib="; fi )
$( if [ ! -z ${VIASH_META_MEMORY_TIB+x} ]; then echo "${VIASH_META_MEMORY_TIB}" | sed "s#'#'\"'\"'#g;s#.*#meta_memory_tib='&'#" ; else echo "# meta_memory_tib="; fi )
$( if [ ! -z ${VIASH_META_MEMORY_PIB+x} ]; then echo "${VIASH_META_MEMORY_PIB}" | sed "s#'#'\"'\"'#g;s#.*#meta_memory_pib='&'#" ; else echo "# meta_memory_pib="; fi )

## VIASH END

set -eo pipefail

# Unset false boolean parameters (biobox standard)
[[ "\$par_vcf" == "false" ]] && unset par_vcf
[[ "\$par_cache" == "false" ]] && unset par_cache
[[ "\$par_offline" == "false" ]] && unset par_offline
[[ "\$par_everything" == "false" ]] && unset par_everything
[[ "\$par_canonical" == "false" ]] && unset par_canonical
[[ "\$par_ccds" == "false" ]] && unset par_ccds
[[ "\$par_protein" == "false" ]] && unset par_protein
[[ "\$par_symbol" == "false" ]] && unset par_symbol
[[ "\$par_hgvs" == "false" ]] && unset par_hgvs
[[ "\$par_af" == "false" ]] && unset par_af
[[ "\$par_af_1kg" == "false" ]] && unset par_af_1kg
[[ "\$par_af_gnomad" == "false" ]] && unset par_af_gnomad
[[ "\$par_max_af" == "false" ]] && unset par_max_af
[[ "\$par_pick" == "false" ]] && unset par_pick
[[ "\$par_pick_allele" == "false" ]] && unset par_pick_allele
[[ "\$par_flag_pick" == "false" ]] && unset par_flag_pick
[[ "\$par_per_gene" == "false" ]] && unset par_per_gene
[[ "\$par_most_severe" == "false" ]] && unset par_most_severe
[[ "\$par_summary" == "false" ]] && unset par_summary
[[ "\$par_filter_common" == "false" ]] && unset par_filter_common
[[ "\$par_no_check_variants_order" == "false" ]] && unset par_no_check_variants_order
[[ "\$par_allow_non_variant" == "false" ]] && unset par_allow_non_variant

# Build command array (preferred pattern)
cmd_args=(
  vep
  --input_file "\$par_input_file"
  --output_file "\$par_output_file"
  \${par_format:+--format "\$par_format"}
  \${par_vcf:+--vcf}
  \${par_species:+--species "\$par_species"}
  \${par_assembly:+--assembly "\$par_assembly"}
  \${par_cache:+--cache}
  \${par_dir:+--dir "\$par_dir"}
  \${par_cache_version:+--cache_version "\$par_cache_version"}
  \${par_offline:+--offline}
  \${par_everything:+--everything}
  \${par_canonical:+--canonical}
  \${par_ccds:+--ccds}
  \${par_protein:+--protein}
  \${par_symbol:+--symbol}
  \${par_hgvs:+--hgvs}
  \${par_sift:+--sift "\$par_sift"}
  \${par_polyphen:+--polyphen "\$par_polyphen"}
  \${par_af:+--af}
  \${par_af_1kg:+--af_1kg}
  \${par_af_gnomad:+--af_gnomad}
  \${par_max_af:+--max_af}
  \${par_pick:+--pick}
  \${par_pick_allele:+--pick_allele}
  \${par_flag_pick:+--flag_pick}
  \${par_per_gene:+--per_gene}
  \${par_pick_order:+--pick_order "\$par_pick_order"}
  \${par_most_severe:+--most_severe}
  \${par_summary:+--summary}
  \${par_filter_common:+--filter_common}
  \${par_buffer_size:+--buffer_size "\$par_buffer_size"}
  \${par_no_check_variants_order:+--no_check_variants_order}
  \${par_allow_non_variant:+--allow_non_variant}
  \${meta_cpus:+--fork "\$meta_cpus"}
)

# Execute command
"\${cmd_args[@]}"
VIASHMAIN
bash "\$tempscript" &
wait "\$!"

VIASHEOF


if [[ "$VIASH_ENGINE_TYPE" == "docker" ]]; then
  # strip viash automount from file paths
  
  if [ ! -z "$VIASH_PAR_INPUT_FILE" ]; then
    VIASH_PAR_INPUT_FILE=$(ViashDockerStripAutomount "$VIASH_PAR_INPUT_FILE")
  fi
  if [ ! -z "$VIASH_PAR_OUTPUT_FILE" ]; then
    VIASH_PAR_OUTPUT_FILE=$(ViashDockerStripAutomount "$VIASH_PAR_OUTPUT_FILE")
  fi
  if [ ! -z "$VIASH_PAR_DIR" ]; then
    VIASH_PAR_DIR=$(ViashDockerStripAutomount "$VIASH_PAR_DIR")
  fi
  if [ ! -z "$VIASH_META_RESOURCES_DIR" ]; then
    VIASH_META_RESOURCES_DIR=$(ViashDockerStripAutomount "$VIASH_META_RESOURCES_DIR")
  fi
  if [ ! -z "$VIASH_META_EXECUTABLE" ]; then
    VIASH_META_EXECUTABLE=$(ViashDockerStripAutomount "$VIASH_META_EXECUTABLE")
  fi
  if [ ! -z "$VIASH_META_CONFIG" ]; then
    VIASH_META_CONFIG=$(ViashDockerStripAutomount "$VIASH_META_CONFIG")
  fi
  if [ ! -z "$VIASH_META_TEMP_DIR" ]; then
    VIASH_META_TEMP_DIR=$(ViashDockerStripAutomount "$VIASH_META_TEMP_DIR")
  fi
fi


# check whether required files exist
if [ ! -z "$VIASH_PAR_OUTPUT_FILE" ] && [ ! -e "$VIASH_PAR_OUTPUT_FILE" ]; then
  ViashError "Output file '$VIASH_PAR_OUTPUT_FILE' does not exist."
  exit 1
fi


exit 0
