#!/usr/bin/env bash

# freebayes v4.0.4
# 
# 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:
#  * Xichen Wu (author)

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="freebayes"
VIASH_META_FUNCTIONALITY_NAME="freebayes"
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 debian:latest
ENTRYPOINT []
RUN apt-get update && \
  DEBIAN_FRONTEND=noninteractive apt-get install -y freebayes && \
  rm -rf /var/lib/apt/lists/*

LABEL org.opencontainers.image.authors="Xichen Wu"
LABEL org.opencontainers.image.description="Companion container for running component genetic_demux freebayes"
LABEL org.opencontainers.image.created="2026-03-17T13:31:38Z"
LABEL org.opencontainers.image.source="https://github.com/openpipelines-bio/openpipeline"
LABEL org.opencontainers.image.revision="fb7dc76676aa63d06ae1421bbdd6312ad4f67312"
LABEL org.opencontainers.image.version="v4.0.4"

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 "freebayes v4.0.4"
  echo ""
  echo "Freebayes is a Bayesian genetic variant detector designed to"
  echo "find small polymorphisms, specifically SNPs."
  echo ""
  echo "Input:"
  echo "    --bam"
  echo "        type: file, file must exist"
  echo "        Add FILE to the set of BAM files to be analyzed."
  echo ""
  echo "    --bam_list"
  echo "        type: file, file must exist"
  echo "        A file containing a list of BAM files to be analyzed."
  echo ""
  echo "    --stdin"
  echo "        type: boolean_true"
  echo "        Read BAM input on stdin."
  echo ""
  echo "    --fasta_reference"
  echo "        type: file, file must exist"
  echo "        Use FILE as the reference sequence for analysis. An index file"
  echo "        (FILE.fai) will be created if none exists. If neither --targets nor"
  echo "        --region are specified, FreeBayes will analyze every position in this"
  echo "        reference."
  echo ""
  echo "    --fasta_reference_index"
  echo "        type: file, file must exist"
  echo "        Use FILE.fai as the index of reference sequence for analysis."
  echo ""
  echo "    --targets"
  echo "        type: file, file must exist"
  echo "        Limit analysis to targets listed in the BED-format FILE."
  echo ""
  echo "    --region"
  echo "        type: string"
  echo "        Limit analysis to the specified region, 0-base coordinates, end_position"
  echo "        not included (same as BED format)."
  echo ""
  echo "    --samples"
  echo "        type: file, file must exist"
  echo "        Limit analysis to samples listed (one per line) in the FILE. By default"
  echo "        FreeBayes will analyze all samples in its input BAM files."
  echo ""
  echo "    --populations"
  echo "        type: file, file must exist"
  echo "        Each line of FILE should list a sample and a population which it is part"
  echo "        of. The population-based bayesian inference model will then be"
  echo "        partitioned on the basis of the populations."
  echo ""
  echo "    --cnv_map"
  echo "        type: file, file must exist"
  echo "        Read a copy number map from the BED file FILE, which has either a"
  echo "        sample-level ploidy or a region-specific format."
  echo ""
  echo "    --gvcf"
  echo "        type: boolean_true"
  echo "        Write gVCF output, which indicates coverage in uncalled regions."
  echo ""
  echo "    --gvcf_chunk"
  echo "        type: integer"
  echo "        When writing gVCF output emit a record for every NUM bases."
  echo ""
  echo "    --variant_input"
  echo "        type: file, file must exist"
  echo "        Use variants reported in VCF file as input to the algorithm. Variants in"
  echo "        this file will included in the output even if there is not enough"
  echo "        support in the data to pass input filters."
  echo ""
  echo "    --only_use_input_alleles"
  echo "        type: boolean_true"
  echo "        Only provide variant calls and genotype likelihoods for sites and"
  echo "        alleles which are provided in the VCF input, and provide output in the"
  echo "        VCF for all input alleles, not just those which have support in the"
  echo "        data."
  echo ""
  echo "    --haplotype_basis_alleles"
  echo "        type: file, file must exist"
  echo "        When specified, only variant alleles provided in this input VCF will be"
  echo "        used for the construction of complex or haplotype alleles."
  echo ""
  echo "    --report_all_haplotype_alleles"
  echo "        type: boolean_true"
  echo "        At sites where genotypes are made over haplotype alleles, provide"
  echo "        information about all alleles in output, not only those which are"
  echo "        called."
  echo ""
  echo "    --report_monomorphic"
  echo "        type: boolean_true"
  echo "        Report even loci which appear to be monomorphic, and report all"
  echo "        considered alleles, even those which are not in called genotypes."
  echo ""
  echo "    --pvar"
  echo "        type: double"
  echo "        default: 0.0"
  echo "        Report sites if the probability that there is a polymorphism at the site"
  echo "        is greater than N. Note that post-filtering is generally recommended"
  echo "        over the use of this parameter."
  echo ""
  echo "    --strict_vcf"
  echo "        type: boolean_true"
  echo "        Generate strict VCF format (FORMAT/GQ will be an int)."
  echo ""
  echo "    --theta"
  echo "        type: double"
  echo "        default: 0.001"
  echo "        The expected mutation rate or pairwise nucleotide diversity among the"
  echo "        population under analysis. This serves as the single parameter to the"
  echo "        Ewens Sampling Formula prior model."
  echo ""
  echo "    --ploidy"
  echo "        type: integer"
  echo "        default: 2"
  echo "        Sets the default ploidy for the analysis to N."
  echo ""
  echo "    --pooled_discrete"
  echo "        type: boolean_true"
  echo "        Assume that samples result from pooled sequencing. Model pooled samples"
  echo "        using discrete genotypes across pools."
  echo ""
  echo "    --pooled_continuous"
  echo "        type: boolean_true"
  echo "        Output all alleles which pass input filters, regardles of genotyping"
  echo "        outcome or model."
  echo ""
  echo "    --use_reference_allele"
  echo "        type: boolean_true"
  echo "        This flag includes the reference allele in the analysis as if it is"
  echo "        another sample from the same population."
  echo ""
  echo "    --reference_quality"
  echo "        type: string"
  echo "        default: 100,60"
  echo "        Assign mapping quality of MQ to the reference allele at each site and"
  echo "        base quality of BQ."
  echo ""
  echo "    --throw_away_snp_obs"
  echo "        type: boolean_true"
  echo "        Ignore SNP alleles."
  echo ""
  echo "    --throw_away_mnps_obs"
  echo "        type: boolean_false"
  echo "        Ignore multi-nuceotide polymorphisms, MNPs. MNPs are excluded as"
  echo "        default."
  echo ""
  echo "    --throw_away_indel_obs"
  echo "        type: boolean_false"
  echo "        Ignore insertion and deletion alleles. Indels are excluded as default."
  echo ""
  echo "    --throw_away_complex_obs"
  echo "        type: boolean_false"
  echo "        Ignore complex events (composites of other classes). Complex are"
  echo "        excluded as default"
  echo ""
  echo "    --use_best_n_alleles"
  echo "        type: integer"
  echo "        default: 0"
  echo "        Evaluate only the best N SNP alleles, ranked by sum of supporting"
  echo "        quality scores."
  echo ""
  echo "    --max_complex_gap"
  echo "        type: integer"
  echo "        default: 3"
  echo "        Allow haplotype calls with contiguous embedded matches of up to this"
  echo "        length."
  echo ""
  echo "    --min_repeat_size"
  echo "        type: integer"
  echo "        default: 5"
  echo "        When assembling observations across repeats, require the total repeat"
  echo "        length at least this many bp."
  echo ""
  echo "    --min_repeat_entropy"
  echo "        type: integer"
  echo "        default: 1"
  echo "        To detect interrupted repeats, build across sequence until it has"
  echo "        entropy > N bits per bp. Set to 0 to turn off."
  echo ""
  echo "    --no_partial_observations"
  echo "        type: boolean_true"
  echo "        Exclude observations which do not fully span the dynamically-determined"
  echo "        detection window.  (default, use all observations, dividing partial"
  echo "        support across matching haplotypes when generating haplotypes.)"
  echo ""
  echo "    --dont_left_align_indels"
  echo "        type: boolean_true"
  echo "        Turn off left-alignment of indels, which is enabled by default."
  echo ""
  echo "    --use_duplicate_reads"
  echo "        type: boolean_true"
  echo "        Include duplicate-marked alignments in the analysis. default: exclude"
  echo "        duplicates marked as such in alignments"
  echo ""
  echo "    --min_mapping_quality"
  echo "        type: integer"
  echo "        default: 1"
  echo "        Exclude alignments from analysis if they have a mapping quality less"
  echo "        than Q."
  echo ""
  echo "    --min_base_quality"
  echo "        type: integer"
  echo "        default: 1"
  echo "        Exclude alleles from analysis if their supporting base quality is less"
  echo "        than Q. Default value is changed according to the instruction of"
  echo "        scSplit."
  echo ""
  echo "    --min_supporting_allele_qsum"
  echo "        type: integer"
  echo "        default: 0"
  echo "        Consider any allele in which the sum of qualities of supporting"
  echo "        observations is at least Q."
  echo ""
  echo "    --min_supporting_mapping_qsum"
  echo "        type: integer"
  echo "        default: 0"
  echo "        Consider any allele in which and the sum of mapping qualities of"
  echo "        supporting reads is at least."
  echo ""
  echo "    --mismatch_base_quality_threshold"
  echo "        type: integer"
  echo "        default: 10"
  echo "        Count mismatches toward --read-mismatch-limit if the base quality of the"
  echo "        mismatch is >= Q."
  echo ""
  echo "    --read_max_mismatch_fraction"
  echo "        type: double"
  echo "        default: 1.0"
  echo "        Exclude reads with more than N mismatches where each mismatch has base"
  echo "        quality >= mismatch-base-quality-threshold."
  echo ""
  echo "    --read_mismatch_limit"
  echo "        type: integer"
  echo "        Exclude reads with more than N [0,1] fraction of mismatches where each"
  echo "        mismatch has base quality >= mismatch-base-quality-threshold."
  echo ""
  echo "    --read_snp_limit"
  echo "        type: integer"
  echo "        Exclude reads with more than N base mismatches, ignoring gaps with"
  echo "        quality >= mismatch-base-quality-threshold."
  echo ""
  echo "    --read_indel_limit"
  echo "        type: integer"
  echo "        Exclude reads with more than N separate gaps."
  echo ""
  echo "    --standard_filters"
  echo "        type: boolean_true"
  echo "        Use stringent input base and mapping quality filters, equivalent to -m"
  echo "        30 -q 20 -R 0 -S 0"
  echo ""
  echo "    --min_alternate_fraction"
  echo "        type: double"
  echo "        default: 0.05"
  echo "        Require at least this fraction of observations supporting an alternate"
  echo "        allele within a single individual in order to evaluate the position."
  echo ""
  echo "    --min_alternate_count"
  echo "        type: integer"
  echo "        default: 2"
  echo "        Require at least this count of observations supporting an alternate"
  echo "        allele within a single individual in order to evaluate the position."
  echo ""
  echo "    --min_alternate_qsum"
  echo "        type: integer"
  echo "        default: 0"
  echo "        Require at least this sum of quality of observations supporting an"
  echo "        alternate allele within a single individual in order to evaluate the"
  echo "        position."
  echo ""
  echo "    --min_alternate_total"
  echo "        type: integer"
  echo "        default: 1"
  echo "        Require at least this count of observations supporting an alternate"
  echo "        allele within the total population in order to use the allele in"
  echo "        analysis."
  echo ""
  echo "    --min_coverage"
  echo "        type: integer"
  echo "        default: 0"
  echo "        Require at least this coverage to process a site."
  echo ""
  echo "    --max_coverage"
  echo "        type: integer"
  echo "        Do not process sites with greater than this coverage."
  echo ""
  echo "    --no_population_priors"
  echo "        type: boolean_true"
  echo "        Equivalent to --pooled-discrete --hwe-priors-off and removal of Ewens"
  echo "        Sampling Formula component of priors."
  echo ""
  echo "    --hwe_priors_off"
  echo "        type: boolean_true"
  echo "        Disable estimation of the probability of the combination arising under"
  echo "        HWE given the allele frequency as estimated by observation frequency."
  echo ""
  echo "    --binomial_obs_priors_off"
  echo "        type: boolean_true"
  echo "        Disable incorporation of prior expectations about observations. Uses"
  echo "        read placement probability, strand balance probability, and read"
  echo "        position probability."
  echo ""
  echo "    --allele_balance_priors_off"
  echo "        type: boolean_true"
  echo "        Disable use of aggregate probability of observation balance between"
  echo "        alleles as a component of the priors."
  echo ""
  echo "    --observation_bias"
  echo "        type: file, file must exist"
  echo "        Read length-dependent allele observation biases from FILE. The format is"
  echo "        [length] [alignment efficiency relative to reference] where the"
  echo "        efficiency is 1 if there is no relative observation bias."
  echo ""
  echo "    --base_quality_cap"
  echo "        type: integer"
  echo "        Limit estimated observation quality by capping base quality at Q."
  echo ""
  echo "    --prob_contamination"
  echo "        type: double"
  echo "        default: 1.0E-8"
  echo "        An estimate of contamination to use for all samples."
  echo ""
  echo "    --legacy_gls"
  echo "        type: boolean_true"
  echo "        Use legacy (polybayes equivalent) genotype likelihood calculations"
  echo ""
  echo "    --contamination_estimates"
  echo "        type: file, file must exist"
  echo "        A file containing per-sample estimates of contamination, such as those"
  echo "        generated by VerifyBamID."
  echo ""
  echo "    --report_genotype_likelihood_max"
  echo "        type: boolean_true"
  echo "        Report genotypes using the maximum-likelihood estimate provided from"
  echo "        genotype likelihoods."
  echo ""
  echo "    --genotyping_max_iterations"
  echo "        type: integer"
  echo "        default: 1000"
  echo "        Iterate no more than N times during genotyping step."
  echo ""
  echo "    --genotyping_max_banddepth"
  echo "        type: integer"
  echo "        default: 6"
  echo "        Integrate no deeper than the Nth best genotype by likelihood when"
  echo "        genotyping."
  echo ""
  echo "    --posterior_integration_limits"
  echo "        type: string"
  echo "        default: 1,3"
  echo "        Integrate all genotype combinations in our posterior space which include"
  echo "        no more than N samples with their Mth best data likelihood."
  echo ""
  echo "    --exclude_unobserved_genotypes"
  echo "        type: boolean_true"
  echo "        Skip sample genotypings for which the sample has no supporting reads."
  echo ""
  echo "    --genotype_variant_threshold"
  echo "        type: integer"
  echo "        Limit posterior integration to samples where the second-best genotype"
  echo "        likelihood is no more than log(N) from the highest genotype likelihood"
  echo "        for the sample."
  echo ""
  echo "    --use_mapping_quality"
  echo "        type: boolean_true"
  echo "        Use mapping quality of alleles when calculating data likelihoods."
  echo ""
  echo "    --harmonic_indel_quality"
  echo "        type: boolean_true"
  echo "        Use a weighted sum of base qualities around an indel, scaled by the"
  echo "        distance from the indel. By default use a minimum BQ in flanking"
  echo "        sequence."
  echo ""
  echo "    --read_dependence_factor"
  echo "        type: double"
  echo "        default: 0.9"
  echo "        Incorporate non-independence of reads by scaling successive observations"
  echo "        by this factor during data likelihood calculations."
  echo ""
  echo "    --genotype_qualities"
  echo "        type: boolean_true"
  echo "        Calculate the marginal probability of genotypes and report as GQ in each"
  echo "        sample field in the VCF output."
  echo ""
  echo "    --debug"
  echo "        type: boolean_true"
  echo "        Print debugging output."
  echo ""
  echo "    --dd"
  echo "        type: boolean_true"
  echo "        Print more verbose debugging output"
  echo ""
  echo "Output:"
  echo "    -o, --output"
  echo "        type: file, output, file must exist"
  echo "        example: freebayes_out"
  echo "        Output directory"
  echo ""
  echo "    --vcf"
  echo "        type: string"
  echo "        example: snp.vcf"
  echo "        Output VCF-format results to FILE."
  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 "freebayes v4.0.4"
            exit
            ;;
        --bam)
            [ -n "$VIASH_PAR_BAM" ] && ViashError Bad arguments for option \'--bam\': \'$VIASH_PAR_BAM\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_BAM="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --bam. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --bam=*)
            [ -n "$VIASH_PAR_BAM" ] && ViashError Bad arguments for option \'--bam=*\': \'$VIASH_PAR_BAM\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_BAM=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --bam_list)
            [ -n "$VIASH_PAR_BAM_LIST" ] && ViashError Bad arguments for option \'--bam_list\': \'$VIASH_PAR_BAM_LIST\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_BAM_LIST="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --bam_list. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --bam_list=*)
            [ -n "$VIASH_PAR_BAM_LIST" ] && ViashError Bad arguments for option \'--bam_list=*\': \'$VIASH_PAR_BAM_LIST\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_BAM_LIST=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --stdin)
            [ -n "$VIASH_PAR_STDIN" ] && ViashError Bad arguments for option \'--stdin\': \'$VIASH_PAR_STDIN\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_STDIN=true
            shift 1
            ;;
        --fasta_reference)
            [ -n "$VIASH_PAR_FASTA_REFERENCE" ] && ViashError Bad arguments for option \'--fasta_reference\': \'$VIASH_PAR_FASTA_REFERENCE\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_FASTA_REFERENCE="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --fasta_reference. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --fasta_reference=*)
            [ -n "$VIASH_PAR_FASTA_REFERENCE" ] && ViashError Bad arguments for option \'--fasta_reference=*\': \'$VIASH_PAR_FASTA_REFERENCE\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_FASTA_REFERENCE=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --fasta_reference_index)
            [ -n "$VIASH_PAR_FASTA_REFERENCE_INDEX" ] && ViashError Bad arguments for option \'--fasta_reference_index\': \'$VIASH_PAR_FASTA_REFERENCE_INDEX\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_FASTA_REFERENCE_INDEX="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --fasta_reference_index. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --fasta_reference_index=*)
            [ -n "$VIASH_PAR_FASTA_REFERENCE_INDEX" ] && ViashError Bad arguments for option \'--fasta_reference_index=*\': \'$VIASH_PAR_FASTA_REFERENCE_INDEX\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_FASTA_REFERENCE_INDEX=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --targets)
            [ -n "$VIASH_PAR_TARGETS" ] && ViashError Bad arguments for option \'--targets\': \'$VIASH_PAR_TARGETS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_TARGETS="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --targets. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --targets=*)
            [ -n "$VIASH_PAR_TARGETS" ] && ViashError Bad arguments for option \'--targets=*\': \'$VIASH_PAR_TARGETS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_TARGETS=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --region)
            [ -n "$VIASH_PAR_REGION" ] && ViashError Bad arguments for option \'--region\': \'$VIASH_PAR_REGION\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_REGION="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --region. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --region=*)
            [ -n "$VIASH_PAR_REGION" ] && ViashError Bad arguments for option \'--region=*\': \'$VIASH_PAR_REGION\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_REGION=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --samples)
            [ -n "$VIASH_PAR_SAMPLES" ] && ViashError Bad arguments for option \'--samples\': \'$VIASH_PAR_SAMPLES\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_SAMPLES="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --samples. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --samples=*)
            [ -n "$VIASH_PAR_SAMPLES" ] && ViashError Bad arguments for option \'--samples=*\': \'$VIASH_PAR_SAMPLES\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_SAMPLES=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --populations)
            [ -n "$VIASH_PAR_POPULATIONS" ] && ViashError Bad arguments for option \'--populations\': \'$VIASH_PAR_POPULATIONS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_POPULATIONS="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --populations. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --populations=*)
            [ -n "$VIASH_PAR_POPULATIONS" ] && ViashError Bad arguments for option \'--populations=*\': \'$VIASH_PAR_POPULATIONS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_POPULATIONS=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --cnv_map)
            [ -n "$VIASH_PAR_CNV_MAP" ] && ViashError Bad arguments for option \'--cnv_map\': \'$VIASH_PAR_CNV_MAP\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_CNV_MAP="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --cnv_map. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --cnv_map=*)
            [ -n "$VIASH_PAR_CNV_MAP" ] && ViashError Bad arguments for option \'--cnv_map=*\': \'$VIASH_PAR_CNV_MAP\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_CNV_MAP=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --gvcf)
            [ -n "$VIASH_PAR_GVCF" ] && ViashError Bad arguments for option \'--gvcf\': \'$VIASH_PAR_GVCF\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_GVCF=true
            shift 1
            ;;
        --gvcf_chunk)
            [ -n "$VIASH_PAR_GVCF_CHUNK" ] && ViashError Bad arguments for option \'--gvcf_chunk\': \'$VIASH_PAR_GVCF_CHUNK\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_GVCF_CHUNK="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --gvcf_chunk. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --gvcf_chunk=*)
            [ -n "$VIASH_PAR_GVCF_CHUNK" ] && ViashError Bad arguments for option \'--gvcf_chunk=*\': \'$VIASH_PAR_GVCF_CHUNK\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_GVCF_CHUNK=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --variant_input)
            [ -n "$VIASH_PAR_VARIANT_INPUT" ] && ViashError Bad arguments for option \'--variant_input\': \'$VIASH_PAR_VARIANT_INPUT\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_VARIANT_INPUT="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --variant_input. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --variant_input=*)
            [ -n "$VIASH_PAR_VARIANT_INPUT" ] && ViashError Bad arguments for option \'--variant_input=*\': \'$VIASH_PAR_VARIANT_INPUT\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_VARIANT_INPUT=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --only_use_input_alleles)
            [ -n "$VIASH_PAR_ONLY_USE_INPUT_ALLELES" ] && ViashError Bad arguments for option \'--only_use_input_alleles\': \'$VIASH_PAR_ONLY_USE_INPUT_ALLELES\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_ONLY_USE_INPUT_ALLELES=true
            shift 1
            ;;
        --haplotype_basis_alleles)
            [ -n "$VIASH_PAR_HAPLOTYPE_BASIS_ALLELES" ] && ViashError Bad arguments for option \'--haplotype_basis_alleles\': \'$VIASH_PAR_HAPLOTYPE_BASIS_ALLELES\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_HAPLOTYPE_BASIS_ALLELES="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --haplotype_basis_alleles. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --haplotype_basis_alleles=*)
            [ -n "$VIASH_PAR_HAPLOTYPE_BASIS_ALLELES" ] && ViashError Bad arguments for option \'--haplotype_basis_alleles=*\': \'$VIASH_PAR_HAPLOTYPE_BASIS_ALLELES\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_HAPLOTYPE_BASIS_ALLELES=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --report_all_haplotype_alleles)
            [ -n "$VIASH_PAR_REPORT_ALL_HAPLOTYPE_ALLELES" ] && ViashError Bad arguments for option \'--report_all_haplotype_alleles\': \'$VIASH_PAR_REPORT_ALL_HAPLOTYPE_ALLELES\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_REPORT_ALL_HAPLOTYPE_ALLELES=true
            shift 1
            ;;
        --report_monomorphic)
            [ -n "$VIASH_PAR_REPORT_MONOMORPHIC" ] && ViashError Bad arguments for option \'--report_monomorphic\': \'$VIASH_PAR_REPORT_MONOMORPHIC\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_REPORT_MONOMORPHIC=true
            shift 1
            ;;
        --pvar)
            [ -n "$VIASH_PAR_PVAR" ] && ViashError Bad arguments for option \'--pvar\': \'$VIASH_PAR_PVAR\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_PVAR="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --pvar. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --pvar=*)
            [ -n "$VIASH_PAR_PVAR" ] && ViashError Bad arguments for option \'--pvar=*\': \'$VIASH_PAR_PVAR\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_PVAR=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --strict_vcf)
            [ -n "$VIASH_PAR_STRICT_VCF" ] && ViashError Bad arguments for option \'--strict_vcf\': \'$VIASH_PAR_STRICT_VCF\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_STRICT_VCF=true
            shift 1
            ;;
        --theta)
            [ -n "$VIASH_PAR_THETA" ] && ViashError Bad arguments for option \'--theta\': \'$VIASH_PAR_THETA\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_THETA="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --theta. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --theta=*)
            [ -n "$VIASH_PAR_THETA" ] && ViashError Bad arguments for option \'--theta=*\': \'$VIASH_PAR_THETA\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_THETA=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --ploidy)
            [ -n "$VIASH_PAR_PLOIDY" ] && ViashError Bad arguments for option \'--ploidy\': \'$VIASH_PAR_PLOIDY\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_PLOIDY="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --ploidy. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --ploidy=*)
            [ -n "$VIASH_PAR_PLOIDY" ] && ViashError Bad arguments for option \'--ploidy=*\': \'$VIASH_PAR_PLOIDY\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_PLOIDY=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --pooled_discrete)
            [ -n "$VIASH_PAR_POOLED_DISCRETE" ] && ViashError Bad arguments for option \'--pooled_discrete\': \'$VIASH_PAR_POOLED_DISCRETE\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_POOLED_DISCRETE=true
            shift 1
            ;;
        --pooled_continuous)
            [ -n "$VIASH_PAR_POOLED_CONTINUOUS" ] && ViashError Bad arguments for option \'--pooled_continuous\': \'$VIASH_PAR_POOLED_CONTINUOUS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_POOLED_CONTINUOUS=true
            shift 1
            ;;
        --use_reference_allele)
            [ -n "$VIASH_PAR_USE_REFERENCE_ALLELE" ] && ViashError Bad arguments for option \'--use_reference_allele\': \'$VIASH_PAR_USE_REFERENCE_ALLELE\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_USE_REFERENCE_ALLELE=true
            shift 1
            ;;
        --reference_quality)
            [ -n "$VIASH_PAR_REFERENCE_QUALITY" ] && ViashError Bad arguments for option \'--reference_quality\': \'$VIASH_PAR_REFERENCE_QUALITY\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_REFERENCE_QUALITY="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --reference_quality. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --reference_quality=*)
            [ -n "$VIASH_PAR_REFERENCE_QUALITY" ] && ViashError Bad arguments for option \'--reference_quality=*\': \'$VIASH_PAR_REFERENCE_QUALITY\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_REFERENCE_QUALITY=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --throw_away_snp_obs)
            [ -n "$VIASH_PAR_THROW_AWAY_SNP_OBS" ] && ViashError Bad arguments for option \'--throw_away_snp_obs\': \'$VIASH_PAR_THROW_AWAY_SNP_OBS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_THROW_AWAY_SNP_OBS=true
            shift 1
            ;;
        --throw_away_mnps_obs)
            [ -n "$VIASH_PAR_THROW_AWAY_MNPS_OBS" ] && ViashError Bad arguments for option \'--throw_away_mnps_obs\': \'$VIASH_PAR_THROW_AWAY_MNPS_OBS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_THROW_AWAY_MNPS_OBS=false
            shift 1
            ;;
        --throw_away_indel_obs)
            [ -n "$VIASH_PAR_THROW_AWAY_INDEL_OBS" ] && ViashError Bad arguments for option \'--throw_away_indel_obs\': \'$VIASH_PAR_THROW_AWAY_INDEL_OBS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_THROW_AWAY_INDEL_OBS=false
            shift 1
            ;;
        --throw_away_complex_obs)
            [ -n "$VIASH_PAR_THROW_AWAY_COMPLEX_OBS" ] && ViashError Bad arguments for option \'--throw_away_complex_obs\': \'$VIASH_PAR_THROW_AWAY_COMPLEX_OBS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_THROW_AWAY_COMPLEX_OBS=false
            shift 1
            ;;
        --use_best_n_alleles)
            [ -n "$VIASH_PAR_USE_BEST_N_ALLELES" ] && ViashError Bad arguments for option \'--use_best_n_alleles\': \'$VIASH_PAR_USE_BEST_N_ALLELES\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_USE_BEST_N_ALLELES="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --use_best_n_alleles. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --use_best_n_alleles=*)
            [ -n "$VIASH_PAR_USE_BEST_N_ALLELES" ] && ViashError Bad arguments for option \'--use_best_n_alleles=*\': \'$VIASH_PAR_USE_BEST_N_ALLELES\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_USE_BEST_N_ALLELES=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --max_complex_gap)
            [ -n "$VIASH_PAR_MAX_COMPLEX_GAP" ] && ViashError Bad arguments for option \'--max_complex_gap\': \'$VIASH_PAR_MAX_COMPLEX_GAP\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_MAX_COMPLEX_GAP="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --max_complex_gap. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --max_complex_gap=*)
            [ -n "$VIASH_PAR_MAX_COMPLEX_GAP" ] && ViashError Bad arguments for option \'--max_complex_gap=*\': \'$VIASH_PAR_MAX_COMPLEX_GAP\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_MAX_COMPLEX_GAP=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --min_repeat_size)
            [ -n "$VIASH_PAR_MIN_REPEAT_SIZE" ] && ViashError Bad arguments for option \'--min_repeat_size\': \'$VIASH_PAR_MIN_REPEAT_SIZE\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_MIN_REPEAT_SIZE="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --min_repeat_size. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --min_repeat_size=*)
            [ -n "$VIASH_PAR_MIN_REPEAT_SIZE" ] && ViashError Bad arguments for option \'--min_repeat_size=*\': \'$VIASH_PAR_MIN_REPEAT_SIZE\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_MIN_REPEAT_SIZE=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --min_repeat_entropy)
            [ -n "$VIASH_PAR_MIN_REPEAT_ENTROPY" ] && ViashError Bad arguments for option \'--min_repeat_entropy\': \'$VIASH_PAR_MIN_REPEAT_ENTROPY\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_MIN_REPEAT_ENTROPY="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --min_repeat_entropy. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --min_repeat_entropy=*)
            [ -n "$VIASH_PAR_MIN_REPEAT_ENTROPY" ] && ViashError Bad arguments for option \'--min_repeat_entropy=*\': \'$VIASH_PAR_MIN_REPEAT_ENTROPY\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_MIN_REPEAT_ENTROPY=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --no_partial_observations)
            [ -n "$VIASH_PAR_NO_PARTIAL_OBSERVATIONS" ] && ViashError Bad arguments for option \'--no_partial_observations\': \'$VIASH_PAR_NO_PARTIAL_OBSERVATIONS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_NO_PARTIAL_OBSERVATIONS=true
            shift 1
            ;;
        --dont_left_align_indels)
            [ -n "$VIASH_PAR_DONT_LEFT_ALIGN_INDELS" ] && ViashError Bad arguments for option \'--dont_left_align_indels\': \'$VIASH_PAR_DONT_LEFT_ALIGN_INDELS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_DONT_LEFT_ALIGN_INDELS=true
            shift 1
            ;;
        --use_duplicate_reads)
            [ -n "$VIASH_PAR_USE_DUPLICATE_READS" ] && ViashError Bad arguments for option \'--use_duplicate_reads\': \'$VIASH_PAR_USE_DUPLICATE_READS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_USE_DUPLICATE_READS=true
            shift 1
            ;;
        --min_mapping_quality)
            [ -n "$VIASH_PAR_MIN_MAPPING_QUALITY" ] && ViashError Bad arguments for option \'--min_mapping_quality\': \'$VIASH_PAR_MIN_MAPPING_QUALITY\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_MIN_MAPPING_QUALITY="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --min_mapping_quality. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --min_mapping_quality=*)
            [ -n "$VIASH_PAR_MIN_MAPPING_QUALITY" ] && ViashError Bad arguments for option \'--min_mapping_quality=*\': \'$VIASH_PAR_MIN_MAPPING_QUALITY\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_MIN_MAPPING_QUALITY=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --min_base_quality)
            [ -n "$VIASH_PAR_MIN_BASE_QUALITY" ] && ViashError Bad arguments for option \'--min_base_quality\': \'$VIASH_PAR_MIN_BASE_QUALITY\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_MIN_BASE_QUALITY="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --min_base_quality. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --min_base_quality=*)
            [ -n "$VIASH_PAR_MIN_BASE_QUALITY" ] && ViashError Bad arguments for option \'--min_base_quality=*\': \'$VIASH_PAR_MIN_BASE_QUALITY\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_MIN_BASE_QUALITY=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --min_supporting_allele_qsum)
            [ -n "$VIASH_PAR_MIN_SUPPORTING_ALLELE_QSUM" ] && ViashError Bad arguments for option \'--min_supporting_allele_qsum\': \'$VIASH_PAR_MIN_SUPPORTING_ALLELE_QSUM\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_MIN_SUPPORTING_ALLELE_QSUM="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --min_supporting_allele_qsum. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --min_supporting_allele_qsum=*)
            [ -n "$VIASH_PAR_MIN_SUPPORTING_ALLELE_QSUM" ] && ViashError Bad arguments for option \'--min_supporting_allele_qsum=*\': \'$VIASH_PAR_MIN_SUPPORTING_ALLELE_QSUM\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_MIN_SUPPORTING_ALLELE_QSUM=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --min_supporting_mapping_qsum)
            [ -n "$VIASH_PAR_MIN_SUPPORTING_MAPPING_QSUM" ] && ViashError Bad arguments for option \'--min_supporting_mapping_qsum\': \'$VIASH_PAR_MIN_SUPPORTING_MAPPING_QSUM\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_MIN_SUPPORTING_MAPPING_QSUM="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --min_supporting_mapping_qsum. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --min_supporting_mapping_qsum=*)
            [ -n "$VIASH_PAR_MIN_SUPPORTING_MAPPING_QSUM" ] && ViashError Bad arguments for option \'--min_supporting_mapping_qsum=*\': \'$VIASH_PAR_MIN_SUPPORTING_MAPPING_QSUM\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_MIN_SUPPORTING_MAPPING_QSUM=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --mismatch_base_quality_threshold)
            [ -n "$VIASH_PAR_MISMATCH_BASE_QUALITY_THRESHOLD" ] && ViashError Bad arguments for option \'--mismatch_base_quality_threshold\': \'$VIASH_PAR_MISMATCH_BASE_QUALITY_THRESHOLD\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_MISMATCH_BASE_QUALITY_THRESHOLD="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --mismatch_base_quality_threshold. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --mismatch_base_quality_threshold=*)
            [ -n "$VIASH_PAR_MISMATCH_BASE_QUALITY_THRESHOLD" ] && ViashError Bad arguments for option \'--mismatch_base_quality_threshold=*\': \'$VIASH_PAR_MISMATCH_BASE_QUALITY_THRESHOLD\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_MISMATCH_BASE_QUALITY_THRESHOLD=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --read_max_mismatch_fraction)
            [ -n "$VIASH_PAR_READ_MAX_MISMATCH_FRACTION" ] && ViashError Bad arguments for option \'--read_max_mismatch_fraction\': \'$VIASH_PAR_READ_MAX_MISMATCH_FRACTION\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_READ_MAX_MISMATCH_FRACTION="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --read_max_mismatch_fraction. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --read_max_mismatch_fraction=*)
            [ -n "$VIASH_PAR_READ_MAX_MISMATCH_FRACTION" ] && ViashError Bad arguments for option \'--read_max_mismatch_fraction=*\': \'$VIASH_PAR_READ_MAX_MISMATCH_FRACTION\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_READ_MAX_MISMATCH_FRACTION=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --read_mismatch_limit)
            [ -n "$VIASH_PAR_READ_MISMATCH_LIMIT" ] && ViashError Bad arguments for option \'--read_mismatch_limit\': \'$VIASH_PAR_READ_MISMATCH_LIMIT\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_READ_MISMATCH_LIMIT="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --read_mismatch_limit. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --read_mismatch_limit=*)
            [ -n "$VIASH_PAR_READ_MISMATCH_LIMIT" ] && ViashError Bad arguments for option \'--read_mismatch_limit=*\': \'$VIASH_PAR_READ_MISMATCH_LIMIT\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_READ_MISMATCH_LIMIT=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --read_snp_limit)
            [ -n "$VIASH_PAR_READ_SNP_LIMIT" ] && ViashError Bad arguments for option \'--read_snp_limit\': \'$VIASH_PAR_READ_SNP_LIMIT\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_READ_SNP_LIMIT="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --read_snp_limit. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --read_snp_limit=*)
            [ -n "$VIASH_PAR_READ_SNP_LIMIT" ] && ViashError Bad arguments for option \'--read_snp_limit=*\': \'$VIASH_PAR_READ_SNP_LIMIT\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_READ_SNP_LIMIT=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --read_indel_limit)
            [ -n "$VIASH_PAR_READ_INDEL_LIMIT" ] && ViashError Bad arguments for option \'--read_indel_limit\': \'$VIASH_PAR_READ_INDEL_LIMIT\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_READ_INDEL_LIMIT="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --read_indel_limit. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --read_indel_limit=*)
            [ -n "$VIASH_PAR_READ_INDEL_LIMIT" ] && ViashError Bad arguments for option \'--read_indel_limit=*\': \'$VIASH_PAR_READ_INDEL_LIMIT\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_READ_INDEL_LIMIT=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --standard_filters)
            [ -n "$VIASH_PAR_STANDARD_FILTERS" ] && ViashError Bad arguments for option \'--standard_filters\': \'$VIASH_PAR_STANDARD_FILTERS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_STANDARD_FILTERS=true
            shift 1
            ;;
        --min_alternate_fraction)
            [ -n "$VIASH_PAR_MIN_ALTERNATE_FRACTION" ] && ViashError Bad arguments for option \'--min_alternate_fraction\': \'$VIASH_PAR_MIN_ALTERNATE_FRACTION\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_MIN_ALTERNATE_FRACTION="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --min_alternate_fraction. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --min_alternate_fraction=*)
            [ -n "$VIASH_PAR_MIN_ALTERNATE_FRACTION" ] && ViashError Bad arguments for option \'--min_alternate_fraction=*\': \'$VIASH_PAR_MIN_ALTERNATE_FRACTION\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_MIN_ALTERNATE_FRACTION=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --min_alternate_count)
            [ -n "$VIASH_PAR_MIN_ALTERNATE_COUNT" ] && ViashError Bad arguments for option \'--min_alternate_count\': \'$VIASH_PAR_MIN_ALTERNATE_COUNT\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_MIN_ALTERNATE_COUNT="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --min_alternate_count. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --min_alternate_count=*)
            [ -n "$VIASH_PAR_MIN_ALTERNATE_COUNT" ] && ViashError Bad arguments for option \'--min_alternate_count=*\': \'$VIASH_PAR_MIN_ALTERNATE_COUNT\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_MIN_ALTERNATE_COUNT=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --min_alternate_qsum)
            [ -n "$VIASH_PAR_MIN_ALTERNATE_QSUM" ] && ViashError Bad arguments for option \'--min_alternate_qsum\': \'$VIASH_PAR_MIN_ALTERNATE_QSUM\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_MIN_ALTERNATE_QSUM="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --min_alternate_qsum. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --min_alternate_qsum=*)
            [ -n "$VIASH_PAR_MIN_ALTERNATE_QSUM" ] && ViashError Bad arguments for option \'--min_alternate_qsum=*\': \'$VIASH_PAR_MIN_ALTERNATE_QSUM\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_MIN_ALTERNATE_QSUM=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --min_alternate_total)
            [ -n "$VIASH_PAR_MIN_ALTERNATE_TOTAL" ] && ViashError Bad arguments for option \'--min_alternate_total\': \'$VIASH_PAR_MIN_ALTERNATE_TOTAL\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_MIN_ALTERNATE_TOTAL="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --min_alternate_total. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --min_alternate_total=*)
            [ -n "$VIASH_PAR_MIN_ALTERNATE_TOTAL" ] && ViashError Bad arguments for option \'--min_alternate_total=*\': \'$VIASH_PAR_MIN_ALTERNATE_TOTAL\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_MIN_ALTERNATE_TOTAL=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --min_coverage)
            [ -n "$VIASH_PAR_MIN_COVERAGE" ] && ViashError Bad arguments for option \'--min_coverage\': \'$VIASH_PAR_MIN_COVERAGE\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_MIN_COVERAGE="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --min_coverage. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --min_coverage=*)
            [ -n "$VIASH_PAR_MIN_COVERAGE" ] && ViashError Bad arguments for option \'--min_coverage=*\': \'$VIASH_PAR_MIN_COVERAGE\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_MIN_COVERAGE=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --max_coverage)
            [ -n "$VIASH_PAR_MAX_COVERAGE" ] && ViashError Bad arguments for option \'--max_coverage\': \'$VIASH_PAR_MAX_COVERAGE\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_MAX_COVERAGE="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --max_coverage. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --max_coverage=*)
            [ -n "$VIASH_PAR_MAX_COVERAGE" ] && ViashError Bad arguments for option \'--max_coverage=*\': \'$VIASH_PAR_MAX_COVERAGE\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_MAX_COVERAGE=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --no_population_priors)
            [ -n "$VIASH_PAR_NO_POPULATION_PRIORS" ] && ViashError Bad arguments for option \'--no_population_priors\': \'$VIASH_PAR_NO_POPULATION_PRIORS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_NO_POPULATION_PRIORS=true
            shift 1
            ;;
        --hwe_priors_off)
            [ -n "$VIASH_PAR_HWE_PRIORS_OFF" ] && ViashError Bad arguments for option \'--hwe_priors_off\': \'$VIASH_PAR_HWE_PRIORS_OFF\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_HWE_PRIORS_OFF=true
            shift 1
            ;;
        --binomial_obs_priors_off)
            [ -n "$VIASH_PAR_BINOMIAL_OBS_PRIORS_OFF" ] && ViashError Bad arguments for option \'--binomial_obs_priors_off\': \'$VIASH_PAR_BINOMIAL_OBS_PRIORS_OFF\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_BINOMIAL_OBS_PRIORS_OFF=true
            shift 1
            ;;
        --allele_balance_priors_off)
            [ -n "$VIASH_PAR_ALLELE_BALANCE_PRIORS_OFF" ] && ViashError Bad arguments for option \'--allele_balance_priors_off\': \'$VIASH_PAR_ALLELE_BALANCE_PRIORS_OFF\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_ALLELE_BALANCE_PRIORS_OFF=true
            shift 1
            ;;
        --observation_bias)
            [ -n "$VIASH_PAR_OBSERVATION_BIAS" ] && ViashError Bad arguments for option \'--observation_bias\': \'$VIASH_PAR_OBSERVATION_BIAS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_OBSERVATION_BIAS="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --observation_bias. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --observation_bias=*)
            [ -n "$VIASH_PAR_OBSERVATION_BIAS" ] && ViashError Bad arguments for option \'--observation_bias=*\': \'$VIASH_PAR_OBSERVATION_BIAS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_OBSERVATION_BIAS=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --base_quality_cap)
            [ -n "$VIASH_PAR_BASE_QUALITY_CAP" ] && ViashError Bad arguments for option \'--base_quality_cap\': \'$VIASH_PAR_BASE_QUALITY_CAP\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_BASE_QUALITY_CAP="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --base_quality_cap. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --base_quality_cap=*)
            [ -n "$VIASH_PAR_BASE_QUALITY_CAP" ] && ViashError Bad arguments for option \'--base_quality_cap=*\': \'$VIASH_PAR_BASE_QUALITY_CAP\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_BASE_QUALITY_CAP=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --prob_contamination)
            [ -n "$VIASH_PAR_PROB_CONTAMINATION" ] && ViashError Bad arguments for option \'--prob_contamination\': \'$VIASH_PAR_PROB_CONTAMINATION\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_PROB_CONTAMINATION="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --prob_contamination. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --prob_contamination=*)
            [ -n "$VIASH_PAR_PROB_CONTAMINATION" ] && ViashError Bad arguments for option \'--prob_contamination=*\': \'$VIASH_PAR_PROB_CONTAMINATION\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_PROB_CONTAMINATION=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --legacy_gls)
            [ -n "$VIASH_PAR_LEGACY_GLS" ] && ViashError Bad arguments for option \'--legacy_gls\': \'$VIASH_PAR_LEGACY_GLS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_LEGACY_GLS=true
            shift 1
            ;;
        --contamination_estimates)
            [ -n "$VIASH_PAR_CONTAMINATION_ESTIMATES" ] && ViashError Bad arguments for option \'--contamination_estimates\': \'$VIASH_PAR_CONTAMINATION_ESTIMATES\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_CONTAMINATION_ESTIMATES="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --contamination_estimates. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --contamination_estimates=*)
            [ -n "$VIASH_PAR_CONTAMINATION_ESTIMATES" ] && ViashError Bad arguments for option \'--contamination_estimates=*\': \'$VIASH_PAR_CONTAMINATION_ESTIMATES\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_CONTAMINATION_ESTIMATES=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --report_genotype_likelihood_max)
            [ -n "$VIASH_PAR_REPORT_GENOTYPE_LIKELIHOOD_MAX" ] && ViashError Bad arguments for option \'--report_genotype_likelihood_max\': \'$VIASH_PAR_REPORT_GENOTYPE_LIKELIHOOD_MAX\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_REPORT_GENOTYPE_LIKELIHOOD_MAX=true
            shift 1
            ;;
        --genotyping_max_iterations)
            [ -n "$VIASH_PAR_GENOTYPING_MAX_ITERATIONS" ] && ViashError Bad arguments for option \'--genotyping_max_iterations\': \'$VIASH_PAR_GENOTYPING_MAX_ITERATIONS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_GENOTYPING_MAX_ITERATIONS="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --genotyping_max_iterations. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --genotyping_max_iterations=*)
            [ -n "$VIASH_PAR_GENOTYPING_MAX_ITERATIONS" ] && ViashError Bad arguments for option \'--genotyping_max_iterations=*\': \'$VIASH_PAR_GENOTYPING_MAX_ITERATIONS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_GENOTYPING_MAX_ITERATIONS=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --genotyping_max_banddepth)
            [ -n "$VIASH_PAR_GENOTYPING_MAX_BANDDEPTH" ] && ViashError Bad arguments for option \'--genotyping_max_banddepth\': \'$VIASH_PAR_GENOTYPING_MAX_BANDDEPTH\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_GENOTYPING_MAX_BANDDEPTH="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --genotyping_max_banddepth. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --genotyping_max_banddepth=*)
            [ -n "$VIASH_PAR_GENOTYPING_MAX_BANDDEPTH" ] && ViashError Bad arguments for option \'--genotyping_max_banddepth=*\': \'$VIASH_PAR_GENOTYPING_MAX_BANDDEPTH\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_GENOTYPING_MAX_BANDDEPTH=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --posterior_integration_limits)
            [ -n "$VIASH_PAR_POSTERIOR_INTEGRATION_LIMITS" ] && ViashError Bad arguments for option \'--posterior_integration_limits\': \'$VIASH_PAR_POSTERIOR_INTEGRATION_LIMITS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_POSTERIOR_INTEGRATION_LIMITS="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --posterior_integration_limits. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --posterior_integration_limits=*)
            [ -n "$VIASH_PAR_POSTERIOR_INTEGRATION_LIMITS" ] && ViashError Bad arguments for option \'--posterior_integration_limits=*\': \'$VIASH_PAR_POSTERIOR_INTEGRATION_LIMITS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_POSTERIOR_INTEGRATION_LIMITS=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --exclude_unobserved_genotypes)
            [ -n "$VIASH_PAR_EXCLUDE_UNOBSERVED_GENOTYPES" ] && ViashError Bad arguments for option \'--exclude_unobserved_genotypes\': \'$VIASH_PAR_EXCLUDE_UNOBSERVED_GENOTYPES\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_EXCLUDE_UNOBSERVED_GENOTYPES=true
            shift 1
            ;;
        --genotype_variant_threshold)
            [ -n "$VIASH_PAR_GENOTYPE_VARIANT_THRESHOLD" ] && ViashError Bad arguments for option \'--genotype_variant_threshold\': \'$VIASH_PAR_GENOTYPE_VARIANT_THRESHOLD\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_GENOTYPE_VARIANT_THRESHOLD="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --genotype_variant_threshold. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --genotype_variant_threshold=*)
            [ -n "$VIASH_PAR_GENOTYPE_VARIANT_THRESHOLD" ] && ViashError Bad arguments for option \'--genotype_variant_threshold=*\': \'$VIASH_PAR_GENOTYPE_VARIANT_THRESHOLD\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_GENOTYPE_VARIANT_THRESHOLD=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --use_mapping_quality)
            [ -n "$VIASH_PAR_USE_MAPPING_QUALITY" ] && ViashError Bad arguments for option \'--use_mapping_quality\': \'$VIASH_PAR_USE_MAPPING_QUALITY\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_USE_MAPPING_QUALITY=true
            shift 1
            ;;
        --harmonic_indel_quality)
            [ -n "$VIASH_PAR_HARMONIC_INDEL_QUALITY" ] && ViashError Bad arguments for option \'--harmonic_indel_quality\': \'$VIASH_PAR_HARMONIC_INDEL_QUALITY\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_HARMONIC_INDEL_QUALITY=true
            shift 1
            ;;
        --read_dependence_factor)
            [ -n "$VIASH_PAR_READ_DEPENDENCE_FACTOR" ] && ViashError Bad arguments for option \'--read_dependence_factor\': \'$VIASH_PAR_READ_DEPENDENCE_FACTOR\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_READ_DEPENDENCE_FACTOR="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --read_dependence_factor. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --read_dependence_factor=*)
            [ -n "$VIASH_PAR_READ_DEPENDENCE_FACTOR" ] && ViashError Bad arguments for option \'--read_dependence_factor=*\': \'$VIASH_PAR_READ_DEPENDENCE_FACTOR\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_READ_DEPENDENCE_FACTOR=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --genotype_qualities)
            [ -n "$VIASH_PAR_GENOTYPE_QUALITIES" ] && ViashError Bad arguments for option \'--genotype_qualities\': \'$VIASH_PAR_GENOTYPE_QUALITIES\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_GENOTYPE_QUALITIES=true
            shift 1
            ;;
        --debug)
            [ -n "$VIASH_PAR_DEBUG" ] && ViashError Bad arguments for option \'--debug\': \'$VIASH_PAR_DEBUG\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_DEBUG=true
            shift 1
            ;;
        --dd)
            [ -n "$VIASH_PAR_DD" ] && ViashError Bad arguments for option \'--dd\': \'$VIASH_PAR_DD\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_DD=true
            shift 1
            ;;
        --output)
            [ -n "$VIASH_PAR_OUTPUT" ] && ViashError Bad arguments for option \'--output\': \'$VIASH_PAR_OUTPUT\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_OUTPUT="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --output. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --output=*)
            [ -n "$VIASH_PAR_OUTPUT" ] && ViashError Bad arguments for option \'--output=*\': \'$VIASH_PAR_OUTPUT\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_OUTPUT=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        -o)
            [ -n "$VIASH_PAR_OUTPUT" ] && ViashError Bad arguments for option \'-o\': \'$VIASH_PAR_OUTPUT\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_OUTPUT="$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="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --vcf. 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=$(ViashRemoveFlags "$1")
            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/openpipeline/genetic_demux/freebayes:v4.0.4'
  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" 'bash'
    exit 0
  fi

  # check if docker image exists
  ViashDockerSetup "$VIASH_DOCKER_IMAGE_ID" ifneedbepullelsecachedbuild
  ViashDockerCheckCommands "$VIASH_DOCKER_IMAGE_ID" '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_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_STDIN+x} ]; then
  VIASH_PAR_STDIN="false"
fi
if [ -z ${VIASH_PAR_GVCF+x} ]; then
  VIASH_PAR_GVCF="false"
fi
if [ -z ${VIASH_PAR_ONLY_USE_INPUT_ALLELES+x} ]; then
  VIASH_PAR_ONLY_USE_INPUT_ALLELES="false"
fi
if [ -z ${VIASH_PAR_REPORT_ALL_HAPLOTYPE_ALLELES+x} ]; then
  VIASH_PAR_REPORT_ALL_HAPLOTYPE_ALLELES="false"
fi
if [ -z ${VIASH_PAR_REPORT_MONOMORPHIC+x} ]; then
  VIASH_PAR_REPORT_MONOMORPHIC="false"
fi
if [ -z ${VIASH_PAR_PVAR+x} ]; then
  VIASH_PAR_PVAR="0.0"
fi
if [ -z ${VIASH_PAR_STRICT_VCF+x} ]; then
  VIASH_PAR_STRICT_VCF="false"
fi
if [ -z ${VIASH_PAR_THETA+x} ]; then
  VIASH_PAR_THETA="0.001"
fi
if [ -z ${VIASH_PAR_PLOIDY+x} ]; then
  VIASH_PAR_PLOIDY="2"
fi
if [ -z ${VIASH_PAR_POOLED_DISCRETE+x} ]; then
  VIASH_PAR_POOLED_DISCRETE="false"
fi
if [ -z ${VIASH_PAR_POOLED_CONTINUOUS+x} ]; then
  VIASH_PAR_POOLED_CONTINUOUS="false"
fi
if [ -z ${VIASH_PAR_USE_REFERENCE_ALLELE+x} ]; then
  VIASH_PAR_USE_REFERENCE_ALLELE="false"
fi
if [ -z ${VIASH_PAR_REFERENCE_QUALITY+x} ]; then
  VIASH_PAR_REFERENCE_QUALITY="100,60"
fi
if [ -z ${VIASH_PAR_THROW_AWAY_SNP_OBS+x} ]; then
  VIASH_PAR_THROW_AWAY_SNP_OBS="false"
fi
if [ -z ${VIASH_PAR_THROW_AWAY_MNPS_OBS+x} ]; then
  VIASH_PAR_THROW_AWAY_MNPS_OBS="true"
fi
if [ -z ${VIASH_PAR_THROW_AWAY_INDEL_OBS+x} ]; then
  VIASH_PAR_THROW_AWAY_INDEL_OBS="true"
fi
if [ -z ${VIASH_PAR_THROW_AWAY_COMPLEX_OBS+x} ]; then
  VIASH_PAR_THROW_AWAY_COMPLEX_OBS="true"
fi
if [ -z ${VIASH_PAR_USE_BEST_N_ALLELES+x} ]; then
  VIASH_PAR_USE_BEST_N_ALLELES="0"
fi
if [ -z ${VIASH_PAR_MAX_COMPLEX_GAP+x} ]; then
  VIASH_PAR_MAX_COMPLEX_GAP="3"
fi
if [ -z ${VIASH_PAR_MIN_REPEAT_SIZE+x} ]; then
  VIASH_PAR_MIN_REPEAT_SIZE="5"
fi
if [ -z ${VIASH_PAR_MIN_REPEAT_ENTROPY+x} ]; then
  VIASH_PAR_MIN_REPEAT_ENTROPY="1"
fi
if [ -z ${VIASH_PAR_NO_PARTIAL_OBSERVATIONS+x} ]; then
  VIASH_PAR_NO_PARTIAL_OBSERVATIONS="false"
fi
if [ -z ${VIASH_PAR_DONT_LEFT_ALIGN_INDELS+x} ]; then
  VIASH_PAR_DONT_LEFT_ALIGN_INDELS="false"
fi
if [ -z ${VIASH_PAR_USE_DUPLICATE_READS+x} ]; then
  VIASH_PAR_USE_DUPLICATE_READS="false"
fi
if [ -z ${VIASH_PAR_MIN_MAPPING_QUALITY+x} ]; then
  VIASH_PAR_MIN_MAPPING_QUALITY="1"
fi
if [ -z ${VIASH_PAR_MIN_BASE_QUALITY+x} ]; then
  VIASH_PAR_MIN_BASE_QUALITY="1"
fi
if [ -z ${VIASH_PAR_MIN_SUPPORTING_ALLELE_QSUM+x} ]; then
  VIASH_PAR_MIN_SUPPORTING_ALLELE_QSUM="0"
fi
if [ -z ${VIASH_PAR_MIN_SUPPORTING_MAPPING_QSUM+x} ]; then
  VIASH_PAR_MIN_SUPPORTING_MAPPING_QSUM="0"
fi
if [ -z ${VIASH_PAR_MISMATCH_BASE_QUALITY_THRESHOLD+x} ]; then
  VIASH_PAR_MISMATCH_BASE_QUALITY_THRESHOLD="10"
fi
if [ -z ${VIASH_PAR_READ_MAX_MISMATCH_FRACTION+x} ]; then
  VIASH_PAR_READ_MAX_MISMATCH_FRACTION="1.0"
fi
if [ -z ${VIASH_PAR_STANDARD_FILTERS+x} ]; then
  VIASH_PAR_STANDARD_FILTERS="false"
fi
if [ -z ${VIASH_PAR_MIN_ALTERNATE_FRACTION+x} ]; then
  VIASH_PAR_MIN_ALTERNATE_FRACTION="0.05"
fi
if [ -z ${VIASH_PAR_MIN_ALTERNATE_COUNT+x} ]; then
  VIASH_PAR_MIN_ALTERNATE_COUNT="2"
fi
if [ -z ${VIASH_PAR_MIN_ALTERNATE_QSUM+x} ]; then
  VIASH_PAR_MIN_ALTERNATE_QSUM="0"
fi
if [ -z ${VIASH_PAR_MIN_ALTERNATE_TOTAL+x} ]; then
  VIASH_PAR_MIN_ALTERNATE_TOTAL="1"
fi
if [ -z ${VIASH_PAR_MIN_COVERAGE+x} ]; then
  VIASH_PAR_MIN_COVERAGE="0"
fi
if [ -z ${VIASH_PAR_NO_POPULATION_PRIORS+x} ]; then
  VIASH_PAR_NO_POPULATION_PRIORS="false"
fi
if [ -z ${VIASH_PAR_HWE_PRIORS_OFF+x} ]; then
  VIASH_PAR_HWE_PRIORS_OFF="false"
fi
if [ -z ${VIASH_PAR_BINOMIAL_OBS_PRIORS_OFF+x} ]; then
  VIASH_PAR_BINOMIAL_OBS_PRIORS_OFF="false"
fi
if [ -z ${VIASH_PAR_ALLELE_BALANCE_PRIORS_OFF+x} ]; then
  VIASH_PAR_ALLELE_BALANCE_PRIORS_OFF="false"
fi
if [ -z ${VIASH_PAR_PROB_CONTAMINATION+x} ]; then
  VIASH_PAR_PROB_CONTAMINATION="1.0E-8"
fi
if [ -z ${VIASH_PAR_LEGACY_GLS+x} ]; then
  VIASH_PAR_LEGACY_GLS="false"
fi
if [ -z ${VIASH_PAR_REPORT_GENOTYPE_LIKELIHOOD_MAX+x} ]; then
  VIASH_PAR_REPORT_GENOTYPE_LIKELIHOOD_MAX="false"
fi
if [ -z ${VIASH_PAR_GENOTYPING_MAX_ITERATIONS+x} ]; then
  VIASH_PAR_GENOTYPING_MAX_ITERATIONS="1000"
fi
if [ -z ${VIASH_PAR_GENOTYPING_MAX_BANDDEPTH+x} ]; then
  VIASH_PAR_GENOTYPING_MAX_BANDDEPTH="6"
fi
if [ -z ${VIASH_PAR_POSTERIOR_INTEGRATION_LIMITS+x} ]; then
  VIASH_PAR_POSTERIOR_INTEGRATION_LIMITS="1,3"
fi
if [ -z ${VIASH_PAR_EXCLUDE_UNOBSERVED_GENOTYPES+x} ]; then
  VIASH_PAR_EXCLUDE_UNOBSERVED_GENOTYPES="false"
fi
if [ -z ${VIASH_PAR_USE_MAPPING_QUALITY+x} ]; then
  VIASH_PAR_USE_MAPPING_QUALITY="false"
fi
if [ -z ${VIASH_PAR_HARMONIC_INDEL_QUALITY+x} ]; then
  VIASH_PAR_HARMONIC_INDEL_QUALITY="false"
fi
if [ -z ${VIASH_PAR_READ_DEPENDENCE_FACTOR+x} ]; then
  VIASH_PAR_READ_DEPENDENCE_FACTOR="0.9"
fi
if [ -z ${VIASH_PAR_GENOTYPE_QUALITIES+x} ]; then
  VIASH_PAR_GENOTYPE_QUALITIES="false"
fi
if [ -z ${VIASH_PAR_DEBUG+x} ]; then
  VIASH_PAR_DEBUG="false"
fi
if [ -z ${VIASH_PAR_DD+x} ]; then
  VIASH_PAR_DD="false"
fi

# check whether required files exist
if [ ! -z "$VIASH_PAR_BAM" ] && [ ! -e "$VIASH_PAR_BAM" ]; then
  ViashError "Input file '$VIASH_PAR_BAM' does not exist."
  exit 1
fi
if [ ! -z "$VIASH_PAR_BAM_LIST" ] && [ ! -e "$VIASH_PAR_BAM_LIST" ]; then
  ViashError "Input file '$VIASH_PAR_BAM_LIST' does not exist."
  exit 1
fi
if [ ! -z "$VIASH_PAR_FASTA_REFERENCE" ] && [ ! -e "$VIASH_PAR_FASTA_REFERENCE" ]; then
  ViashError "Input file '$VIASH_PAR_FASTA_REFERENCE' does not exist."
  exit 1
fi
if [ ! -z "$VIASH_PAR_FASTA_REFERENCE_INDEX" ] && [ ! -e "$VIASH_PAR_FASTA_REFERENCE_INDEX" ]; then
  ViashError "Input file '$VIASH_PAR_FASTA_REFERENCE_INDEX' does not exist."
  exit 1
fi
if [ ! -z "$VIASH_PAR_TARGETS" ] && [ ! -e "$VIASH_PAR_TARGETS" ]; then
  ViashError "Input file '$VIASH_PAR_TARGETS' does not exist."
  exit 1
fi
if [ ! -z "$VIASH_PAR_SAMPLES" ] && [ ! -e "$VIASH_PAR_SAMPLES" ]; then
  ViashError "Input file '$VIASH_PAR_SAMPLES' does not exist."
  exit 1
fi
if [ ! -z "$VIASH_PAR_POPULATIONS" ] && [ ! -e "$VIASH_PAR_POPULATIONS" ]; then
  ViashError "Input file '$VIASH_PAR_POPULATIONS' does not exist."
  exit 1
fi
if [ ! -z "$VIASH_PAR_CNV_MAP" ] && [ ! -e "$VIASH_PAR_CNV_MAP" ]; then
  ViashError "Input file '$VIASH_PAR_CNV_MAP' does not exist."
  exit 1
fi
if [ ! -z "$VIASH_PAR_VARIANT_INPUT" ] && [ ! -e "$VIASH_PAR_VARIANT_INPUT" ]; then
  ViashError "Input file '$VIASH_PAR_VARIANT_INPUT' does not exist."
  exit 1
fi
if [ ! -z "$VIASH_PAR_HAPLOTYPE_BASIS_ALLELES" ] && [ ! -e "$VIASH_PAR_HAPLOTYPE_BASIS_ALLELES" ]; then
  ViashError "Input file '$VIASH_PAR_HAPLOTYPE_BASIS_ALLELES' does not exist."
  exit 1
fi
if [ ! -z "$VIASH_PAR_OBSERVATION_BIAS" ] && [ ! -e "$VIASH_PAR_OBSERVATION_BIAS" ]; then
  ViashError "Input file '$VIASH_PAR_OBSERVATION_BIAS' does not exist."
  exit 1
fi
if [ ! -z "$VIASH_PAR_CONTAMINATION_ESTIMATES" ] && [ ! -e "$VIASH_PAR_CONTAMINATION_ESTIMATES" ]; then
  ViashError "Input file '$VIASH_PAR_CONTAMINATION_ESTIMATES' does not exist."
  exit 1
fi

# check whether parameters values are of the right type
if [[ -n "$VIASH_PAR_STDIN" ]]; then
  if ! [[ "$VIASH_PAR_STDIN" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--stdin' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_GVCF" ]]; then
  if ! [[ "$VIASH_PAR_GVCF" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--gvcf' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_GVCF_CHUNK" ]]; then
  if ! [[ "$VIASH_PAR_GVCF_CHUNK" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError '--gvcf_chunk' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_ONLY_USE_INPUT_ALLELES" ]]; then
  if ! [[ "$VIASH_PAR_ONLY_USE_INPUT_ALLELES" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--only_use_input_alleles' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_REPORT_ALL_HAPLOTYPE_ALLELES" ]]; then
  if ! [[ "$VIASH_PAR_REPORT_ALL_HAPLOTYPE_ALLELES" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--report_all_haplotype_alleles' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_REPORT_MONOMORPHIC" ]]; then
  if ! [[ "$VIASH_PAR_REPORT_MONOMORPHIC" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--report_monomorphic' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_PVAR" ]]; then
  if ! [[ "$VIASH_PAR_PVAR" =~ ^[-+]?(\.[0-9]+|[0-9]+(\.[0-9]*)?)([eE][-+]?[0-9]+)?$ ]]; then
    ViashError '--pvar' has to be a double. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_STRICT_VCF" ]]; then
  if ! [[ "$VIASH_PAR_STRICT_VCF" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--strict_vcf' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_THETA" ]]; then
  if ! [[ "$VIASH_PAR_THETA" =~ ^[-+]?(\.[0-9]+|[0-9]+(\.[0-9]*)?)([eE][-+]?[0-9]+)?$ ]]; then
    ViashError '--theta' has to be a double. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_PLOIDY" ]]; then
  if ! [[ "$VIASH_PAR_PLOIDY" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError '--ploidy' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_POOLED_DISCRETE" ]]; then
  if ! [[ "$VIASH_PAR_POOLED_DISCRETE" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--pooled_discrete' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_POOLED_CONTINUOUS" ]]; then
  if ! [[ "$VIASH_PAR_POOLED_CONTINUOUS" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--pooled_continuous' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_USE_REFERENCE_ALLELE" ]]; then
  if ! [[ "$VIASH_PAR_USE_REFERENCE_ALLELE" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--use_reference_allele' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_THROW_AWAY_SNP_OBS" ]]; then
  if ! [[ "$VIASH_PAR_THROW_AWAY_SNP_OBS" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--throw_away_snp_obs' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_THROW_AWAY_MNPS_OBS" ]]; then
  if ! [[ "$VIASH_PAR_THROW_AWAY_MNPS_OBS" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--throw_away_mnps_obs' has to be a boolean_false. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_THROW_AWAY_INDEL_OBS" ]]; then
  if ! [[ "$VIASH_PAR_THROW_AWAY_INDEL_OBS" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--throw_away_indel_obs' has to be a boolean_false. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_THROW_AWAY_COMPLEX_OBS" ]]; then
  if ! [[ "$VIASH_PAR_THROW_AWAY_COMPLEX_OBS" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--throw_away_complex_obs' has to be a boolean_false. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_USE_BEST_N_ALLELES" ]]; then
  if ! [[ "$VIASH_PAR_USE_BEST_N_ALLELES" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError '--use_best_n_alleles' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_MAX_COMPLEX_GAP" ]]; then
  if ! [[ "$VIASH_PAR_MAX_COMPLEX_GAP" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError '--max_complex_gap' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_MIN_REPEAT_SIZE" ]]; then
  if ! [[ "$VIASH_PAR_MIN_REPEAT_SIZE" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError '--min_repeat_size' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_MIN_REPEAT_ENTROPY" ]]; then
  if ! [[ "$VIASH_PAR_MIN_REPEAT_ENTROPY" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError '--min_repeat_entropy' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_NO_PARTIAL_OBSERVATIONS" ]]; then
  if ! [[ "$VIASH_PAR_NO_PARTIAL_OBSERVATIONS" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--no_partial_observations' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_DONT_LEFT_ALIGN_INDELS" ]]; then
  if ! [[ "$VIASH_PAR_DONT_LEFT_ALIGN_INDELS" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--dont_left_align_indels' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_USE_DUPLICATE_READS" ]]; then
  if ! [[ "$VIASH_PAR_USE_DUPLICATE_READS" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--use_duplicate_reads' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_MIN_MAPPING_QUALITY" ]]; then
  if ! [[ "$VIASH_PAR_MIN_MAPPING_QUALITY" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError '--min_mapping_quality' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_MIN_BASE_QUALITY" ]]; then
  if ! [[ "$VIASH_PAR_MIN_BASE_QUALITY" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError '--min_base_quality' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_MIN_SUPPORTING_ALLELE_QSUM" ]]; then
  if ! [[ "$VIASH_PAR_MIN_SUPPORTING_ALLELE_QSUM" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError '--min_supporting_allele_qsum' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_MIN_SUPPORTING_MAPPING_QSUM" ]]; then
  if ! [[ "$VIASH_PAR_MIN_SUPPORTING_MAPPING_QSUM" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError '--min_supporting_mapping_qsum' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_MISMATCH_BASE_QUALITY_THRESHOLD" ]]; then
  if ! [[ "$VIASH_PAR_MISMATCH_BASE_QUALITY_THRESHOLD" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError '--mismatch_base_quality_threshold' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_READ_MAX_MISMATCH_FRACTION" ]]; then
  if ! [[ "$VIASH_PAR_READ_MAX_MISMATCH_FRACTION" =~ ^[-+]?(\.[0-9]+|[0-9]+(\.[0-9]*)?)([eE][-+]?[0-9]+)?$ ]]; then
    ViashError '--read_max_mismatch_fraction' has to be a double. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_READ_MISMATCH_LIMIT" ]]; then
  if ! [[ "$VIASH_PAR_READ_MISMATCH_LIMIT" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError '--read_mismatch_limit' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_READ_SNP_LIMIT" ]]; then
  if ! [[ "$VIASH_PAR_READ_SNP_LIMIT" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError '--read_snp_limit' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_READ_INDEL_LIMIT" ]]; then
  if ! [[ "$VIASH_PAR_READ_INDEL_LIMIT" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError '--read_indel_limit' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_STANDARD_FILTERS" ]]; then
  if ! [[ "$VIASH_PAR_STANDARD_FILTERS" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--standard_filters' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_MIN_ALTERNATE_FRACTION" ]]; then
  if ! [[ "$VIASH_PAR_MIN_ALTERNATE_FRACTION" =~ ^[-+]?(\.[0-9]+|[0-9]+(\.[0-9]*)?)([eE][-+]?[0-9]+)?$ ]]; then
    ViashError '--min_alternate_fraction' has to be a double. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_MIN_ALTERNATE_COUNT" ]]; then
  if ! [[ "$VIASH_PAR_MIN_ALTERNATE_COUNT" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError '--min_alternate_count' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_MIN_ALTERNATE_QSUM" ]]; then
  if ! [[ "$VIASH_PAR_MIN_ALTERNATE_QSUM" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError '--min_alternate_qsum' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_MIN_ALTERNATE_TOTAL" ]]; then
  if ! [[ "$VIASH_PAR_MIN_ALTERNATE_TOTAL" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError '--min_alternate_total' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_MIN_COVERAGE" ]]; then
  if ! [[ "$VIASH_PAR_MIN_COVERAGE" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError '--min_coverage' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_MAX_COVERAGE" ]]; then
  if ! [[ "$VIASH_PAR_MAX_COVERAGE" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError '--max_coverage' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_NO_POPULATION_PRIORS" ]]; then
  if ! [[ "$VIASH_PAR_NO_POPULATION_PRIORS" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--no_population_priors' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_HWE_PRIORS_OFF" ]]; then
  if ! [[ "$VIASH_PAR_HWE_PRIORS_OFF" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--hwe_priors_off' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_BINOMIAL_OBS_PRIORS_OFF" ]]; then
  if ! [[ "$VIASH_PAR_BINOMIAL_OBS_PRIORS_OFF" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--binomial_obs_priors_off' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_ALLELE_BALANCE_PRIORS_OFF" ]]; then
  if ! [[ "$VIASH_PAR_ALLELE_BALANCE_PRIORS_OFF" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--allele_balance_priors_off' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_BASE_QUALITY_CAP" ]]; then
  if ! [[ "$VIASH_PAR_BASE_QUALITY_CAP" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError '--base_quality_cap' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_PROB_CONTAMINATION" ]]; then
  if ! [[ "$VIASH_PAR_PROB_CONTAMINATION" =~ ^[-+]?(\.[0-9]+|[0-9]+(\.[0-9]*)?)([eE][-+]?[0-9]+)?$ ]]; then
    ViashError '--prob_contamination' has to be a double. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_LEGACY_GLS" ]]; then
  if ! [[ "$VIASH_PAR_LEGACY_GLS" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--legacy_gls' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_REPORT_GENOTYPE_LIKELIHOOD_MAX" ]]; then
  if ! [[ "$VIASH_PAR_REPORT_GENOTYPE_LIKELIHOOD_MAX" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--report_genotype_likelihood_max' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_GENOTYPING_MAX_ITERATIONS" ]]; then
  if ! [[ "$VIASH_PAR_GENOTYPING_MAX_ITERATIONS" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError '--genotyping_max_iterations' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_GENOTYPING_MAX_BANDDEPTH" ]]; then
  if ! [[ "$VIASH_PAR_GENOTYPING_MAX_BANDDEPTH" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError '--genotyping_max_banddepth' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_EXCLUDE_UNOBSERVED_GENOTYPES" ]]; then
  if ! [[ "$VIASH_PAR_EXCLUDE_UNOBSERVED_GENOTYPES" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--exclude_unobserved_genotypes' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_GENOTYPE_VARIANT_THRESHOLD" ]]; then
  if ! [[ "$VIASH_PAR_GENOTYPE_VARIANT_THRESHOLD" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError '--genotype_variant_threshold' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_USE_MAPPING_QUALITY" ]]; then
  if ! [[ "$VIASH_PAR_USE_MAPPING_QUALITY" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--use_mapping_quality' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_HARMONIC_INDEL_QUALITY" ]]; then
  if ! [[ "$VIASH_PAR_HARMONIC_INDEL_QUALITY" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--harmonic_indel_quality' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_READ_DEPENDENCE_FACTOR" ]]; then
  if ! [[ "$VIASH_PAR_READ_DEPENDENCE_FACTOR" =~ ^[-+]?(\.[0-9]+|[0-9]+(\.[0-9]*)?)([eE][-+]?[0-9]+)?$ ]]; then
    ViashError '--read_dependence_factor' has to be a double. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_GENOTYPE_QUALITIES" ]]; then
  if ! [[ "$VIASH_PAR_GENOTYPE_QUALITIES" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--genotype_qualities' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_DEBUG" ]]; then
  if ! [[ "$VIASH_PAR_DEBUG" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--debug' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_DD" ]]; then
  if ! [[ "$VIASH_PAR_DD" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--dd' 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

# create parent directories of output files, if so desired
if [ ! -z "$VIASH_PAR_OUTPUT" ] && [ ! -d "$(dirname "$VIASH_PAR_OUTPUT")" ]; then
  mkdir -p "$(dirname "$VIASH_PAR_OUTPUT")"
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_BAM" ]; then
  VIASH_DIRECTORY_MOUNTS+=( "$(ViashDockerAutodetectMountArg "$VIASH_PAR_BAM")" )
  VIASH_PAR_BAM=$(ViashDockerAutodetectMount "$VIASH_PAR_BAM")
fi
if [ ! -z "$VIASH_PAR_BAM_LIST" ]; then
  VIASH_DIRECTORY_MOUNTS+=( "$(ViashDockerAutodetectMountArg "$VIASH_PAR_BAM_LIST")" )
  VIASH_PAR_BAM_LIST=$(ViashDockerAutodetectMount "$VIASH_PAR_BAM_LIST")
fi
if [ ! -z "$VIASH_PAR_FASTA_REFERENCE" ]; then
  VIASH_DIRECTORY_MOUNTS+=( "$(ViashDockerAutodetectMountArg "$VIASH_PAR_FASTA_REFERENCE")" )
  VIASH_PAR_FASTA_REFERENCE=$(ViashDockerAutodetectMount "$VIASH_PAR_FASTA_REFERENCE")
fi
if [ ! -z "$VIASH_PAR_FASTA_REFERENCE_INDEX" ]; then
  VIASH_DIRECTORY_MOUNTS+=( "$(ViashDockerAutodetectMountArg "$VIASH_PAR_FASTA_REFERENCE_INDEX")" )
  VIASH_PAR_FASTA_REFERENCE_INDEX=$(ViashDockerAutodetectMount "$VIASH_PAR_FASTA_REFERENCE_INDEX")
fi
if [ ! -z "$VIASH_PAR_TARGETS" ]; then
  VIASH_DIRECTORY_MOUNTS+=( "$(ViashDockerAutodetectMountArg "$VIASH_PAR_TARGETS")" )
  VIASH_PAR_TARGETS=$(ViashDockerAutodetectMount "$VIASH_PAR_TARGETS")
fi
if [ ! -z "$VIASH_PAR_SAMPLES" ]; then
  VIASH_DIRECTORY_MOUNTS+=( "$(ViashDockerAutodetectMountArg "$VIASH_PAR_SAMPLES")" )
  VIASH_PAR_SAMPLES=$(ViashDockerAutodetectMount "$VIASH_PAR_SAMPLES")
fi
if [ ! -z "$VIASH_PAR_POPULATIONS" ]; then
  VIASH_DIRECTORY_MOUNTS+=( "$(ViashDockerAutodetectMountArg "$VIASH_PAR_POPULATIONS")" )
  VIASH_PAR_POPULATIONS=$(ViashDockerAutodetectMount "$VIASH_PAR_POPULATIONS")
fi
if [ ! -z "$VIASH_PAR_CNV_MAP" ]; then
  VIASH_DIRECTORY_MOUNTS+=( "$(ViashDockerAutodetectMountArg "$VIASH_PAR_CNV_MAP")" )
  VIASH_PAR_CNV_MAP=$(ViashDockerAutodetectMount "$VIASH_PAR_CNV_MAP")
fi
if [ ! -z "$VIASH_PAR_VARIANT_INPUT" ]; then
  VIASH_DIRECTORY_MOUNTS+=( "$(ViashDockerAutodetectMountArg "$VIASH_PAR_VARIANT_INPUT")" )
  VIASH_PAR_VARIANT_INPUT=$(ViashDockerAutodetectMount "$VIASH_PAR_VARIANT_INPUT")
fi
if [ ! -z "$VIASH_PAR_HAPLOTYPE_BASIS_ALLELES" ]; then
  VIASH_DIRECTORY_MOUNTS+=( "$(ViashDockerAutodetectMountArg "$VIASH_PAR_HAPLOTYPE_BASIS_ALLELES")" )
  VIASH_PAR_HAPLOTYPE_BASIS_ALLELES=$(ViashDockerAutodetectMount "$VIASH_PAR_HAPLOTYPE_BASIS_ALLELES")
fi
if [ ! -z "$VIASH_PAR_OBSERVATION_BIAS" ]; then
  VIASH_DIRECTORY_MOUNTS+=( "$(ViashDockerAutodetectMountArg "$VIASH_PAR_OBSERVATION_BIAS")" )
  VIASH_PAR_OBSERVATION_BIAS=$(ViashDockerAutodetectMount "$VIASH_PAR_OBSERVATION_BIAS")
fi
if [ ! -z "$VIASH_PAR_CONTAMINATION_ESTIMATES" ]; then
  VIASH_DIRECTORY_MOUNTS+=( "$(ViashDockerAutodetectMountArg "$VIASH_PAR_CONTAMINATION_ESTIMATES")" )
  VIASH_PAR_CONTAMINATION_ESTIMATES=$(ViashDockerAutodetectMount "$VIASH_PAR_CONTAMINATION_ESTIMATES")
fi
if [ ! -z "$VIASH_PAR_OUTPUT" ]; then
  VIASH_DIRECTORY_MOUNTS+=( "$(ViashDockerAutodetectMountArg "$VIASH_PAR_OUTPUT")" )
  VIASH_PAR_OUTPUT=$(ViashDockerAutodetectMount "$VIASH_PAR_OUTPUT")
  VIASH_CHOWN_VARS+=( "$VIASH_PAR_OUTPUT" )
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-freebayes-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'
## VIASH START
# The following code has been auto-generated by Viash.
$( if [ ! -z ${VIASH_PAR_BAM+x} ]; then echo "${VIASH_PAR_BAM}" | sed "s#'#'\"'\"'#g;s#.*#par_bam='&'#" ; else echo "# par_bam="; fi )
$( if [ ! -z ${VIASH_PAR_BAM_LIST+x} ]; then echo "${VIASH_PAR_BAM_LIST}" | sed "s#'#'\"'\"'#g;s#.*#par_bam_list='&'#" ; else echo "# par_bam_list="; fi )
$( if [ ! -z ${VIASH_PAR_STDIN+x} ]; then echo "${VIASH_PAR_STDIN}" | sed "s#'#'\"'\"'#g;s#.*#par_stdin='&'#" ; else echo "# par_stdin="; fi )
$( if [ ! -z ${VIASH_PAR_FASTA_REFERENCE+x} ]; then echo "${VIASH_PAR_FASTA_REFERENCE}" | sed "s#'#'\"'\"'#g;s#.*#par_fasta_reference='&'#" ; else echo "# par_fasta_reference="; fi )
$( if [ ! -z ${VIASH_PAR_FASTA_REFERENCE_INDEX+x} ]; then echo "${VIASH_PAR_FASTA_REFERENCE_INDEX}" | sed "s#'#'\"'\"'#g;s#.*#par_fasta_reference_index='&'#" ; else echo "# par_fasta_reference_index="; fi )
$( if [ ! -z ${VIASH_PAR_TARGETS+x} ]; then echo "${VIASH_PAR_TARGETS}" | sed "s#'#'\"'\"'#g;s#.*#par_targets='&'#" ; else echo "# par_targets="; fi )
$( if [ ! -z ${VIASH_PAR_REGION+x} ]; then echo "${VIASH_PAR_REGION}" | sed "s#'#'\"'\"'#g;s#.*#par_region='&'#" ; else echo "# par_region="; fi )
$( if [ ! -z ${VIASH_PAR_SAMPLES+x} ]; then echo "${VIASH_PAR_SAMPLES}" | sed "s#'#'\"'\"'#g;s#.*#par_samples='&'#" ; else echo "# par_samples="; fi )
$( if [ ! -z ${VIASH_PAR_POPULATIONS+x} ]; then echo "${VIASH_PAR_POPULATIONS}" | sed "s#'#'\"'\"'#g;s#.*#par_populations='&'#" ; else echo "# par_populations="; fi )
$( if [ ! -z ${VIASH_PAR_CNV_MAP+x} ]; then echo "${VIASH_PAR_CNV_MAP}" | sed "s#'#'\"'\"'#g;s#.*#par_cnv_map='&'#" ; else echo "# par_cnv_map="; fi )
$( if [ ! -z ${VIASH_PAR_GVCF+x} ]; then echo "${VIASH_PAR_GVCF}" | sed "s#'#'\"'\"'#g;s#.*#par_gvcf='&'#" ; else echo "# par_gvcf="; fi )
$( if [ ! -z ${VIASH_PAR_GVCF_CHUNK+x} ]; then echo "${VIASH_PAR_GVCF_CHUNK}" | sed "s#'#'\"'\"'#g;s#.*#par_gvcf_chunk='&'#" ; else echo "# par_gvcf_chunk="; fi )
$( if [ ! -z ${VIASH_PAR_VARIANT_INPUT+x} ]; then echo "${VIASH_PAR_VARIANT_INPUT}" | sed "s#'#'\"'\"'#g;s#.*#par_variant_input='&'#" ; else echo "# par_variant_input="; fi )
$( if [ ! -z ${VIASH_PAR_ONLY_USE_INPUT_ALLELES+x} ]; then echo "${VIASH_PAR_ONLY_USE_INPUT_ALLELES}" | sed "s#'#'\"'\"'#g;s#.*#par_only_use_input_alleles='&'#" ; else echo "# par_only_use_input_alleles="; fi )
$( if [ ! -z ${VIASH_PAR_HAPLOTYPE_BASIS_ALLELES+x} ]; then echo "${VIASH_PAR_HAPLOTYPE_BASIS_ALLELES}" | sed "s#'#'\"'\"'#g;s#.*#par_haplotype_basis_alleles='&'#" ; else echo "# par_haplotype_basis_alleles="; fi )
$( if [ ! -z ${VIASH_PAR_REPORT_ALL_HAPLOTYPE_ALLELES+x} ]; then echo "${VIASH_PAR_REPORT_ALL_HAPLOTYPE_ALLELES}" | sed "s#'#'\"'\"'#g;s#.*#par_report_all_haplotype_alleles='&'#" ; else echo "# par_report_all_haplotype_alleles="; fi )
$( if [ ! -z ${VIASH_PAR_REPORT_MONOMORPHIC+x} ]; then echo "${VIASH_PAR_REPORT_MONOMORPHIC}" | sed "s#'#'\"'\"'#g;s#.*#par_report_monomorphic='&'#" ; else echo "# par_report_monomorphic="; fi )
$( if [ ! -z ${VIASH_PAR_PVAR+x} ]; then echo "${VIASH_PAR_PVAR}" | sed "s#'#'\"'\"'#g;s#.*#par_pvar='&'#" ; else echo "# par_pvar="; fi )
$( if [ ! -z ${VIASH_PAR_STRICT_VCF+x} ]; then echo "${VIASH_PAR_STRICT_VCF}" | sed "s#'#'\"'\"'#g;s#.*#par_strict_vcf='&'#" ; else echo "# par_strict_vcf="; fi )
$( if [ ! -z ${VIASH_PAR_THETA+x} ]; then echo "${VIASH_PAR_THETA}" | sed "s#'#'\"'\"'#g;s#.*#par_theta='&'#" ; else echo "# par_theta="; fi )
$( if [ ! -z ${VIASH_PAR_PLOIDY+x} ]; then echo "${VIASH_PAR_PLOIDY}" | sed "s#'#'\"'\"'#g;s#.*#par_ploidy='&'#" ; else echo "# par_ploidy="; fi )
$( if [ ! -z ${VIASH_PAR_POOLED_DISCRETE+x} ]; then echo "${VIASH_PAR_POOLED_DISCRETE}" | sed "s#'#'\"'\"'#g;s#.*#par_pooled_discrete='&'#" ; else echo "# par_pooled_discrete="; fi )
$( if [ ! -z ${VIASH_PAR_POOLED_CONTINUOUS+x} ]; then echo "${VIASH_PAR_POOLED_CONTINUOUS}" | sed "s#'#'\"'\"'#g;s#.*#par_pooled_continuous='&'#" ; else echo "# par_pooled_continuous="; fi )
$( if [ ! -z ${VIASH_PAR_USE_REFERENCE_ALLELE+x} ]; then echo "${VIASH_PAR_USE_REFERENCE_ALLELE}" | sed "s#'#'\"'\"'#g;s#.*#par_use_reference_allele='&'#" ; else echo "# par_use_reference_allele="; fi )
$( if [ ! -z ${VIASH_PAR_REFERENCE_QUALITY+x} ]; then echo "${VIASH_PAR_REFERENCE_QUALITY}" | sed "s#'#'\"'\"'#g;s#.*#par_reference_quality='&'#" ; else echo "# par_reference_quality="; fi )
$( if [ ! -z ${VIASH_PAR_THROW_AWAY_SNP_OBS+x} ]; then echo "${VIASH_PAR_THROW_AWAY_SNP_OBS}" | sed "s#'#'\"'\"'#g;s#.*#par_throw_away_snp_obs='&'#" ; else echo "# par_throw_away_snp_obs="; fi )
$( if [ ! -z ${VIASH_PAR_THROW_AWAY_MNPS_OBS+x} ]; then echo "${VIASH_PAR_THROW_AWAY_MNPS_OBS}" | sed "s#'#'\"'\"'#g;s#.*#par_throw_away_mnps_obs='&'#" ; else echo "# par_throw_away_mnps_obs="; fi )
$( if [ ! -z ${VIASH_PAR_THROW_AWAY_INDEL_OBS+x} ]; then echo "${VIASH_PAR_THROW_AWAY_INDEL_OBS}" | sed "s#'#'\"'\"'#g;s#.*#par_throw_away_indel_obs='&'#" ; else echo "# par_throw_away_indel_obs="; fi )
$( if [ ! -z ${VIASH_PAR_THROW_AWAY_COMPLEX_OBS+x} ]; then echo "${VIASH_PAR_THROW_AWAY_COMPLEX_OBS}" | sed "s#'#'\"'\"'#g;s#.*#par_throw_away_complex_obs='&'#" ; else echo "# par_throw_away_complex_obs="; fi )
$( if [ ! -z ${VIASH_PAR_USE_BEST_N_ALLELES+x} ]; then echo "${VIASH_PAR_USE_BEST_N_ALLELES}" | sed "s#'#'\"'\"'#g;s#.*#par_use_best_n_alleles='&'#" ; else echo "# par_use_best_n_alleles="; fi )
$( if [ ! -z ${VIASH_PAR_MAX_COMPLEX_GAP+x} ]; then echo "${VIASH_PAR_MAX_COMPLEX_GAP}" | sed "s#'#'\"'\"'#g;s#.*#par_max_complex_gap='&'#" ; else echo "# par_max_complex_gap="; fi )
$( if [ ! -z ${VIASH_PAR_MIN_REPEAT_SIZE+x} ]; then echo "${VIASH_PAR_MIN_REPEAT_SIZE}" | sed "s#'#'\"'\"'#g;s#.*#par_min_repeat_size='&'#" ; else echo "# par_min_repeat_size="; fi )
$( if [ ! -z ${VIASH_PAR_MIN_REPEAT_ENTROPY+x} ]; then echo "${VIASH_PAR_MIN_REPEAT_ENTROPY}" | sed "s#'#'\"'\"'#g;s#.*#par_min_repeat_entropy='&'#" ; else echo "# par_min_repeat_entropy="; fi )
$( if [ ! -z ${VIASH_PAR_NO_PARTIAL_OBSERVATIONS+x} ]; then echo "${VIASH_PAR_NO_PARTIAL_OBSERVATIONS}" | sed "s#'#'\"'\"'#g;s#.*#par_no_partial_observations='&'#" ; else echo "# par_no_partial_observations="; fi )
$( if [ ! -z ${VIASH_PAR_DONT_LEFT_ALIGN_INDELS+x} ]; then echo "${VIASH_PAR_DONT_LEFT_ALIGN_INDELS}" | sed "s#'#'\"'\"'#g;s#.*#par_dont_left_align_indels='&'#" ; else echo "# par_dont_left_align_indels="; fi )
$( if [ ! -z ${VIASH_PAR_USE_DUPLICATE_READS+x} ]; then echo "${VIASH_PAR_USE_DUPLICATE_READS}" | sed "s#'#'\"'\"'#g;s#.*#par_use_duplicate_reads='&'#" ; else echo "# par_use_duplicate_reads="; fi )
$( if [ ! -z ${VIASH_PAR_MIN_MAPPING_QUALITY+x} ]; then echo "${VIASH_PAR_MIN_MAPPING_QUALITY}" | sed "s#'#'\"'\"'#g;s#.*#par_min_mapping_quality='&'#" ; else echo "# par_min_mapping_quality="; fi )
$( if [ ! -z ${VIASH_PAR_MIN_BASE_QUALITY+x} ]; then echo "${VIASH_PAR_MIN_BASE_QUALITY}" | sed "s#'#'\"'\"'#g;s#.*#par_min_base_quality='&'#" ; else echo "# par_min_base_quality="; fi )
$( if [ ! -z ${VIASH_PAR_MIN_SUPPORTING_ALLELE_QSUM+x} ]; then echo "${VIASH_PAR_MIN_SUPPORTING_ALLELE_QSUM}" | sed "s#'#'\"'\"'#g;s#.*#par_min_supporting_allele_qsum='&'#" ; else echo "# par_min_supporting_allele_qsum="; fi )
$( if [ ! -z ${VIASH_PAR_MIN_SUPPORTING_MAPPING_QSUM+x} ]; then echo "${VIASH_PAR_MIN_SUPPORTING_MAPPING_QSUM}" | sed "s#'#'\"'\"'#g;s#.*#par_min_supporting_mapping_qsum='&'#" ; else echo "# par_min_supporting_mapping_qsum="; fi )
$( if [ ! -z ${VIASH_PAR_MISMATCH_BASE_QUALITY_THRESHOLD+x} ]; then echo "${VIASH_PAR_MISMATCH_BASE_QUALITY_THRESHOLD}" | sed "s#'#'\"'\"'#g;s#.*#par_mismatch_base_quality_threshold='&'#" ; else echo "# par_mismatch_base_quality_threshold="; fi )
$( if [ ! -z ${VIASH_PAR_READ_MAX_MISMATCH_FRACTION+x} ]; then echo "${VIASH_PAR_READ_MAX_MISMATCH_FRACTION}" | sed "s#'#'\"'\"'#g;s#.*#par_read_max_mismatch_fraction='&'#" ; else echo "# par_read_max_mismatch_fraction="; fi )
$( if [ ! -z ${VIASH_PAR_READ_MISMATCH_LIMIT+x} ]; then echo "${VIASH_PAR_READ_MISMATCH_LIMIT}" | sed "s#'#'\"'\"'#g;s#.*#par_read_mismatch_limit='&'#" ; else echo "# par_read_mismatch_limit="; fi )
$( if [ ! -z ${VIASH_PAR_READ_SNP_LIMIT+x} ]; then echo "${VIASH_PAR_READ_SNP_LIMIT}" | sed "s#'#'\"'\"'#g;s#.*#par_read_snp_limit='&'#" ; else echo "# par_read_snp_limit="; fi )
$( if [ ! -z ${VIASH_PAR_READ_INDEL_LIMIT+x} ]; then echo "${VIASH_PAR_READ_INDEL_LIMIT}" | sed "s#'#'\"'\"'#g;s#.*#par_read_indel_limit='&'#" ; else echo "# par_read_indel_limit="; fi )
$( if [ ! -z ${VIASH_PAR_STANDARD_FILTERS+x} ]; then echo "${VIASH_PAR_STANDARD_FILTERS}" | sed "s#'#'\"'\"'#g;s#.*#par_standard_filters='&'#" ; else echo "# par_standard_filters="; fi )
$( if [ ! -z ${VIASH_PAR_MIN_ALTERNATE_FRACTION+x} ]; then echo "${VIASH_PAR_MIN_ALTERNATE_FRACTION}" | sed "s#'#'\"'\"'#g;s#.*#par_min_alternate_fraction='&'#" ; else echo "# par_min_alternate_fraction="; fi )
$( if [ ! -z ${VIASH_PAR_MIN_ALTERNATE_COUNT+x} ]; then echo "${VIASH_PAR_MIN_ALTERNATE_COUNT}" | sed "s#'#'\"'\"'#g;s#.*#par_min_alternate_count='&'#" ; else echo "# par_min_alternate_count="; fi )
$( if [ ! -z ${VIASH_PAR_MIN_ALTERNATE_QSUM+x} ]; then echo "${VIASH_PAR_MIN_ALTERNATE_QSUM}" | sed "s#'#'\"'\"'#g;s#.*#par_min_alternate_qsum='&'#" ; else echo "# par_min_alternate_qsum="; fi )
$( if [ ! -z ${VIASH_PAR_MIN_ALTERNATE_TOTAL+x} ]; then echo "${VIASH_PAR_MIN_ALTERNATE_TOTAL}" | sed "s#'#'\"'\"'#g;s#.*#par_min_alternate_total='&'#" ; else echo "# par_min_alternate_total="; fi )
$( if [ ! -z ${VIASH_PAR_MIN_COVERAGE+x} ]; then echo "${VIASH_PAR_MIN_COVERAGE}" | sed "s#'#'\"'\"'#g;s#.*#par_min_coverage='&'#" ; else echo "# par_min_coverage="; fi )
$( if [ ! -z ${VIASH_PAR_MAX_COVERAGE+x} ]; then echo "${VIASH_PAR_MAX_COVERAGE}" | sed "s#'#'\"'\"'#g;s#.*#par_max_coverage='&'#" ; else echo "# par_max_coverage="; fi )
$( if [ ! -z ${VIASH_PAR_NO_POPULATION_PRIORS+x} ]; then echo "${VIASH_PAR_NO_POPULATION_PRIORS}" | sed "s#'#'\"'\"'#g;s#.*#par_no_population_priors='&'#" ; else echo "# par_no_population_priors="; fi )
$( if [ ! -z ${VIASH_PAR_HWE_PRIORS_OFF+x} ]; then echo "${VIASH_PAR_HWE_PRIORS_OFF}" | sed "s#'#'\"'\"'#g;s#.*#par_hwe_priors_off='&'#" ; else echo "# par_hwe_priors_off="; fi )
$( if [ ! -z ${VIASH_PAR_BINOMIAL_OBS_PRIORS_OFF+x} ]; then echo "${VIASH_PAR_BINOMIAL_OBS_PRIORS_OFF}" | sed "s#'#'\"'\"'#g;s#.*#par_binomial_obs_priors_off='&'#" ; else echo "# par_binomial_obs_priors_off="; fi )
$( if [ ! -z ${VIASH_PAR_ALLELE_BALANCE_PRIORS_OFF+x} ]; then echo "${VIASH_PAR_ALLELE_BALANCE_PRIORS_OFF}" | sed "s#'#'\"'\"'#g;s#.*#par_allele_balance_priors_off='&'#" ; else echo "# par_allele_balance_priors_off="; fi )
$( if [ ! -z ${VIASH_PAR_OBSERVATION_BIAS+x} ]; then echo "${VIASH_PAR_OBSERVATION_BIAS}" | sed "s#'#'\"'\"'#g;s#.*#par_observation_bias='&'#" ; else echo "# par_observation_bias="; fi )
$( if [ ! -z ${VIASH_PAR_BASE_QUALITY_CAP+x} ]; then echo "${VIASH_PAR_BASE_QUALITY_CAP}" | sed "s#'#'\"'\"'#g;s#.*#par_base_quality_cap='&'#" ; else echo "# par_base_quality_cap="; fi )
$( if [ ! -z ${VIASH_PAR_PROB_CONTAMINATION+x} ]; then echo "${VIASH_PAR_PROB_CONTAMINATION}" | sed "s#'#'\"'\"'#g;s#.*#par_prob_contamination='&'#" ; else echo "# par_prob_contamination="; fi )
$( if [ ! -z ${VIASH_PAR_LEGACY_GLS+x} ]; then echo "${VIASH_PAR_LEGACY_GLS}" | sed "s#'#'\"'\"'#g;s#.*#par_legacy_gls='&'#" ; else echo "# par_legacy_gls="; fi )
$( if [ ! -z ${VIASH_PAR_CONTAMINATION_ESTIMATES+x} ]; then echo "${VIASH_PAR_CONTAMINATION_ESTIMATES}" | sed "s#'#'\"'\"'#g;s#.*#par_contamination_estimates='&'#" ; else echo "# par_contamination_estimates="; fi )
$( if [ ! -z ${VIASH_PAR_REPORT_GENOTYPE_LIKELIHOOD_MAX+x} ]; then echo "${VIASH_PAR_REPORT_GENOTYPE_LIKELIHOOD_MAX}" | sed "s#'#'\"'\"'#g;s#.*#par_report_genotype_likelihood_max='&'#" ; else echo "# par_report_genotype_likelihood_max="; fi )
$( if [ ! -z ${VIASH_PAR_GENOTYPING_MAX_ITERATIONS+x} ]; then echo "${VIASH_PAR_GENOTYPING_MAX_ITERATIONS}" | sed "s#'#'\"'\"'#g;s#.*#par_genotyping_max_iterations='&'#" ; else echo "# par_genotyping_max_iterations="; fi )
$( if [ ! -z ${VIASH_PAR_GENOTYPING_MAX_BANDDEPTH+x} ]; then echo "${VIASH_PAR_GENOTYPING_MAX_BANDDEPTH}" | sed "s#'#'\"'\"'#g;s#.*#par_genotyping_max_banddepth='&'#" ; else echo "# par_genotyping_max_banddepth="; fi )
$( if [ ! -z ${VIASH_PAR_POSTERIOR_INTEGRATION_LIMITS+x} ]; then echo "${VIASH_PAR_POSTERIOR_INTEGRATION_LIMITS}" | sed "s#'#'\"'\"'#g;s#.*#par_posterior_integration_limits='&'#" ; else echo "# par_posterior_integration_limits="; fi )
$( if [ ! -z ${VIASH_PAR_EXCLUDE_UNOBSERVED_GENOTYPES+x} ]; then echo "${VIASH_PAR_EXCLUDE_UNOBSERVED_GENOTYPES}" | sed "s#'#'\"'\"'#g;s#.*#par_exclude_unobserved_genotypes='&'#" ; else echo "# par_exclude_unobserved_genotypes="; fi )
$( if [ ! -z ${VIASH_PAR_GENOTYPE_VARIANT_THRESHOLD+x} ]; then echo "${VIASH_PAR_GENOTYPE_VARIANT_THRESHOLD}" | sed "s#'#'\"'\"'#g;s#.*#par_genotype_variant_threshold='&'#" ; else echo "# par_genotype_variant_threshold="; fi )
$( if [ ! -z ${VIASH_PAR_USE_MAPPING_QUALITY+x} ]; then echo "${VIASH_PAR_USE_MAPPING_QUALITY}" | sed "s#'#'\"'\"'#g;s#.*#par_use_mapping_quality='&'#" ; else echo "# par_use_mapping_quality="; fi )
$( if [ ! -z ${VIASH_PAR_HARMONIC_INDEL_QUALITY+x} ]; then echo "${VIASH_PAR_HARMONIC_INDEL_QUALITY}" | sed "s#'#'\"'\"'#g;s#.*#par_harmonic_indel_quality='&'#" ; else echo "# par_harmonic_indel_quality="; fi )
$( if [ ! -z ${VIASH_PAR_READ_DEPENDENCE_FACTOR+x} ]; then echo "${VIASH_PAR_READ_DEPENDENCE_FACTOR}" | sed "s#'#'\"'\"'#g;s#.*#par_read_dependence_factor='&'#" ; else echo "# par_read_dependence_factor="; fi )
$( if [ ! -z ${VIASH_PAR_GENOTYPE_QUALITIES+x} ]; then echo "${VIASH_PAR_GENOTYPE_QUALITIES}" | sed "s#'#'\"'\"'#g;s#.*#par_genotype_qualities='&'#" ; else echo "# par_genotype_qualities="; fi )
$( if [ ! -z ${VIASH_PAR_DEBUG+x} ]; then echo "${VIASH_PAR_DEBUG}" | sed "s#'#'\"'\"'#g;s#.*#par_debug='&'#" ; else echo "# par_debug="; fi )
$( if [ ! -z ${VIASH_PAR_DD+x} ]; then echo "${VIASH_PAR_DD}" | sed "s#'#'\"'\"'#g;s#.*#par_dd='&'#" ; else echo "# par_dd="; fi )
$( if [ ! -z ${VIASH_PAR_OUTPUT+x} ]; then echo "${VIASH_PAR_OUTPUT}" | sed "s#'#'\"'\"'#g;s#.*#par_output='&'#" ; else echo "# par_output="; 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_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
#!/bin/bash
set -eo pipefail

# Unset boolean flags if their values are not 'true'
for flag in par_stdin par_gvcf par_only_use_input_alleles par_report_all_haplotype_alleles par_report_monomorphic par_strict_vcf \\
             par_pooled_discrete par_pooled_continuous par_use_reference_allele par_throw_away_snp_obs par_throw_away_indel_obs par_throw_away_mnps_obs par_throw_away_complex_obs \\
             par_no_partial_observations par_dont_left_align_indels par_use_duplicate_reads par_standard_filters par_no_population_priors \\
             par_hwe_priors_off par_binomial_obs_priors_off par_allele_balance_priors_off par_legacy_gls par_report_genotype_likelihood_max \\
             par_exclude_unobserved_genotypes par_use_mapping_quality par_harmonic_indel_quality par_genotype_qualities par_debug par_dd; do
  [[ "\${!flag}" != "true" ]] && unset "\$flag"
done

# Create output directory if it doesn't exist
if [ ! -d "\$par_output" ]; then
  mkdir -p "\$par_output"
fi

freebayes \\
  --fasta-reference \$par_fasta_reference \\
  --pvar \$par_pvar \\
  --theta \$par_theta \\
  --ploidy \$par_ploidy \\
  --min-repeat-entropy \$par_min_repeat_entropy \\
  --reference-quality \$par_reference_quality \\
  --use-best-n-alleles \$par_use_best_n_alleles \\
  --max-complex-gap \$par_max_complex_gap \\
  --min-repeat-size \$par_min_repeat_size \\
  --min-mapping-quality \$par_min_mapping_quality \\
  --min-base-quality \$par_min_base_quality \\
  --min-supporting-allele-qsum \$par_min_supporting_allele_qsum \\
  --min-supporting-mapping-qsum \$par_min_supporting_mapping_qsum \\
  --mismatch-base-quality-threshold \$par_mismatch_base_quality_threshold \\
  --read-max-mismatch-fraction \$par_read_max_mismatch_fraction \\
  --min-alternate-fraction \$par_min_alternate_fraction \\
  --min-alternate-count \$par_min_alternate_count \\
  --min-alternate-qsum \$par_min_alternate_qsum \\
  --min-alternate-total \$par_min_alternate_total \\
  --min-coverage \$par_min_coverage \\
  --genotyping-max-iterations \$par_genotyping_max_iterations \\
  --genotyping-max-banddepth \$par_genotyping_max_banddepth \\
  --posterior-integration-limits \$par_posterior_integration_limits \\
  --read-dependence-factor \$par_read_dependence_factor \\
  --vcf \${par_output}/\${par_vcf} \\
  \${par_bam:+--bam \$par_bam} \\
  \${par_bam_list:+--bam-list \$par_bam_list} \\
  \${par_stdin:+--stdin} \\
  \${par_targets:+--targets \$par_targets} \\
  \${par_region:+--region \$par_region} \\
  \${par_max_coverage:+--max-coverage \$par_max_coverage} \\
  \${par_samples:+--samples \$par_samples} \\
  \${par_populations:+--populations \$par_populations} \\
  \${par_cnv_map:+--cnv-map \$par_cnv_map} \\
  \${par_gvcf:+--gvcf} \\
  \${par_gvcf_chunk:+--gvcf-chunk \$par_gvcf_chunk} \\
  \${par_variant_input:+--variant-input \$par_variant_input} \\
  \${par_only_use_input_alleles:+--only-use-input-alleles} \\
  \${par_haplotype_basis_alleles:+--haplotype-basis-alleles \$par_haplotype_basis_alleles} \\
  \${par_report_all_haplotype_alleles:+--report-all-haplotype-alleles} \\
  \${par_report_monomorphic:+--report-monomorphic} \\
  \${par_strict_vcf:+--strict-vcf} \\
  \${par_pooled_discrete:+--pooled-discrete} \\
  \${par_pooled_continuous:+--pooled-continuous} \\
  \${par_use_reference_allele:+--use-reference-allele} \\
  \${par_throw_away_snp_obs:+--throw-away-snp-obs} \\
  \${par_throw_away_indel_obs:+--throw-away-indel-obs} \\
  \${par_throw_away_mnps_obs:+--throw-away-mnps-obs} \\
  \${par_throw_away_complex_obs:+--throw-away-complex-obs} \\
  \${par_no_partial_observations:+--no-partial-observations} \\
  \${par_dont_left_align_indels:+--dont-left-align-indels} \\
  \${par_use_duplicate_reads:+--use-duplicate-reads} \\
  \${par_standard_filters:+--standard-filters} \\
  \${par_no_population_priors:+--no-population-priors} \\
  \${par_hwe_priors_off:+--hwe-priors-off} \\
  \${par_binomial_obs_priors_off:+--binomial-obs-priors-off} \\
  \${par_allele_balance_priors_off:+--allele-balance-priors-off} \\
  \${par_legacy_gls:+--legacy-gls} \\
  \${par_report_genotype_likelihood_max:+--report-genotype-likelihood-max} \\
  \${par_exclude_unobserved_genotypes:+--exclude-unobserved-genotypes} \\
  \${par_use_mapping_quality:+--use-mapping-quality} \\
  \${par_harmonic_indel_quality:+--harmonic-indel-quality} \\
  \${par_genotype_qualities:+--genotype-qualities} \\
  \${par_debug:+--debug} \\
  \${par_dd:+-dd} \\
  \${par_observation_bias:+--observation-bias \$par_observation_bias} \\
  \${par_read_mismatch_limit:+--read-mismatch-limit \$par_read_mismatch_limit} \\
  \${par_read_snp_limit:+--read-snp-limit \$par_read_snp_limit} \\
  \${par_read_indel_limit:+--read-indel-limit \$par_read_indel_limit} \\
  \${par_base_quality_cap:+--base-quality-cap \$par_base_quality_cap} \\
  \${par_prob_contamination:+--prob-contamination \$par_prob_contamination} \\
  \${par_contamination_estimates:+--contamination-estimates \$par_contamination_estimates} \\
  \${par_genotype_variant_threshold:+--genotype-variant-threshold \$par_genotype_variant_threshold}
VIASHMAIN
bash "\$tempscript" &
wait "\$!"

VIASHEOF


if [[ "$VIASH_ENGINE_TYPE" == "docker" ]]; then
  # strip viash automount from file paths
  
  if [ ! -z "$VIASH_PAR_BAM" ]; then
    VIASH_PAR_BAM=$(ViashDockerStripAutomount "$VIASH_PAR_BAM")
  fi
  if [ ! -z "$VIASH_PAR_BAM_LIST" ]; then
    VIASH_PAR_BAM_LIST=$(ViashDockerStripAutomount "$VIASH_PAR_BAM_LIST")
  fi
  if [ ! -z "$VIASH_PAR_FASTA_REFERENCE" ]; then
    VIASH_PAR_FASTA_REFERENCE=$(ViashDockerStripAutomount "$VIASH_PAR_FASTA_REFERENCE")
  fi
  if [ ! -z "$VIASH_PAR_FASTA_REFERENCE_INDEX" ]; then
    VIASH_PAR_FASTA_REFERENCE_INDEX=$(ViashDockerStripAutomount "$VIASH_PAR_FASTA_REFERENCE_INDEX")
  fi
  if [ ! -z "$VIASH_PAR_TARGETS" ]; then
    VIASH_PAR_TARGETS=$(ViashDockerStripAutomount "$VIASH_PAR_TARGETS")
  fi
  if [ ! -z "$VIASH_PAR_SAMPLES" ]; then
    VIASH_PAR_SAMPLES=$(ViashDockerStripAutomount "$VIASH_PAR_SAMPLES")
  fi
  if [ ! -z "$VIASH_PAR_POPULATIONS" ]; then
    VIASH_PAR_POPULATIONS=$(ViashDockerStripAutomount "$VIASH_PAR_POPULATIONS")
  fi
  if [ ! -z "$VIASH_PAR_CNV_MAP" ]; then
    VIASH_PAR_CNV_MAP=$(ViashDockerStripAutomount "$VIASH_PAR_CNV_MAP")
  fi
  if [ ! -z "$VIASH_PAR_VARIANT_INPUT" ]; then
    VIASH_PAR_VARIANT_INPUT=$(ViashDockerStripAutomount "$VIASH_PAR_VARIANT_INPUT")
  fi
  if [ ! -z "$VIASH_PAR_HAPLOTYPE_BASIS_ALLELES" ]; then
    VIASH_PAR_HAPLOTYPE_BASIS_ALLELES=$(ViashDockerStripAutomount "$VIASH_PAR_HAPLOTYPE_BASIS_ALLELES")
  fi
  if [ ! -z "$VIASH_PAR_OBSERVATION_BIAS" ]; then
    VIASH_PAR_OBSERVATION_BIAS=$(ViashDockerStripAutomount "$VIASH_PAR_OBSERVATION_BIAS")
  fi
  if [ ! -z "$VIASH_PAR_CONTAMINATION_ESTIMATES" ]; then
    VIASH_PAR_CONTAMINATION_ESTIMATES=$(ViashDockerStripAutomount "$VIASH_PAR_CONTAMINATION_ESTIMATES")
  fi
  if [ ! -z "$VIASH_PAR_OUTPUT" ]; then
    VIASH_PAR_OUTPUT=$(ViashDockerStripAutomount "$VIASH_PAR_OUTPUT")
  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" ] && [ ! -e "$VIASH_PAR_OUTPUT" ]; then
  ViashError "Output file '$VIASH_PAR_OUTPUT' does not exist."
  exit 1
fi


exit 0
