#!/usr/bin/env bash

# umi_tools_dedup main
# 
# 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:
#  * Emma Rousseau (author, maintainer)

set -e

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

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

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

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

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

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

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

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

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

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

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

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

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

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



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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  if [[ "$engine_id" == "docker" ]]; then
    cat << 'VIASHDOCKER'
FROM quay.io/biocontainers/umi_tools:1.1.5--py39hf95cd2a_1
ENTRYPOINT []
RUN umi_tools -v | sed 's/ version//g' > /var/software_versions.txt

LABEL org.opencontainers.image.authors="Emma Rousseau"
LABEL org.opencontainers.image.description="Companion container for running component umi_tools umi_tools_dedup"
LABEL org.opencontainers.image.created="2025-10-03T08:11:13Z"
LABEL org.opencontainers.image.source="https://github.com/CGATOxford/UMI-tools"
LABEL org.opencontainers.image.revision="9991e9a4f5ddd5085a4e2becf962950b1daf594b"
LABEL org.opencontainers.image.version="main"

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 "umi_tools_dedup main"
  echo ""
  echo "Deduplicate reads based on the mapping co-ordinate and the UMI attached to the"
  echo "read."
  echo ""
  echo "Inputs:"
  echo "    --stdin, --input"
  echo "        type: file, required parameter, file must exist"
  echo "        Input BAM or SAM file. Use --in_sam to specify SAM format."
  echo ""
  echo "    --in_sam"
  echo "        type: boolean_true"
  echo "        By default, inputs are assumed to be in BAM format. Use this options to"
  echo "        specify the use of SAM"
  echo "        format for input."
  echo ""
  echo "    --bai"
  echo "        type: file, file must exist"
  echo "        BAM index"
  echo ""
  echo "    --random_seed"
  echo "        type: integer"
  echo "        Random seed to initialize number generator with."
  echo ""
  echo "Outputs:"
  echo "    --stdout, --output"
  echo "        type: file, required parameter, output, file must exist"
  echo "        Deduplicated BAM file."
  echo ""
  echo "    --out_sam"
  echo "        type: boolean_true"
  echo "        By default, outputa are written in BAM format. Use this options to"
  echo "        specify the use of SAM format"
  echo "        for output."
  echo ""
  echo "    --paired"
  echo "        type: boolean_true"
  echo "        BAM is paired end - output both read pairs. This will also force the use"
  echo "        of the template length"
  echo "        to determine reads with the same mapping coordinates."
  echo ""
  echo "    --output_stats"
  echo "        type: string"
  echo "        Generate files containing UMI based deduplication statistics files with"
  echo "        this prefix in the file names."
  echo ""
  echo "    --extract_umi_method"
  echo "        type: string"
  echo "        example: read_id"
  echo "        choices: [ read_id, tag, umis ]"
  echo "        Specify the method by which the barcodes were encoded in the read."
  echo "        The options are:"
  echo "          * read_id (default)"
  echo "          * tag"
  echo "          * umis"
  echo ""
  echo "    --umi_tag"
  echo "        type: string"
  echo "        The tag containing the UMI sequence. This is only required if the"
  echo "        extract_umi_method is set to tag."
  echo ""
  echo "    --umi_separator"
  echo "        type: string"
  echo "        example: _"
  echo "        The separator used to separate the UMI from the read sequence. This is"
  echo "        only required if the"
  echo "        extract_umi_method is set to id_read. Default: \`_\`."
  echo ""
  echo "    --umi_tag_split"
  echo "        type: string"
  echo "        Separate the UMI in tag by <SPLIT> and take the first element."
  echo ""
  echo "    --umi_tag_delimiter"
  echo "        type: string"
  echo "        Separate the UMI in by <DELIMITER> and concatenate the elements."
  echo ""
  echo "    --cell_tag"
  echo "        type: string"
  echo "        The tag containing the cell barcode sequence. This is only required if"
  echo "        the extract_umi_method"
  echo "        is set to tag."
  echo ""
  echo "    --cell_tag_split"
  echo "        type: string"
  echo "        Separate the cell barcode in tag by <SPLIT> and take the first element."
  echo ""
  echo "    --cell_tag_delimiter"
  echo "        type: string"
  echo "        Separate the cell barcode in by <DELIMITER> and concatenate the"
  echo "        elements."
  echo ""
  echo "Grouping Options:"
  echo "    --method"
  echo "        type: string"
  echo "        example: directional"
  echo "        choices: [ unique, percentile, cluster, adjacency, directional ]"
  echo "        The method to use for grouping reads."
  echo "        The options are:"
  echo "          * unique"
  echo "          * percentile"
  echo "          * cluster"
  echo "          * adjacency"
  echo "          * directional (default)"
  echo ""
  echo "    --edit_distance_threshold"
  echo "        type: integer"
  echo "        example: 1"
  echo "        For the adjacency and cluster methods the threshold for the edit"
  echo "        distance to connect two"
  echo "        UMIs in the network can be increased. The default value of 1 works best"
  echo "        unless the UMI is"
  echo "        very long (>14bp). Default: \`1\`."
  echo ""
  echo "    --spliced_is_unique"
  echo "        type: boolean_true"
  echo "        Causes two reads that start in the same position on the same strand and"
  echo "        having the same UMI"
  echo "        to be considered unique if one is spliced and the other is not. (Uses"
  echo "        the 'N' cigar operation"
  echo "        to test for splicing)."
  echo ""
  echo "    --soft_clip_threshold"
  echo "        type: integer"
  echo "        example: 4"
  echo "        Mappers that soft clip will sometimes do so rather than mapping a"
  echo "        spliced read if there is only"
  echo "        a small overhang over the exon junction. By setting this option, you can"
  echo "        treat reads with at"
  echo "        least this many bases soft-clipped at the 3' end as spliced. Default:"
  echo "        \`4\`."
  echo ""
  echo "    --multimapping_detection_method"
  echo "        type: string"
  echo "        If the sam/bam contains tags to identify multimapping reads, you can"
  echo "        specify for use when selecting"
  echo "        the best read at a given loci. Supported tags are \`NH\`, \`X0\` and \`XT\`."
  echo "        If not specified, the read"
  echo "        with the highest mapping quality will be selected."
  echo ""
  echo "    --read_length"
  echo "        type: boolean_true"
  echo "        Use the read length as a criteria when deduping, for e.g. sRNA-Seq."
  echo ""
  echo "Single-cell RNA-Seq Options:"
  echo "    --per_gene"
  echo "        type: boolean_true"
  echo "        Reads will be grouped together if they have the same gene. This is"
  echo "        useful if your library prep"
  echo "        generates PCR duplicates with non identical alignment positions such as"
  echo "        CEL-Seq. Note this option"
  echo "        is hardcoded to be on with the count command. I.e. counting is always"
  echo "        performed per-gene. Must be"
  echo "        combined with either --gene_tag or --per_contig option."
  echo ""
  echo "    --gene_tag"
  echo "        type: string"
  echo "        Deduplicate per gene. The gene information is encoded in the bam read"
  echo "        tag specified."
  echo ""
  echo "    --assigned_status_tag"
  echo "        type: string"
  echo "        BAM tag which describes whether a read is assigned to a gene. Defaults"
  echo "        to the same value as given"
  echo "        for --gene_tag."
  echo ""
  echo "    --skip_tags_regex"
  echo "        type: string"
  echo "        Use in conjunction with the --assigned_status_tag option to skip any"
  echo "        reads where the tag matches"
  echo "        this regex. Default (\"^[__|Unassigned]\") matches anything which starts"
  echo "        with \"__\" or \"Unassigned\"."
  echo ""
  echo "    --per_contig"
  echo "        type: boolean_true"
  echo "        Deduplicate per contig (field 3 in BAM; RNAME). All reads with the sam"
  echo "        contig will be considered to"
  echo "        have the same alignment position. This is useful if you have aligned to"
  echo "        a reference transcriptome"
  echo "        with one transcript per gene. If you have aligned to a transcriptome"
  echo "        with more than one transcript"
  echo "        per gene, you can supply a map between transcripts and gene using the"
  echo "        --gene_transcript_map option."
  echo ""
  echo "    --gene_transcript_map"
  echo "        type: file, file must exist"
  echo "        A file containing a mapping between gene names and transcript names. The"
  echo "        file should be tab"
  echo "        separated with the gene name in the first column and the transcript name"
  echo "        in the second column."
  echo ""
  echo "    --per_cell"
  echo "        type: boolean_true"
  echo "        Reads will only be grouped together if they have the same cell barcode."
  echo "        Can be combined with"
  echo "        --per_gene."
  echo ""
  echo "SAM/BAM Options:"
  echo "    --mapping_quality"
  echo "        type: integer"
  echo "        example: 0"
  echo "        Minimium mapping quality (MAPQ) for a read to be retained. Default: \`0\`."
  echo ""
  echo "    --unmapped_reads"
  echo "        type: string"
  echo "        example: discard"
  echo "        How unmapped reads should be handled."
  echo "        The options are:"
  echo "          * \"discard\": Discard all unmapped reads. (default)"
  echo "          * \"use\":     If read2 is unmapped, deduplicate using read1 only."
  echo "        Requires --paired."
  echo "          * \"output\":  Output unmapped reads/read pairs without UMI"
  echo "        grouping/deduplication. Only available in umi_tools group."
  echo ""
  echo "    --chimeric_pairs"
  echo "        type: string"
  echo "        example: use"
  echo "        choices: [ discard, use, output ]"
  echo "        How chimeric pairs should be handled."
  echo "        The options are:"
  echo "          * \"discard\": Discard all chimeric read pairs."
  echo "          * \"use\":     Deduplicate using read1 only. (default)"
  echo "          * \"output\":  Output chimeric pairs without UMI grouping/deduplication."
  echo "        Only available in"
  echo "                       umi_tools group."
  echo ""
  echo "    --unpaired_reads"
  echo "        type: string"
  echo "        example: use"
  echo "        choices: [ discard, use, output ]"
  echo "        How unpaired reads should be handled."
  echo "        The options are:"
  echo "          * \"discard\": Discard all unmapped reads."
  echo "          * \"use\": If read2 is unmapped, deduplicate using read1 only. Requires"
  echo "        --paired. (default)"
  echo "          * \"output\":  Output unmapped reads/read pairs without UMI"
  echo "        grouping/deduplication. Only available"
  echo "                       in umi_tools group."
  echo ""
  echo "    --ignore_umi"
  echo "        type: boolean_true"
  echo "        Ignore the UMI and group reads using mapping coordinates only."
  echo ""
  echo "    --subset"
  echo "        type: double"
  echo "        Only consider a fraction of the reads, chosen at random. This is useful"
  echo "        for doing saturation"
  echo "        analyses."
  echo ""
  echo "    --chrom"
  echo "        type: string"
  echo "        Only consider a single chromosome. This is useful for debugging/testing"
  echo "        purposes."
  echo ""
  echo "Group/Dedup Options:"
  echo "    --no_sort_output"
  echo "        type: boolean_true"
  echo "        By default, output is sorted. This involves the use of a temporary"
  echo "        unsorted file (saved in"
  echo "        --temp_dir). Use this option to turn off sorting."
  echo ""
  echo "    --buffer_whole_contig"
  echo "        type: boolean_true"
  echo "        Forces dedup to parse an entire contig before yielding any reads for"
  echo "        deduplication. This is the"
  echo "        only way to absolutely guarantee that all reads with the same start"
  echo "        position are grouped together"
  echo "        for deduplication since dedup uses the start position of the read, not"
  echo "        the alignment coordinate on"
  echo "        which the reads are sorted. However, by default, dedup reads for another"
  echo "        1000bp before outputting"
  echo "        read groups which will avoid any reads being missed with short read"
  echo "        sequencing (<1000bp)."
  echo ""
  echo "Common Options:"
  echo "    -L, --log"
  echo "        type: file, file must exist"
  echo "        File with logging information."
  echo ""
  echo "    --log2stderr"
  echo "        type: boolean_true"
  echo "        Send logging information to stderr."
  echo ""
  echo "    -v, --verbose"
  echo "        type: integer"
  echo "        example: 0"
  echo "        Log level. The higher, the more output. Default: \`0\`."
  echo ""
  echo "    -E, --error"
  echo "        type: file, file must exist"
  echo "        File with error information."
  echo ""
  echo "    --temp_dir"
  echo "        type: string"
  echo "        Directory for temporary files. If not set, the bash environmental"
  echo "        variable TMPDIR is used."
  echo ""
  echo "    --compresslevel"
  echo "        type: integer"
  echo "        example: 6"
  echo "        Level of Gzip compression to use. Default=6 matches GNU gzip rather than"
  echo "        python gzip default."
  echo "        Default: \`6\`."
  echo ""
  echo "    --timeit"
  echo "        type: file, file must exist"
  echo "        Store timing information in file."
  echo ""
  echo "    --timeit_name"
  echo "        type: string"
  echo "        example: all"
  echo "        Name in timing file for this class of jobs. Default: \`all\`."
  echo ""
  echo "    --timeit_header"
  echo "        type: string"
  echo "        Add header for timing information."
  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 "umi_tools_dedup main"
            exit
            ;;
        --input)
            [ -n "$VIASH_PAR_INPUT" ] && ViashError Bad arguments for option \'--input\': \'$VIASH_PAR_INPUT\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_INPUT="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --input. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --input=*)
            [ -n "$VIASH_PAR_INPUT" ] && ViashError Bad arguments for option \'--input=*\': \'$VIASH_PAR_INPUT\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_INPUT=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --stdin)
            [ -n "$VIASH_PAR_INPUT" ] && ViashError Bad arguments for option \'--stdin\': \'$VIASH_PAR_INPUT\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_INPUT="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --stdin. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --in_sam)
            [ -n "$VIASH_PAR_IN_SAM" ] && ViashError Bad arguments for option \'--in_sam\': \'$VIASH_PAR_IN_SAM\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_IN_SAM=true
            shift 1
            ;;
        --bai)
            [ -n "$VIASH_PAR_BAI" ] && ViashError Bad arguments for option \'--bai\': \'$VIASH_PAR_BAI\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_BAI="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --bai. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --bai=*)
            [ -n "$VIASH_PAR_BAI" ] && ViashError Bad arguments for option \'--bai=*\': \'$VIASH_PAR_BAI\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_BAI=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --random_seed)
            [ -n "$VIASH_PAR_RANDOM_SEED" ] && ViashError Bad arguments for option \'--random_seed\': \'$VIASH_PAR_RANDOM_SEED\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_RANDOM_SEED="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --random_seed. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --random_seed=*)
            [ -n "$VIASH_PAR_RANDOM_SEED" ] && ViashError Bad arguments for option \'--random_seed=*\': \'$VIASH_PAR_RANDOM_SEED\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_RANDOM_SEED=$(ViashRemoveFlags "$1")
            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
            ;;
        --stdout)
            [ -n "$VIASH_PAR_OUTPUT" ] && ViashError Bad arguments for option \'--stdout\': \'$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 --stdout. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --out_sam)
            [ -n "$VIASH_PAR_OUT_SAM" ] && ViashError Bad arguments for option \'--out_sam\': \'$VIASH_PAR_OUT_SAM\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_OUT_SAM=true
            shift 1
            ;;
        --paired)
            [ -n "$VIASH_PAR_PAIRED" ] && ViashError Bad arguments for option \'--paired\': \'$VIASH_PAR_PAIRED\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_PAIRED=true
            shift 1
            ;;
        --output_stats)
            [ -n "$VIASH_PAR_OUTPUT_STATS" ] && ViashError Bad arguments for option \'--output_stats\': \'$VIASH_PAR_OUTPUT_STATS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_OUTPUT_STATS="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --output_stats. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --output_stats=*)
            [ -n "$VIASH_PAR_OUTPUT_STATS" ] && ViashError Bad arguments for option \'--output_stats=*\': \'$VIASH_PAR_OUTPUT_STATS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_OUTPUT_STATS=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --extract_umi_method)
            [ -n "$VIASH_PAR_EXTRACT_UMI_METHOD" ] && ViashError Bad arguments for option \'--extract_umi_method\': \'$VIASH_PAR_EXTRACT_UMI_METHOD\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_EXTRACT_UMI_METHOD="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --extract_umi_method. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --extract_umi_method=*)
            [ -n "$VIASH_PAR_EXTRACT_UMI_METHOD" ] && ViashError Bad arguments for option \'--extract_umi_method=*\': \'$VIASH_PAR_EXTRACT_UMI_METHOD\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_EXTRACT_UMI_METHOD=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --umi_tag)
            [ -n "$VIASH_PAR_UMI_TAG" ] && ViashError Bad arguments for option \'--umi_tag\': \'$VIASH_PAR_UMI_TAG\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_UMI_TAG="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --umi_tag. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --umi_tag=*)
            [ -n "$VIASH_PAR_UMI_TAG" ] && ViashError Bad arguments for option \'--umi_tag=*\': \'$VIASH_PAR_UMI_TAG\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_UMI_TAG=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --umi_separator)
            [ -n "$VIASH_PAR_UMI_SEPARATOR" ] && ViashError Bad arguments for option \'--umi_separator\': \'$VIASH_PAR_UMI_SEPARATOR\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_UMI_SEPARATOR="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --umi_separator. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --umi_separator=*)
            [ -n "$VIASH_PAR_UMI_SEPARATOR" ] && ViashError Bad arguments for option \'--umi_separator=*\': \'$VIASH_PAR_UMI_SEPARATOR\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_UMI_SEPARATOR=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --umi_tag_split)
            [ -n "$VIASH_PAR_UMI_TAG_SPLIT" ] && ViashError Bad arguments for option \'--umi_tag_split\': \'$VIASH_PAR_UMI_TAG_SPLIT\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_UMI_TAG_SPLIT="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --umi_tag_split. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --umi_tag_split=*)
            [ -n "$VIASH_PAR_UMI_TAG_SPLIT" ] && ViashError Bad arguments for option \'--umi_tag_split=*\': \'$VIASH_PAR_UMI_TAG_SPLIT\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_UMI_TAG_SPLIT=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --umi_tag_delimiter)
            [ -n "$VIASH_PAR_UMI_TAG_DELIMITER" ] && ViashError Bad arguments for option \'--umi_tag_delimiter\': \'$VIASH_PAR_UMI_TAG_DELIMITER\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_UMI_TAG_DELIMITER="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --umi_tag_delimiter. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --umi_tag_delimiter=*)
            [ -n "$VIASH_PAR_UMI_TAG_DELIMITER" ] && ViashError Bad arguments for option \'--umi_tag_delimiter=*\': \'$VIASH_PAR_UMI_TAG_DELIMITER\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_UMI_TAG_DELIMITER=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --cell_tag)
            [ -n "$VIASH_PAR_CELL_TAG" ] && ViashError Bad arguments for option \'--cell_tag\': \'$VIASH_PAR_CELL_TAG\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_CELL_TAG="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --cell_tag. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --cell_tag=*)
            [ -n "$VIASH_PAR_CELL_TAG" ] && ViashError Bad arguments for option \'--cell_tag=*\': \'$VIASH_PAR_CELL_TAG\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_CELL_TAG=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --cell_tag_split)
            [ -n "$VIASH_PAR_CELL_TAG_SPLIT" ] && ViashError Bad arguments for option \'--cell_tag_split\': \'$VIASH_PAR_CELL_TAG_SPLIT\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_CELL_TAG_SPLIT="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --cell_tag_split. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --cell_tag_split=*)
            [ -n "$VIASH_PAR_CELL_TAG_SPLIT" ] && ViashError Bad arguments for option \'--cell_tag_split=*\': \'$VIASH_PAR_CELL_TAG_SPLIT\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_CELL_TAG_SPLIT=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --cell_tag_delimiter)
            [ -n "$VIASH_PAR_CELL_TAG_DELIMITER" ] && ViashError Bad arguments for option \'--cell_tag_delimiter\': \'$VIASH_PAR_CELL_TAG_DELIMITER\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_CELL_TAG_DELIMITER="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --cell_tag_delimiter. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --cell_tag_delimiter=*)
            [ -n "$VIASH_PAR_CELL_TAG_DELIMITER" ] && ViashError Bad arguments for option \'--cell_tag_delimiter=*\': \'$VIASH_PAR_CELL_TAG_DELIMITER\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_CELL_TAG_DELIMITER=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --method)
            [ -n "$VIASH_PAR_METHOD" ] && ViashError Bad arguments for option \'--method\': \'$VIASH_PAR_METHOD\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_METHOD="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --method. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --method=*)
            [ -n "$VIASH_PAR_METHOD" ] && ViashError Bad arguments for option \'--method=*\': \'$VIASH_PAR_METHOD\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_METHOD=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --edit_distance_threshold)
            [ -n "$VIASH_PAR_EDIT_DISTANCE_THRESHOLD" ] && ViashError Bad arguments for option \'--edit_distance_threshold\': \'$VIASH_PAR_EDIT_DISTANCE_THRESHOLD\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_EDIT_DISTANCE_THRESHOLD="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --edit_distance_threshold. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --edit_distance_threshold=*)
            [ -n "$VIASH_PAR_EDIT_DISTANCE_THRESHOLD" ] && ViashError Bad arguments for option \'--edit_distance_threshold=*\': \'$VIASH_PAR_EDIT_DISTANCE_THRESHOLD\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_EDIT_DISTANCE_THRESHOLD=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --spliced_is_unique)
            [ -n "$VIASH_PAR_SPLICED_IS_UNIQUE" ] && ViashError Bad arguments for option \'--spliced_is_unique\': \'$VIASH_PAR_SPLICED_IS_UNIQUE\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_SPLICED_IS_UNIQUE=true
            shift 1
            ;;
        --soft_clip_threshold)
            [ -n "$VIASH_PAR_SOFT_CLIP_THRESHOLD" ] && ViashError Bad arguments for option \'--soft_clip_threshold\': \'$VIASH_PAR_SOFT_CLIP_THRESHOLD\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_SOFT_CLIP_THRESHOLD="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --soft_clip_threshold. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --soft_clip_threshold=*)
            [ -n "$VIASH_PAR_SOFT_CLIP_THRESHOLD" ] && ViashError Bad arguments for option \'--soft_clip_threshold=*\': \'$VIASH_PAR_SOFT_CLIP_THRESHOLD\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_SOFT_CLIP_THRESHOLD=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --multimapping_detection_method)
            [ -n "$VIASH_PAR_MULTIMAPPING_DETECTION_METHOD" ] && ViashError Bad arguments for option \'--multimapping_detection_method\': \'$VIASH_PAR_MULTIMAPPING_DETECTION_METHOD\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_MULTIMAPPING_DETECTION_METHOD="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --multimapping_detection_method. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --multimapping_detection_method=*)
            [ -n "$VIASH_PAR_MULTIMAPPING_DETECTION_METHOD" ] && ViashError Bad arguments for option \'--multimapping_detection_method=*\': \'$VIASH_PAR_MULTIMAPPING_DETECTION_METHOD\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_MULTIMAPPING_DETECTION_METHOD=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --read_length)
            [ -n "$VIASH_PAR_READ_LENGTH" ] && ViashError Bad arguments for option \'--read_length\': \'$VIASH_PAR_READ_LENGTH\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_READ_LENGTH=true
            shift 1
            ;;
        --per_gene)
            [ -n "$VIASH_PAR_PER_GENE" ] && ViashError Bad arguments for option \'--per_gene\': \'$VIASH_PAR_PER_GENE\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_PER_GENE=true
            shift 1
            ;;
        --gene_tag)
            [ -n "$VIASH_PAR_GENE_TAG" ] && ViashError Bad arguments for option \'--gene_tag\': \'$VIASH_PAR_GENE_TAG\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_GENE_TAG="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --gene_tag. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --gene_tag=*)
            [ -n "$VIASH_PAR_GENE_TAG" ] && ViashError Bad arguments for option \'--gene_tag=*\': \'$VIASH_PAR_GENE_TAG\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_GENE_TAG=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --assigned_status_tag)
            [ -n "$VIASH_PAR_ASSIGNED_STATUS_TAG" ] && ViashError Bad arguments for option \'--assigned_status_tag\': \'$VIASH_PAR_ASSIGNED_STATUS_TAG\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_ASSIGNED_STATUS_TAG="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --assigned_status_tag. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --assigned_status_tag=*)
            [ -n "$VIASH_PAR_ASSIGNED_STATUS_TAG" ] && ViashError Bad arguments for option \'--assigned_status_tag=*\': \'$VIASH_PAR_ASSIGNED_STATUS_TAG\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_ASSIGNED_STATUS_TAG=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --skip_tags_regex)
            [ -n "$VIASH_PAR_SKIP_TAGS_REGEX" ] && ViashError Bad arguments for option \'--skip_tags_regex\': \'$VIASH_PAR_SKIP_TAGS_REGEX\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_SKIP_TAGS_REGEX="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --skip_tags_regex. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --skip_tags_regex=*)
            [ -n "$VIASH_PAR_SKIP_TAGS_REGEX" ] && ViashError Bad arguments for option \'--skip_tags_regex=*\': \'$VIASH_PAR_SKIP_TAGS_REGEX\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_SKIP_TAGS_REGEX=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --per_contig)
            [ -n "$VIASH_PAR_PER_CONTIG" ] && ViashError Bad arguments for option \'--per_contig\': \'$VIASH_PAR_PER_CONTIG\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_PER_CONTIG=true
            shift 1
            ;;
        --gene_transcript_map)
            [ -n "$VIASH_PAR_GENE_TRANSCRIPT_MAP" ] && ViashError Bad arguments for option \'--gene_transcript_map\': \'$VIASH_PAR_GENE_TRANSCRIPT_MAP\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_GENE_TRANSCRIPT_MAP="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --gene_transcript_map. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --gene_transcript_map=*)
            [ -n "$VIASH_PAR_GENE_TRANSCRIPT_MAP" ] && ViashError Bad arguments for option \'--gene_transcript_map=*\': \'$VIASH_PAR_GENE_TRANSCRIPT_MAP\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_GENE_TRANSCRIPT_MAP=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --per_cell)
            [ -n "$VIASH_PAR_PER_CELL" ] && ViashError Bad arguments for option \'--per_cell\': \'$VIASH_PAR_PER_CELL\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_PER_CELL=true
            shift 1
            ;;
        --mapping_quality)
            [ -n "$VIASH_PAR_MAPPING_QUALITY" ] && ViashError Bad arguments for option \'--mapping_quality\': \'$VIASH_PAR_MAPPING_QUALITY\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_MAPPING_QUALITY="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --mapping_quality. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --mapping_quality=*)
            [ -n "$VIASH_PAR_MAPPING_QUALITY" ] && ViashError Bad arguments for option \'--mapping_quality=*\': \'$VIASH_PAR_MAPPING_QUALITY\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_MAPPING_QUALITY=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --unmapped_reads)
            [ -n "$VIASH_PAR_UNMAPPED_READS" ] && ViashError Bad arguments for option \'--unmapped_reads\': \'$VIASH_PAR_UNMAPPED_READS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_UNMAPPED_READS="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --unmapped_reads. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --unmapped_reads=*)
            [ -n "$VIASH_PAR_UNMAPPED_READS" ] && ViashError Bad arguments for option \'--unmapped_reads=*\': \'$VIASH_PAR_UNMAPPED_READS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_UNMAPPED_READS=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --chimeric_pairs)
            [ -n "$VIASH_PAR_CHIMERIC_PAIRS" ] && ViashError Bad arguments for option \'--chimeric_pairs\': \'$VIASH_PAR_CHIMERIC_PAIRS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_CHIMERIC_PAIRS="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --chimeric_pairs. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --chimeric_pairs=*)
            [ -n "$VIASH_PAR_CHIMERIC_PAIRS" ] && ViashError Bad arguments for option \'--chimeric_pairs=*\': \'$VIASH_PAR_CHIMERIC_PAIRS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_CHIMERIC_PAIRS=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --unpaired_reads)
            [ -n "$VIASH_PAR_UNPAIRED_READS" ] && ViashError Bad arguments for option \'--unpaired_reads\': \'$VIASH_PAR_UNPAIRED_READS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_UNPAIRED_READS="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --unpaired_reads. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --unpaired_reads=*)
            [ -n "$VIASH_PAR_UNPAIRED_READS" ] && ViashError Bad arguments for option \'--unpaired_reads=*\': \'$VIASH_PAR_UNPAIRED_READS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_UNPAIRED_READS=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --ignore_umi)
            [ -n "$VIASH_PAR_IGNORE_UMI" ] && ViashError Bad arguments for option \'--ignore_umi\': \'$VIASH_PAR_IGNORE_UMI\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_IGNORE_UMI=true
            shift 1
            ;;
        --subset)
            [ -n "$VIASH_PAR_SUBSET" ] && ViashError Bad arguments for option \'--subset\': \'$VIASH_PAR_SUBSET\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_SUBSET="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --subset. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --subset=*)
            [ -n "$VIASH_PAR_SUBSET" ] && ViashError Bad arguments for option \'--subset=*\': \'$VIASH_PAR_SUBSET\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_SUBSET=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --chrom)
            [ -n "$VIASH_PAR_CHROM" ] && ViashError Bad arguments for option \'--chrom\': \'$VIASH_PAR_CHROM\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_CHROM="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --chrom. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --chrom=*)
            [ -n "$VIASH_PAR_CHROM" ] && ViashError Bad arguments for option \'--chrom=*\': \'$VIASH_PAR_CHROM\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_CHROM=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --no_sort_output)
            [ -n "$VIASH_PAR_NO_SORT_OUTPUT" ] && ViashError Bad arguments for option \'--no_sort_output\': \'$VIASH_PAR_NO_SORT_OUTPUT\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_NO_SORT_OUTPUT=true
            shift 1
            ;;
        --buffer_whole_contig)
            [ -n "$VIASH_PAR_BUFFER_WHOLE_CONTIG" ] && ViashError Bad arguments for option \'--buffer_whole_contig\': \'$VIASH_PAR_BUFFER_WHOLE_CONTIG\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_BUFFER_WHOLE_CONTIG=true
            shift 1
            ;;
        --log)
            [ -n "$VIASH_PAR_LOG" ] && ViashError Bad arguments for option \'--log\': \'$VIASH_PAR_LOG\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_LOG="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --log. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --log=*)
            [ -n "$VIASH_PAR_LOG" ] && ViashError Bad arguments for option \'--log=*\': \'$VIASH_PAR_LOG\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_LOG=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        -L)
            [ -n "$VIASH_PAR_LOG" ] && ViashError Bad arguments for option \'-L\': \'$VIASH_PAR_LOG\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_LOG="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to -L. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --log2stderr)
            [ -n "$VIASH_PAR_LOG2STDERR" ] && ViashError Bad arguments for option \'--log2stderr\': \'$VIASH_PAR_LOG2STDERR\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_LOG2STDERR=true
            shift 1
            ;;
        --verbose)
            [ -n "$VIASH_PAR_VERBOSE" ] && ViashError Bad arguments for option \'--verbose\': \'$VIASH_PAR_VERBOSE\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_VERBOSE="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --verbose. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --verbose=*)
            [ -n "$VIASH_PAR_VERBOSE" ] && ViashError Bad arguments for option \'--verbose=*\': \'$VIASH_PAR_VERBOSE\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_VERBOSE=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        -v)
            [ -n "$VIASH_PAR_VERBOSE" ] && ViashError Bad arguments for option \'-v\': \'$VIASH_PAR_VERBOSE\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_VERBOSE="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to -v. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --error)
            [ -n "$VIASH_PAR_ERROR" ] && ViashError Bad arguments for option \'--error\': \'$VIASH_PAR_ERROR\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_ERROR="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --error. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --error=*)
            [ -n "$VIASH_PAR_ERROR" ] && ViashError Bad arguments for option \'--error=*\': \'$VIASH_PAR_ERROR\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_ERROR=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        -E)
            [ -n "$VIASH_PAR_ERROR" ] && ViashError Bad arguments for option \'-E\': \'$VIASH_PAR_ERROR\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_ERROR="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to -E. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --temp_dir)
            [ -n "$VIASH_PAR_TEMP_DIR" ] && ViashError Bad arguments for option \'--temp_dir\': \'$VIASH_PAR_TEMP_DIR\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_TEMP_DIR="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --temp_dir. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --temp_dir=*)
            [ -n "$VIASH_PAR_TEMP_DIR" ] && ViashError Bad arguments for option \'--temp_dir=*\': \'$VIASH_PAR_TEMP_DIR\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_TEMP_DIR=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --compresslevel)
            [ -n "$VIASH_PAR_COMPRESSLEVEL" ] && ViashError Bad arguments for option \'--compresslevel\': \'$VIASH_PAR_COMPRESSLEVEL\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_COMPRESSLEVEL="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --compresslevel. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --compresslevel=*)
            [ -n "$VIASH_PAR_COMPRESSLEVEL" ] && ViashError Bad arguments for option \'--compresslevel=*\': \'$VIASH_PAR_COMPRESSLEVEL\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_COMPRESSLEVEL=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --timeit)
            [ -n "$VIASH_PAR_TIMEIT" ] && ViashError Bad arguments for option \'--timeit\': \'$VIASH_PAR_TIMEIT\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_TIMEIT="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --timeit. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --timeit=*)
            [ -n "$VIASH_PAR_TIMEIT" ] && ViashError Bad arguments for option \'--timeit=*\': \'$VIASH_PAR_TIMEIT\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_TIMEIT=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --timeit_name)
            [ -n "$VIASH_PAR_TIMEIT_NAME" ] && ViashError Bad arguments for option \'--timeit_name\': \'$VIASH_PAR_TIMEIT_NAME\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_TIMEIT_NAME="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --timeit_name. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --timeit_name=*)
            [ -n "$VIASH_PAR_TIMEIT_NAME" ] && ViashError Bad arguments for option \'--timeit_name=*\': \'$VIASH_PAR_TIMEIT_NAME\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_TIMEIT_NAME=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --timeit_header)
            [ -n "$VIASH_PAR_TIMEIT_HEADER" ] && ViashError Bad arguments for option \'--timeit_header\': \'$VIASH_PAR_TIMEIT_HEADER\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_TIMEIT_HEADER="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --timeit_header. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --timeit_header=*)
            [ -n "$VIASH_PAR_TIMEIT_HEADER" ] && ViashError Bad arguments for option \'--timeit_header=*\': \'$VIASH_PAR_TIMEIT_HEADER\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_TIMEIT_HEADER=$(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/biobox/umi_tools/umi_tools_dedup:main'
  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" 'ps' 'bash'
    exit 0
  fi

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

# setting computational defaults

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


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

# filling in defaults
if [ -z ${VIASH_PAR_IN_SAM+x} ]; then
  VIASH_PAR_IN_SAM="false"
fi
if [ -z ${VIASH_PAR_OUT_SAM+x} ]; then
  VIASH_PAR_OUT_SAM="false"
fi
if [ -z ${VIASH_PAR_PAIRED+x} ]; then
  VIASH_PAR_PAIRED="false"
fi
if [ -z ${VIASH_PAR_SPLICED_IS_UNIQUE+x} ]; then
  VIASH_PAR_SPLICED_IS_UNIQUE="false"
fi
if [ -z ${VIASH_PAR_READ_LENGTH+x} ]; then
  VIASH_PAR_READ_LENGTH="false"
fi
if [ -z ${VIASH_PAR_PER_GENE+x} ]; then
  VIASH_PAR_PER_GENE="false"
fi
if [ -z ${VIASH_PAR_PER_CONTIG+x} ]; then
  VIASH_PAR_PER_CONTIG="false"
fi
if [ -z ${VIASH_PAR_PER_CELL+x} ]; then
  VIASH_PAR_PER_CELL="false"
fi
if [ -z ${VIASH_PAR_IGNORE_UMI+x} ]; then
  VIASH_PAR_IGNORE_UMI="false"
fi
if [ -z ${VIASH_PAR_NO_SORT_OUTPUT+x} ]; then
  VIASH_PAR_NO_SORT_OUTPUT="false"
fi
if [ -z ${VIASH_PAR_BUFFER_WHOLE_CONTIG+x} ]; then
  VIASH_PAR_BUFFER_WHOLE_CONTIG="false"
fi
if [ -z ${VIASH_PAR_LOG2STDERR+x} ]; then
  VIASH_PAR_LOG2STDERR="false"
fi

# check whether required files exist
if [ ! -z "$VIASH_PAR_INPUT" ] && [ ! -e "$VIASH_PAR_INPUT" ]; then
  ViashError "Input file '$VIASH_PAR_INPUT' does not exist."
  exit 1
fi
if [ ! -z "$VIASH_PAR_BAI" ] && [ ! -e "$VIASH_PAR_BAI" ]; then
  ViashError "Input file '$VIASH_PAR_BAI' does not exist."
  exit 1
fi
if [ ! -z "$VIASH_PAR_GENE_TRANSCRIPT_MAP" ] && [ ! -e "$VIASH_PAR_GENE_TRANSCRIPT_MAP" ]; then
  ViashError "Input file '$VIASH_PAR_GENE_TRANSCRIPT_MAP' does not exist."
  exit 1
fi
if [ ! -z "$VIASH_PAR_LOG" ] && [ ! -e "$VIASH_PAR_LOG" ]; then
  ViashError "Input file '$VIASH_PAR_LOG' does not exist."
  exit 1
fi
if [ ! -z "$VIASH_PAR_ERROR" ] && [ ! -e "$VIASH_PAR_ERROR" ]; then
  ViashError "Input file '$VIASH_PAR_ERROR' does not exist."
  exit 1
fi
if [ ! -z "$VIASH_PAR_TIMEIT" ] && [ ! -e "$VIASH_PAR_TIMEIT" ]; then
  ViashError "Input file '$VIASH_PAR_TIMEIT' does not exist."
  exit 1
fi

# check whether parameters values are of the right type
if [[ -n "$VIASH_PAR_IN_SAM" ]]; then
  if ! [[ "$VIASH_PAR_IN_SAM" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--in_sam' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_RANDOM_SEED" ]]; then
  if ! [[ "$VIASH_PAR_RANDOM_SEED" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError '--random_seed' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_OUT_SAM" ]]; then
  if ! [[ "$VIASH_PAR_OUT_SAM" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--out_sam' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_PAIRED" ]]; then
  if ! [[ "$VIASH_PAR_PAIRED" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--paired' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_EDIT_DISTANCE_THRESHOLD" ]]; then
  if ! [[ "$VIASH_PAR_EDIT_DISTANCE_THRESHOLD" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError '--edit_distance_threshold' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_SPLICED_IS_UNIQUE" ]]; then
  if ! [[ "$VIASH_PAR_SPLICED_IS_UNIQUE" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--spliced_is_unique' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_SOFT_CLIP_THRESHOLD" ]]; then
  if ! [[ "$VIASH_PAR_SOFT_CLIP_THRESHOLD" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError '--soft_clip_threshold' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_READ_LENGTH" ]]; then
  if ! [[ "$VIASH_PAR_READ_LENGTH" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--read_length' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_PER_GENE" ]]; then
  if ! [[ "$VIASH_PAR_PER_GENE" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--per_gene' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_PER_CONTIG" ]]; then
  if ! [[ "$VIASH_PAR_PER_CONTIG" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--per_contig' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_PER_CELL" ]]; then
  if ! [[ "$VIASH_PAR_PER_CELL" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--per_cell' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_MAPPING_QUALITY" ]]; then
  if ! [[ "$VIASH_PAR_MAPPING_QUALITY" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError '--mapping_quality' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_IGNORE_UMI" ]]; then
  if ! [[ "$VIASH_PAR_IGNORE_UMI" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--ignore_umi' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_SUBSET" ]]; then
  if ! [[ "$VIASH_PAR_SUBSET" =~ ^[-+]?(\.[0-9]+|[0-9]+(\.[0-9]*)?)([eE][-+]?[0-9]+)?$ ]]; then
    ViashError '--subset' has to be a double. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_NO_SORT_OUTPUT" ]]; then
  if ! [[ "$VIASH_PAR_NO_SORT_OUTPUT" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--no_sort_output' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_BUFFER_WHOLE_CONTIG" ]]; then
  if ! [[ "$VIASH_PAR_BUFFER_WHOLE_CONTIG" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--buffer_whole_contig' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_LOG2STDERR" ]]; then
  if ! [[ "$VIASH_PAR_LOG2STDERR" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--log2stderr' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_VERBOSE" ]]; then
  if ! [[ "$VIASH_PAR_VERBOSE" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError '--verbose' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_COMPRESSLEVEL" ]]; then
  if ! [[ "$VIASH_PAR_COMPRESSLEVEL" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError '--compresslevel' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_META_CPUS" ]]; then
  if ! [[ "$VIASH_META_CPUS" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError 'cpus' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_META_MEMORY_B" ]]; then
  if ! [[ "$VIASH_META_MEMORY_B" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError 'memory_b' has to be a long. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_META_MEMORY_KB" ]]; then
  if ! [[ "$VIASH_META_MEMORY_KB" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError 'memory_kb' has to be a long. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_META_MEMORY_MB" ]]; then
  if ! [[ "$VIASH_META_MEMORY_MB" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError 'memory_mb' has to be a long. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_META_MEMORY_GB" ]]; then
  if ! [[ "$VIASH_META_MEMORY_GB" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError 'memory_gb' has to be a long. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_META_MEMORY_TB" ]]; then
  if ! [[ "$VIASH_META_MEMORY_TB" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError 'memory_tb' has to be a long. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_META_MEMORY_PB" ]]; then
  if ! [[ "$VIASH_META_MEMORY_PB" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError 'memory_pb' has to be a long. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_META_MEMORY_KIB" ]]; then
  if ! [[ "$VIASH_META_MEMORY_KIB" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError 'memory_kib' has to be a long. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_META_MEMORY_MIB" ]]; then
  if ! [[ "$VIASH_META_MEMORY_MIB" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError 'memory_mib' has to be a long. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_META_MEMORY_GIB" ]]; then
  if ! [[ "$VIASH_META_MEMORY_GIB" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError 'memory_gib' has to be a long. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_META_MEMORY_TIB" ]]; then
  if ! [[ "$VIASH_META_MEMORY_TIB" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError 'memory_tib' has to be a long. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_META_MEMORY_PIB" ]]; then
  if ! [[ "$VIASH_META_MEMORY_PIB" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError 'memory_pib' has to be a long. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi

# check whether value is belongs to a set of choices
if [ ! -z "$VIASH_PAR_EXTRACT_UMI_METHOD" ]; then
  VIASH_PAR_EXTRACT_UMI_METHOD_CHOICES=("read_id;tag;umis")
  IFS=';'
  set -f
  if ! [[ ";${VIASH_PAR_EXTRACT_UMI_METHOD_CHOICES[*]};" =~ ";$VIASH_PAR_EXTRACT_UMI_METHOD;" ]]; then
    ViashError '--extract_umi_method' specified value of \'$VIASH_PAR_EXTRACT_UMI_METHOD\' is not in the list of allowed values. Use "--help" to get more information on the parameters.
    exit 1
  fi
  set +f
  unset IFS
fi

if [ ! -z "$VIASH_PAR_METHOD" ]; then
  VIASH_PAR_METHOD_CHOICES=("unique;percentile;cluster;adjacency;directional")
  IFS=';'
  set -f
  if ! [[ ";${VIASH_PAR_METHOD_CHOICES[*]};" =~ ";$VIASH_PAR_METHOD;" ]]; then
    ViashError '--method' specified value of \'$VIASH_PAR_METHOD\' is not in the list of allowed values. Use "--help" to get more information on the parameters.
    exit 1
  fi
  set +f
  unset IFS
fi

if [ ! -z "$VIASH_PAR_CHIMERIC_PAIRS" ]; then
  VIASH_PAR_CHIMERIC_PAIRS_CHOICES=("discard;use;output")
  IFS=';'
  set -f
  if ! [[ ";${VIASH_PAR_CHIMERIC_PAIRS_CHOICES[*]};" =~ ";$VIASH_PAR_CHIMERIC_PAIRS;" ]]; then
    ViashError '--chimeric_pairs' specified value of \'$VIASH_PAR_CHIMERIC_PAIRS\' is not in the list of allowed values. Use "--help" to get more information on the parameters.
    exit 1
  fi
  set +f
  unset IFS
fi

if [ ! -z "$VIASH_PAR_UNPAIRED_READS" ]; then
  VIASH_PAR_UNPAIRED_READS_CHOICES=("discard;use;output")
  IFS=';'
  set -f
  if ! [[ ";${VIASH_PAR_UNPAIRED_READS_CHOICES[*]};" =~ ";$VIASH_PAR_UNPAIRED_READS;" ]]; then
    ViashError '--unpaired_reads' specified value of \'$VIASH_PAR_UNPAIRED_READS\' is not in the list of allowed values. Use "--help" to get more information on the parameters.
    exit 1
  fi
  set +f
  unset IFS
fi

# create parent directories of output files, if so desired
if [ ! -z "$VIASH_PAR_OUTPUT" ] && [ ! -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_INPUT" ]; then
  VIASH_DIRECTORY_MOUNTS+=( "$(ViashDockerAutodetectMountArg "$VIASH_PAR_INPUT")" )
  VIASH_PAR_INPUT=$(ViashDockerAutodetectMount "$VIASH_PAR_INPUT")
fi
if [ ! -z "$VIASH_PAR_BAI" ]; then
  VIASH_DIRECTORY_MOUNTS+=( "$(ViashDockerAutodetectMountArg "$VIASH_PAR_BAI")" )
  VIASH_PAR_BAI=$(ViashDockerAutodetectMount "$VIASH_PAR_BAI")
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_PAR_GENE_TRANSCRIPT_MAP" ]; then
  VIASH_DIRECTORY_MOUNTS+=( "$(ViashDockerAutodetectMountArg "$VIASH_PAR_GENE_TRANSCRIPT_MAP")" )
  VIASH_PAR_GENE_TRANSCRIPT_MAP=$(ViashDockerAutodetectMount "$VIASH_PAR_GENE_TRANSCRIPT_MAP")
fi
if [ ! -z "$VIASH_PAR_LOG" ]; then
  VIASH_DIRECTORY_MOUNTS+=( "$(ViashDockerAutodetectMountArg "$VIASH_PAR_LOG")" )
  VIASH_PAR_LOG=$(ViashDockerAutodetectMount "$VIASH_PAR_LOG")
fi
if [ ! -z "$VIASH_PAR_ERROR" ]; then
  VIASH_DIRECTORY_MOUNTS+=( "$(ViashDockerAutodetectMountArg "$VIASH_PAR_ERROR")" )
  VIASH_PAR_ERROR=$(ViashDockerAutodetectMount "$VIASH_PAR_ERROR")
fi
if [ ! -z "$VIASH_PAR_TIMEIT" ]; then
  VIASH_DIRECTORY_MOUNTS+=( "$(ViashDockerAutodetectMountArg "$VIASH_PAR_TIMEIT")" )
  VIASH_PAR_TIMEIT=$(ViashDockerAutodetectMount "$VIASH_PAR_TIMEIT")
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-umi_tools_dedup-XXXXXX").sh
function clean_up {
  rm "\$tempscript"
}
function interrupt {
  echo -e "\nCTRL-C Pressed..."
  exit 1
}
trap clean_up EXIT
trap interrupt INT SIGINT
cat > "\$tempscript" << 'VIASHMAIN'
#!/bin/bash

## VIASH START
# The following code has been auto-generated by Viash.
$( if [ ! -z ${VIASH_PAR_INPUT+x} ]; then echo "${VIASH_PAR_INPUT}" | sed "s#'#'\"'\"'#g;s#.*#par_input='&'#" ; else echo "# par_input="; fi )
$( if [ ! -z ${VIASH_PAR_IN_SAM+x} ]; then echo "${VIASH_PAR_IN_SAM}" | sed "s#'#'\"'\"'#g;s#.*#par_in_sam='&'#" ; else echo "# par_in_sam="; fi )
$( if [ ! -z ${VIASH_PAR_BAI+x} ]; then echo "${VIASH_PAR_BAI}" | sed "s#'#'\"'\"'#g;s#.*#par_bai='&'#" ; else echo "# par_bai="; fi )
$( if [ ! -z ${VIASH_PAR_RANDOM_SEED+x} ]; then echo "${VIASH_PAR_RANDOM_SEED}" | sed "s#'#'\"'\"'#g;s#.*#par_random_seed='&'#" ; else echo "# par_random_seed="; 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_OUT_SAM+x} ]; then echo "${VIASH_PAR_OUT_SAM}" | sed "s#'#'\"'\"'#g;s#.*#par_out_sam='&'#" ; else echo "# par_out_sam="; fi )
$( if [ ! -z ${VIASH_PAR_PAIRED+x} ]; then echo "${VIASH_PAR_PAIRED}" | sed "s#'#'\"'\"'#g;s#.*#par_paired='&'#" ; else echo "# par_paired="; fi )
$( if [ ! -z ${VIASH_PAR_OUTPUT_STATS+x} ]; then echo "${VIASH_PAR_OUTPUT_STATS}" | sed "s#'#'\"'\"'#g;s#.*#par_output_stats='&'#" ; else echo "# par_output_stats="; fi )
$( if [ ! -z ${VIASH_PAR_EXTRACT_UMI_METHOD+x} ]; then echo "${VIASH_PAR_EXTRACT_UMI_METHOD}" | sed "s#'#'\"'\"'#g;s#.*#par_extract_umi_method='&'#" ; else echo "# par_extract_umi_method="; fi )
$( if [ ! -z ${VIASH_PAR_UMI_TAG+x} ]; then echo "${VIASH_PAR_UMI_TAG}" | sed "s#'#'\"'\"'#g;s#.*#par_umi_tag='&'#" ; else echo "# par_umi_tag="; fi )
$( if [ ! -z ${VIASH_PAR_UMI_SEPARATOR+x} ]; then echo "${VIASH_PAR_UMI_SEPARATOR}" | sed "s#'#'\"'\"'#g;s#.*#par_umi_separator='&'#" ; else echo "# par_umi_separator="; fi )
$( if [ ! -z ${VIASH_PAR_UMI_TAG_SPLIT+x} ]; then echo "${VIASH_PAR_UMI_TAG_SPLIT}" | sed "s#'#'\"'\"'#g;s#.*#par_umi_tag_split='&'#" ; else echo "# par_umi_tag_split="; fi )
$( if [ ! -z ${VIASH_PAR_UMI_TAG_DELIMITER+x} ]; then echo "${VIASH_PAR_UMI_TAG_DELIMITER}" | sed "s#'#'\"'\"'#g;s#.*#par_umi_tag_delimiter='&'#" ; else echo "# par_umi_tag_delimiter="; fi )
$( if [ ! -z ${VIASH_PAR_CELL_TAG+x} ]; then echo "${VIASH_PAR_CELL_TAG}" | sed "s#'#'\"'\"'#g;s#.*#par_cell_tag='&'#" ; else echo "# par_cell_tag="; fi )
$( if [ ! -z ${VIASH_PAR_CELL_TAG_SPLIT+x} ]; then echo "${VIASH_PAR_CELL_TAG_SPLIT}" | sed "s#'#'\"'\"'#g;s#.*#par_cell_tag_split='&'#" ; else echo "# par_cell_tag_split="; fi )
$( if [ ! -z ${VIASH_PAR_CELL_TAG_DELIMITER+x} ]; then echo "${VIASH_PAR_CELL_TAG_DELIMITER}" | sed "s#'#'\"'\"'#g;s#.*#par_cell_tag_delimiter='&'#" ; else echo "# par_cell_tag_delimiter="; fi )
$( if [ ! -z ${VIASH_PAR_METHOD+x} ]; then echo "${VIASH_PAR_METHOD}" | sed "s#'#'\"'\"'#g;s#.*#par_method='&'#" ; else echo "# par_method="; fi )
$( if [ ! -z ${VIASH_PAR_EDIT_DISTANCE_THRESHOLD+x} ]; then echo "${VIASH_PAR_EDIT_DISTANCE_THRESHOLD}" | sed "s#'#'\"'\"'#g;s#.*#par_edit_distance_threshold='&'#" ; else echo "# par_edit_distance_threshold="; fi )
$( if [ ! -z ${VIASH_PAR_SPLICED_IS_UNIQUE+x} ]; then echo "${VIASH_PAR_SPLICED_IS_UNIQUE}" | sed "s#'#'\"'\"'#g;s#.*#par_spliced_is_unique='&'#" ; else echo "# par_spliced_is_unique="; fi )
$( if [ ! -z ${VIASH_PAR_SOFT_CLIP_THRESHOLD+x} ]; then echo "${VIASH_PAR_SOFT_CLIP_THRESHOLD}" | sed "s#'#'\"'\"'#g;s#.*#par_soft_clip_threshold='&'#" ; else echo "# par_soft_clip_threshold="; fi )
$( if [ ! -z ${VIASH_PAR_MULTIMAPPING_DETECTION_METHOD+x} ]; then echo "${VIASH_PAR_MULTIMAPPING_DETECTION_METHOD}" | sed "s#'#'\"'\"'#g;s#.*#par_multimapping_detection_method='&'#" ; else echo "# par_multimapping_detection_method="; fi )
$( if [ ! -z ${VIASH_PAR_READ_LENGTH+x} ]; then echo "${VIASH_PAR_READ_LENGTH}" | sed "s#'#'\"'\"'#g;s#.*#par_read_length='&'#" ; else echo "# par_read_length="; fi )
$( if [ ! -z ${VIASH_PAR_PER_GENE+x} ]; then echo "${VIASH_PAR_PER_GENE}" | sed "s#'#'\"'\"'#g;s#.*#par_per_gene='&'#" ; else echo "# par_per_gene="; fi )
$( if [ ! -z ${VIASH_PAR_GENE_TAG+x} ]; then echo "${VIASH_PAR_GENE_TAG}" | sed "s#'#'\"'\"'#g;s#.*#par_gene_tag='&'#" ; else echo "# par_gene_tag="; fi )
$( if [ ! -z ${VIASH_PAR_ASSIGNED_STATUS_TAG+x} ]; then echo "${VIASH_PAR_ASSIGNED_STATUS_TAG}" | sed "s#'#'\"'\"'#g;s#.*#par_assigned_status_tag='&'#" ; else echo "# par_assigned_status_tag="; fi )
$( if [ ! -z ${VIASH_PAR_SKIP_TAGS_REGEX+x} ]; then echo "${VIASH_PAR_SKIP_TAGS_REGEX}" | sed "s#'#'\"'\"'#g;s#.*#par_skip_tags_regex='&'#" ; else echo "# par_skip_tags_regex="; fi )
$( if [ ! -z ${VIASH_PAR_PER_CONTIG+x} ]; then echo "${VIASH_PAR_PER_CONTIG}" | sed "s#'#'\"'\"'#g;s#.*#par_per_contig='&'#" ; else echo "# par_per_contig="; fi )
$( if [ ! -z ${VIASH_PAR_GENE_TRANSCRIPT_MAP+x} ]; then echo "${VIASH_PAR_GENE_TRANSCRIPT_MAP}" | sed "s#'#'\"'\"'#g;s#.*#par_gene_transcript_map='&'#" ; else echo "# par_gene_transcript_map="; fi )
$( if [ ! -z ${VIASH_PAR_PER_CELL+x} ]; then echo "${VIASH_PAR_PER_CELL}" | sed "s#'#'\"'\"'#g;s#.*#par_per_cell='&'#" ; else echo "# par_per_cell="; fi )
$( if [ ! -z ${VIASH_PAR_MAPPING_QUALITY+x} ]; then echo "${VIASH_PAR_MAPPING_QUALITY}" | sed "s#'#'\"'\"'#g;s#.*#par_mapping_quality='&'#" ; else echo "# par_mapping_quality="; fi )
$( if [ ! -z ${VIASH_PAR_UNMAPPED_READS+x} ]; then echo "${VIASH_PAR_UNMAPPED_READS}" | sed "s#'#'\"'\"'#g;s#.*#par_unmapped_reads='&'#" ; else echo "# par_unmapped_reads="; fi )
$( if [ ! -z ${VIASH_PAR_CHIMERIC_PAIRS+x} ]; then echo "${VIASH_PAR_CHIMERIC_PAIRS}" | sed "s#'#'\"'\"'#g;s#.*#par_chimeric_pairs='&'#" ; else echo "# par_chimeric_pairs="; fi )
$( if [ ! -z ${VIASH_PAR_UNPAIRED_READS+x} ]; then echo "${VIASH_PAR_UNPAIRED_READS}" | sed "s#'#'\"'\"'#g;s#.*#par_unpaired_reads='&'#" ; else echo "# par_unpaired_reads="; fi )
$( if [ ! -z ${VIASH_PAR_IGNORE_UMI+x} ]; then echo "${VIASH_PAR_IGNORE_UMI}" | sed "s#'#'\"'\"'#g;s#.*#par_ignore_umi='&'#" ; else echo "# par_ignore_umi="; fi )
$( if [ ! -z ${VIASH_PAR_SUBSET+x} ]; then echo "${VIASH_PAR_SUBSET}" | sed "s#'#'\"'\"'#g;s#.*#par_subset='&'#" ; else echo "# par_subset="; fi )
$( if [ ! -z ${VIASH_PAR_CHROM+x} ]; then echo "${VIASH_PAR_CHROM}" | sed "s#'#'\"'\"'#g;s#.*#par_chrom='&'#" ; else echo "# par_chrom="; fi )
$( if [ ! -z ${VIASH_PAR_NO_SORT_OUTPUT+x} ]; then echo "${VIASH_PAR_NO_SORT_OUTPUT}" | sed "s#'#'\"'\"'#g;s#.*#par_no_sort_output='&'#" ; else echo "# par_no_sort_output="; fi )
$( if [ ! -z ${VIASH_PAR_BUFFER_WHOLE_CONTIG+x} ]; then echo "${VIASH_PAR_BUFFER_WHOLE_CONTIG}" | sed "s#'#'\"'\"'#g;s#.*#par_buffer_whole_contig='&'#" ; else echo "# par_buffer_whole_contig="; fi )
$( if [ ! -z ${VIASH_PAR_LOG+x} ]; then echo "${VIASH_PAR_LOG}" | sed "s#'#'\"'\"'#g;s#.*#par_log='&'#" ; else echo "# par_log="; fi )
$( if [ ! -z ${VIASH_PAR_LOG2STDERR+x} ]; then echo "${VIASH_PAR_LOG2STDERR}" | sed "s#'#'\"'\"'#g;s#.*#par_log2stderr='&'#" ; else echo "# par_log2stderr="; fi )
$( if [ ! -z ${VIASH_PAR_VERBOSE+x} ]; then echo "${VIASH_PAR_VERBOSE}" | sed "s#'#'\"'\"'#g;s#.*#par_verbose='&'#" ; else echo "# par_verbose="; fi )
$( if [ ! -z ${VIASH_PAR_ERROR+x} ]; then echo "${VIASH_PAR_ERROR}" | sed "s#'#'\"'\"'#g;s#.*#par_error='&'#" ; else echo "# par_error="; fi )
$( if [ ! -z ${VIASH_PAR_TEMP_DIR+x} ]; then echo "${VIASH_PAR_TEMP_DIR}" | sed "s#'#'\"'\"'#g;s#.*#par_temp_dir='&'#" ; else echo "# par_temp_dir="; fi )
$( if [ ! -z ${VIASH_PAR_COMPRESSLEVEL+x} ]; then echo "${VIASH_PAR_COMPRESSLEVEL}" | sed "s#'#'\"'\"'#g;s#.*#par_compresslevel='&'#" ; else echo "# par_compresslevel="; fi )
$( if [ ! -z ${VIASH_PAR_TIMEIT+x} ]; then echo "${VIASH_PAR_TIMEIT}" | sed "s#'#'\"'\"'#g;s#.*#par_timeit='&'#" ; else echo "# par_timeit="; fi )
$( if [ ! -z ${VIASH_PAR_TIMEIT_NAME+x} ]; then echo "${VIASH_PAR_TIMEIT_NAME}" | sed "s#'#'\"'\"'#g;s#.*#par_timeit_name='&'#" ; else echo "# par_timeit_name="; fi )
$( if [ ! -z ${VIASH_PAR_TIMEIT_HEADER+x} ]; then echo "${VIASH_PAR_TIMEIT_HEADER}" | sed "s#'#'\"'\"'#g;s#.*#par_timeit_header='&'#" ; else echo "# par_timeit_header="; fi )
$( if [ ! -z ${VIASH_META_NAME+x} ]; then echo "${VIASH_META_NAME}" | sed "s#'#'\"'\"'#g;s#.*#meta_name='&'#" ; else echo "# meta_name="; fi )
$( if [ ! -z ${VIASH_META_FUNCTIONALITY_NAME+x} ]; then echo "${VIASH_META_FUNCTIONALITY_NAME}" | sed "s#'#'\"'\"'#g;s#.*#meta_functionality_name='&'#" ; else echo "# meta_functionality_name="; fi )
$( if [ ! -z ${VIASH_META_RESOURCES_DIR+x} ]; then echo "${VIASH_META_RESOURCES_DIR}" | sed "s#'#'\"'\"'#g;s#.*#meta_resources_dir='&'#" ; else echo "# meta_resources_dir="; fi )
$( if [ ! -z ${VIASH_META_EXECUTABLE+x} ]; then echo "${VIASH_META_EXECUTABLE}" | sed "s#'#'\"'\"'#g;s#.*#meta_executable='&'#" ; else echo "# meta_executable="; fi )
$( if [ ! -z ${VIASH_META_CONFIG+x} ]; then echo "${VIASH_META_CONFIG}" | sed "s#'#'\"'\"'#g;s#.*#meta_config='&'#" ; else echo "# meta_config="; fi )
$( if [ ! -z ${VIASH_META_TEMP_DIR+x} ]; then echo "${VIASH_META_TEMP_DIR}" | sed "s#'#'\"'\"'#g;s#.*#meta_temp_dir='&'#" ; else echo "# meta_temp_dir="; fi )
$( if [ ! -z ${VIASH_META_CPUS+x} ]; then echo "${VIASH_META_CPUS}" | sed "s#'#'\"'\"'#g;s#.*#meta_cpus='&'#" ; else echo "# meta_cpus="; fi )
$( if [ ! -z ${VIASH_META_MEMORY_B+x} ]; then echo "${VIASH_META_MEMORY_B}" | sed "s#'#'\"'\"'#g;s#.*#meta_memory_b='&'#" ; else echo "# meta_memory_b="; fi )
$( if [ ! -z ${VIASH_META_MEMORY_KB+x} ]; then echo "${VIASH_META_MEMORY_KB}" | sed "s#'#'\"'\"'#g;s#.*#meta_memory_kb='&'#" ; else echo "# meta_memory_kb="; fi )
$( if [ ! -z ${VIASH_META_MEMORY_MB+x} ]; then echo "${VIASH_META_MEMORY_MB}" | sed "s#'#'\"'\"'#g;s#.*#meta_memory_mb='&'#" ; else echo "# meta_memory_mb="; fi )
$( if [ ! -z ${VIASH_META_MEMORY_GB+x} ]; then echo "${VIASH_META_MEMORY_GB}" | sed "s#'#'\"'\"'#g;s#.*#meta_memory_gb='&'#" ; else echo "# meta_memory_gb="; fi )
$( if [ ! -z ${VIASH_META_MEMORY_TB+x} ]; then echo "${VIASH_META_MEMORY_TB}" | sed "s#'#'\"'\"'#g;s#.*#meta_memory_tb='&'#" ; else echo "# meta_memory_tb="; fi )
$( if [ ! -z ${VIASH_META_MEMORY_PB+x} ]; then echo "${VIASH_META_MEMORY_PB}" | sed "s#'#'\"'\"'#g;s#.*#meta_memory_pb='&'#" ; else echo "# meta_memory_pb="; fi )
$( if [ ! -z ${VIASH_META_MEMORY_KIB+x} ]; then echo "${VIASH_META_MEMORY_KIB}" | sed "s#'#'\"'\"'#g;s#.*#meta_memory_kib='&'#" ; else echo "# meta_memory_kib="; fi )
$( if [ ! -z ${VIASH_META_MEMORY_MIB+x} ]; then echo "${VIASH_META_MEMORY_MIB}" | sed "s#'#'\"'\"'#g;s#.*#meta_memory_mib='&'#" ; else echo "# meta_memory_mib="; fi )
$( if [ ! -z ${VIASH_META_MEMORY_GIB+x} ]; then echo "${VIASH_META_MEMORY_GIB}" | sed "s#'#'\"'\"'#g;s#.*#meta_memory_gib='&'#" ; else echo "# meta_memory_gib="; fi )
$( if [ ! -z ${VIASH_META_MEMORY_TIB+x} ]; then echo "${VIASH_META_MEMORY_TIB}" | sed "s#'#'\"'\"'#g;s#.*#meta_memory_tib='&'#" ; else echo "# meta_memory_tib="; fi )
$( if [ ! -z ${VIASH_META_MEMORY_PIB+x} ]; then echo "${VIASH_META_MEMORY_PIB}" | sed "s#'#'\"'\"'#g;s#.*#meta_memory_pib='&'#" ; else echo "# meta_memory_pib="; fi )

## VIASH END

set -e

test_dir="\${metal_executable}/test_data"

unset_if_false=(
   par_paired
   par_in_sam
   par_out_sam
   par_spliced_is_unique
   par_per_gene
   par_per_contig
   par_per_cell
   par_no_sort_output
   par_buffer_whole_contig
   par_ignore_umi
   par_subset
   par_log2stderr
   par_read_length
)

for par in \${unset_if_false[@]}; do
    test_val="\${!par}"
    [[ "\$test_val" == "false" ]] && unset \$par
done

umi_tools dedup \\
    --stdin "\$par_input" \\
    \${par_in_sam:+--in-sam} \\
    --stdout "\$par_output" \\
    \${par_out_sam:+--out-sam} \\
    \${par_paired:+--paired} \\
    \${par_output_stats:+--output-stats "\$par_output_stats"} \\
    \${par_extract_umi_method:+--extract-umi-method "\$par_extract_umi_method"} \\
    \${par_umi_tag:+--umi-tag "\$par_umi_tag"} \\
    \${par_umi_separator:+--umi-separator "\$par_umi_separator"} \\
    \${par_umi_tag_split:+--umi-tag-split "\$par_umi_tag_split"} \\
    \${par_umi_tag_delimiter:+--umi-tag-delimiter "\$par_umi_tag_delimiter"} \\
    \${par_cell_tag:+--cell-tag "\$par_cell_tag"} \\
    \${par_cell_tag_split:+--cell-tag-split "\$par_cell_tag_split"} \\
    \${par_cell_tag_delimiter:+--cell-tag-delimiter "\$par_cell_tag_delimiter"} \\
    \${par_method:+--method "\$par_method"} \\
    \${par_edit_distance_threshold:+--edit-distance-threshold "\$par_edit_distance_threshold"} \\
    \${par_spliced_is_unique:+--spliced-is-unique} \\
    \${par_soft_clip_threshold:+--soft-clip-threshold "\$par_soft_clip_threshold"} \\
    \${par_multimapping_detection_method:+--multimapping-detection-method "\$par_multimapping_detection_method"} \\
    \${par_read_length:+--read-length} \\
    \${par_per_gene:+--per-gene} \\
    \${par_gene_tag:+--gene-tag "\$par_gene_tag"} \\
    \${par_assigned_status_tag:+--assigned-status-tag "\$par_assigned_status_tag"} \\
    \${par_skip_tags_regex:+--skip-tags-regex "\$par_skip_tags_regex"} \\
    \${par_per_contig:+--per-contig} \\
    \${par_gene_transcript_map:+--gene-transcript-map "\$par_gene_transcript_map"} \\
    \${par_per_cell:+--per-cell} \\
    \${par_mapping_quality:+--mapping-quality "\$par_mapping_quality"} \\
    \${par_unmapped_reads:+--unmapped-reads "\$par_unmapped_reads"} \\
    \${par_chimeric_pairs:+--chimeric-pairs "\$par_chimeric_pairs"} \\
    \${par_unpaired_reads:+--unpaired-reads "\$par_unpaired_reads"} \\
    \${par_ignore_umi:+--ignore-umi} \\
    \${par_subset:+--subset "\$par_subset"} \\
    \${par_chrom:+--chrom "\$par_chrom"} \\
    \${par_no_sort_output:+--no-sort-output} \\
    \${par_buffer_whole_contig:+--buffer-whole-contig} \\
    \${par_log:+-L "\$par_log"} \\
    \${par_log2stderr:+--log2stderr} \\
    \${par_verbose:+-v "\$par_verbose"} \\
    \${par_error:+-E "\$par_error"} \\
    \${par_temp_dir:+--temp-dir "\$par_temp_dir"} \\
    \${par_compresslevel:+--compresslevel "\$par_compresslevel"} \\
    \${par_timeit:+--timeit "\$par_timeit"} \\
    \${par_timeit_name:+--timeit-name "\$par_timeit_name"} \\
    \${par_timeit_header:+--timeit-header "\$par_timeit_header"} \\
    \${par_random_seed:+--random-seed "\$par_random_seed"}

exit 0
VIASHMAIN
bash "\$tempscript" &
wait "\$!"

VIASHEOF


if [[ "$VIASH_ENGINE_TYPE" == "docker" ]]; then
  # strip viash automount from file paths
  
  if [ ! -z "$VIASH_PAR_INPUT" ]; then
    VIASH_PAR_INPUT=$(ViashDockerStripAutomount "$VIASH_PAR_INPUT")
  fi
  if [ ! -z "$VIASH_PAR_BAI" ]; then
    VIASH_PAR_BAI=$(ViashDockerStripAutomount "$VIASH_PAR_BAI")
  fi
  if [ ! -z "$VIASH_PAR_OUTPUT" ]; then
    VIASH_PAR_OUTPUT=$(ViashDockerStripAutomount "$VIASH_PAR_OUTPUT")
  fi
  if [ ! -z "$VIASH_PAR_GENE_TRANSCRIPT_MAP" ]; then
    VIASH_PAR_GENE_TRANSCRIPT_MAP=$(ViashDockerStripAutomount "$VIASH_PAR_GENE_TRANSCRIPT_MAP")
  fi
  if [ ! -z "$VIASH_PAR_LOG" ]; then
    VIASH_PAR_LOG=$(ViashDockerStripAutomount "$VIASH_PAR_LOG")
  fi
  if [ ! -z "$VIASH_PAR_ERROR" ]; then
    VIASH_PAR_ERROR=$(ViashDockerStripAutomount "$VIASH_PAR_ERROR")
  fi
  if [ ! -z "$VIASH_PAR_TIMEIT" ]; then
    VIASH_PAR_TIMEIT=$(ViashDockerStripAutomount "$VIASH_PAR_TIMEIT")
  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
