#!/usr/bin/env bash

# bowtie2_align 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:
#  * Robrecht Cannoodt (author, maintainer)

set -e

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

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

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

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

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

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

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

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

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

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

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

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

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

# define meta fields
VIASH_META_NAME="bowtie2_align"
VIASH_META_FUNCTIONALITY_NAME="bowtie2_align"
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/bowtie2:2.5.4--he96a11b_6
ENTRYPOINT []
RUN bowtie2 --version 2>&1 | head -1 | sed 's/.*version /bowtie2: /' > /var/software_versions.txt

LABEL org.opencontainers.image.authors="Robrecht Cannoodt"
LABEL org.opencontainers.image.description="Companion container for running component bowtie2 bowtie2_align"
LABEL org.opencontainers.image.created="2025-10-03T08:11:13Z"
LABEL org.opencontainers.image.source="https://github.com/BenLangmead/bowtie2"
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 "bowtie2_align main"
  echo ""
  echo "Align single-end and paired-end reads to a reference genome using Bowtie2."
  echo ""
  echo "Bowtie2 is an ultrafast and memory-efficient tool for aligning sequencing reads"
  echo "to long reference sequences. It is particularly good at aligning reads of about"
  echo "50 up to 100s of characters, and particularly good at aligning to relatively"
  echo "long (e.g. mammalian) genomes."
  echo ""
  echo "Inputs:"
  echo "    --index"
  echo "        type: string, required parameter"
  echo "        example: genome_index"
  echo "        Index filename prefix (minus trailing .X.bt2)."
  echo ""
  echo "    --mate1"
  echo "        type: file, multiple values allowed, file must exist"
  echo "        example: reads_R1.fastq.gz"
  echo "        Files with #1 mates, paired with files in --mate2."
  echo ""
  echo "    --mate2"
  echo "        type: file, multiple values allowed, file must exist"
  echo "        example: reads_R2.fastq.gz"
  echo "        Files with #2 mates, paired with files in --mate1."
  echo ""
  echo "    --unpaired"
  echo "        type: file, multiple values allowed, file must exist"
  echo "        example: reads.fastq.gz"
  echo "        Files with unpaired reads."
  echo ""
  echo "    --interleaved"
  echo "        type: file, multiple values allowed, file must exist"
  echo "        example: interleaved.fastq.gz"
  echo "        Files with interleaved paired-end FASTQ/FASTA reads."
  echo ""
  echo "    --bam_input"
  echo "        type: file, multiple values allowed, file must exist"
  echo "        example: unaligned.bam"
  echo "        Files are unaligned BAM sorted by read name."
  echo ""
  echo "Outputs:"
  echo "    --output"
  echo "        type: file, required parameter, output, file must exist"
  echo "        example: aligned.sam"
  echo "        File for SAM output (default stdout)."
  echo ""
  echo "    --un"
  echo "        type: file, output, file must exist"
  echo "        example: unaligned.fastq"
  echo "        Write unpaired reads that didn't align to file."
  echo ""
  echo "    --al"
  echo "        type: file, output, file must exist"
  echo "        example: aligned.fastq"
  echo "        Write unpaired reads that aligned at least once to file."
  echo ""
  echo "    --un_conc"
  echo "        type: file, output, file must exist"
  echo "        example: unaligned_pairs.fastq"
  echo "        Write pairs that didn't align concordantly to file."
  echo ""
  echo "    --al_conc"
  echo "        type: file, output, file must exist"
  echo "        example: aligned_pairs.fastq"
  echo "        Write pairs that aligned concordantly at least once to file."
  echo ""
  echo "    --met_file"
  echo "        type: file, output, file must exist"
  echo "        example: metrics.txt"
  echo "        Send metrics to file."
  echo ""
  echo "Input Format Options:"
  echo "    --fastq"
  echo "        type: boolean_true"
  echo "        Query input files are FASTQ .fq/.fastq (default)."
  echo ""
  echo "    --tab5"
  echo "        type: boolean_true"
  echo "        Query input files are TAB5 .tab5."
  echo ""
  echo "    --tab6"
  echo "        type: boolean_true"
  echo "        Query input files are TAB6 .tab6."
  echo ""
  echo "    --qseq"
  echo "        type: boolean_true"
  echo "        Query input files are in Illumina's qseq format."
  echo ""
  echo "    --fasta"
  echo "        type: boolean_true"
  echo "        Query input files are (multi-)FASTA .fa/.mfa."
  echo ""
  echo "    --raw"
  echo "        type: boolean_true"
  echo "        Query input files are raw one-sequence-per-line."
  echo ""
  echo "    --cmdline"
  echo "        type: boolean_true"
  echo "        <m1>, <m2>, <r> are sequences themselves, not files."
  echo ""
  echo "    --skip"
  echo "        type: integer"
  echo "        example: 1000"
  echo "        Skip the first <int> reads/pairs in the input."
  echo ""
  echo "    --upto"
  echo "        type: integer"
  echo "        example: 10000"
  echo "        Stop after first <int> reads/pairs."
  echo ""
  echo "    --trim5"
  echo "        type: integer"
  echo "        example: 5"
  echo "        Trim <int> bases from 5'/left end of reads."
  echo ""
  echo "    --trim3"
  echo "        type: integer"
  echo "        example: 3"
  echo "        Trim <int> bases from 3'/right end of reads."
  echo ""
  echo "    --trim_to"
  echo "        type: string"
  echo "        example: 3:100"
  echo "        Trim reads exceeding <int> bases from either 3' or 5' end. Format:"
  echo "        [3:|5:]<int>"
  echo ""
  echo "    --continuous_fasta"
  echo "        type: string"
  echo "        example: k:25,i:1"
  echo "        Query input files are continuous FASTA where reads are k-mers. Format:"
  echo "        k:<int>,i:<int>"
  echo ""
  echo "    --phred33"
  echo "        type: boolean_true"
  echo "        Qualities are Phred+33 (default)."
  echo ""
  echo "    --phred64"
  echo "        type: boolean_true"
  echo "        Qualities are Phred+64."
  echo ""
  echo "    --int_quals"
  echo "        type: boolean_true"
  echo "        Qualities encoded as space-delimited integers."
  echo ""
  echo "Alignment Presets:"
  echo "    --very_fast"
  echo "        type: boolean_true"
  echo "        Same as -D 5 -R 1 -N 0 -L 22 -i S,0,2.50."
  echo ""
  echo "    --fast"
  echo "        type: boolean_true"
  echo "        Same as -D 10 -R 2 -N 0 -L 22 -i S,0,2.50."
  echo ""
  echo "    --sensitive"
  echo "        type: boolean_true"
  echo "        Same as -D 15 -R 2 -N 0 -L 22 -i S,1,1.15 (default)."
  echo ""
  echo "    --very_sensitive"
  echo "        type: boolean_true"
  echo "        Same as -D 20 -R 3 -N 0 -L 20 -i S,1,0.50."
  echo ""
  echo "    --very_fast_local"
  echo "        type: boolean_true"
  echo "        Same as -D 5 -R 1 -N 0 -L 25 -i S,1,2.00."
  echo ""
  echo "    --fast_local"
  echo "        type: boolean_true"
  echo "        Same as -D 10 -R 2 -N 0 -L 22 -i S,1,1.75."
  echo ""
  echo "    --sensitive_local"
  echo "        type: boolean_true"
  echo "        Same as -D 15 -R 2 -N 0 -L 20 -i S,1,0.75."
  echo ""
  echo "    --very_sensitive_local"
  echo "        type: boolean_true"
  echo "        Same as -D 20 -R 3 -N 0 -L 20 -i S,1,0.50."
  echo ""
  echo "Alignment Options:"
  echo "    --N"
  echo "        type: integer"
  echo "        example: 1"
  echo "        Max # mismatches in seed alignment; can be 0 or 1."
  echo ""
  echo "    --L"
  echo "        type: integer"
  echo "        example: 22"
  echo "        Length of seed substrings; must be >3, <32."
  echo ""
  echo "    --i"
  echo "        type: string"
  echo "        example: S,1,1.15"
  echo "        Interval between seed substrings w/r/t read len."
  echo ""
  echo "    --n_ceil"
  echo "        type: string"
  echo "        example: L,0,0.15"
  echo "        Function for max # non-A/C/G/Ts permitted in aln."
  echo ""
  echo "    --dpad"
  echo "        type: integer"
  echo "        example: 15"
  echo "        Include <int> extra ref chars on sides of DP table."
  echo ""
  echo "    --gbar"
  echo "        type: integer"
  echo "        example: 4"
  echo "        Disallow gaps within <int> nucs of read extremes."
  echo ""
  echo "    --ignore_quals"
  echo "        type: boolean_true"
  echo "        Treat all quality values as 30 on Phred scale."
  echo ""
  echo "    --nofw"
  echo "        type: boolean_true"
  echo "        Do not align forward (original) version of read."
  echo ""
  echo "    --norc"
  echo "        type: boolean_true"
  echo "        Do not align reverse-complement version of read."
  echo ""
  echo "    --no_1mm_upfront"
  echo "        type: boolean_true"
  echo "        Do not allow 1 mismatch alignments before attempting to scan for the"
  echo "        optimal seeded alignments."
  echo ""
  echo "    --end_to_end"
  echo "        type: boolean_true"
  echo "        Entire read must align; no clipping (default)."
  echo ""
  echo "    --local"
  echo "        type: boolean_true"
  echo "        Local alignment; ends might be soft clipped."
  echo ""
  echo "Scoring Options:"
  echo "    --ma"
  echo "        type: integer"
  echo "        example: 2"
  echo "        Match bonus (0 for --end-to-end, 2 for --local)."
  echo ""
  echo "    --mp"
  echo "        type: string"
  echo "        example: 6"
  echo "        Max penalty for mismatch; lower qual = lower penalty."
  echo ""
  echo "    --np"
  echo "        type: integer"
  echo "        example: 1"
  echo "        Penalty for non-A/C/G/Ts in read/ref."
  echo ""
  echo "    --rdg"
  echo "        type: string"
  echo "        example: 5,3"
  echo "        Read gap open, extend penalties."
  echo ""
  echo "    --rfg"
  echo "        type: string"
  echo "        example: 5,3"
  echo "        Reference gap open, extend penalties."
  echo ""
  echo "    --score_min"
  echo "        type: string"
  echo "        example: L,-0.6,-0.6"
  echo "        Min acceptable alignment score w/r/t read length."
  echo ""
  echo "Reporting Options:"
  echo "    --k"
  echo "        type: integer"
  echo "        example: 10"
  echo "        Report up to <int> alns per read; MAPQ not meaningful."
  echo ""
  echo "    --all"
  echo "        type: boolean_true"
  echo "        Report all alignments; very slow, MAPQ not meaningful."
  echo ""
  echo "Effort Options:"
  echo "    --D"
  echo "        type: integer"
  echo "        example: 15"
  echo "        Give up extending after <int> failed extends in a row."
  echo ""
  echo "    --R"
  echo "        type: integer"
  echo "        example: 2"
  echo "        For reads w/ repetitive seeds, try <int> sets of seeds."
  echo ""
  echo "Paired-end Options:"
  echo "    --minins"
  echo "        type: integer"
  echo "        example: 0"
  echo "        Minimum fragment length."
  echo ""
  echo "    --maxins"
  echo "        type: integer"
  echo "        example: 500"
  echo "        Maximum fragment length."
  echo ""
  echo "    --fr"
  echo "        type: boolean_true"
  echo "        -1, -2 mates align fw/rev (default)."
  echo ""
  echo "    --rf"
  echo "        type: boolean_true"
  echo "        -1, -2 mates align rev/fw."
  echo ""
  echo "    --ff"
  echo "        type: boolean_true"
  echo "        -1, -2 mates align fw/fw."
  echo ""
  echo "    --no_mixed"
  echo "        type: boolean_true"
  echo "        Suppress unpaired alignments for paired reads."
  echo ""
  echo "    --no_discordant"
  echo "        type: boolean_true"
  echo "        Suppress discordant alignments for paired reads."
  echo ""
  echo "    --dovetail"
  echo "        type: boolean_true"
  echo "        Concordant when mates extend past each other."
  echo ""
  echo "    --no_contain"
  echo "        type: boolean_true"
  echo "        Not concordant when one mate alignment contains other."
  echo ""
  echo "    --no_overlap"
  echo "        type: boolean_true"
  echo "        Not concordant when mates overlap at all."
  echo ""
  echo "SAM Output Options:"
  echo "    --time"
  echo "        type: boolean_true"
  echo "        Print wall-clock time taken by search phases."
  echo ""
  echo "    --quiet"
  echo "        type: boolean_true"
  echo "        Print nothing to stderr except serious errors."
  echo ""
  echo "    --met_stderr"
  echo "        type: boolean_true"
  echo "        Send metrics to stderr."
  echo ""
  echo "    --met"
  echo "        type: integer"
  echo "        example: 1"
  echo "        Report internal counters & metrics every <int> secs."
  echo ""
  echo "    --no_unal"
  echo "        type: boolean_true"
  echo "        Suppress SAM records for unaligned reads."
  echo ""
  echo "    --no_head"
  echo "        type: boolean_true"
  echo "        Suppress header lines, i.e. lines starting with @."
  echo ""
  echo "    --no_sq"
  echo "        type: boolean_true"
  echo "        Suppress @SQ header lines."
  echo ""
  echo "    --rg_id"
  echo "        type: string"
  echo "        example: sample1"
  echo "        Set read group id, reflected in @RG line and RG:Z: opt field."
  echo ""
  echo "    --rg"
  echo "        type: string"
  echo "        example: SM:sample1"
  echo "        Add <text> (\"lab:value\") to @RG line of SAM header."
  echo ""
  echo "    --omit_sec_seq"
  echo "        type: boolean_true"
  echo "        Put '*' in SEQ and QUAL fields for secondary alignments."
  echo ""
  echo "    --sam_no_qname_trunc"
  echo "        type: boolean_true"
  echo "        Suppress standard behavior of truncating readname at first whitespace."
  echo ""
  echo "    --xeq"
  echo "        type: boolean_true"
  echo "        Use '='/'X', instead of 'M,' to specify matches/mismatches in SAM"
  echo "        record."
  echo ""
  echo "    --soft_clipped_unmapped_tlen"
  echo "        type: boolean_true"
  echo "        Exclude soft-clipped bases when reporting TLEN."
  echo ""
  echo "    --sam_append_comment"
  echo "        type: boolean_true"
  echo "        Append FASTA/FASTQ comment to SAM record."
  echo ""
  echo "    --sam_opt_config"
  echo "        type: string"
  echo "        example: -MD,YP,-AS"
  echo "        Use config to toggle SAM Optional fields. Example: '-MD,YP,-AS'"
  echo ""
  echo "BAM Options:"
  echo "    --align_paired_reads"
  echo "        type: boolean_true"
  echo "        Align paired-end reads instead of unpaired BAM reads."
  echo ""
  echo "    --preserve_tags"
  echo "        type: boolean_true"
  echo "        Preserve tags from the original BAM record."
  echo ""
  echo "Performance Options:"
  echo "    --reorder"
  echo "        type: boolean_true"
  echo "        Force SAM output order to match order of input reads."
  echo ""
  echo "    --mm"
  echo "        type: boolean_true"
  echo "        Use memory-mapped I/O for index; many 'bowtie's can share."
  echo ""
  echo "Other Options:"
  echo "    --qc_filter"
  echo "        type: boolean_true"
  echo "        Filter out reads that are bad according to QSEQ filter."
  echo ""
  echo "    --seed"
  echo "        type: integer"
  echo "        example: 42"
  echo "        Seed for random number generator."
  echo ""
  echo "    --non_deterministic"
  echo "        type: boolean_true"
  echo "        Seed rand. gen. arbitrarily instead of using read attributes."
  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 "bowtie2_align main"
            exit
            ;;
        --index)
            [ -n "$VIASH_PAR_INDEX" ] && ViashError Bad arguments for option \'--index\': \'$VIASH_PAR_INDEX\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_INDEX="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --index. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --index=*)
            [ -n "$VIASH_PAR_INDEX" ] && ViashError Bad arguments for option \'--index=*\': \'$VIASH_PAR_INDEX\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_INDEX=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --mate1)
            if [ -z "$VIASH_PAR_MATE1" ]; then
              VIASH_PAR_MATE1="$2"
            else
              VIASH_PAR_MATE1="$VIASH_PAR_MATE1;""$2"
            fi
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --mate1. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --mate1=*)
            if [ -z "$VIASH_PAR_MATE1" ]; then
              VIASH_PAR_MATE1=$(ViashRemoveFlags "$1")
            else
              VIASH_PAR_MATE1="$VIASH_PAR_MATE1;"$(ViashRemoveFlags "$1")
            fi
            shift 1
            ;;
        --mate2)
            if [ -z "$VIASH_PAR_MATE2" ]; then
              VIASH_PAR_MATE2="$2"
            else
              VIASH_PAR_MATE2="$VIASH_PAR_MATE2;""$2"
            fi
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --mate2. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --mate2=*)
            if [ -z "$VIASH_PAR_MATE2" ]; then
              VIASH_PAR_MATE2=$(ViashRemoveFlags "$1")
            else
              VIASH_PAR_MATE2="$VIASH_PAR_MATE2;"$(ViashRemoveFlags "$1")
            fi
            shift 1
            ;;
        --unpaired)
            if [ -z "$VIASH_PAR_UNPAIRED" ]; then
              VIASH_PAR_UNPAIRED="$2"
            else
              VIASH_PAR_UNPAIRED="$VIASH_PAR_UNPAIRED;""$2"
            fi
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --unpaired. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --unpaired=*)
            if [ -z "$VIASH_PAR_UNPAIRED" ]; then
              VIASH_PAR_UNPAIRED=$(ViashRemoveFlags "$1")
            else
              VIASH_PAR_UNPAIRED="$VIASH_PAR_UNPAIRED;"$(ViashRemoveFlags "$1")
            fi
            shift 1
            ;;
        --interleaved)
            if [ -z "$VIASH_PAR_INTERLEAVED" ]; then
              VIASH_PAR_INTERLEAVED="$2"
            else
              VIASH_PAR_INTERLEAVED="$VIASH_PAR_INTERLEAVED;""$2"
            fi
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --interleaved. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --interleaved=*)
            if [ -z "$VIASH_PAR_INTERLEAVED" ]; then
              VIASH_PAR_INTERLEAVED=$(ViashRemoveFlags "$1")
            else
              VIASH_PAR_INTERLEAVED="$VIASH_PAR_INTERLEAVED;"$(ViashRemoveFlags "$1")
            fi
            shift 1
            ;;
        --bam_input)
            if [ -z "$VIASH_PAR_BAM_INPUT" ]; then
              VIASH_PAR_BAM_INPUT="$2"
            else
              VIASH_PAR_BAM_INPUT="$VIASH_PAR_BAM_INPUT;""$2"
            fi
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --bam_input. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --bam_input=*)
            if [ -z "$VIASH_PAR_BAM_INPUT" ]; then
              VIASH_PAR_BAM_INPUT=$(ViashRemoveFlags "$1")
            else
              VIASH_PAR_BAM_INPUT="$VIASH_PAR_BAM_INPUT;"$(ViashRemoveFlags "$1")
            fi
            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
            ;;
        --un)
            [ -n "$VIASH_PAR_UN" ] && ViashError Bad arguments for option \'--un\': \'$VIASH_PAR_UN\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_UN="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --un. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --un=*)
            [ -n "$VIASH_PAR_UN" ] && ViashError Bad arguments for option \'--un=*\': \'$VIASH_PAR_UN\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_UN=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --al)
            [ -n "$VIASH_PAR_AL" ] && ViashError Bad arguments for option \'--al\': \'$VIASH_PAR_AL\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_AL="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --al. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --al=*)
            [ -n "$VIASH_PAR_AL" ] && ViashError Bad arguments for option \'--al=*\': \'$VIASH_PAR_AL\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_AL=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --un_conc)
            [ -n "$VIASH_PAR_UN_CONC" ] && ViashError Bad arguments for option \'--un_conc\': \'$VIASH_PAR_UN_CONC\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_UN_CONC="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --un_conc. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --un_conc=*)
            [ -n "$VIASH_PAR_UN_CONC" ] && ViashError Bad arguments for option \'--un_conc=*\': \'$VIASH_PAR_UN_CONC\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_UN_CONC=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --al_conc)
            [ -n "$VIASH_PAR_AL_CONC" ] && ViashError Bad arguments for option \'--al_conc\': \'$VIASH_PAR_AL_CONC\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_AL_CONC="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --al_conc. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --al_conc=*)
            [ -n "$VIASH_PAR_AL_CONC" ] && ViashError Bad arguments for option \'--al_conc=*\': \'$VIASH_PAR_AL_CONC\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_AL_CONC=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --met_file)
            [ -n "$VIASH_PAR_MET_FILE" ] && ViashError Bad arguments for option \'--met_file\': \'$VIASH_PAR_MET_FILE\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_MET_FILE="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --met_file. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --met_file=*)
            [ -n "$VIASH_PAR_MET_FILE" ] && ViashError Bad arguments for option \'--met_file=*\': \'$VIASH_PAR_MET_FILE\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_MET_FILE=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --fastq)
            [ -n "$VIASH_PAR_FASTQ" ] && ViashError Bad arguments for option \'--fastq\': \'$VIASH_PAR_FASTQ\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_FASTQ=true
            shift 1
            ;;
        --tab5)
            [ -n "$VIASH_PAR_TAB5" ] && ViashError Bad arguments for option \'--tab5\': \'$VIASH_PAR_TAB5\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_TAB5=true
            shift 1
            ;;
        --tab6)
            [ -n "$VIASH_PAR_TAB6" ] && ViashError Bad arguments for option \'--tab6\': \'$VIASH_PAR_TAB6\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_TAB6=true
            shift 1
            ;;
        --qseq)
            [ -n "$VIASH_PAR_QSEQ" ] && ViashError Bad arguments for option \'--qseq\': \'$VIASH_PAR_QSEQ\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_QSEQ=true
            shift 1
            ;;
        --fasta)
            [ -n "$VIASH_PAR_FASTA" ] && ViashError Bad arguments for option \'--fasta\': \'$VIASH_PAR_FASTA\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_FASTA=true
            shift 1
            ;;
        --raw)
            [ -n "$VIASH_PAR_RAW" ] && ViashError Bad arguments for option \'--raw\': \'$VIASH_PAR_RAW\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_RAW=true
            shift 1
            ;;
        --cmdline)
            [ -n "$VIASH_PAR_CMDLINE" ] && ViashError Bad arguments for option \'--cmdline\': \'$VIASH_PAR_CMDLINE\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_CMDLINE=true
            shift 1
            ;;
        --skip)
            [ -n "$VIASH_PAR_SKIP" ] && ViashError Bad arguments for option \'--skip\': \'$VIASH_PAR_SKIP\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_SKIP="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --skip. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --skip=*)
            [ -n "$VIASH_PAR_SKIP" ] && ViashError Bad arguments for option \'--skip=*\': \'$VIASH_PAR_SKIP\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_SKIP=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --upto)
            [ -n "$VIASH_PAR_UPTO" ] && ViashError Bad arguments for option \'--upto\': \'$VIASH_PAR_UPTO\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_UPTO="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --upto. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --upto=*)
            [ -n "$VIASH_PAR_UPTO" ] && ViashError Bad arguments for option \'--upto=*\': \'$VIASH_PAR_UPTO\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_UPTO=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --trim5)
            [ -n "$VIASH_PAR_TRIM5" ] && ViashError Bad arguments for option \'--trim5\': \'$VIASH_PAR_TRIM5\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_TRIM5="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --trim5. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --trim5=*)
            [ -n "$VIASH_PAR_TRIM5" ] && ViashError Bad arguments for option \'--trim5=*\': \'$VIASH_PAR_TRIM5\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_TRIM5=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --trim3)
            [ -n "$VIASH_PAR_TRIM3" ] && ViashError Bad arguments for option \'--trim3\': \'$VIASH_PAR_TRIM3\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_TRIM3="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --trim3. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --trim3=*)
            [ -n "$VIASH_PAR_TRIM3" ] && ViashError Bad arguments for option \'--trim3=*\': \'$VIASH_PAR_TRIM3\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_TRIM3=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --trim_to)
            [ -n "$VIASH_PAR_TRIM_TO" ] && ViashError Bad arguments for option \'--trim_to\': \'$VIASH_PAR_TRIM_TO\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_TRIM_TO="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --trim_to. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --trim_to=*)
            [ -n "$VIASH_PAR_TRIM_TO" ] && ViashError Bad arguments for option \'--trim_to=*\': \'$VIASH_PAR_TRIM_TO\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_TRIM_TO=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --continuous_fasta)
            [ -n "$VIASH_PAR_CONTINUOUS_FASTA" ] && ViashError Bad arguments for option \'--continuous_fasta\': \'$VIASH_PAR_CONTINUOUS_FASTA\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_CONTINUOUS_FASTA="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --continuous_fasta. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --continuous_fasta=*)
            [ -n "$VIASH_PAR_CONTINUOUS_FASTA" ] && ViashError Bad arguments for option \'--continuous_fasta=*\': \'$VIASH_PAR_CONTINUOUS_FASTA\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_CONTINUOUS_FASTA=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --phred33)
            [ -n "$VIASH_PAR_PHRED33" ] && ViashError Bad arguments for option \'--phred33\': \'$VIASH_PAR_PHRED33\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_PHRED33=true
            shift 1
            ;;
        --phred64)
            [ -n "$VIASH_PAR_PHRED64" ] && ViashError Bad arguments for option \'--phred64\': \'$VIASH_PAR_PHRED64\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_PHRED64=true
            shift 1
            ;;
        --int_quals)
            [ -n "$VIASH_PAR_INT_QUALS" ] && ViashError Bad arguments for option \'--int_quals\': \'$VIASH_PAR_INT_QUALS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_INT_QUALS=true
            shift 1
            ;;
        --very_fast)
            [ -n "$VIASH_PAR_VERY_FAST" ] && ViashError Bad arguments for option \'--very_fast\': \'$VIASH_PAR_VERY_FAST\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_VERY_FAST=true
            shift 1
            ;;
        --fast)
            [ -n "$VIASH_PAR_FAST" ] && ViashError Bad arguments for option \'--fast\': \'$VIASH_PAR_FAST\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_FAST=true
            shift 1
            ;;
        --sensitive)
            [ -n "$VIASH_PAR_SENSITIVE" ] && ViashError Bad arguments for option \'--sensitive\': \'$VIASH_PAR_SENSITIVE\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_SENSITIVE=true
            shift 1
            ;;
        --very_sensitive)
            [ -n "$VIASH_PAR_VERY_SENSITIVE" ] && ViashError Bad arguments for option \'--very_sensitive\': \'$VIASH_PAR_VERY_SENSITIVE\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_VERY_SENSITIVE=true
            shift 1
            ;;
        --very_fast_local)
            [ -n "$VIASH_PAR_VERY_FAST_LOCAL" ] && ViashError Bad arguments for option \'--very_fast_local\': \'$VIASH_PAR_VERY_FAST_LOCAL\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_VERY_FAST_LOCAL=true
            shift 1
            ;;
        --fast_local)
            [ -n "$VIASH_PAR_FAST_LOCAL" ] && ViashError Bad arguments for option \'--fast_local\': \'$VIASH_PAR_FAST_LOCAL\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_FAST_LOCAL=true
            shift 1
            ;;
        --sensitive_local)
            [ -n "$VIASH_PAR_SENSITIVE_LOCAL" ] && ViashError Bad arguments for option \'--sensitive_local\': \'$VIASH_PAR_SENSITIVE_LOCAL\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_SENSITIVE_LOCAL=true
            shift 1
            ;;
        --very_sensitive_local)
            [ -n "$VIASH_PAR_VERY_SENSITIVE_LOCAL" ] && ViashError Bad arguments for option \'--very_sensitive_local\': \'$VIASH_PAR_VERY_SENSITIVE_LOCAL\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_VERY_SENSITIVE_LOCAL=true
            shift 1
            ;;
        --N)
            [ -n "$VIASH_PAR_N" ] && ViashError Bad arguments for option \'--N\': \'$VIASH_PAR_N\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_N="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --N. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --N=*)
            [ -n "$VIASH_PAR_N" ] && ViashError Bad arguments for option \'--N=*\': \'$VIASH_PAR_N\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_N=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --L)
            [ -n "$VIASH_PAR_L" ] && ViashError Bad arguments for option \'--L\': \'$VIASH_PAR_L\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_L="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --L. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --L=*)
            [ -n "$VIASH_PAR_L" ] && ViashError Bad arguments for option \'--L=*\': \'$VIASH_PAR_L\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_L=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --i)
            [ -n "$VIASH_PAR_I" ] && ViashError Bad arguments for option \'--i\': \'$VIASH_PAR_I\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_I="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --i. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --i=*)
            [ -n "$VIASH_PAR_I" ] && ViashError Bad arguments for option \'--i=*\': \'$VIASH_PAR_I\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_I=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --n_ceil)
            [ -n "$VIASH_PAR_N_CEIL" ] && ViashError Bad arguments for option \'--n_ceil\': \'$VIASH_PAR_N_CEIL\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_N_CEIL="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --n_ceil. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --n_ceil=*)
            [ -n "$VIASH_PAR_N_CEIL" ] && ViashError Bad arguments for option \'--n_ceil=*\': \'$VIASH_PAR_N_CEIL\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_N_CEIL=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --dpad)
            [ -n "$VIASH_PAR_DPAD" ] && ViashError Bad arguments for option \'--dpad\': \'$VIASH_PAR_DPAD\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_DPAD="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --dpad. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --dpad=*)
            [ -n "$VIASH_PAR_DPAD" ] && ViashError Bad arguments for option \'--dpad=*\': \'$VIASH_PAR_DPAD\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_DPAD=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --gbar)
            [ -n "$VIASH_PAR_GBAR" ] && ViashError Bad arguments for option \'--gbar\': \'$VIASH_PAR_GBAR\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_GBAR="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --gbar. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --gbar=*)
            [ -n "$VIASH_PAR_GBAR" ] && ViashError Bad arguments for option \'--gbar=*\': \'$VIASH_PAR_GBAR\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_GBAR=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --ignore_quals)
            [ -n "$VIASH_PAR_IGNORE_QUALS" ] && ViashError Bad arguments for option \'--ignore_quals\': \'$VIASH_PAR_IGNORE_QUALS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_IGNORE_QUALS=true
            shift 1
            ;;
        --nofw)
            [ -n "$VIASH_PAR_NOFW" ] && ViashError Bad arguments for option \'--nofw\': \'$VIASH_PAR_NOFW\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_NOFW=true
            shift 1
            ;;
        --norc)
            [ -n "$VIASH_PAR_NORC" ] && ViashError Bad arguments for option \'--norc\': \'$VIASH_PAR_NORC\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_NORC=true
            shift 1
            ;;
        --no_1mm_upfront)
            [ -n "$VIASH_PAR_NO_1MM_UPFRONT" ] && ViashError Bad arguments for option \'--no_1mm_upfront\': \'$VIASH_PAR_NO_1MM_UPFRONT\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_NO_1MM_UPFRONT=true
            shift 1
            ;;
        --end_to_end)
            [ -n "$VIASH_PAR_END_TO_END" ] && ViashError Bad arguments for option \'--end_to_end\': \'$VIASH_PAR_END_TO_END\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_END_TO_END=true
            shift 1
            ;;
        --local)
            [ -n "$VIASH_PAR_LOCAL" ] && ViashError Bad arguments for option \'--local\': \'$VIASH_PAR_LOCAL\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_LOCAL=true
            shift 1
            ;;
        --ma)
            [ -n "$VIASH_PAR_MA" ] && ViashError Bad arguments for option \'--ma\': \'$VIASH_PAR_MA\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_MA="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --ma. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --ma=*)
            [ -n "$VIASH_PAR_MA" ] && ViashError Bad arguments for option \'--ma=*\': \'$VIASH_PAR_MA\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_MA=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --mp)
            [ -n "$VIASH_PAR_MP" ] && ViashError Bad arguments for option \'--mp\': \'$VIASH_PAR_MP\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_MP="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --mp. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --mp=*)
            [ -n "$VIASH_PAR_MP" ] && ViashError Bad arguments for option \'--mp=*\': \'$VIASH_PAR_MP\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_MP=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --np)
            [ -n "$VIASH_PAR_NP" ] && ViashError Bad arguments for option \'--np\': \'$VIASH_PAR_NP\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_NP="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --np. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --np=*)
            [ -n "$VIASH_PAR_NP" ] && ViashError Bad arguments for option \'--np=*\': \'$VIASH_PAR_NP\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_NP=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --rdg)
            [ -n "$VIASH_PAR_RDG" ] && ViashError Bad arguments for option \'--rdg\': \'$VIASH_PAR_RDG\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_RDG="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --rdg. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --rdg=*)
            [ -n "$VIASH_PAR_RDG" ] && ViashError Bad arguments for option \'--rdg=*\': \'$VIASH_PAR_RDG\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_RDG=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --rfg)
            [ -n "$VIASH_PAR_RFG" ] && ViashError Bad arguments for option \'--rfg\': \'$VIASH_PAR_RFG\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_RFG="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --rfg. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --rfg=*)
            [ -n "$VIASH_PAR_RFG" ] && ViashError Bad arguments for option \'--rfg=*\': \'$VIASH_PAR_RFG\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_RFG=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --score_min)
            [ -n "$VIASH_PAR_SCORE_MIN" ] && ViashError Bad arguments for option \'--score_min\': \'$VIASH_PAR_SCORE_MIN\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_SCORE_MIN="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --score_min. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --score_min=*)
            [ -n "$VIASH_PAR_SCORE_MIN" ] && ViashError Bad arguments for option \'--score_min=*\': \'$VIASH_PAR_SCORE_MIN\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_SCORE_MIN=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --k)
            [ -n "$VIASH_PAR_K" ] && ViashError Bad arguments for option \'--k\': \'$VIASH_PAR_K\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_K="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --k. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --k=*)
            [ -n "$VIASH_PAR_K" ] && ViashError Bad arguments for option \'--k=*\': \'$VIASH_PAR_K\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_K=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --all)
            [ -n "$VIASH_PAR_ALL" ] && ViashError Bad arguments for option \'--all\': \'$VIASH_PAR_ALL\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_ALL=true
            shift 1
            ;;
        --D)
            [ -n "$VIASH_PAR_D" ] && ViashError Bad arguments for option \'--D\': \'$VIASH_PAR_D\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_D="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --D. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --D=*)
            [ -n "$VIASH_PAR_D" ] && ViashError Bad arguments for option \'--D=*\': \'$VIASH_PAR_D\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_D=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --R)
            [ -n "$VIASH_PAR_R" ] && ViashError Bad arguments for option \'--R\': \'$VIASH_PAR_R\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_R="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --R. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --R=*)
            [ -n "$VIASH_PAR_R" ] && ViashError Bad arguments for option \'--R=*\': \'$VIASH_PAR_R\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_R=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --minins)
            [ -n "$VIASH_PAR_MININS" ] && ViashError Bad arguments for option \'--minins\': \'$VIASH_PAR_MININS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_MININS="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --minins. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --minins=*)
            [ -n "$VIASH_PAR_MININS" ] && ViashError Bad arguments for option \'--minins=*\': \'$VIASH_PAR_MININS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_MININS=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --maxins)
            [ -n "$VIASH_PAR_MAXINS" ] && ViashError Bad arguments for option \'--maxins\': \'$VIASH_PAR_MAXINS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_MAXINS="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --maxins. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --maxins=*)
            [ -n "$VIASH_PAR_MAXINS" ] && ViashError Bad arguments for option \'--maxins=*\': \'$VIASH_PAR_MAXINS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_MAXINS=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --fr)
            [ -n "$VIASH_PAR_FR" ] && ViashError Bad arguments for option \'--fr\': \'$VIASH_PAR_FR\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_FR=true
            shift 1
            ;;
        --rf)
            [ -n "$VIASH_PAR_RF" ] && ViashError Bad arguments for option \'--rf\': \'$VIASH_PAR_RF\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_RF=true
            shift 1
            ;;
        --ff)
            [ -n "$VIASH_PAR_FF" ] && ViashError Bad arguments for option \'--ff\': \'$VIASH_PAR_FF\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_FF=true
            shift 1
            ;;
        --no_mixed)
            [ -n "$VIASH_PAR_NO_MIXED" ] && ViashError Bad arguments for option \'--no_mixed\': \'$VIASH_PAR_NO_MIXED\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_NO_MIXED=true
            shift 1
            ;;
        --no_discordant)
            [ -n "$VIASH_PAR_NO_DISCORDANT" ] && ViashError Bad arguments for option \'--no_discordant\': \'$VIASH_PAR_NO_DISCORDANT\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_NO_DISCORDANT=true
            shift 1
            ;;
        --dovetail)
            [ -n "$VIASH_PAR_DOVETAIL" ] && ViashError Bad arguments for option \'--dovetail\': \'$VIASH_PAR_DOVETAIL\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_DOVETAIL=true
            shift 1
            ;;
        --no_contain)
            [ -n "$VIASH_PAR_NO_CONTAIN" ] && ViashError Bad arguments for option \'--no_contain\': \'$VIASH_PAR_NO_CONTAIN\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_NO_CONTAIN=true
            shift 1
            ;;
        --no_overlap)
            [ -n "$VIASH_PAR_NO_OVERLAP" ] && ViashError Bad arguments for option \'--no_overlap\': \'$VIASH_PAR_NO_OVERLAP\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_NO_OVERLAP=true
            shift 1
            ;;
        --time)
            [ -n "$VIASH_PAR_TIME" ] && ViashError Bad arguments for option \'--time\': \'$VIASH_PAR_TIME\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_TIME=true
            shift 1
            ;;
        --quiet)
            [ -n "$VIASH_PAR_QUIET" ] && ViashError Bad arguments for option \'--quiet\': \'$VIASH_PAR_QUIET\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_QUIET=true
            shift 1
            ;;
        --met_stderr)
            [ -n "$VIASH_PAR_MET_STDERR" ] && ViashError Bad arguments for option \'--met_stderr\': \'$VIASH_PAR_MET_STDERR\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_MET_STDERR=true
            shift 1
            ;;
        --met)
            [ -n "$VIASH_PAR_MET" ] && ViashError Bad arguments for option \'--met\': \'$VIASH_PAR_MET\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_MET="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --met. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --met=*)
            [ -n "$VIASH_PAR_MET" ] && ViashError Bad arguments for option \'--met=*\': \'$VIASH_PAR_MET\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_MET=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --no_unal)
            [ -n "$VIASH_PAR_NO_UNAL" ] && ViashError Bad arguments for option \'--no_unal\': \'$VIASH_PAR_NO_UNAL\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_NO_UNAL=true
            shift 1
            ;;
        --no_head)
            [ -n "$VIASH_PAR_NO_HEAD" ] && ViashError Bad arguments for option \'--no_head\': \'$VIASH_PAR_NO_HEAD\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_NO_HEAD=true
            shift 1
            ;;
        --no_sq)
            [ -n "$VIASH_PAR_NO_SQ" ] && ViashError Bad arguments for option \'--no_sq\': \'$VIASH_PAR_NO_SQ\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_NO_SQ=true
            shift 1
            ;;
        --rg_id)
            [ -n "$VIASH_PAR_RG_ID" ] && ViashError Bad arguments for option \'--rg_id\': \'$VIASH_PAR_RG_ID\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_RG_ID="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --rg_id. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --rg_id=*)
            [ -n "$VIASH_PAR_RG_ID" ] && ViashError Bad arguments for option \'--rg_id=*\': \'$VIASH_PAR_RG_ID\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_RG_ID=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --rg)
            [ -n "$VIASH_PAR_RG" ] && ViashError Bad arguments for option \'--rg\': \'$VIASH_PAR_RG\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_RG="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --rg. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --rg=*)
            [ -n "$VIASH_PAR_RG" ] && ViashError Bad arguments for option \'--rg=*\': \'$VIASH_PAR_RG\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_RG=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --omit_sec_seq)
            [ -n "$VIASH_PAR_OMIT_SEC_SEQ" ] && ViashError Bad arguments for option \'--omit_sec_seq\': \'$VIASH_PAR_OMIT_SEC_SEQ\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_OMIT_SEC_SEQ=true
            shift 1
            ;;
        --sam_no_qname_trunc)
            [ -n "$VIASH_PAR_SAM_NO_QNAME_TRUNC" ] && ViashError Bad arguments for option \'--sam_no_qname_trunc\': \'$VIASH_PAR_SAM_NO_QNAME_TRUNC\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_SAM_NO_QNAME_TRUNC=true
            shift 1
            ;;
        --xeq)
            [ -n "$VIASH_PAR_XEQ" ] && ViashError Bad arguments for option \'--xeq\': \'$VIASH_PAR_XEQ\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_XEQ=true
            shift 1
            ;;
        --soft_clipped_unmapped_tlen)
            [ -n "$VIASH_PAR_SOFT_CLIPPED_UNMAPPED_TLEN" ] && ViashError Bad arguments for option \'--soft_clipped_unmapped_tlen\': \'$VIASH_PAR_SOFT_CLIPPED_UNMAPPED_TLEN\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_SOFT_CLIPPED_UNMAPPED_TLEN=true
            shift 1
            ;;
        --sam_append_comment)
            [ -n "$VIASH_PAR_SAM_APPEND_COMMENT" ] && ViashError Bad arguments for option \'--sam_append_comment\': \'$VIASH_PAR_SAM_APPEND_COMMENT\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_SAM_APPEND_COMMENT=true
            shift 1
            ;;
        --sam_opt_config)
            [ -n "$VIASH_PAR_SAM_OPT_CONFIG" ] && ViashError Bad arguments for option \'--sam_opt_config\': \'$VIASH_PAR_SAM_OPT_CONFIG\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_SAM_OPT_CONFIG="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --sam_opt_config. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --sam_opt_config=*)
            [ -n "$VIASH_PAR_SAM_OPT_CONFIG" ] && ViashError Bad arguments for option \'--sam_opt_config=*\': \'$VIASH_PAR_SAM_OPT_CONFIG\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_SAM_OPT_CONFIG=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --align_paired_reads)
            [ -n "$VIASH_PAR_ALIGN_PAIRED_READS" ] && ViashError Bad arguments for option \'--align_paired_reads\': \'$VIASH_PAR_ALIGN_PAIRED_READS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_ALIGN_PAIRED_READS=true
            shift 1
            ;;
        --preserve_tags)
            [ -n "$VIASH_PAR_PRESERVE_TAGS" ] && ViashError Bad arguments for option \'--preserve_tags\': \'$VIASH_PAR_PRESERVE_TAGS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_PRESERVE_TAGS=true
            shift 1
            ;;
        --reorder)
            [ -n "$VIASH_PAR_REORDER" ] && ViashError Bad arguments for option \'--reorder\': \'$VIASH_PAR_REORDER\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_REORDER=true
            shift 1
            ;;
        --mm)
            [ -n "$VIASH_PAR_MM" ] && ViashError Bad arguments for option \'--mm\': \'$VIASH_PAR_MM\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_MM=true
            shift 1
            ;;
        --qc_filter)
            [ -n "$VIASH_PAR_QC_FILTER" ] && ViashError Bad arguments for option \'--qc_filter\': \'$VIASH_PAR_QC_FILTER\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_QC_FILTER=true
            shift 1
            ;;
        --seed)
            [ -n "$VIASH_PAR_SEED" ] && ViashError Bad arguments for option \'--seed\': \'$VIASH_PAR_SEED\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_SEED="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --seed. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --seed=*)
            [ -n "$VIASH_PAR_SEED" ] && ViashError Bad arguments for option \'--seed=*\': \'$VIASH_PAR_SEED\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_SEED=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --non_deterministic)
            [ -n "$VIASH_PAR_NON_DETERMINISTIC" ] && ViashError Bad arguments for option \'--non_deterministic\': \'$VIASH_PAR_NON_DETERMINISTIC\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_NON_DETERMINISTIC=true
            shift 1
            ;;
        ---engine)
            VIASH_ENGINE_ID="$2"
            shift 2
            ;;
        ---engine=*)
            VIASH_ENGINE_ID="$(ViashRemoveFlags "$1")"
            shift 1
            ;;
        ---setup)
            VIASH_MODE='setup'
            VIASH_SETUP_STRATEGY="$2"
            shift 2
            ;;
        ---setup=*)
            VIASH_MODE='setup'
            VIASH_SETUP_STRATEGY="$(ViashRemoveFlags "$1")"
            shift 1
            ;;
        ---dockerfile)
            VIASH_MODE='dockerfile'
            shift 1
            ;;
        ---docker_run_args)
            VIASH_DOCKER_RUN_ARGS+=("$2")
            shift 2
            ;;
        ---docker_run_args=*)
            VIASH_DOCKER_RUN_ARGS+=("$(ViashRemoveFlags "$1")")
            shift 1
            ;;
        ---docker_image_id)
            VIASH_MODE='docker_image_id'
            shift 1
            ;;
        ---debug)
            VIASH_MODE='debug'
            shift 1
            ;;
        ---cpus)
            [ -n "$VIASH_META_CPUS" ] && ViashError Bad arguments for option \'---cpus\': \'$VIASH_META_CPUS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_META_CPUS="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to ---cpus. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        ---cpus=*)
            [ -n "$VIASH_META_CPUS" ] && ViashError Bad arguments for option \'---cpus=*\': \'$VIASH_META_CPUS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_META_CPUS=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        ---memory)
            [ -n "$VIASH_META_MEMORY" ] && ViashError Bad arguments for option \'---memory\': \'$VIASH_META_MEMORY\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_META_MEMORY="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to ---memory. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        ---memory=*)
            [ -n "$VIASH_META_MEMORY" ] && ViashError Bad arguments for option \'---memory=*\': \'$VIASH_META_MEMORY\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_META_MEMORY=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        *)  # positional arg or unknown option
            # since the positional args will be eval'd, can we always quote, instead of using ViashQuote
            VIASH_POSITIONAL_ARGS="$VIASH_POSITIONAL_ARGS '$1'"
            [[ $1 == -* ]] && ViashWarning $1 looks like a parameter but is not a defined parameter and will instead be treated as a positional argument. Use "--help" to get more information on the parameters.
            shift # past argument
            ;;
    esac
done

# parse positional parameters
eval set -- $VIASH_POSITIONAL_ARGS


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

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

  # determine docker image id
  if [[ "$VIASH_ENGINE_ID" == 'docker' ]]; then
    VIASH_DOCKER_IMAGE_ID='images.viash-hub.com/vsh/biobox/bowtie2/bowtie2_align: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" 'bowtie2' 'ps' 'bash'
    exit 0
  fi

  # check if docker image exists
  ViashDockerSetup "$VIASH_DOCKER_IMAGE_ID" ifneedbepullelsecachedbuild
  ViashDockerCheckCommands "$VIASH_DOCKER_IMAGE_ID" 'bowtie2' '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_INDEX+x} ]; then
  ViashError '--index' 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_FASTQ+x} ]; then
  VIASH_PAR_FASTQ="false"
fi
if [ -z ${VIASH_PAR_TAB5+x} ]; then
  VIASH_PAR_TAB5="false"
fi
if [ -z ${VIASH_PAR_TAB6+x} ]; then
  VIASH_PAR_TAB6="false"
fi
if [ -z ${VIASH_PAR_QSEQ+x} ]; then
  VIASH_PAR_QSEQ="false"
fi
if [ -z ${VIASH_PAR_FASTA+x} ]; then
  VIASH_PAR_FASTA="false"
fi
if [ -z ${VIASH_PAR_RAW+x} ]; then
  VIASH_PAR_RAW="false"
fi
if [ -z ${VIASH_PAR_CMDLINE+x} ]; then
  VIASH_PAR_CMDLINE="false"
fi
if [ -z ${VIASH_PAR_PHRED33+x} ]; then
  VIASH_PAR_PHRED33="false"
fi
if [ -z ${VIASH_PAR_PHRED64+x} ]; then
  VIASH_PAR_PHRED64="false"
fi
if [ -z ${VIASH_PAR_INT_QUALS+x} ]; then
  VIASH_PAR_INT_QUALS="false"
fi
if [ -z ${VIASH_PAR_VERY_FAST+x} ]; then
  VIASH_PAR_VERY_FAST="false"
fi
if [ -z ${VIASH_PAR_FAST+x} ]; then
  VIASH_PAR_FAST="false"
fi
if [ -z ${VIASH_PAR_SENSITIVE+x} ]; then
  VIASH_PAR_SENSITIVE="false"
fi
if [ -z ${VIASH_PAR_VERY_SENSITIVE+x} ]; then
  VIASH_PAR_VERY_SENSITIVE="false"
fi
if [ -z ${VIASH_PAR_VERY_FAST_LOCAL+x} ]; then
  VIASH_PAR_VERY_FAST_LOCAL="false"
fi
if [ -z ${VIASH_PAR_FAST_LOCAL+x} ]; then
  VIASH_PAR_FAST_LOCAL="false"
fi
if [ -z ${VIASH_PAR_SENSITIVE_LOCAL+x} ]; then
  VIASH_PAR_SENSITIVE_LOCAL="false"
fi
if [ -z ${VIASH_PAR_VERY_SENSITIVE_LOCAL+x} ]; then
  VIASH_PAR_VERY_SENSITIVE_LOCAL="false"
fi
if [ -z ${VIASH_PAR_IGNORE_QUALS+x} ]; then
  VIASH_PAR_IGNORE_QUALS="false"
fi
if [ -z ${VIASH_PAR_NOFW+x} ]; then
  VIASH_PAR_NOFW="false"
fi
if [ -z ${VIASH_PAR_NORC+x} ]; then
  VIASH_PAR_NORC="false"
fi
if [ -z ${VIASH_PAR_NO_1MM_UPFRONT+x} ]; then
  VIASH_PAR_NO_1MM_UPFRONT="false"
fi
if [ -z ${VIASH_PAR_END_TO_END+x} ]; then
  VIASH_PAR_END_TO_END="false"
fi
if [ -z ${VIASH_PAR_LOCAL+x} ]; then
  VIASH_PAR_LOCAL="false"
fi
if [ -z ${VIASH_PAR_ALL+x} ]; then
  VIASH_PAR_ALL="false"
fi
if [ -z ${VIASH_PAR_FR+x} ]; then
  VIASH_PAR_FR="false"
fi
if [ -z ${VIASH_PAR_RF+x} ]; then
  VIASH_PAR_RF="false"
fi
if [ -z ${VIASH_PAR_FF+x} ]; then
  VIASH_PAR_FF="false"
fi
if [ -z ${VIASH_PAR_NO_MIXED+x} ]; then
  VIASH_PAR_NO_MIXED="false"
fi
if [ -z ${VIASH_PAR_NO_DISCORDANT+x} ]; then
  VIASH_PAR_NO_DISCORDANT="false"
fi
if [ -z ${VIASH_PAR_DOVETAIL+x} ]; then
  VIASH_PAR_DOVETAIL="false"
fi
if [ -z ${VIASH_PAR_NO_CONTAIN+x} ]; then
  VIASH_PAR_NO_CONTAIN="false"
fi
if [ -z ${VIASH_PAR_NO_OVERLAP+x} ]; then
  VIASH_PAR_NO_OVERLAP="false"
fi
if [ -z ${VIASH_PAR_TIME+x} ]; then
  VIASH_PAR_TIME="false"
fi
if [ -z ${VIASH_PAR_QUIET+x} ]; then
  VIASH_PAR_QUIET="false"
fi
if [ -z ${VIASH_PAR_MET_STDERR+x} ]; then
  VIASH_PAR_MET_STDERR="false"
fi
if [ -z ${VIASH_PAR_NO_UNAL+x} ]; then
  VIASH_PAR_NO_UNAL="false"
fi
if [ -z ${VIASH_PAR_NO_HEAD+x} ]; then
  VIASH_PAR_NO_HEAD="false"
fi
if [ -z ${VIASH_PAR_NO_SQ+x} ]; then
  VIASH_PAR_NO_SQ="false"
fi
if [ -z ${VIASH_PAR_OMIT_SEC_SEQ+x} ]; then
  VIASH_PAR_OMIT_SEC_SEQ="false"
fi
if [ -z ${VIASH_PAR_SAM_NO_QNAME_TRUNC+x} ]; then
  VIASH_PAR_SAM_NO_QNAME_TRUNC="false"
fi
if [ -z ${VIASH_PAR_XEQ+x} ]; then
  VIASH_PAR_XEQ="false"
fi
if [ -z ${VIASH_PAR_SOFT_CLIPPED_UNMAPPED_TLEN+x} ]; then
  VIASH_PAR_SOFT_CLIPPED_UNMAPPED_TLEN="false"
fi
if [ -z ${VIASH_PAR_SAM_APPEND_COMMENT+x} ]; then
  VIASH_PAR_SAM_APPEND_COMMENT="false"
fi
if [ -z ${VIASH_PAR_ALIGN_PAIRED_READS+x} ]; then
  VIASH_PAR_ALIGN_PAIRED_READS="false"
fi
if [ -z ${VIASH_PAR_PRESERVE_TAGS+x} ]; then
  VIASH_PAR_PRESERVE_TAGS="false"
fi
if [ -z ${VIASH_PAR_REORDER+x} ]; then
  VIASH_PAR_REORDER="false"
fi
if [ -z ${VIASH_PAR_MM+x} ]; then
  VIASH_PAR_MM="false"
fi
if [ -z ${VIASH_PAR_QC_FILTER+x} ]; then
  VIASH_PAR_QC_FILTER="false"
fi
if [ -z ${VIASH_PAR_NON_DETERMINISTIC+x} ]; then
  VIASH_PAR_NON_DETERMINISTIC="false"
fi

# check whether required files exist
if [ ! -z "$VIASH_PAR_MATE1" ]; then
  IFS=';'
  set -f
  for file in $VIASH_PAR_MATE1; do
    unset IFS
    if [ ! -e "$file" ]; then
      ViashError "Input file '$file' does not exist."
      exit 1
    fi
  done
  set +f
fi
if [ ! -z "$VIASH_PAR_MATE2" ]; then
  IFS=';'
  set -f
  for file in $VIASH_PAR_MATE2; do
    unset IFS
    if [ ! -e "$file" ]; then
      ViashError "Input file '$file' does not exist."
      exit 1
    fi
  done
  set +f
fi
if [ ! -z "$VIASH_PAR_UNPAIRED" ]; then
  IFS=';'
  set -f
  for file in $VIASH_PAR_UNPAIRED; do
    unset IFS
    if [ ! -e "$file" ]; then
      ViashError "Input file '$file' does not exist."
      exit 1
    fi
  done
  set +f
fi
if [ ! -z "$VIASH_PAR_INTERLEAVED" ]; then
  IFS=';'
  set -f
  for file in $VIASH_PAR_INTERLEAVED; do
    unset IFS
    if [ ! -e "$file" ]; then
      ViashError "Input file '$file' does not exist."
      exit 1
    fi
  done
  set +f
fi
if [ ! -z "$VIASH_PAR_BAM_INPUT" ]; then
  IFS=';'
  set -f
  for file in $VIASH_PAR_BAM_INPUT; do
    unset IFS
    if [ ! -e "$file" ]; then
      ViashError "Input file '$file' does not exist."
      exit 1
    fi
  done
  set +f
fi

# check whether parameters values are of the right type
if [[ -n "$VIASH_PAR_FASTQ" ]]; then
  if ! [[ "$VIASH_PAR_FASTQ" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--fastq' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_TAB5" ]]; then
  if ! [[ "$VIASH_PAR_TAB5" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--tab5' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_TAB6" ]]; then
  if ! [[ "$VIASH_PAR_TAB6" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--tab6' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_QSEQ" ]]; then
  if ! [[ "$VIASH_PAR_QSEQ" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--qseq' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_FASTA" ]]; then
  if ! [[ "$VIASH_PAR_FASTA" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--fasta' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_RAW" ]]; then
  if ! [[ "$VIASH_PAR_RAW" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--raw' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_CMDLINE" ]]; then
  if ! [[ "$VIASH_PAR_CMDLINE" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--cmdline' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_SKIP" ]]; then
  if ! [[ "$VIASH_PAR_SKIP" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError '--skip' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_UPTO" ]]; then
  if ! [[ "$VIASH_PAR_UPTO" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError '--upto' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_TRIM5" ]]; then
  if ! [[ "$VIASH_PAR_TRIM5" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError '--trim5' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_TRIM3" ]]; then
  if ! [[ "$VIASH_PAR_TRIM3" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError '--trim3' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_PHRED33" ]]; then
  if ! [[ "$VIASH_PAR_PHRED33" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--phred33' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_PHRED64" ]]; then
  if ! [[ "$VIASH_PAR_PHRED64" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--phred64' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_INT_QUALS" ]]; then
  if ! [[ "$VIASH_PAR_INT_QUALS" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--int_quals' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_VERY_FAST" ]]; then
  if ! [[ "$VIASH_PAR_VERY_FAST" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--very_fast' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_FAST" ]]; then
  if ! [[ "$VIASH_PAR_FAST" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--fast' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_SENSITIVE" ]]; then
  if ! [[ "$VIASH_PAR_SENSITIVE" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--sensitive' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_VERY_SENSITIVE" ]]; then
  if ! [[ "$VIASH_PAR_VERY_SENSITIVE" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--very_sensitive' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_VERY_FAST_LOCAL" ]]; then
  if ! [[ "$VIASH_PAR_VERY_FAST_LOCAL" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--very_fast_local' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_FAST_LOCAL" ]]; then
  if ! [[ "$VIASH_PAR_FAST_LOCAL" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--fast_local' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_SENSITIVE_LOCAL" ]]; then
  if ! [[ "$VIASH_PAR_SENSITIVE_LOCAL" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--sensitive_local' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_VERY_SENSITIVE_LOCAL" ]]; then
  if ! [[ "$VIASH_PAR_VERY_SENSITIVE_LOCAL" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--very_sensitive_local' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_N" ]]; then
  if ! [[ "$VIASH_PAR_N" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError '--N' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_L" ]]; then
  if ! [[ "$VIASH_PAR_L" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError '--L' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_DPAD" ]]; then
  if ! [[ "$VIASH_PAR_DPAD" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError '--dpad' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_GBAR" ]]; then
  if ! [[ "$VIASH_PAR_GBAR" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError '--gbar' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_IGNORE_QUALS" ]]; then
  if ! [[ "$VIASH_PAR_IGNORE_QUALS" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--ignore_quals' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_NOFW" ]]; then
  if ! [[ "$VIASH_PAR_NOFW" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--nofw' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_NORC" ]]; then
  if ! [[ "$VIASH_PAR_NORC" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--norc' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_NO_1MM_UPFRONT" ]]; then
  if ! [[ "$VIASH_PAR_NO_1MM_UPFRONT" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--no_1mm_upfront' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_END_TO_END" ]]; then
  if ! [[ "$VIASH_PAR_END_TO_END" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--end_to_end' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_LOCAL" ]]; then
  if ! [[ "$VIASH_PAR_LOCAL" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--local' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_MA" ]]; then
  if ! [[ "$VIASH_PAR_MA" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError '--ma' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_NP" ]]; then
  if ! [[ "$VIASH_PAR_NP" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError '--np' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_K" ]]; then
  if ! [[ "$VIASH_PAR_K" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError '--k' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_ALL" ]]; then
  if ! [[ "$VIASH_PAR_ALL" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--all' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_D" ]]; then
  if ! [[ "$VIASH_PAR_D" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError '--D' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_R" ]]; then
  if ! [[ "$VIASH_PAR_R" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError '--R' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_MININS" ]]; then
  if ! [[ "$VIASH_PAR_MININS" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError '--minins' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_MAXINS" ]]; then
  if ! [[ "$VIASH_PAR_MAXINS" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError '--maxins' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_FR" ]]; then
  if ! [[ "$VIASH_PAR_FR" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--fr' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_RF" ]]; then
  if ! [[ "$VIASH_PAR_RF" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--rf' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_FF" ]]; then
  if ! [[ "$VIASH_PAR_FF" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--ff' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_NO_MIXED" ]]; then
  if ! [[ "$VIASH_PAR_NO_MIXED" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--no_mixed' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_NO_DISCORDANT" ]]; then
  if ! [[ "$VIASH_PAR_NO_DISCORDANT" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--no_discordant' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_DOVETAIL" ]]; then
  if ! [[ "$VIASH_PAR_DOVETAIL" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--dovetail' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_NO_CONTAIN" ]]; then
  if ! [[ "$VIASH_PAR_NO_CONTAIN" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--no_contain' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_NO_OVERLAP" ]]; then
  if ! [[ "$VIASH_PAR_NO_OVERLAP" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--no_overlap' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_TIME" ]]; then
  if ! [[ "$VIASH_PAR_TIME" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--time' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_QUIET" ]]; then
  if ! [[ "$VIASH_PAR_QUIET" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--quiet' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_MET_STDERR" ]]; then
  if ! [[ "$VIASH_PAR_MET_STDERR" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--met_stderr' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_MET" ]]; then
  if ! [[ "$VIASH_PAR_MET" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError '--met' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_NO_UNAL" ]]; then
  if ! [[ "$VIASH_PAR_NO_UNAL" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--no_unal' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_NO_HEAD" ]]; then
  if ! [[ "$VIASH_PAR_NO_HEAD" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--no_head' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_NO_SQ" ]]; then
  if ! [[ "$VIASH_PAR_NO_SQ" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--no_sq' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_OMIT_SEC_SEQ" ]]; then
  if ! [[ "$VIASH_PAR_OMIT_SEC_SEQ" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--omit_sec_seq' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_SAM_NO_QNAME_TRUNC" ]]; then
  if ! [[ "$VIASH_PAR_SAM_NO_QNAME_TRUNC" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--sam_no_qname_trunc' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_XEQ" ]]; then
  if ! [[ "$VIASH_PAR_XEQ" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--xeq' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_SOFT_CLIPPED_UNMAPPED_TLEN" ]]; then
  if ! [[ "$VIASH_PAR_SOFT_CLIPPED_UNMAPPED_TLEN" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--soft_clipped_unmapped_tlen' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_SAM_APPEND_COMMENT" ]]; then
  if ! [[ "$VIASH_PAR_SAM_APPEND_COMMENT" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--sam_append_comment' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_ALIGN_PAIRED_READS" ]]; then
  if ! [[ "$VIASH_PAR_ALIGN_PAIRED_READS" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--align_paired_reads' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_PRESERVE_TAGS" ]]; then
  if ! [[ "$VIASH_PAR_PRESERVE_TAGS" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--preserve_tags' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_REORDER" ]]; then
  if ! [[ "$VIASH_PAR_REORDER" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--reorder' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_MM" ]]; then
  if ! [[ "$VIASH_PAR_MM" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--mm' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_QC_FILTER" ]]; then
  if ! [[ "$VIASH_PAR_QC_FILTER" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--qc_filter' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_SEED" ]]; then
  if ! [[ "$VIASH_PAR_SEED" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError '--seed' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_NON_DETERMINISTIC" ]]; then
  if ! [[ "$VIASH_PAR_NON_DETERMINISTIC" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--non_deterministic' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_META_CPUS" ]]; then
  if ! [[ "$VIASH_META_CPUS" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError 'cpus' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_META_MEMORY_B" ]]; then
  if ! [[ "$VIASH_META_MEMORY_B" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError 'memory_b' has to be a long. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_META_MEMORY_KB" ]]; then
  if ! [[ "$VIASH_META_MEMORY_KB" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError 'memory_kb' has to be a long. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_META_MEMORY_MB" ]]; then
  if ! [[ "$VIASH_META_MEMORY_MB" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError 'memory_mb' has to be a long. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_META_MEMORY_GB" ]]; then
  if ! [[ "$VIASH_META_MEMORY_GB" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError 'memory_gb' has to be a long. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_META_MEMORY_TB" ]]; then
  if ! [[ "$VIASH_META_MEMORY_TB" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError 'memory_tb' has to be a long. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_META_MEMORY_PB" ]]; then
  if ! [[ "$VIASH_META_MEMORY_PB" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError 'memory_pb' has to be a long. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_META_MEMORY_KIB" ]]; then
  if ! [[ "$VIASH_META_MEMORY_KIB" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError 'memory_kib' has to be a long. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_META_MEMORY_MIB" ]]; then
  if ! [[ "$VIASH_META_MEMORY_MIB" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError 'memory_mib' has to be a long. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_META_MEMORY_GIB" ]]; then
  if ! [[ "$VIASH_META_MEMORY_GIB" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError 'memory_gib' has to be a long. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_META_MEMORY_TIB" ]]; then
  if ! [[ "$VIASH_META_MEMORY_TIB" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError 'memory_tib' has to be a long. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_META_MEMORY_PIB" ]]; then
  if ! [[ "$VIASH_META_MEMORY_PIB" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError 'memory_pib' has to be a long. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi

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

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

if [[ "$VIASH_ENGINE_TYPE" == "docker" ]]; then
  # detect volumes from file arguments
  VIASH_CHOWN_VARS=()
if [ ! -z "$VIASH_PAR_MATE1" ]; then
  VIASH_TEST_MATE1=()
  IFS=';'
  for var in $VIASH_PAR_MATE1; do
    unset IFS
    VIASH_DIRECTORY_MOUNTS+=( "$(ViashDockerAutodetectMountArg "$var")" )
    var=$(ViashDockerAutodetectMount "$var")
    VIASH_TEST_MATE1+=( "$var" )
  done
  VIASH_PAR_MATE1=$(IFS=';' ; echo "${VIASH_TEST_MATE1[*]}")
fi
if [ ! -z "$VIASH_PAR_MATE2" ]; then
  VIASH_TEST_MATE2=()
  IFS=';'
  for var in $VIASH_PAR_MATE2; do
    unset IFS
    VIASH_DIRECTORY_MOUNTS+=( "$(ViashDockerAutodetectMountArg "$var")" )
    var=$(ViashDockerAutodetectMount "$var")
    VIASH_TEST_MATE2+=( "$var" )
  done
  VIASH_PAR_MATE2=$(IFS=';' ; echo "${VIASH_TEST_MATE2[*]}")
fi
if [ ! -z "$VIASH_PAR_UNPAIRED" ]; then
  VIASH_TEST_UNPAIRED=()
  IFS=';'
  for var in $VIASH_PAR_UNPAIRED; do
    unset IFS
    VIASH_DIRECTORY_MOUNTS+=( "$(ViashDockerAutodetectMountArg "$var")" )
    var=$(ViashDockerAutodetectMount "$var")
    VIASH_TEST_UNPAIRED+=( "$var" )
  done
  VIASH_PAR_UNPAIRED=$(IFS=';' ; echo "${VIASH_TEST_UNPAIRED[*]}")
fi
if [ ! -z "$VIASH_PAR_INTERLEAVED" ]; then
  VIASH_TEST_INTERLEAVED=()
  IFS=';'
  for var in $VIASH_PAR_INTERLEAVED; do
    unset IFS
    VIASH_DIRECTORY_MOUNTS+=( "$(ViashDockerAutodetectMountArg "$var")" )
    var=$(ViashDockerAutodetectMount "$var")
    VIASH_TEST_INTERLEAVED+=( "$var" )
  done
  VIASH_PAR_INTERLEAVED=$(IFS=';' ; echo "${VIASH_TEST_INTERLEAVED[*]}")
fi
if [ ! -z "$VIASH_PAR_BAM_INPUT" ]; then
  VIASH_TEST_BAM_INPUT=()
  IFS=';'
  for var in $VIASH_PAR_BAM_INPUT; do
    unset IFS
    VIASH_DIRECTORY_MOUNTS+=( "$(ViashDockerAutodetectMountArg "$var")" )
    var=$(ViashDockerAutodetectMount "$var")
    VIASH_TEST_BAM_INPUT+=( "$var" )
  done
  VIASH_PAR_BAM_INPUT=$(IFS=';' ; echo "${VIASH_TEST_BAM_INPUT[*]}")
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_UN" ]; then
  VIASH_DIRECTORY_MOUNTS+=( "$(ViashDockerAutodetectMountArg "$VIASH_PAR_UN")" )
  VIASH_PAR_UN=$(ViashDockerAutodetectMount "$VIASH_PAR_UN")
  VIASH_CHOWN_VARS+=( "$VIASH_PAR_UN" )
fi
if [ ! -z "$VIASH_PAR_AL" ]; then
  VIASH_DIRECTORY_MOUNTS+=( "$(ViashDockerAutodetectMountArg "$VIASH_PAR_AL")" )
  VIASH_PAR_AL=$(ViashDockerAutodetectMount "$VIASH_PAR_AL")
  VIASH_CHOWN_VARS+=( "$VIASH_PAR_AL" )
fi
if [ ! -z "$VIASH_PAR_UN_CONC" ]; then
  VIASH_DIRECTORY_MOUNTS+=( "$(ViashDockerAutodetectMountArg "$VIASH_PAR_UN_CONC")" )
  VIASH_PAR_UN_CONC=$(ViashDockerAutodetectMount "$VIASH_PAR_UN_CONC")
  VIASH_CHOWN_VARS+=( "$VIASH_PAR_UN_CONC" )
fi
if [ ! -z "$VIASH_PAR_AL_CONC" ]; then
  VIASH_DIRECTORY_MOUNTS+=( "$(ViashDockerAutodetectMountArg "$VIASH_PAR_AL_CONC")" )
  VIASH_PAR_AL_CONC=$(ViashDockerAutodetectMount "$VIASH_PAR_AL_CONC")
  VIASH_CHOWN_VARS+=( "$VIASH_PAR_AL_CONC" )
fi
if [ ! -z "$VIASH_PAR_MET_FILE" ]; then
  VIASH_DIRECTORY_MOUNTS+=( "$(ViashDockerAutodetectMountArg "$VIASH_PAR_MET_FILE")" )
  VIASH_PAR_MET_FILE=$(ViashDockerAutodetectMount "$VIASH_PAR_MET_FILE")
  VIASH_CHOWN_VARS+=( "$VIASH_PAR_MET_FILE" )
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-bowtie2_align-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_INDEX+x} ]; then echo "${VIASH_PAR_INDEX}" | sed "s#'#'\"'\"'#g;s#.*#par_index='&'#" ; else echo "# par_index="; fi )
$( if [ ! -z ${VIASH_PAR_MATE1+x} ]; then echo "${VIASH_PAR_MATE1}" | sed "s#'#'\"'\"'#g;s#.*#par_mate1='&'#" ; else echo "# par_mate1="; fi )
$( if [ ! -z ${VIASH_PAR_MATE2+x} ]; then echo "${VIASH_PAR_MATE2}" | sed "s#'#'\"'\"'#g;s#.*#par_mate2='&'#" ; else echo "# par_mate2="; fi )
$( if [ ! -z ${VIASH_PAR_UNPAIRED+x} ]; then echo "${VIASH_PAR_UNPAIRED}" | sed "s#'#'\"'\"'#g;s#.*#par_unpaired='&'#" ; else echo "# par_unpaired="; fi )
$( if [ ! -z ${VIASH_PAR_INTERLEAVED+x} ]; then echo "${VIASH_PAR_INTERLEAVED}" | sed "s#'#'\"'\"'#g;s#.*#par_interleaved='&'#" ; else echo "# par_interleaved="; fi )
$( if [ ! -z ${VIASH_PAR_BAM_INPUT+x} ]; then echo "${VIASH_PAR_BAM_INPUT}" | sed "s#'#'\"'\"'#g;s#.*#par_bam_input='&'#" ; else echo "# par_bam_input="; 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_UN+x} ]; then echo "${VIASH_PAR_UN}" | sed "s#'#'\"'\"'#g;s#.*#par_un='&'#" ; else echo "# par_un="; fi )
$( if [ ! -z ${VIASH_PAR_AL+x} ]; then echo "${VIASH_PAR_AL}" | sed "s#'#'\"'\"'#g;s#.*#par_al='&'#" ; else echo "# par_al="; fi )
$( if [ ! -z ${VIASH_PAR_UN_CONC+x} ]; then echo "${VIASH_PAR_UN_CONC}" | sed "s#'#'\"'\"'#g;s#.*#par_un_conc='&'#" ; else echo "# par_un_conc="; fi )
$( if [ ! -z ${VIASH_PAR_AL_CONC+x} ]; then echo "${VIASH_PAR_AL_CONC}" | sed "s#'#'\"'\"'#g;s#.*#par_al_conc='&'#" ; else echo "# par_al_conc="; fi )
$( if [ ! -z ${VIASH_PAR_MET_FILE+x} ]; then echo "${VIASH_PAR_MET_FILE}" | sed "s#'#'\"'\"'#g;s#.*#par_met_file='&'#" ; else echo "# par_met_file="; fi )
$( if [ ! -z ${VIASH_PAR_FASTQ+x} ]; then echo "${VIASH_PAR_FASTQ}" | sed "s#'#'\"'\"'#g;s#.*#par_fastq='&'#" ; else echo "# par_fastq="; fi )
$( if [ ! -z ${VIASH_PAR_TAB5+x} ]; then echo "${VIASH_PAR_TAB5}" | sed "s#'#'\"'\"'#g;s#.*#par_tab5='&'#" ; else echo "# par_tab5="; fi )
$( if [ ! -z ${VIASH_PAR_TAB6+x} ]; then echo "${VIASH_PAR_TAB6}" | sed "s#'#'\"'\"'#g;s#.*#par_tab6='&'#" ; else echo "# par_tab6="; fi )
$( if [ ! -z ${VIASH_PAR_QSEQ+x} ]; then echo "${VIASH_PAR_QSEQ}" | sed "s#'#'\"'\"'#g;s#.*#par_qseq='&'#" ; else echo "# par_qseq="; fi )
$( if [ ! -z ${VIASH_PAR_FASTA+x} ]; then echo "${VIASH_PAR_FASTA}" | sed "s#'#'\"'\"'#g;s#.*#par_fasta='&'#" ; else echo "# par_fasta="; fi )
$( if [ ! -z ${VIASH_PAR_RAW+x} ]; then echo "${VIASH_PAR_RAW}" | sed "s#'#'\"'\"'#g;s#.*#par_raw='&'#" ; else echo "# par_raw="; fi )
$( if [ ! -z ${VIASH_PAR_CMDLINE+x} ]; then echo "${VIASH_PAR_CMDLINE}" | sed "s#'#'\"'\"'#g;s#.*#par_cmdline='&'#" ; else echo "# par_cmdline="; fi )
$( if [ ! -z ${VIASH_PAR_SKIP+x} ]; then echo "${VIASH_PAR_SKIP}" | sed "s#'#'\"'\"'#g;s#.*#par_skip='&'#" ; else echo "# par_skip="; fi )
$( if [ ! -z ${VIASH_PAR_UPTO+x} ]; then echo "${VIASH_PAR_UPTO}" | sed "s#'#'\"'\"'#g;s#.*#par_upto='&'#" ; else echo "# par_upto="; fi )
$( if [ ! -z ${VIASH_PAR_TRIM5+x} ]; then echo "${VIASH_PAR_TRIM5}" | sed "s#'#'\"'\"'#g;s#.*#par_trim5='&'#" ; else echo "# par_trim5="; fi )
$( if [ ! -z ${VIASH_PAR_TRIM3+x} ]; then echo "${VIASH_PAR_TRIM3}" | sed "s#'#'\"'\"'#g;s#.*#par_trim3='&'#" ; else echo "# par_trim3="; fi )
$( if [ ! -z ${VIASH_PAR_TRIM_TO+x} ]; then echo "${VIASH_PAR_TRIM_TO}" | sed "s#'#'\"'\"'#g;s#.*#par_trim_to='&'#" ; else echo "# par_trim_to="; fi )
$( if [ ! -z ${VIASH_PAR_CONTINUOUS_FASTA+x} ]; then echo "${VIASH_PAR_CONTINUOUS_FASTA}" | sed "s#'#'\"'\"'#g;s#.*#par_continuous_fasta='&'#" ; else echo "# par_continuous_fasta="; fi )
$( if [ ! -z ${VIASH_PAR_PHRED33+x} ]; then echo "${VIASH_PAR_PHRED33}" | sed "s#'#'\"'\"'#g;s#.*#par_phred33='&'#" ; else echo "# par_phred33="; fi )
$( if [ ! -z ${VIASH_PAR_PHRED64+x} ]; then echo "${VIASH_PAR_PHRED64}" | sed "s#'#'\"'\"'#g;s#.*#par_phred64='&'#" ; else echo "# par_phred64="; fi )
$( if [ ! -z ${VIASH_PAR_INT_QUALS+x} ]; then echo "${VIASH_PAR_INT_QUALS}" | sed "s#'#'\"'\"'#g;s#.*#par_int_quals='&'#" ; else echo "# par_int_quals="; fi )
$( if [ ! -z ${VIASH_PAR_VERY_FAST+x} ]; then echo "${VIASH_PAR_VERY_FAST}" | sed "s#'#'\"'\"'#g;s#.*#par_very_fast='&'#" ; else echo "# par_very_fast="; fi )
$( if [ ! -z ${VIASH_PAR_FAST+x} ]; then echo "${VIASH_PAR_FAST}" | sed "s#'#'\"'\"'#g;s#.*#par_fast='&'#" ; else echo "# par_fast="; fi )
$( if [ ! -z ${VIASH_PAR_SENSITIVE+x} ]; then echo "${VIASH_PAR_SENSITIVE}" | sed "s#'#'\"'\"'#g;s#.*#par_sensitive='&'#" ; else echo "# par_sensitive="; fi )
$( if [ ! -z ${VIASH_PAR_VERY_SENSITIVE+x} ]; then echo "${VIASH_PAR_VERY_SENSITIVE}" | sed "s#'#'\"'\"'#g;s#.*#par_very_sensitive='&'#" ; else echo "# par_very_sensitive="; fi )
$( if [ ! -z ${VIASH_PAR_VERY_FAST_LOCAL+x} ]; then echo "${VIASH_PAR_VERY_FAST_LOCAL}" | sed "s#'#'\"'\"'#g;s#.*#par_very_fast_local='&'#" ; else echo "# par_very_fast_local="; fi )
$( if [ ! -z ${VIASH_PAR_FAST_LOCAL+x} ]; then echo "${VIASH_PAR_FAST_LOCAL}" | sed "s#'#'\"'\"'#g;s#.*#par_fast_local='&'#" ; else echo "# par_fast_local="; fi )
$( if [ ! -z ${VIASH_PAR_SENSITIVE_LOCAL+x} ]; then echo "${VIASH_PAR_SENSITIVE_LOCAL}" | sed "s#'#'\"'\"'#g;s#.*#par_sensitive_local='&'#" ; else echo "# par_sensitive_local="; fi )
$( if [ ! -z ${VIASH_PAR_VERY_SENSITIVE_LOCAL+x} ]; then echo "${VIASH_PAR_VERY_SENSITIVE_LOCAL}" | sed "s#'#'\"'\"'#g;s#.*#par_very_sensitive_local='&'#" ; else echo "# par_very_sensitive_local="; fi )
$( if [ ! -z ${VIASH_PAR_N+x} ]; then echo "${VIASH_PAR_N}" | sed "s#'#'\"'\"'#g;s#.*#par_N='&'#" ; else echo "# par_N="; fi )
$( if [ ! -z ${VIASH_PAR_L+x} ]; then echo "${VIASH_PAR_L}" | sed "s#'#'\"'\"'#g;s#.*#par_L='&'#" ; else echo "# par_L="; fi )
$( if [ ! -z ${VIASH_PAR_I+x} ]; then echo "${VIASH_PAR_I}" | sed "s#'#'\"'\"'#g;s#.*#par_i='&'#" ; else echo "# par_i="; fi )
$( if [ ! -z ${VIASH_PAR_N_CEIL+x} ]; then echo "${VIASH_PAR_N_CEIL}" | sed "s#'#'\"'\"'#g;s#.*#par_n_ceil='&'#" ; else echo "# par_n_ceil="; fi )
$( if [ ! -z ${VIASH_PAR_DPAD+x} ]; then echo "${VIASH_PAR_DPAD}" | sed "s#'#'\"'\"'#g;s#.*#par_dpad='&'#" ; else echo "# par_dpad="; fi )
$( if [ ! -z ${VIASH_PAR_GBAR+x} ]; then echo "${VIASH_PAR_GBAR}" | sed "s#'#'\"'\"'#g;s#.*#par_gbar='&'#" ; else echo "# par_gbar="; fi )
$( if [ ! -z ${VIASH_PAR_IGNORE_QUALS+x} ]; then echo "${VIASH_PAR_IGNORE_QUALS}" | sed "s#'#'\"'\"'#g;s#.*#par_ignore_quals='&'#" ; else echo "# par_ignore_quals="; fi )
$( if [ ! -z ${VIASH_PAR_NOFW+x} ]; then echo "${VIASH_PAR_NOFW}" | sed "s#'#'\"'\"'#g;s#.*#par_nofw='&'#" ; else echo "# par_nofw="; fi )
$( if [ ! -z ${VIASH_PAR_NORC+x} ]; then echo "${VIASH_PAR_NORC}" | sed "s#'#'\"'\"'#g;s#.*#par_norc='&'#" ; else echo "# par_norc="; fi )
$( if [ ! -z ${VIASH_PAR_NO_1MM_UPFRONT+x} ]; then echo "${VIASH_PAR_NO_1MM_UPFRONT}" | sed "s#'#'\"'\"'#g;s#.*#par_no_1mm_upfront='&'#" ; else echo "# par_no_1mm_upfront="; fi )
$( if [ ! -z ${VIASH_PAR_END_TO_END+x} ]; then echo "${VIASH_PAR_END_TO_END}" | sed "s#'#'\"'\"'#g;s#.*#par_end_to_end='&'#" ; else echo "# par_end_to_end="; fi )
$( if [ ! -z ${VIASH_PAR_LOCAL+x} ]; then echo "${VIASH_PAR_LOCAL}" | sed "s#'#'\"'\"'#g;s#.*#par_local='&'#" ; else echo "# par_local="; fi )
$( if [ ! -z ${VIASH_PAR_MA+x} ]; then echo "${VIASH_PAR_MA}" | sed "s#'#'\"'\"'#g;s#.*#par_ma='&'#" ; else echo "# par_ma="; fi )
$( if [ ! -z ${VIASH_PAR_MP+x} ]; then echo "${VIASH_PAR_MP}" | sed "s#'#'\"'\"'#g;s#.*#par_mp='&'#" ; else echo "# par_mp="; fi )
$( if [ ! -z ${VIASH_PAR_NP+x} ]; then echo "${VIASH_PAR_NP}" | sed "s#'#'\"'\"'#g;s#.*#par_np='&'#" ; else echo "# par_np="; fi )
$( if [ ! -z ${VIASH_PAR_RDG+x} ]; then echo "${VIASH_PAR_RDG}" | sed "s#'#'\"'\"'#g;s#.*#par_rdg='&'#" ; else echo "# par_rdg="; fi )
$( if [ ! -z ${VIASH_PAR_RFG+x} ]; then echo "${VIASH_PAR_RFG}" | sed "s#'#'\"'\"'#g;s#.*#par_rfg='&'#" ; else echo "# par_rfg="; fi )
$( if [ ! -z ${VIASH_PAR_SCORE_MIN+x} ]; then echo "${VIASH_PAR_SCORE_MIN}" | sed "s#'#'\"'\"'#g;s#.*#par_score_min='&'#" ; else echo "# par_score_min="; fi )
$( if [ ! -z ${VIASH_PAR_K+x} ]; then echo "${VIASH_PAR_K}" | sed "s#'#'\"'\"'#g;s#.*#par_k='&'#" ; else echo "# par_k="; fi )
$( if [ ! -z ${VIASH_PAR_ALL+x} ]; then echo "${VIASH_PAR_ALL}" | sed "s#'#'\"'\"'#g;s#.*#par_all='&'#" ; else echo "# par_all="; fi )
$( if [ ! -z ${VIASH_PAR_D+x} ]; then echo "${VIASH_PAR_D}" | sed "s#'#'\"'\"'#g;s#.*#par_D='&'#" ; else echo "# par_D="; fi )
$( if [ ! -z ${VIASH_PAR_R+x} ]; then echo "${VIASH_PAR_R}" | sed "s#'#'\"'\"'#g;s#.*#par_R='&'#" ; else echo "# par_R="; fi )
$( if [ ! -z ${VIASH_PAR_MININS+x} ]; then echo "${VIASH_PAR_MININS}" | sed "s#'#'\"'\"'#g;s#.*#par_minins='&'#" ; else echo "# par_minins="; fi )
$( if [ ! -z ${VIASH_PAR_MAXINS+x} ]; then echo "${VIASH_PAR_MAXINS}" | sed "s#'#'\"'\"'#g;s#.*#par_maxins='&'#" ; else echo "# par_maxins="; fi )
$( if [ ! -z ${VIASH_PAR_FR+x} ]; then echo "${VIASH_PAR_FR}" | sed "s#'#'\"'\"'#g;s#.*#par_fr='&'#" ; else echo "# par_fr="; fi )
$( if [ ! -z ${VIASH_PAR_RF+x} ]; then echo "${VIASH_PAR_RF}" | sed "s#'#'\"'\"'#g;s#.*#par_rf='&'#" ; else echo "# par_rf="; fi )
$( if [ ! -z ${VIASH_PAR_FF+x} ]; then echo "${VIASH_PAR_FF}" | sed "s#'#'\"'\"'#g;s#.*#par_ff='&'#" ; else echo "# par_ff="; fi )
$( if [ ! -z ${VIASH_PAR_NO_MIXED+x} ]; then echo "${VIASH_PAR_NO_MIXED}" | sed "s#'#'\"'\"'#g;s#.*#par_no_mixed='&'#" ; else echo "# par_no_mixed="; fi )
$( if [ ! -z ${VIASH_PAR_NO_DISCORDANT+x} ]; then echo "${VIASH_PAR_NO_DISCORDANT}" | sed "s#'#'\"'\"'#g;s#.*#par_no_discordant='&'#" ; else echo "# par_no_discordant="; fi )
$( if [ ! -z ${VIASH_PAR_DOVETAIL+x} ]; then echo "${VIASH_PAR_DOVETAIL}" | sed "s#'#'\"'\"'#g;s#.*#par_dovetail='&'#" ; else echo "# par_dovetail="; fi )
$( if [ ! -z ${VIASH_PAR_NO_CONTAIN+x} ]; then echo "${VIASH_PAR_NO_CONTAIN}" | sed "s#'#'\"'\"'#g;s#.*#par_no_contain='&'#" ; else echo "# par_no_contain="; fi )
$( if [ ! -z ${VIASH_PAR_NO_OVERLAP+x} ]; then echo "${VIASH_PAR_NO_OVERLAP}" | sed "s#'#'\"'\"'#g;s#.*#par_no_overlap='&'#" ; else echo "# par_no_overlap="; fi )
$( if [ ! -z ${VIASH_PAR_TIME+x} ]; then echo "${VIASH_PAR_TIME}" | sed "s#'#'\"'\"'#g;s#.*#par_time='&'#" ; else echo "# par_time="; fi )
$( if [ ! -z ${VIASH_PAR_QUIET+x} ]; then echo "${VIASH_PAR_QUIET}" | sed "s#'#'\"'\"'#g;s#.*#par_quiet='&'#" ; else echo "# par_quiet="; fi )
$( if [ ! -z ${VIASH_PAR_MET_STDERR+x} ]; then echo "${VIASH_PAR_MET_STDERR}" | sed "s#'#'\"'\"'#g;s#.*#par_met_stderr='&'#" ; else echo "# par_met_stderr="; fi )
$( if [ ! -z ${VIASH_PAR_MET+x} ]; then echo "${VIASH_PAR_MET}" | sed "s#'#'\"'\"'#g;s#.*#par_met='&'#" ; else echo "# par_met="; fi )
$( if [ ! -z ${VIASH_PAR_NO_UNAL+x} ]; then echo "${VIASH_PAR_NO_UNAL}" | sed "s#'#'\"'\"'#g;s#.*#par_no_unal='&'#" ; else echo "# par_no_unal="; fi )
$( if [ ! -z ${VIASH_PAR_NO_HEAD+x} ]; then echo "${VIASH_PAR_NO_HEAD}" | sed "s#'#'\"'\"'#g;s#.*#par_no_head='&'#" ; else echo "# par_no_head="; fi )
$( if [ ! -z ${VIASH_PAR_NO_SQ+x} ]; then echo "${VIASH_PAR_NO_SQ}" | sed "s#'#'\"'\"'#g;s#.*#par_no_sq='&'#" ; else echo "# par_no_sq="; fi )
$( if [ ! -z ${VIASH_PAR_RG_ID+x} ]; then echo "${VIASH_PAR_RG_ID}" | sed "s#'#'\"'\"'#g;s#.*#par_rg_id='&'#" ; else echo "# par_rg_id="; fi )
$( if [ ! -z ${VIASH_PAR_RG+x} ]; then echo "${VIASH_PAR_RG}" | sed "s#'#'\"'\"'#g;s#.*#par_rg='&'#" ; else echo "# par_rg="; fi )
$( if [ ! -z ${VIASH_PAR_OMIT_SEC_SEQ+x} ]; then echo "${VIASH_PAR_OMIT_SEC_SEQ}" | sed "s#'#'\"'\"'#g;s#.*#par_omit_sec_seq='&'#" ; else echo "# par_omit_sec_seq="; fi )
$( if [ ! -z ${VIASH_PAR_SAM_NO_QNAME_TRUNC+x} ]; then echo "${VIASH_PAR_SAM_NO_QNAME_TRUNC}" | sed "s#'#'\"'\"'#g;s#.*#par_sam_no_qname_trunc='&'#" ; else echo "# par_sam_no_qname_trunc="; fi )
$( if [ ! -z ${VIASH_PAR_XEQ+x} ]; then echo "${VIASH_PAR_XEQ}" | sed "s#'#'\"'\"'#g;s#.*#par_xeq='&'#" ; else echo "# par_xeq="; fi )
$( if [ ! -z ${VIASH_PAR_SOFT_CLIPPED_UNMAPPED_TLEN+x} ]; then echo "${VIASH_PAR_SOFT_CLIPPED_UNMAPPED_TLEN}" | sed "s#'#'\"'\"'#g;s#.*#par_soft_clipped_unmapped_tlen='&'#" ; else echo "# par_soft_clipped_unmapped_tlen="; fi )
$( if [ ! -z ${VIASH_PAR_SAM_APPEND_COMMENT+x} ]; then echo "${VIASH_PAR_SAM_APPEND_COMMENT}" | sed "s#'#'\"'\"'#g;s#.*#par_sam_append_comment='&'#" ; else echo "# par_sam_append_comment="; fi )
$( if [ ! -z ${VIASH_PAR_SAM_OPT_CONFIG+x} ]; then echo "${VIASH_PAR_SAM_OPT_CONFIG}" | sed "s#'#'\"'\"'#g;s#.*#par_sam_opt_config='&'#" ; else echo "# par_sam_opt_config="; fi )
$( if [ ! -z ${VIASH_PAR_ALIGN_PAIRED_READS+x} ]; then echo "${VIASH_PAR_ALIGN_PAIRED_READS}" | sed "s#'#'\"'\"'#g;s#.*#par_align_paired_reads='&'#" ; else echo "# par_align_paired_reads="; fi )
$( if [ ! -z ${VIASH_PAR_PRESERVE_TAGS+x} ]; then echo "${VIASH_PAR_PRESERVE_TAGS}" | sed "s#'#'\"'\"'#g;s#.*#par_preserve_tags='&'#" ; else echo "# par_preserve_tags="; fi )
$( if [ ! -z ${VIASH_PAR_REORDER+x} ]; then echo "${VIASH_PAR_REORDER}" | sed "s#'#'\"'\"'#g;s#.*#par_reorder='&'#" ; else echo "# par_reorder="; fi )
$( if [ ! -z ${VIASH_PAR_MM+x} ]; then echo "${VIASH_PAR_MM}" | sed "s#'#'\"'\"'#g;s#.*#par_mm='&'#" ; else echo "# par_mm="; fi )
$( if [ ! -z ${VIASH_PAR_QC_FILTER+x} ]; then echo "${VIASH_PAR_QC_FILTER}" | sed "s#'#'\"'\"'#g;s#.*#par_qc_filter='&'#" ; else echo "# par_qc_filter="; fi )
$( if [ ! -z ${VIASH_PAR_SEED+x} ]; then echo "${VIASH_PAR_SEED}" | sed "s#'#'\"'\"'#g;s#.*#par_seed='&'#" ; else echo "# par_seed="; fi )
$( if [ ! -z ${VIASH_PAR_NON_DETERMINISTIC+x} ]; then echo "${VIASH_PAR_NON_DETERMINISTIC}" | sed "s#'#'\"'\"'#g;s#.*#par_non_deterministic='&'#" ; else echo "# par_non_deterministic="; fi )
$( if [ ! -z ${VIASH_META_NAME+x} ]; then echo "${VIASH_META_NAME}" | sed "s#'#'\"'\"'#g;s#.*#meta_name='&'#" ; else echo "# meta_name="; fi )
$( if [ ! -z ${VIASH_META_FUNCTIONALITY_NAME+x} ]; then echo "${VIASH_META_FUNCTIONALITY_NAME}" | sed "s#'#'\"'\"'#g;s#.*#meta_functionality_name='&'#" ; else echo "# meta_functionality_name="; fi )
$( if [ ! -z ${VIASH_META_RESOURCES_DIR+x} ]; then echo "${VIASH_META_RESOURCES_DIR}" | sed "s#'#'\"'\"'#g;s#.*#meta_resources_dir='&'#" ; else echo "# meta_resources_dir="; fi )
$( if [ ! -z ${VIASH_META_EXECUTABLE+x} ]; then echo "${VIASH_META_EXECUTABLE}" | sed "s#'#'\"'\"'#g;s#.*#meta_executable='&'#" ; else echo "# meta_executable="; fi )
$( if [ ! -z ${VIASH_META_CONFIG+x} ]; then echo "${VIASH_META_CONFIG}" | sed "s#'#'\"'\"'#g;s#.*#meta_config='&'#" ; else echo "# meta_config="; fi )
$( if [ ! -z ${VIASH_META_TEMP_DIR+x} ]; then echo "${VIASH_META_TEMP_DIR}" | sed "s#'#'\"'\"'#g;s#.*#meta_temp_dir='&'#" ; else echo "# meta_temp_dir="; fi )
$( if [ ! -z ${VIASH_META_CPUS+x} ]; then echo "${VIASH_META_CPUS}" | sed "s#'#'\"'\"'#g;s#.*#meta_cpus='&'#" ; else echo "# meta_cpus="; fi )
$( if [ ! -z ${VIASH_META_MEMORY_B+x} ]; then echo "${VIASH_META_MEMORY_B}" | sed "s#'#'\"'\"'#g;s#.*#meta_memory_b='&'#" ; else echo "# meta_memory_b="; fi )
$( if [ ! -z ${VIASH_META_MEMORY_KB+x} ]; then echo "${VIASH_META_MEMORY_KB}" | sed "s#'#'\"'\"'#g;s#.*#meta_memory_kb='&'#" ; else echo "# meta_memory_kb="; fi )
$( if [ ! -z ${VIASH_META_MEMORY_MB+x} ]; then echo "${VIASH_META_MEMORY_MB}" | sed "s#'#'\"'\"'#g;s#.*#meta_memory_mb='&'#" ; else echo "# meta_memory_mb="; fi )
$( if [ ! -z ${VIASH_META_MEMORY_GB+x} ]; then echo "${VIASH_META_MEMORY_GB}" | sed "s#'#'\"'\"'#g;s#.*#meta_memory_gb='&'#" ; else echo "# meta_memory_gb="; fi )
$( if [ ! -z ${VIASH_META_MEMORY_TB+x} ]; then echo "${VIASH_META_MEMORY_TB}" | sed "s#'#'\"'\"'#g;s#.*#meta_memory_tb='&'#" ; else echo "# meta_memory_tb="; fi )
$( if [ ! -z ${VIASH_META_MEMORY_PB+x} ]; then echo "${VIASH_META_MEMORY_PB}" | sed "s#'#'\"'\"'#g;s#.*#meta_memory_pb='&'#" ; else echo "# meta_memory_pb="; fi )
$( if [ ! -z ${VIASH_META_MEMORY_KIB+x} ]; then echo "${VIASH_META_MEMORY_KIB}" | sed "s#'#'\"'\"'#g;s#.*#meta_memory_kib='&'#" ; else echo "# meta_memory_kib="; fi )
$( if [ ! -z ${VIASH_META_MEMORY_MIB+x} ]; then echo "${VIASH_META_MEMORY_MIB}" | sed "s#'#'\"'\"'#g;s#.*#meta_memory_mib='&'#" ; else echo "# meta_memory_mib="; fi )
$( if [ ! -z ${VIASH_META_MEMORY_GIB+x} ]; then echo "${VIASH_META_MEMORY_GIB}" | sed "s#'#'\"'\"'#g;s#.*#meta_memory_gib='&'#" ; else echo "# meta_memory_gib="; fi )
$( if [ ! -z ${VIASH_META_MEMORY_TIB+x} ]; then echo "${VIASH_META_MEMORY_TIB}" | sed "s#'#'\"'\"'#g;s#.*#meta_memory_tib='&'#" ; else echo "# meta_memory_tib="; fi )
$( if [ ! -z ${VIASH_META_MEMORY_PIB+x} ]; then echo "${VIASH_META_MEMORY_PIB}" | sed "s#'#'\"'\"'#g;s#.*#meta_memory_pib='&'#" ; else echo "# meta_memory_pib="; fi )

## VIASH END

set -eo pipefail

# unset flags
[[ "\$par_fastq" == "false" ]] && unset par_fastq
[[ "\$par_tab5" == "false" ]] && unset par_tab5
[[ "\$par_tab6" == "false" ]] && unset par_tab6
[[ "\$par_qseq" == "false" ]] && unset par_qseq
[[ "\$par_fasta" == "false" ]] && unset par_fasta
[[ "\$par_raw" == "false" ]] && unset par_raw
[[ "\$par_cmdline" == "false" ]] && unset par_cmdline
[[ "\$par_phred33" == "false" ]] && unset par_phred33
[[ "\$par_phred64" == "false" ]] && unset par_phred64
[[ "\$par_int_quals" == "false" ]] && unset par_int_quals
[[ "\$par_very_fast" == "false" ]] && unset par_very_fast
[[ "\$par_fast" == "false" ]] && unset par_fast
[[ "\$par_sensitive" == "false" ]] && unset par_sensitive
[[ "\$par_very_sensitive" == "false" ]] && unset par_very_sensitive
[[ "\$par_very_fast_local" == "false" ]] && unset par_very_fast_local
[[ "\$par_fast_local" == "false" ]] && unset par_fast_local
[[ "\$par_sensitive_local" == "false" ]] && unset par_sensitive_local
[[ "\$par_very_sensitive_local" == "false" ]] && unset par_very_sensitive_local
[[ "\$par_ignore_quals" == "false" ]] && unset par_ignore_quals
[[ "\$par_nofw" == "false" ]] && unset par_nofw
[[ "\$par_norc" == "false" ]] && unset par_norc
[[ "\$par_no_1mm_upfront" == "false" ]] && unset par_no_1mm_upfront
[[ "\$par_end_to_end" == "false" ]] && unset par_end_to_end
[[ "\$par_local" == "false" ]] && unset par_local
[[ "\$par_all" == "false" ]] && unset par_all
[[ "\$par_fr" == "false" ]] && unset par_fr
[[ "\$par_rf" == "false" ]] && unset par_rf
[[ "\$par_ff" == "false" ]] && unset par_ff
[[ "\$par_no_mixed" == "false" ]] && unset par_no_mixed
[[ "\$par_no_discordant" == "false" ]] && unset par_no_discordant
[[ "\$par_dovetail" == "false" ]] && unset par_dovetail
[[ "\$par_no_contain" == "false" ]] && unset par_no_contain
[[ "\$par_no_overlap" == "false" ]] && unset par_no_overlap
[[ "\$par_time" == "false" ]] && unset par_time
[[ "\$par_quiet" == "false" ]] && unset par_quiet
[[ "\$par_met_stderr" == "false" ]] && unset par_met_stderr
[[ "\$par_no_unal" == "false" ]] && unset par_no_unal
[[ "\$par_no_head" == "false" ]] && unset par_no_head
[[ "\$par_no_sq" == "false" ]] && unset par_no_sq
[[ "\$par_omit_sec_seq" == "false" ]] && unset par_omit_sec_seq
[[ "\$par_sam_no_qname_trunc" == "false" ]] && unset par_sam_no_qname_trunc
[[ "\$par_xeq" == "false" ]] && unset par_xeq
[[ "\$par_soft_clipped_unmapped_tlen" == "false" ]] && unset par_soft_clipped_unmapped_tlen
[[ "\$par_sam_append_comment" == "false" ]] && unset par_sam_append_comment
[[ "\$par_align_paired_reads" == "false" ]] && unset par_align_paired_reads
[[ "\$par_preserve_tags" == "false" ]] && unset par_preserve_tags
[[ "\$par_reorder" == "false" ]] && unset par_reorder
[[ "\$par_mm" == "false" ]] && unset par_mm
[[ "\$par_qc_filter" == "false" ]] && unset par_qc_filter
[[ "\$par_non_deterministic" == "false" ]] && unset par_non_deterministic

# Validate input arguments
if [[ -z "\$par_index" ]]; then
  echo "Error: --index is required" >&2
  exit 1
fi

# Validate that at least one input type is specified
if [[ -z "\$par_mate1" && -z "\$par_mate2" && -z "\$par_unpaired" && -z "\$par_interleaved" && -z "\$par_bam_input" ]]; then
  echo "Error: At least one input type must be specified (--mate1/--mate2, --unpaired, --interleaved, or --bam_input)" >&2
  exit 1
fi

# Validate paired-end input
if [[ -n "\$par_mate1" && -z "\$par_mate2" ]] || [[ -z "\$par_mate1" && -n "\$par_mate2" ]]; then
  echo "Error: Both --mate1 and --mate2 must be specified for paired-end reads" >&2
  exit 1
fi

# Build the command arguments
cmd_args=(
    -x "\$par_index"
    \${par_mate1:+-1 "\$(IFS=','; echo "\${par_mate1[*]}")"}
    \${par_mate2:+-2 "\$(IFS=','; echo "\${par_mate2[*]}")"}
    \${par_unpaired:+-U "\$(IFS=','; echo "\${par_unpaired[*]}")"}
    \${par_interleaved:+--interleaved "\$(IFS=','; echo "\${par_interleaved[*]}")"}
    \${par_bam_input:+-b "\$(IFS=','; echo "\${par_bam_input[*]}")"}
    -S "\$par_output"
    \${par_fastq:+-q}
    \${par_tab5:+--tab5}
    \${par_tab6:+--tab6}
    \${par_qseq:+--qseq}
    \${par_fasta:+-f}
    \${par_raw:+-r}
    \${par_cmdline:+-c}
    \${par_skip:+-s "\$par_skip"}
    \${par_upto:+-u "\$par_upto"}
    \${par_trim5:+-5 "\$par_trim5"}
    \${par_trim3:+-3 "\$par_trim3"}
    \${par_trim_to:+--trim-to "\$par_trim_to"}
    \${par_continuous_fasta:+-F "\$par_continuous_fasta"}
    \${par_phred33:+--phred33}
    \${par_phred64:+--phred64}
    \${par_int_quals:+--int-quals}
    \${par_very_fast:+--very-fast}
    \${par_fast:+--fast}
    \${par_sensitive:+--sensitive}
    \${par_very_sensitive:+--very-sensitive}
    \${par_very_fast_local:+--very-fast-local}
    \${par_fast_local:+--fast-local}
    \${par_sensitive_local:+--sensitive-local}
    \${par_very_sensitive_local:+--very-sensitive-local}
    \${par_N:+-N "\$par_N"}
    \${par_L:+-L "\$par_L"}
    \${par_i:+-i "\$par_i"}
    \${par_n_ceil:+--n-ceil "\$par_n_ceil"}
    \${par_dpad:+--dpad "\$par_dpad"}
    \${par_gbar:+--gbar "\$par_gbar"}
    \${par_ignore_quals:+--ignore-quals}
    \${par_nofw:+--nofw}
    \${par_norc:+--norc}
    \${par_no_1mm_upfront:+--no-1mm-upfront}
    \${par_end_to_end:+--end-to-end}
    \${par_local:+--local}
    \${par_ma:+--ma "\$par_ma"}
    \${par_mp:+--mp "\$par_mp"}
    \${par_np:+--np "\$par_np"}
    \${par_rdg:+--rdg "\$par_rdg"}
    \${par_rfg:+--rfg "\$par_rfg"}
    \${par_score_min:+--score-min "\$par_score_min"}
    \${par_k:+-k "\$par_k"}
    \${par_all:+-a}
    \${par_D:+-D "\$par_D"}
    \${par_R:+-R "\$par_R"}
    \${par_minins:+-I "\$par_minins"}
    \${par_maxins:+-X "\$par_maxins"}
    \${par_fr:+--fr}
    \${par_rf:+--rf}
    \${par_ff:+--ff}
    \${par_no_mixed:+--no-mixed}
    \${par_no_discordant:+--no-discordant}
    \${par_dovetail:+--dovetail}
    \${par_no_contain:+--no-contain}
    \${par_no_overlap:+--no-overlap}
    \${par_time:+-t}
    \${par_un:+--un "\$par_un"}
    \${par_al:+--al "\$par_al"}
    \${par_un_conc:+--un-conc "\$par_un_conc"}
    \${par_al_conc:+--al-conc "\$par_al_conc"}
    \${par_quiet:+--quiet}
    \${par_met_file:+--met-file "\$par_met_file"}
    \${par_met_stderr:+--met-stderr}
    \${par_met:+--met "\$par_met"}
    \${par_no_unal:+--no-unal}
    \${par_no_head:+--no-head}
    \${par_no_sq:+--no-sq}
    \${par_rg_id:+--rg-id "\$par_rg_id"}
    \${par_rg:+--rg "\$par_rg"}
    \${par_omit_sec_seq:+--omit-sec-seq}
    \${par_sam_no_qname_trunc:+--sam-no-qname-trunc}
    \${par_xeq:+--xeq}
    \${par_soft_clipped_unmapped_tlen:+--soft-clipped-unmapped-tlen}
    \${par_sam_append_comment:+--sam-append-comment}
    \${par_sam_opt_config:+--sam-opt-config "\$par_sam_opt_config"}
    \${par_align_paired_reads:+--align-paired-reads}
    \${par_preserve_tags:+--preserve-tags}
    \${meta_cpus:+-p "\$meta_cpus"}
    \${par_reorder:+--reorder}
    \${par_mm:+--mm}
    \${par_qc_filter:+--qc-filter}
    \${par_seed:+--seed "\$par_seed"}
    \${par_non_deterministic:+--non-deterministic}
)

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

VIASHEOF


if [[ "$VIASH_ENGINE_TYPE" == "docker" ]]; then
  # strip viash automount from file paths
  
  if [ ! -z "$VIASH_PAR_MATE1" ]; then
    unset VIASH_TEST_MATE1
    IFS=';'
    for var in $VIASH_PAR_MATE1; do
      unset IFS
      if [ -z "$VIASH_TEST_MATE1" ]; then
      VIASH_TEST_MATE1="$(ViashDockerStripAutomount "$var")"
    else
      VIASH_TEST_MATE1="$VIASH_TEST_MATE1;""$(ViashDockerStripAutomount "$var")"
    fi
    done
    VIASH_PAR_MATE1="$VIASH_TEST_MATE1"
  fi
  if [ ! -z "$VIASH_PAR_MATE2" ]; then
    unset VIASH_TEST_MATE2
    IFS=';'
    for var in $VIASH_PAR_MATE2; do
      unset IFS
      if [ -z "$VIASH_TEST_MATE2" ]; then
      VIASH_TEST_MATE2="$(ViashDockerStripAutomount "$var")"
    else
      VIASH_TEST_MATE2="$VIASH_TEST_MATE2;""$(ViashDockerStripAutomount "$var")"
    fi
    done
    VIASH_PAR_MATE2="$VIASH_TEST_MATE2"
  fi
  if [ ! -z "$VIASH_PAR_UNPAIRED" ]; then
    unset VIASH_TEST_UNPAIRED
    IFS=';'
    for var in $VIASH_PAR_UNPAIRED; do
      unset IFS
      if [ -z "$VIASH_TEST_UNPAIRED" ]; then
      VIASH_TEST_UNPAIRED="$(ViashDockerStripAutomount "$var")"
    else
      VIASH_TEST_UNPAIRED="$VIASH_TEST_UNPAIRED;""$(ViashDockerStripAutomount "$var")"
    fi
    done
    VIASH_PAR_UNPAIRED="$VIASH_TEST_UNPAIRED"
  fi
  if [ ! -z "$VIASH_PAR_INTERLEAVED" ]; then
    unset VIASH_TEST_INTERLEAVED
    IFS=';'
    for var in $VIASH_PAR_INTERLEAVED; do
      unset IFS
      if [ -z "$VIASH_TEST_INTERLEAVED" ]; then
      VIASH_TEST_INTERLEAVED="$(ViashDockerStripAutomount "$var")"
    else
      VIASH_TEST_INTERLEAVED="$VIASH_TEST_INTERLEAVED;""$(ViashDockerStripAutomount "$var")"
    fi
    done
    VIASH_PAR_INTERLEAVED="$VIASH_TEST_INTERLEAVED"
  fi
  if [ ! -z "$VIASH_PAR_BAM_INPUT" ]; then
    unset VIASH_TEST_BAM_INPUT
    IFS=';'
    for var in $VIASH_PAR_BAM_INPUT; do
      unset IFS
      if [ -z "$VIASH_TEST_BAM_INPUT" ]; then
      VIASH_TEST_BAM_INPUT="$(ViashDockerStripAutomount "$var")"
    else
      VIASH_TEST_BAM_INPUT="$VIASH_TEST_BAM_INPUT;""$(ViashDockerStripAutomount "$var")"
    fi
    done
    VIASH_PAR_BAM_INPUT="$VIASH_TEST_BAM_INPUT"
  fi
  if [ ! -z "$VIASH_PAR_OUTPUT" ]; then
    VIASH_PAR_OUTPUT=$(ViashDockerStripAutomount "$VIASH_PAR_OUTPUT")
  fi
  if [ ! -z "$VIASH_PAR_UN" ]; then
    VIASH_PAR_UN=$(ViashDockerStripAutomount "$VIASH_PAR_UN")
  fi
  if [ ! -z "$VIASH_PAR_AL" ]; then
    VIASH_PAR_AL=$(ViashDockerStripAutomount "$VIASH_PAR_AL")
  fi
  if [ ! -z "$VIASH_PAR_UN_CONC" ]; then
    VIASH_PAR_UN_CONC=$(ViashDockerStripAutomount "$VIASH_PAR_UN_CONC")
  fi
  if [ ! -z "$VIASH_PAR_AL_CONC" ]; then
    VIASH_PAR_AL_CONC=$(ViashDockerStripAutomount "$VIASH_PAR_AL_CONC")
  fi
  if [ ! -z "$VIASH_PAR_MET_FILE" ]; then
    VIASH_PAR_MET_FILE=$(ViashDockerStripAutomount "$VIASH_PAR_MET_FILE")
  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
if [ ! -z "$VIASH_PAR_UN" ] && [ ! -e "$VIASH_PAR_UN" ]; then
  ViashError "Output file '$VIASH_PAR_UN' does not exist."
  exit 1
fi
if [ ! -z "$VIASH_PAR_AL" ] && [ ! -e "$VIASH_PAR_AL" ]; then
  ViashError "Output file '$VIASH_PAR_AL' does not exist."
  exit 1
fi
if [ ! -z "$VIASH_PAR_UN_CONC" ] && [ ! -e "$VIASH_PAR_UN_CONC" ]; then
  ViashError "Output file '$VIASH_PAR_UN_CONC' does not exist."
  exit 1
fi
if [ ! -z "$VIASH_PAR_AL_CONC" ] && [ ! -e "$VIASH_PAR_AL_CONC" ]; then
  ViashError "Output file '$VIASH_PAR_AL_CONC' does not exist."
  exit 1
fi
if [ ! -z "$VIASH_PAR_MET_FILE" ] && [ ! -e "$VIASH_PAR_MET_FILE" ]; then
  ViashError "Output file '$VIASH_PAR_MET_FILE' does not exist."
  exit 1
fi


exit 0
