#!/usr/bin/env bash

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

set -e

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

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

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

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

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

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

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

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

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

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

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

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

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

# define meta fields
VIASH_META_NAME="gffread"
VIASH_META_FUNCTIONALITY_NAME="gffread"
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"


# ViashHelp: Display helpful explanation about this executable
function ViashHelp {
  echo "gffread v0.3.0"
  echo ""
  echo "Validate, filter, convert and perform various other operations on GFF files."
  echo ""
  echo "Inputs:"
  echo "    --input"
  echo "        type: file, required parameter, file must exist"
  echo "        example: annotation.gff"
  echo "        A reference file in either the GFF3, GFF2 or GTF format."
  echo ""
  echo "    -m, --chr_mapping"
  echo "        type: file, file must exist"
  echo "        <chr_replace> is a name mapping table for converting reference sequence"
  echo "        names,"
  echo "        having this 2-column format: <original_ref_ID> <new_ref_ID>."
  echo ""
  echo "    -s, --seq_info"
  echo "        type: file, file must exist"
  echo "        <seq_info.fsize> is a tab-delimited file providing this info for each of"
  echo "        the mapped"
  echo "        sequences: <seq-name> <seq-length> <seq-description> (useful for"
  echo "        --description option with"
  echo "        mRNA/EST/protein mappings)."
  echo ""
  echo "    -g, --genome"
  echo "        type: file, file must exist"
  echo "        example: genome.fa"
  echo "        Full path to a multi-fasta file with the genomic sequences for all input"
  echo "        mappings,"
  echo "        OR a directory with single-fasta files (one per genomic sequence, with"
  echo "        file names"
  echo "        matching sequence names)."
  echo ""
  echo "Outputs:"
  echo "    -o, --outfile"
  echo "        type: file, required parameter, output, file must exist"
  echo "        example: output.gff"
  echo "        Write the output records into <outfile>."
  echo ""
  echo "    --force_exons"
  echo "        type: boolean_true"
  echo "        Make sure that the lowest level GFF features are considered \"exon\""
  echo "        features."
  echo ""
  echo "    --gene2exon"
  echo "        type: boolean_true"
  echo "        For single-line genes not parenting any transcripts, add an exon feature"
  echo "        spanning"
  echo "        the entire gene (treat it as a transcript)."
  echo ""
  echo "    --t_adopt"
  echo "        type: boolean_true"
  echo "        Try to find a parent gene overlapping/containing a transcript that does"
  echo "        not have"
  echo "        any explicit gene Parent."
  echo ""
  echo "    -D, --decode"
  echo "        type: boolean_true"
  echo "        Decode url encoded characters within attributes."
  echo ""
  echo "    -Z, --merge_exons"
  echo "        type: boolean_true"
  echo "        Merge very close exons into a single exon (when intron size<4)."
  echo ""
  echo "    -j, --junctions"
  echo "        type: boolean_true"
  echo "        Output the junctions and the corresponding transcripts."
  echo ""
  echo "    -w, --spliced_exons"
  echo "        type: file, output"
  echo "        example: exons.fa"
  echo "        Write a fasta file with spliced exons for each transcript."
  echo ""
  echo "    --w_add"
  echo "        type: integer"
  echo "        For the --spliced_exons option, extract additional <N> bases both"
  echo "        upstream and"
  echo "        downstream of the transcript boundaries."
  echo ""
  echo "    --w_nocds"
  echo "        type: boolean_true"
  echo "        For --spliced_exons, disable the output of CDS info in the FASTA file."
  echo ""
  echo "    -x, --spliced_cds"
  echo "        type: file"
  echo "        example: cds.fa"
  echo "        Write a fasta file with spliced CDS for each GFF transcript."
  echo ""
  echo "    -y, --tr_cds"
  echo "        type: file"
  echo "        example: tr_cds.fa"
  echo "        Write a protein fasta file with the translation of CDS for each record."
  echo ""
  echo "    -W, --w_coords"
  echo "        type: boolean_true"
  echo "        For --spliced_exons, --spliced_cds and -tr_cds options, write in the"
  echo "        FASTA defline"
  echo "        all the exon coordinates projected onto the spliced sequence."
  echo ""
  echo "    -S, --stop_dot"
  echo "        type: boolean_true"
  echo "        For --tr_cds option, use '*' instead of '.' as stop codon translation."
  echo ""
  echo "    -L, --id_version"
  echo "        type: boolean_true"
  echo "        Ensembl GTF to GFF3 conversion, adds version to IDs."
  echo ""
  echo "    -t, --trackname"
  echo "        type: string"
  echo "        Use <trackname> in the 2nd column of each GFF/GTF output line."
  echo ""
  echo "    -T, --gtf_output"
  echo "        type: boolean_true"
  echo "        Main output will be GTF instead of GFF3."
  echo ""
  echo "    --bed"
  echo "        type: boolean_true"
  echo "        Output records in BED format instead of default GFF3."
  echo ""
  echo "    --tlf"
  echo "        type: boolean_true"
  echo "        Output \"transcript line format\" which is like GFF but with exons and CDS"
  echo "        related"
  echo "        features stored as GFF attributes in the transcript feature line, like"
  echo "        this:"
  echo "          exoncount=N;exons=<exons>;CDSphase=<N>;CDS=<CDScoords>"
  echo "        <exons> is a comma-delimited list of exon_start-exon_end coordinates;"
  echo "        <CDScoords> is CDS_start:CDS_end coordinates or a list like <exons>."
  echo ""
  echo "    --table"
  echo "        type: string, multiple values allowed"
  echo "        Output a simple tab delimited format instead of GFF, with columns having"
  echo "        the values"
  echo "        of GFF attributes given in <attrlist>; special pseudo-attributes"
  echo "        (prefixed by @) are"
  echo "        recognized:"
  echo "          @id, @geneid, @chr, @start, @end, @strand, @numexons, @exons, @cds,"
  echo "        @covlen, @cdslen"
  echo "        If any of --spliced_exons/--tr_cds/--spliced_cds FASTA output files are"
  echo "        enabled, the"
  echo "        same fields (excluding @id) are appended to the definition line of"
  echo "        corresponding FASTA"
  echo "        records."
  echo ""
  echo "    -E, -v, --expose_dups"
  echo "        type: boolean_true"
  echo "        Expose (warn about) duplicate transcript IDs and other potential"
  echo "        problems with the"
  echo "        given GFF/GTF records."
  echo ""
  echo "Options:"
  echo "    --ids"
  echo "        type: file, file must exist"
  echo "        Discard records/transcripts if their IDs are not listed in <IDs.lst>."
  echo ""
  echo "    --nids"
  echo "        type: file, file must exist"
  echo "        Discard records/transcripts if their IDs are listed in <IDs.lst>."
  echo ""
  echo "    -i, --maxintron"
  echo "        type: integer"
  echo "        Discard transcripts having an intron larger than <maxintron>."
  echo ""
  echo "    -l, --minlen"
  echo "        type: integer"
  echo "        Discard transcripts shorter than <minlen> bases."
  echo ""
  echo "    -r, --range"
  echo "        type: string"
  echo "        Only show transcripts overlapping coordinate range <start>..<end> (on"
  echo "        chromosome/contig"
  echo "        <chr>, strand <strand> if provided)."
  echo ""
  echo "    -R, --strict_range"
  echo "        type: boolean_true"
  echo "        For --range option, discard all transcripts that are not fully contained"
  echo "        within the given"
  echo "        range."
  echo ""
  echo "    --jmatch"
  echo "        type: string"
  echo "        Only output transcripts matching the given junction."
  echo ""
  echo "    -U, --no_single_exon"
  echo "        type: boolean_true"
  echo "        Discard single-exon transcripts."
  echo ""
  echo "    -C, --coding"
  echo "        type: boolean_true"
  echo "        Coding only: discard mRNAs that have no CDS features."
  echo ""
  echo "    --nc"
  echo "        type: boolean_true"
  echo "        Non-coding only: discard mRNAs that have CDS features."
  echo ""
  echo "    --ignore_locus"
  echo "        type: boolean_true"
  echo "        Discard locus features and attributes found in the input."
  echo ""
  echo "    -A, --description"
  echo "        type: boolean_true"
  echo "        Use the description field from <seq_info.fsize> and add it as the value"
  echo "        for a 'descr'"
  echo "        attribute to the GFF record."
  echo ""
  echo "Sorting:"
  echo "    --sort_alpha"
  echo "        type: boolean_true"
  echo "        Chromosomes (reference sequences) are sorted alphabetically."
  echo ""
  echo "    --sort_by"
  echo "        type: file, file must exist"
  echo "        Sort the reference sequences by the order in which their names are given"
  echo "        in the"
  echo "        <refseq.lst> file."
  echo ""
  echo "Misc options:"
  echo "    -F, --keep_attrs"
  echo "        type: boolean_true"
  echo "        Keep all GFF attributes (for non-exon features)."
  echo ""
  echo "    --keep_exon_attrs"
  echo "        type: boolean_true"
  echo "        For -F option, do not attempt to reduce redundant exon/CDS attributes."
  echo ""
  echo "    -G, --no_exon_attrs"
  echo "        type: boolean_true"
  echo "        Do not keep exon attributes, move them to the transcript feature (for"
  echo "        GFF3 output)."
  echo ""
  echo "    --attrs"
  echo "        type: string"
  echo "        Only output the GTF/GFF attributes listed in <attr-list> which is a"
  echo "        comma delimited"
  echo "        list of attribute names to."
  echo ""
  echo "    --keep_genes"
  echo "        type: boolean_true"
  echo "        In transcript-only mode (default), also preserve gene records."
  echo ""
  echo "    --keep_comments"
  echo "        type: boolean_true"
  echo "        For GFF3 input/output, try to preserve comments."
  echo ""
  echo "    -O, --process_other"
  echo "        type: boolean_true"
  echo "        process other non-transcript GFF records (by default non-transcript"
  echo "        records are ignored)."
  echo ""
  echo "    -V, --rm_stop_codons"
  echo "        type: boolean_true"
  echo "        Discard any mRNAs with CDS having in-frame stop codons (requires"
  echo "        --genome)."
  echo ""
  echo "    -H, --adj_cds_start"
  echo "        type: boolean_true"
  echo "        For --rm_stop_codons option, check and adjust the starting CDS phase if"
  echo "        the original phase"
  echo "        leads to a translation with an in-frame stop codon."
  echo ""
  echo "    -B, --opposite_strand"
  echo "        type: boolean_true"
  echo "        For -V option, single-exon transcripts are also checked on the opposite"
  echo "        strand (requires"
  echo "        --genome)."
  echo ""
  echo "    -P, --coding_status"
  echo "        type: boolean_true"
  echo "        Add transcript level GFF attributes about the coding status of each"
  echo "        transcript, including"
  echo "        partialness or in-frame stop codons (requires --genome)."
  echo ""
  echo "    --add_hasCDS"
  echo "        type: boolean_true"
  echo "        Add a \"hasCDS\" attribute with value \"true\" for transcripts that have CDS"
  echo "        features."
  echo ""
  echo "    --adj_stop"
  echo "        type: boolean_true"
  echo "        Stop codon adjustment: enables --coding_status and performs automatic"
  echo "        adjustment of the CDS stop"
  echo "        coordinate if premature or downstream."
  echo ""
  echo "    -N, --rm_noncanon"
  echo "        type: boolean_true"
  echo "        Discard multi-exon mRNAs that have any intron with a non-canonical"
  echo "        splice site consensus"
  echo "        (i.e. not GT-AG, GC-AG or AT-AC)."
  echo ""
  echo "    -J, --complete_cds"
  echo "        type: boolean_true"
  echo "        Discard any mRNAs that either lack initial START codon or the terminal"
  echo "        STOP codon, or"
  echo "        have an in-frame stop codon (i.e. only print mRNAs with a complete CDS)."
  echo ""
  echo "    --no_pseudo"
  echo "        type: boolean_true"
  echo "        Filter out records matching the 'pseudo' keyword."
  echo ""
  echo "    --in_bed"
  echo "        type: boolean_true"
  echo "        Input should be parsed as BED format (automatic if the input filename"
  echo "        ends with .bed*)."
  echo ""
  echo "    --in_tlf"
  echo "        type: boolean_true"
  echo "        Input GFF-like one-line-per-transcript format without exon/CDS features"
  echo "        (see --tlf option"
  echo "        below); automatic if the input filename ends with .tlf)."
  echo ""
  echo "    --stream"
  echo "        type: boolean_true"
  echo "        Fast processing of input GFF/BED transcripts as they are received (no"
  echo "        sorting, exons must"
  echo "        be grouped by transcript in the input data)."
  echo ""
  echo "Clustering:"
  echo "    -M, --merge"
  echo "        type: boolean_true"
  echo "        Cluster the input transcripts into loci, discarding \"redundant\""
  echo "        transcripts (those with"
  echo "        the same exact introns and fully contained or equal boundaries)."
  echo ""
  echo "    -d, --dupinfo"
  echo "        type: file, file must exist"
  echo "        For --merge option, write duplication info to file <dupinfo>."
  echo ""
  echo "    --cluster_only"
  echo "        type: boolean_true"
  echo "        Same as --merge but without discarding any of the \"duplicate\""
  echo "        transcripts, only create"
  echo "        \"locus\" features."
  echo ""
  echo "    -K, --rm_redundant"
  echo "        type: boolean_true"
  echo "        For --merge option: also discard as redundant the shorter, fully"
  echo "        contained transcripts (intron"
  echo "        chains matching a part of the container)."
  echo ""
  echo "    -Q, --no_boundary"
  echo "        type: boolean_true"
  echo "        For --merge option, no longer require boundary containment when"
  echo "        assessing redundancy (can be"
  echo "        combined with --rm_redundant); only introns have to match for multi-exon"
  echo "        transcripts, and >=80%"
  echo "        overlap for single-exon transcripts."
  echo ""
  echo "    -Y, --no_overlap"
  echo "        type: boolean_true"
  echo "        For --merge option, enforce --no_boundary but also discard overlapping"
  echo "        single-exon transcripts,"
  echo "        even on the opposite strand (can be combined with --rm_redudant)."
}

# 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/gffread:0.12.7--hdcf5f25_3
ENTRYPOINT []
RUN echo "gffread: \"$(gffread --version 2>&1)\"" > /var/software_versions.txt

LABEL org.opencontainers.image.authors="Emma Rousseau"
LABEL org.opencontainers.image.description="Companion container for running component gffread"
LABEL org.opencontainers.image.created="2024-12-03T10:39:43Z"
LABEL org.opencontainers.image.source="https://github.com/gpertea/gffread"
LABEL org.opencontainers.image.revision="d86bd5cf62104af02caa852aacd352b1aa97ed60"
LABEL org.opencontainers.image.version="v0.3.0"

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)

# 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 "gffread v0.3.0"
            exit
            ;;
        --input)
            [ -n "$VIASH_PAR_INPUT" ] && ViashError Bad arguments for option \'--input\': \'$VIASH_PAR_INPUT\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_INPUT="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --input. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --input=*)
            [ -n "$VIASH_PAR_INPUT" ] && ViashError Bad arguments for option \'--input=*\': \'$VIASH_PAR_INPUT\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_INPUT=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --chr_mapping)
            [ -n "$VIASH_PAR_CHR_MAPPING" ] && ViashError Bad arguments for option \'--chr_mapping\': \'$VIASH_PAR_CHR_MAPPING\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_CHR_MAPPING="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --chr_mapping. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --chr_mapping=*)
            [ -n "$VIASH_PAR_CHR_MAPPING" ] && ViashError Bad arguments for option \'--chr_mapping=*\': \'$VIASH_PAR_CHR_MAPPING\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_CHR_MAPPING=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        -m)
            [ -n "$VIASH_PAR_CHR_MAPPING" ] && ViashError Bad arguments for option \'-m\': \'$VIASH_PAR_CHR_MAPPING\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_CHR_MAPPING="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to -m. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --seq_info)
            [ -n "$VIASH_PAR_SEQ_INFO" ] && ViashError Bad arguments for option \'--seq_info\': \'$VIASH_PAR_SEQ_INFO\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_SEQ_INFO="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --seq_info. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --seq_info=*)
            [ -n "$VIASH_PAR_SEQ_INFO" ] && ViashError Bad arguments for option \'--seq_info=*\': \'$VIASH_PAR_SEQ_INFO\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_SEQ_INFO=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        -s)
            [ -n "$VIASH_PAR_SEQ_INFO" ] && ViashError Bad arguments for option \'-s\': \'$VIASH_PAR_SEQ_INFO\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_SEQ_INFO="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to -s. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --genome)
            [ -n "$VIASH_PAR_GENOME" ] && ViashError Bad arguments for option \'--genome\': \'$VIASH_PAR_GENOME\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_GENOME="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --genome. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --genome=*)
            [ -n "$VIASH_PAR_GENOME" ] && ViashError Bad arguments for option \'--genome=*\': \'$VIASH_PAR_GENOME\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_GENOME=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        -g)
            [ -n "$VIASH_PAR_GENOME" ] && ViashError Bad arguments for option \'-g\': \'$VIASH_PAR_GENOME\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_GENOME="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to -g. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --outfile)
            [ -n "$VIASH_PAR_OUTFILE" ] && ViashError Bad arguments for option \'--outfile\': \'$VIASH_PAR_OUTFILE\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_OUTFILE="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --outfile. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --outfile=*)
            [ -n "$VIASH_PAR_OUTFILE" ] && ViashError Bad arguments for option \'--outfile=*\': \'$VIASH_PAR_OUTFILE\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_OUTFILE=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        -o)
            [ -n "$VIASH_PAR_OUTFILE" ] && ViashError Bad arguments for option \'-o\': \'$VIASH_PAR_OUTFILE\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_OUTFILE="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to -o. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --force_exons)
            [ -n "$VIASH_PAR_FORCE_EXONS" ] && ViashError Bad arguments for option \'--force_exons\': \'$VIASH_PAR_FORCE_EXONS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_FORCE_EXONS=true
            shift 1
            ;;
        --gene2exon)
            [ -n "$VIASH_PAR_GENE2EXON" ] && ViashError Bad arguments for option \'--gene2exon\': \'$VIASH_PAR_GENE2EXON\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_GENE2EXON=true
            shift 1
            ;;
        --t_adopt)
            [ -n "$VIASH_PAR_T_ADOPT" ] && ViashError Bad arguments for option \'--t_adopt\': \'$VIASH_PAR_T_ADOPT\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_T_ADOPT=true
            shift 1
            ;;
        --decode)
            [ -n "$VIASH_PAR_DECODE" ] && ViashError Bad arguments for option \'--decode\': \'$VIASH_PAR_DECODE\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_DECODE=true
            shift 1
            ;;
        -D)
            [ -n "$VIASH_PAR_DECODE" ] && ViashError Bad arguments for option \'-D\': \'$VIASH_PAR_DECODE\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_DECODE=true
            shift 1
            ;;
        --merge_exons)
            [ -n "$VIASH_PAR_MERGE_EXONS" ] && ViashError Bad arguments for option \'--merge_exons\': \'$VIASH_PAR_MERGE_EXONS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_MERGE_EXONS=true
            shift 1
            ;;
        -Z)
            [ -n "$VIASH_PAR_MERGE_EXONS" ] && ViashError Bad arguments for option \'-Z\': \'$VIASH_PAR_MERGE_EXONS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_MERGE_EXONS=true
            shift 1
            ;;
        --junctions)
            [ -n "$VIASH_PAR_JUNCTIONS" ] && ViashError Bad arguments for option \'--junctions\': \'$VIASH_PAR_JUNCTIONS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_JUNCTIONS=true
            shift 1
            ;;
        -j)
            [ -n "$VIASH_PAR_JUNCTIONS" ] && ViashError Bad arguments for option \'-j\': \'$VIASH_PAR_JUNCTIONS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_JUNCTIONS=true
            shift 1
            ;;
        --spliced_exons)
            [ -n "$VIASH_PAR_SPLICED_EXONS" ] && ViashError Bad arguments for option \'--spliced_exons\': \'$VIASH_PAR_SPLICED_EXONS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_SPLICED_EXONS="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --spliced_exons. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --spliced_exons=*)
            [ -n "$VIASH_PAR_SPLICED_EXONS" ] && ViashError Bad arguments for option \'--spliced_exons=*\': \'$VIASH_PAR_SPLICED_EXONS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_SPLICED_EXONS=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        -w)
            [ -n "$VIASH_PAR_SPLICED_EXONS" ] && ViashError Bad arguments for option \'-w\': \'$VIASH_PAR_SPLICED_EXONS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_SPLICED_EXONS="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to -w. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --w_add)
            [ -n "$VIASH_PAR_W_ADD" ] && ViashError Bad arguments for option \'--w_add\': \'$VIASH_PAR_W_ADD\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_W_ADD="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --w_add. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --w_add=*)
            [ -n "$VIASH_PAR_W_ADD" ] && ViashError Bad arguments for option \'--w_add=*\': \'$VIASH_PAR_W_ADD\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_W_ADD=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --w_nocds)
            [ -n "$VIASH_PAR_W_NOCDS" ] && ViashError Bad arguments for option \'--w_nocds\': \'$VIASH_PAR_W_NOCDS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_W_NOCDS=true
            shift 1
            ;;
        --spliced_cds)
            [ -n "$VIASH_PAR_SPLICED_CDS" ] && ViashError Bad arguments for option \'--spliced_cds\': \'$VIASH_PAR_SPLICED_CDS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_SPLICED_CDS="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --spliced_cds. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --spliced_cds=*)
            [ -n "$VIASH_PAR_SPLICED_CDS" ] && ViashError Bad arguments for option \'--spliced_cds=*\': \'$VIASH_PAR_SPLICED_CDS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_SPLICED_CDS=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        -x)
            [ -n "$VIASH_PAR_SPLICED_CDS" ] && ViashError Bad arguments for option \'-x\': \'$VIASH_PAR_SPLICED_CDS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_SPLICED_CDS="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to -x. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --tr_cds)
            [ -n "$VIASH_PAR_TR_CDS" ] && ViashError Bad arguments for option \'--tr_cds\': \'$VIASH_PAR_TR_CDS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_TR_CDS="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --tr_cds. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --tr_cds=*)
            [ -n "$VIASH_PAR_TR_CDS" ] && ViashError Bad arguments for option \'--tr_cds=*\': \'$VIASH_PAR_TR_CDS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_TR_CDS=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        -y)
            [ -n "$VIASH_PAR_TR_CDS" ] && ViashError Bad arguments for option \'-y\': \'$VIASH_PAR_TR_CDS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_TR_CDS="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to -y. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --w_coords)
            [ -n "$VIASH_PAR_W_COORDS" ] && ViashError Bad arguments for option \'--w_coords\': \'$VIASH_PAR_W_COORDS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_W_COORDS=true
            shift 1
            ;;
        -W)
            [ -n "$VIASH_PAR_W_COORDS" ] && ViashError Bad arguments for option \'-W\': \'$VIASH_PAR_W_COORDS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_W_COORDS=true
            shift 1
            ;;
        --stop_dot)
            [ -n "$VIASH_PAR_STOP_DOT" ] && ViashError Bad arguments for option \'--stop_dot\': \'$VIASH_PAR_STOP_DOT\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_STOP_DOT=true
            shift 1
            ;;
        -S)
            [ -n "$VIASH_PAR_STOP_DOT" ] && ViashError Bad arguments for option \'-S\': \'$VIASH_PAR_STOP_DOT\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_STOP_DOT=true
            shift 1
            ;;
        --id_version)
            [ -n "$VIASH_PAR_ID_VERSION" ] && ViashError Bad arguments for option \'--id_version\': \'$VIASH_PAR_ID_VERSION\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_ID_VERSION=true
            shift 1
            ;;
        -L)
            [ -n "$VIASH_PAR_ID_VERSION" ] && ViashError Bad arguments for option \'-L\': \'$VIASH_PAR_ID_VERSION\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_ID_VERSION=true
            shift 1
            ;;
        --trackname)
            [ -n "$VIASH_PAR_TRACKNAME" ] && ViashError Bad arguments for option \'--trackname\': \'$VIASH_PAR_TRACKNAME\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_TRACKNAME="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --trackname. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --trackname=*)
            [ -n "$VIASH_PAR_TRACKNAME" ] && ViashError Bad arguments for option \'--trackname=*\': \'$VIASH_PAR_TRACKNAME\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_TRACKNAME=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        -t)
            [ -n "$VIASH_PAR_TRACKNAME" ] && ViashError Bad arguments for option \'-t\': \'$VIASH_PAR_TRACKNAME\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_TRACKNAME="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to -t. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --gtf_output)
            [ -n "$VIASH_PAR_GTF_OUTPUT" ] && ViashError Bad arguments for option \'--gtf_output\': \'$VIASH_PAR_GTF_OUTPUT\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_GTF_OUTPUT=true
            shift 1
            ;;
        -T)
            [ -n "$VIASH_PAR_GTF_OUTPUT" ] && ViashError Bad arguments for option \'-T\': \'$VIASH_PAR_GTF_OUTPUT\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_GTF_OUTPUT=true
            shift 1
            ;;
        --bed)
            [ -n "$VIASH_PAR_BED" ] && ViashError Bad arguments for option \'--bed\': \'$VIASH_PAR_BED\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_BED=true
            shift 1
            ;;
        --tlf)
            [ -n "$VIASH_PAR_TLF" ] && ViashError Bad arguments for option \'--tlf\': \'$VIASH_PAR_TLF\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_TLF=true
            shift 1
            ;;
        --table)
            if [ -z "$VIASH_PAR_TABLE" ]; then
              VIASH_PAR_TABLE="$2"
            else
              VIASH_PAR_TABLE="$VIASH_PAR_TABLE;""$2"
            fi
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --table. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --table=*)
            if [ -z "$VIASH_PAR_TABLE" ]; then
              VIASH_PAR_TABLE=$(ViashRemoveFlags "$1")
            else
              VIASH_PAR_TABLE="$VIASH_PAR_TABLE;"$(ViashRemoveFlags "$1")
            fi
            shift 1
            ;;
        --expose_dups)
            [ -n "$VIASH_PAR_EXPOSE_DUPS" ] && ViashError Bad arguments for option \'--expose_dups\': \'$VIASH_PAR_EXPOSE_DUPS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_EXPOSE_DUPS=true
            shift 1
            ;;
        -E)
            [ -n "$VIASH_PAR_EXPOSE_DUPS" ] && ViashError Bad arguments for option \'-E\': \'$VIASH_PAR_EXPOSE_DUPS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_EXPOSE_DUPS=true
            shift 1
            ;;
        -v)
            [ -n "$VIASH_PAR_EXPOSE_DUPS" ] && ViashError Bad arguments for option \'-v\': \'$VIASH_PAR_EXPOSE_DUPS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_EXPOSE_DUPS=true
            shift 1
            ;;
        --ids)
            [ -n "$VIASH_PAR_IDS" ] && ViashError Bad arguments for option \'--ids\': \'$VIASH_PAR_IDS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_IDS="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --ids. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --ids=*)
            [ -n "$VIASH_PAR_IDS" ] && ViashError Bad arguments for option \'--ids=*\': \'$VIASH_PAR_IDS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_IDS=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --nids)
            [ -n "$VIASH_PAR_NIDS" ] && ViashError Bad arguments for option \'--nids\': \'$VIASH_PAR_NIDS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_NIDS="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --nids. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --nids=*)
            [ -n "$VIASH_PAR_NIDS" ] && ViashError Bad arguments for option \'--nids=*\': \'$VIASH_PAR_NIDS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_NIDS=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --maxintron)
            [ -n "$VIASH_PAR_MAXINTRON" ] && ViashError Bad arguments for option \'--maxintron\': \'$VIASH_PAR_MAXINTRON\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_MAXINTRON="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --maxintron. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --maxintron=*)
            [ -n "$VIASH_PAR_MAXINTRON" ] && ViashError Bad arguments for option \'--maxintron=*\': \'$VIASH_PAR_MAXINTRON\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_MAXINTRON=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        -i)
            [ -n "$VIASH_PAR_MAXINTRON" ] && ViashError Bad arguments for option \'-i\': \'$VIASH_PAR_MAXINTRON\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_MAXINTRON="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to -i. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --minlen)
            [ -n "$VIASH_PAR_MINLEN" ] && ViashError Bad arguments for option \'--minlen\': \'$VIASH_PAR_MINLEN\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_MINLEN="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --minlen. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --minlen=*)
            [ -n "$VIASH_PAR_MINLEN" ] && ViashError Bad arguments for option \'--minlen=*\': \'$VIASH_PAR_MINLEN\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_MINLEN=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        -l)
            [ -n "$VIASH_PAR_MINLEN" ] && ViashError Bad arguments for option \'-l\': \'$VIASH_PAR_MINLEN\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_MINLEN="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to -l. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --range)
            [ -n "$VIASH_PAR_RANGE" ] && ViashError Bad arguments for option \'--range\': \'$VIASH_PAR_RANGE\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_RANGE="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --range. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --range=*)
            [ -n "$VIASH_PAR_RANGE" ] && ViashError Bad arguments for option \'--range=*\': \'$VIASH_PAR_RANGE\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_RANGE=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        -r)
            [ -n "$VIASH_PAR_RANGE" ] && ViashError Bad arguments for option \'-r\': \'$VIASH_PAR_RANGE\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_RANGE="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to -r. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --strict_range)
            [ -n "$VIASH_PAR_STRICT_RANGE" ] && ViashError Bad arguments for option \'--strict_range\': \'$VIASH_PAR_STRICT_RANGE\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_STRICT_RANGE=true
            shift 1
            ;;
        -R)
            [ -n "$VIASH_PAR_STRICT_RANGE" ] && ViashError Bad arguments for option \'-R\': \'$VIASH_PAR_STRICT_RANGE\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_STRICT_RANGE=true
            shift 1
            ;;
        --jmatch)
            [ -n "$VIASH_PAR_JMATCH" ] && ViashError Bad arguments for option \'--jmatch\': \'$VIASH_PAR_JMATCH\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_JMATCH="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --jmatch. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --jmatch=*)
            [ -n "$VIASH_PAR_JMATCH" ] && ViashError Bad arguments for option \'--jmatch=*\': \'$VIASH_PAR_JMATCH\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_JMATCH=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --no_single_exon)
            [ -n "$VIASH_PAR_NO_SINGLE_EXON" ] && ViashError Bad arguments for option \'--no_single_exon\': \'$VIASH_PAR_NO_SINGLE_EXON\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_NO_SINGLE_EXON=true
            shift 1
            ;;
        -U)
            [ -n "$VIASH_PAR_NO_SINGLE_EXON" ] && ViashError Bad arguments for option \'-U\': \'$VIASH_PAR_NO_SINGLE_EXON\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_NO_SINGLE_EXON=true
            shift 1
            ;;
        --coding)
            [ -n "$VIASH_PAR_CODING" ] && ViashError Bad arguments for option \'--coding\': \'$VIASH_PAR_CODING\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_CODING=true
            shift 1
            ;;
        -C)
            [ -n "$VIASH_PAR_CODING" ] && ViashError Bad arguments for option \'-C\': \'$VIASH_PAR_CODING\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_CODING=true
            shift 1
            ;;
        --nc)
            [ -n "$VIASH_PAR_NC" ] && ViashError Bad arguments for option \'--nc\': \'$VIASH_PAR_NC\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_NC=true
            shift 1
            ;;
        --ignore_locus)
            [ -n "$VIASH_PAR_IGNORE_LOCUS" ] && ViashError Bad arguments for option \'--ignore_locus\': \'$VIASH_PAR_IGNORE_LOCUS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_IGNORE_LOCUS=true
            shift 1
            ;;
        --description)
            [ -n "$VIASH_PAR_DESCRIPTION" ] && ViashError Bad arguments for option \'--description\': \'$VIASH_PAR_DESCRIPTION\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_DESCRIPTION=true
            shift 1
            ;;
        -A)
            [ -n "$VIASH_PAR_DESCRIPTION" ] && ViashError Bad arguments for option \'-A\': \'$VIASH_PAR_DESCRIPTION\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_DESCRIPTION=true
            shift 1
            ;;
        --sort_alpha)
            [ -n "$VIASH_PAR_SORT_ALPHA" ] && ViashError Bad arguments for option \'--sort_alpha\': \'$VIASH_PAR_SORT_ALPHA\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_SORT_ALPHA=true
            shift 1
            ;;
        --sort_by)
            [ -n "$VIASH_PAR_SORT_BY" ] && ViashError Bad arguments for option \'--sort_by\': \'$VIASH_PAR_SORT_BY\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_SORT_BY="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --sort_by. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --sort_by=*)
            [ -n "$VIASH_PAR_SORT_BY" ] && ViashError Bad arguments for option \'--sort_by=*\': \'$VIASH_PAR_SORT_BY\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_SORT_BY=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --keep_attrs)
            [ -n "$VIASH_PAR_KEEP_ATTRS" ] && ViashError Bad arguments for option \'--keep_attrs\': \'$VIASH_PAR_KEEP_ATTRS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_KEEP_ATTRS=true
            shift 1
            ;;
        -F)
            [ -n "$VIASH_PAR_KEEP_ATTRS" ] && ViashError Bad arguments for option \'-F\': \'$VIASH_PAR_KEEP_ATTRS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_KEEP_ATTRS=true
            shift 1
            ;;
        --keep_exon_attrs)
            [ -n "$VIASH_PAR_KEEP_EXON_ATTRS" ] && ViashError Bad arguments for option \'--keep_exon_attrs\': \'$VIASH_PAR_KEEP_EXON_ATTRS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_KEEP_EXON_ATTRS=true
            shift 1
            ;;
        --no_exon_attrs)
            [ -n "$VIASH_PAR_NO_EXON_ATTRS" ] && ViashError Bad arguments for option \'--no_exon_attrs\': \'$VIASH_PAR_NO_EXON_ATTRS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_NO_EXON_ATTRS=true
            shift 1
            ;;
        -G)
            [ -n "$VIASH_PAR_NO_EXON_ATTRS" ] && ViashError Bad arguments for option \'-G\': \'$VIASH_PAR_NO_EXON_ATTRS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_NO_EXON_ATTRS=true
            shift 1
            ;;
        --attrs)
            [ -n "$VIASH_PAR_ATTRS" ] && ViashError Bad arguments for option \'--attrs\': \'$VIASH_PAR_ATTRS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_ATTRS="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --attrs. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --attrs=*)
            [ -n "$VIASH_PAR_ATTRS" ] && ViashError Bad arguments for option \'--attrs=*\': \'$VIASH_PAR_ATTRS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_ATTRS=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --keep_genes)
            [ -n "$VIASH_PAR_KEEP_GENES" ] && ViashError Bad arguments for option \'--keep_genes\': \'$VIASH_PAR_KEEP_GENES\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_KEEP_GENES=true
            shift 1
            ;;
        --keep_comments)
            [ -n "$VIASH_PAR_KEEP_COMMENTS" ] && ViashError Bad arguments for option \'--keep_comments\': \'$VIASH_PAR_KEEP_COMMENTS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_KEEP_COMMENTS=true
            shift 1
            ;;
        --process_other)
            [ -n "$VIASH_PAR_PROCESS_OTHER" ] && ViashError Bad arguments for option \'--process_other\': \'$VIASH_PAR_PROCESS_OTHER\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_PROCESS_OTHER=true
            shift 1
            ;;
        -O)
            [ -n "$VIASH_PAR_PROCESS_OTHER" ] && ViashError Bad arguments for option \'-O\': \'$VIASH_PAR_PROCESS_OTHER\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_PROCESS_OTHER=true
            shift 1
            ;;
        --rm_stop_codons)
            [ -n "$VIASH_PAR_RM_STOP_CODONS" ] && ViashError Bad arguments for option \'--rm_stop_codons\': \'$VIASH_PAR_RM_STOP_CODONS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_RM_STOP_CODONS=true
            shift 1
            ;;
        -V)
            [ -n "$VIASH_PAR_RM_STOP_CODONS" ] && ViashError Bad arguments for option \'-V\': \'$VIASH_PAR_RM_STOP_CODONS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_RM_STOP_CODONS=true
            shift 1
            ;;
        --adj_cds_start)
            [ -n "$VIASH_PAR_ADJ_CDS_START" ] && ViashError Bad arguments for option \'--adj_cds_start\': \'$VIASH_PAR_ADJ_CDS_START\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_ADJ_CDS_START=true
            shift 1
            ;;
        -H)
            [ -n "$VIASH_PAR_ADJ_CDS_START" ] && ViashError Bad arguments for option \'-H\': \'$VIASH_PAR_ADJ_CDS_START\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_ADJ_CDS_START=true
            shift 1
            ;;
        --opposite_strand)
            [ -n "$VIASH_PAR_OPPOSITE_STRAND" ] && ViashError Bad arguments for option \'--opposite_strand\': \'$VIASH_PAR_OPPOSITE_STRAND\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_OPPOSITE_STRAND=true
            shift 1
            ;;
        -B)
            [ -n "$VIASH_PAR_OPPOSITE_STRAND" ] && ViashError Bad arguments for option \'-B\': \'$VIASH_PAR_OPPOSITE_STRAND\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_OPPOSITE_STRAND=true
            shift 1
            ;;
        --coding_status)
            [ -n "$VIASH_PAR_CODING_STATUS" ] && ViashError Bad arguments for option \'--coding_status\': \'$VIASH_PAR_CODING_STATUS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_CODING_STATUS=true
            shift 1
            ;;
        -P)
            [ -n "$VIASH_PAR_CODING_STATUS" ] && ViashError Bad arguments for option \'-P\': \'$VIASH_PAR_CODING_STATUS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_CODING_STATUS=true
            shift 1
            ;;
        --add_hasCDS)
            [ -n "$VIASH_PAR_ADD_HASCDS" ] && ViashError Bad arguments for option \'--add_hasCDS\': \'$VIASH_PAR_ADD_HASCDS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_ADD_HASCDS=true
            shift 1
            ;;
        --adj_stop)
            [ -n "$VIASH_PAR_ADJ_STOP" ] && ViashError Bad arguments for option \'--adj_stop\': \'$VIASH_PAR_ADJ_STOP\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_ADJ_STOP=true
            shift 1
            ;;
        --rm_noncanon)
            [ -n "$VIASH_PAR_RM_NONCANON" ] && ViashError Bad arguments for option \'--rm_noncanon\': \'$VIASH_PAR_RM_NONCANON\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_RM_NONCANON=true
            shift 1
            ;;
        -N)
            [ -n "$VIASH_PAR_RM_NONCANON" ] && ViashError Bad arguments for option \'-N\': \'$VIASH_PAR_RM_NONCANON\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_RM_NONCANON=true
            shift 1
            ;;
        --complete_cds)
            [ -n "$VIASH_PAR_COMPLETE_CDS" ] && ViashError Bad arguments for option \'--complete_cds\': \'$VIASH_PAR_COMPLETE_CDS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_COMPLETE_CDS=true
            shift 1
            ;;
        -J)
            [ -n "$VIASH_PAR_COMPLETE_CDS" ] && ViashError Bad arguments for option \'-J\': \'$VIASH_PAR_COMPLETE_CDS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_COMPLETE_CDS=true
            shift 1
            ;;
        --no_pseudo)
            [ -n "$VIASH_PAR_NO_PSEUDO" ] && ViashError Bad arguments for option \'--no_pseudo\': \'$VIASH_PAR_NO_PSEUDO\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_NO_PSEUDO=true
            shift 1
            ;;
        --in_bed)
            [ -n "$VIASH_PAR_IN_BED" ] && ViashError Bad arguments for option \'--in_bed\': \'$VIASH_PAR_IN_BED\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_IN_BED=true
            shift 1
            ;;
        --in_tlf)
            [ -n "$VIASH_PAR_IN_TLF" ] && ViashError Bad arguments for option \'--in_tlf\': \'$VIASH_PAR_IN_TLF\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_IN_TLF=true
            shift 1
            ;;
        --stream)
            [ -n "$VIASH_PAR_STREAM" ] && ViashError Bad arguments for option \'--stream\': \'$VIASH_PAR_STREAM\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_STREAM=true
            shift 1
            ;;
        --merge)
            [ -n "$VIASH_PAR_MERGE" ] && ViashError Bad arguments for option \'--merge\': \'$VIASH_PAR_MERGE\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_MERGE=true
            shift 1
            ;;
        -M)
            [ -n "$VIASH_PAR_MERGE" ] && ViashError Bad arguments for option \'-M\': \'$VIASH_PAR_MERGE\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_MERGE=true
            shift 1
            ;;
        --dupinfo)
            [ -n "$VIASH_PAR_DUPINFO" ] && ViashError Bad arguments for option \'--dupinfo\': \'$VIASH_PAR_DUPINFO\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_DUPINFO="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --dupinfo. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --dupinfo=*)
            [ -n "$VIASH_PAR_DUPINFO" ] && ViashError Bad arguments for option \'--dupinfo=*\': \'$VIASH_PAR_DUPINFO\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_DUPINFO=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        -d)
            [ -n "$VIASH_PAR_DUPINFO" ] && ViashError Bad arguments for option \'-d\': \'$VIASH_PAR_DUPINFO\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_DUPINFO="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to -d. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --cluster_only)
            [ -n "$VIASH_PAR_CLUSTER_ONLY" ] && ViashError Bad arguments for option \'--cluster_only\': \'$VIASH_PAR_CLUSTER_ONLY\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_CLUSTER_ONLY=true
            shift 1
            ;;
        --rm_redundant)
            [ -n "$VIASH_PAR_RM_REDUNDANT" ] && ViashError Bad arguments for option \'--rm_redundant\': \'$VIASH_PAR_RM_REDUNDANT\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_RM_REDUNDANT=true
            shift 1
            ;;
        -K)
            [ -n "$VIASH_PAR_RM_REDUNDANT" ] && ViashError Bad arguments for option \'-K\': \'$VIASH_PAR_RM_REDUNDANT\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_RM_REDUNDANT=true
            shift 1
            ;;
        --no_boundary)
            [ -n "$VIASH_PAR_NO_BOUNDARY" ] && ViashError Bad arguments for option \'--no_boundary\': \'$VIASH_PAR_NO_BOUNDARY\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_NO_BOUNDARY=true
            shift 1
            ;;
        -Q)
            [ -n "$VIASH_PAR_NO_BOUNDARY" ] && ViashError Bad arguments for option \'-Q\': \'$VIASH_PAR_NO_BOUNDARY\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_NO_BOUNDARY=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
            ;;
        -Y)
            [ -n "$VIASH_PAR_NO_OVERLAP" ] && ViashError Bad arguments for option \'-Y\': \'$VIASH_PAR_NO_OVERLAP\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_NO_OVERLAP=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/gffread:v0.3.0'
  fi

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

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

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

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

# setting computational defaults

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


# check whether required parameters exist
if [ -z ${VIASH_PAR_INPUT+x} ]; then
  ViashError '--input' is a required argument. Use "--help" to get more information on the parameters.
  exit 1
fi
if [ -z ${VIASH_PAR_OUTFILE+x} ]; then
  ViashError '--outfile' 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_FORCE_EXONS+x} ]; then
  VIASH_PAR_FORCE_EXONS="false"
fi
if [ -z ${VIASH_PAR_GENE2EXON+x} ]; then
  VIASH_PAR_GENE2EXON="false"
fi
if [ -z ${VIASH_PAR_T_ADOPT+x} ]; then
  VIASH_PAR_T_ADOPT="false"
fi
if [ -z ${VIASH_PAR_DECODE+x} ]; then
  VIASH_PAR_DECODE="false"
fi
if [ -z ${VIASH_PAR_MERGE_EXONS+x} ]; then
  VIASH_PAR_MERGE_EXONS="false"
fi
if [ -z ${VIASH_PAR_JUNCTIONS+x} ]; then
  VIASH_PAR_JUNCTIONS="false"
fi
if [ -z ${VIASH_PAR_W_NOCDS+x} ]; then
  VIASH_PAR_W_NOCDS="false"
fi
if [ -z ${VIASH_PAR_W_COORDS+x} ]; then
  VIASH_PAR_W_COORDS="false"
fi
if [ -z ${VIASH_PAR_STOP_DOT+x} ]; then
  VIASH_PAR_STOP_DOT="false"
fi
if [ -z ${VIASH_PAR_ID_VERSION+x} ]; then
  VIASH_PAR_ID_VERSION="false"
fi
if [ -z ${VIASH_PAR_GTF_OUTPUT+x} ]; then
  VIASH_PAR_GTF_OUTPUT="false"
fi
if [ -z ${VIASH_PAR_BED+x} ]; then
  VIASH_PAR_BED="false"
fi
if [ -z ${VIASH_PAR_TLF+x} ]; then
  VIASH_PAR_TLF="false"
fi
if [ -z ${VIASH_PAR_EXPOSE_DUPS+x} ]; then
  VIASH_PAR_EXPOSE_DUPS="false"
fi
if [ -z ${VIASH_PAR_STRICT_RANGE+x} ]; then
  VIASH_PAR_STRICT_RANGE="false"
fi
if [ -z ${VIASH_PAR_NO_SINGLE_EXON+x} ]; then
  VIASH_PAR_NO_SINGLE_EXON="false"
fi
if [ -z ${VIASH_PAR_CODING+x} ]; then
  VIASH_PAR_CODING="false"
fi
if [ -z ${VIASH_PAR_NC+x} ]; then
  VIASH_PAR_NC="false"
fi
if [ -z ${VIASH_PAR_IGNORE_LOCUS+x} ]; then
  VIASH_PAR_IGNORE_LOCUS="false"
fi
if [ -z ${VIASH_PAR_DESCRIPTION+x} ]; then
  VIASH_PAR_DESCRIPTION="false"
fi
if [ -z ${VIASH_PAR_SORT_ALPHA+x} ]; then
  VIASH_PAR_SORT_ALPHA="false"
fi
if [ -z ${VIASH_PAR_KEEP_ATTRS+x} ]; then
  VIASH_PAR_KEEP_ATTRS="false"
fi
if [ -z ${VIASH_PAR_KEEP_EXON_ATTRS+x} ]; then
  VIASH_PAR_KEEP_EXON_ATTRS="false"
fi
if [ -z ${VIASH_PAR_NO_EXON_ATTRS+x} ]; then
  VIASH_PAR_NO_EXON_ATTRS="false"
fi
if [ -z ${VIASH_PAR_KEEP_GENES+x} ]; then
  VIASH_PAR_KEEP_GENES="false"
fi
if [ -z ${VIASH_PAR_KEEP_COMMENTS+x} ]; then
  VIASH_PAR_KEEP_COMMENTS="false"
fi
if [ -z ${VIASH_PAR_PROCESS_OTHER+x} ]; then
  VIASH_PAR_PROCESS_OTHER="false"
fi
if [ -z ${VIASH_PAR_RM_STOP_CODONS+x} ]; then
  VIASH_PAR_RM_STOP_CODONS="false"
fi
if [ -z ${VIASH_PAR_ADJ_CDS_START+x} ]; then
  VIASH_PAR_ADJ_CDS_START="false"
fi
if [ -z ${VIASH_PAR_OPPOSITE_STRAND+x} ]; then
  VIASH_PAR_OPPOSITE_STRAND="false"
fi
if [ -z ${VIASH_PAR_CODING_STATUS+x} ]; then
  VIASH_PAR_CODING_STATUS="false"
fi
if [ -z ${VIASH_PAR_ADD_HASCDS+x} ]; then
  VIASH_PAR_ADD_HASCDS="false"
fi
if [ -z ${VIASH_PAR_ADJ_STOP+x} ]; then
  VIASH_PAR_ADJ_STOP="false"
fi
if [ -z ${VIASH_PAR_RM_NONCANON+x} ]; then
  VIASH_PAR_RM_NONCANON="false"
fi
if [ -z ${VIASH_PAR_COMPLETE_CDS+x} ]; then
  VIASH_PAR_COMPLETE_CDS="false"
fi
if [ -z ${VIASH_PAR_NO_PSEUDO+x} ]; then
  VIASH_PAR_NO_PSEUDO="false"
fi
if [ -z ${VIASH_PAR_IN_BED+x} ]; then
  VIASH_PAR_IN_BED="false"
fi
if [ -z ${VIASH_PAR_IN_TLF+x} ]; then
  VIASH_PAR_IN_TLF="false"
fi
if [ -z ${VIASH_PAR_STREAM+x} ]; then
  VIASH_PAR_STREAM="false"
fi
if [ -z ${VIASH_PAR_MERGE+x} ]; then
  VIASH_PAR_MERGE="false"
fi
if [ -z ${VIASH_PAR_CLUSTER_ONLY+x} ]; then
  VIASH_PAR_CLUSTER_ONLY="false"
fi
if [ -z ${VIASH_PAR_RM_REDUNDANT+x} ]; then
  VIASH_PAR_RM_REDUNDANT="false"
fi
if [ -z ${VIASH_PAR_NO_BOUNDARY+x} ]; then
  VIASH_PAR_NO_BOUNDARY="false"
fi
if [ -z ${VIASH_PAR_NO_OVERLAP+x} ]; then
  VIASH_PAR_NO_OVERLAP="false"
fi

# check whether required files exist
if [ ! -z "$VIASH_PAR_INPUT" ] && [ ! -e "$VIASH_PAR_INPUT" ]; then
  ViashError "Input file '$VIASH_PAR_INPUT' does not exist."
  exit 1
fi
if [ ! -z "$VIASH_PAR_CHR_MAPPING" ] && [ ! -e "$VIASH_PAR_CHR_MAPPING" ]; then
  ViashError "Input file '$VIASH_PAR_CHR_MAPPING' does not exist."
  exit 1
fi
if [ ! -z "$VIASH_PAR_SEQ_INFO" ] && [ ! -e "$VIASH_PAR_SEQ_INFO" ]; then
  ViashError "Input file '$VIASH_PAR_SEQ_INFO' does not exist."
  exit 1
fi
if [ ! -z "$VIASH_PAR_GENOME" ] && [ ! -e "$VIASH_PAR_GENOME" ]; then
  ViashError "Input file '$VIASH_PAR_GENOME' does not exist."
  exit 1
fi
if [ ! -z "$VIASH_PAR_IDS" ] && [ ! -e "$VIASH_PAR_IDS" ]; then
  ViashError "Input file '$VIASH_PAR_IDS' does not exist."
  exit 1
fi
if [ ! -z "$VIASH_PAR_NIDS" ] && [ ! -e "$VIASH_PAR_NIDS" ]; then
  ViashError "Input file '$VIASH_PAR_NIDS' does not exist."
  exit 1
fi
if [ ! -z "$VIASH_PAR_SORT_BY" ] && [ ! -e "$VIASH_PAR_SORT_BY" ]; then
  ViashError "Input file '$VIASH_PAR_SORT_BY' does not exist."
  exit 1
fi
if [ ! -z "$VIASH_PAR_DUPINFO" ] && [ ! -e "$VIASH_PAR_DUPINFO" ]; then
  ViashError "Input file '$VIASH_PAR_DUPINFO' does not exist."
  exit 1
fi

# check whether parameters values are of the right type
if [[ -n "$VIASH_PAR_FORCE_EXONS" ]]; then
  if ! [[ "$VIASH_PAR_FORCE_EXONS" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--force_exons' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_GENE2EXON" ]]; then
  if ! [[ "$VIASH_PAR_GENE2EXON" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--gene2exon' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_T_ADOPT" ]]; then
  if ! [[ "$VIASH_PAR_T_ADOPT" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--t_adopt' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_DECODE" ]]; then
  if ! [[ "$VIASH_PAR_DECODE" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--decode' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_MERGE_EXONS" ]]; then
  if ! [[ "$VIASH_PAR_MERGE_EXONS" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--merge_exons' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_JUNCTIONS" ]]; then
  if ! [[ "$VIASH_PAR_JUNCTIONS" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--junctions' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_W_ADD" ]]; then
  if ! [[ "$VIASH_PAR_W_ADD" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError '--w_add' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_W_NOCDS" ]]; then
  if ! [[ "$VIASH_PAR_W_NOCDS" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--w_nocds' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_W_COORDS" ]]; then
  if ! [[ "$VIASH_PAR_W_COORDS" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--w_coords' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_STOP_DOT" ]]; then
  if ! [[ "$VIASH_PAR_STOP_DOT" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--stop_dot' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_ID_VERSION" ]]; then
  if ! [[ "$VIASH_PAR_ID_VERSION" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--id_version' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_GTF_OUTPUT" ]]; then
  if ! [[ "$VIASH_PAR_GTF_OUTPUT" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--gtf_output' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_BED" ]]; then
  if ! [[ "$VIASH_PAR_BED" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--bed' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_TLF" ]]; then
  if ! [[ "$VIASH_PAR_TLF" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--tlf' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_EXPOSE_DUPS" ]]; then
  if ! [[ "$VIASH_PAR_EXPOSE_DUPS" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--expose_dups' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_MAXINTRON" ]]; then
  if ! [[ "$VIASH_PAR_MAXINTRON" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError '--maxintron' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_MINLEN" ]]; then
  if ! [[ "$VIASH_PAR_MINLEN" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError '--minlen' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_STRICT_RANGE" ]]; then
  if ! [[ "$VIASH_PAR_STRICT_RANGE" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--strict_range' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_NO_SINGLE_EXON" ]]; then
  if ! [[ "$VIASH_PAR_NO_SINGLE_EXON" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--no_single_exon' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_CODING" ]]; then
  if ! [[ "$VIASH_PAR_CODING" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--coding' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_NC" ]]; then
  if ! [[ "$VIASH_PAR_NC" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--nc' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_IGNORE_LOCUS" ]]; then
  if ! [[ "$VIASH_PAR_IGNORE_LOCUS" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--ignore_locus' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_DESCRIPTION" ]]; then
  if ! [[ "$VIASH_PAR_DESCRIPTION" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--description' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_SORT_ALPHA" ]]; then
  if ! [[ "$VIASH_PAR_SORT_ALPHA" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--sort_alpha' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_KEEP_ATTRS" ]]; then
  if ! [[ "$VIASH_PAR_KEEP_ATTRS" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--keep_attrs' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_KEEP_EXON_ATTRS" ]]; then
  if ! [[ "$VIASH_PAR_KEEP_EXON_ATTRS" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--keep_exon_attrs' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_NO_EXON_ATTRS" ]]; then
  if ! [[ "$VIASH_PAR_NO_EXON_ATTRS" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--no_exon_attrs' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_KEEP_GENES" ]]; then
  if ! [[ "$VIASH_PAR_KEEP_GENES" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--keep_genes' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_KEEP_COMMENTS" ]]; then
  if ! [[ "$VIASH_PAR_KEEP_COMMENTS" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--keep_comments' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_PROCESS_OTHER" ]]; then
  if ! [[ "$VIASH_PAR_PROCESS_OTHER" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--process_other' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_RM_STOP_CODONS" ]]; then
  if ! [[ "$VIASH_PAR_RM_STOP_CODONS" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--rm_stop_codons' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_ADJ_CDS_START" ]]; then
  if ! [[ "$VIASH_PAR_ADJ_CDS_START" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--adj_cds_start' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_OPPOSITE_STRAND" ]]; then
  if ! [[ "$VIASH_PAR_OPPOSITE_STRAND" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--opposite_strand' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_CODING_STATUS" ]]; then
  if ! [[ "$VIASH_PAR_CODING_STATUS" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--coding_status' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_ADD_HASCDS" ]]; then
  if ! [[ "$VIASH_PAR_ADD_HASCDS" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--add_hasCDS' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_ADJ_STOP" ]]; then
  if ! [[ "$VIASH_PAR_ADJ_STOP" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--adj_stop' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_RM_NONCANON" ]]; then
  if ! [[ "$VIASH_PAR_RM_NONCANON" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--rm_noncanon' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_COMPLETE_CDS" ]]; then
  if ! [[ "$VIASH_PAR_COMPLETE_CDS" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--complete_cds' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_NO_PSEUDO" ]]; then
  if ! [[ "$VIASH_PAR_NO_PSEUDO" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--no_pseudo' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_IN_BED" ]]; then
  if ! [[ "$VIASH_PAR_IN_BED" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--in_bed' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_IN_TLF" ]]; then
  if ! [[ "$VIASH_PAR_IN_TLF" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--in_tlf' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_STREAM" ]]; then
  if ! [[ "$VIASH_PAR_STREAM" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--stream' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_MERGE" ]]; then
  if ! [[ "$VIASH_PAR_MERGE" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--merge' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_CLUSTER_ONLY" ]]; then
  if ! [[ "$VIASH_PAR_CLUSTER_ONLY" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--cluster_only' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_RM_REDUNDANT" ]]; then
  if ! [[ "$VIASH_PAR_RM_REDUNDANT" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--rm_redundant' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_NO_BOUNDARY" ]]; then
  if ! [[ "$VIASH_PAR_NO_BOUNDARY" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--no_boundary' 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_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_OUTFILE" ] && [ ! -d "$(dirname "$VIASH_PAR_OUTFILE")" ]; then
  mkdir -p "$(dirname "$VIASH_PAR_OUTFILE")"
fi
if [ ! -z "$VIASH_PAR_SPLICED_EXONS" ] && [ ! -d "$(dirname "$VIASH_PAR_SPLICED_EXONS")" ]; then
  mkdir -p "$(dirname "$VIASH_PAR_SPLICED_EXONS")"
fi

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

if [[ "$VIASH_ENGINE_TYPE" == "docker" ]]; then
  # detect volumes from file arguments
  VIASH_CHOWN_VARS=()
if [ ! -z "$VIASH_PAR_INPUT" ]; then
  VIASH_DIRECTORY_MOUNTS+=( "$(ViashDockerAutodetectMountArg "$VIASH_PAR_INPUT")" )
  VIASH_PAR_INPUT=$(ViashDockerAutodetectMount "$VIASH_PAR_INPUT")
fi
if [ ! -z "$VIASH_PAR_CHR_MAPPING" ]; then
  VIASH_DIRECTORY_MOUNTS+=( "$(ViashDockerAutodetectMountArg "$VIASH_PAR_CHR_MAPPING")" )
  VIASH_PAR_CHR_MAPPING=$(ViashDockerAutodetectMount "$VIASH_PAR_CHR_MAPPING")
fi
if [ ! -z "$VIASH_PAR_SEQ_INFO" ]; then
  VIASH_DIRECTORY_MOUNTS+=( "$(ViashDockerAutodetectMountArg "$VIASH_PAR_SEQ_INFO")" )
  VIASH_PAR_SEQ_INFO=$(ViashDockerAutodetectMount "$VIASH_PAR_SEQ_INFO")
fi
if [ ! -z "$VIASH_PAR_GENOME" ]; then
  VIASH_DIRECTORY_MOUNTS+=( "$(ViashDockerAutodetectMountArg "$VIASH_PAR_GENOME")" )
  VIASH_PAR_GENOME=$(ViashDockerAutodetectMount "$VIASH_PAR_GENOME")
fi
if [ ! -z "$VIASH_PAR_OUTFILE" ]; then
  VIASH_DIRECTORY_MOUNTS+=( "$(ViashDockerAutodetectMountArg "$VIASH_PAR_OUTFILE")" )
  VIASH_PAR_OUTFILE=$(ViashDockerAutodetectMount "$VIASH_PAR_OUTFILE")
  VIASH_CHOWN_VARS+=( "$VIASH_PAR_OUTFILE" )
fi
if [ ! -z "$VIASH_PAR_SPLICED_EXONS" ]; then
  VIASH_DIRECTORY_MOUNTS+=( "$(ViashDockerAutodetectMountArg "$VIASH_PAR_SPLICED_EXONS")" )
  VIASH_PAR_SPLICED_EXONS=$(ViashDockerAutodetectMount "$VIASH_PAR_SPLICED_EXONS")
  VIASH_CHOWN_VARS+=( "$VIASH_PAR_SPLICED_EXONS" )
fi
if [ ! -z "$VIASH_PAR_SPLICED_CDS" ]; then
  VIASH_DIRECTORY_MOUNTS+=( "$(ViashDockerAutodetectMountArg "$VIASH_PAR_SPLICED_CDS")" )
  VIASH_PAR_SPLICED_CDS=$(ViashDockerAutodetectMount "$VIASH_PAR_SPLICED_CDS")
fi
if [ ! -z "$VIASH_PAR_TR_CDS" ]; then
  VIASH_DIRECTORY_MOUNTS+=( "$(ViashDockerAutodetectMountArg "$VIASH_PAR_TR_CDS")" )
  VIASH_PAR_TR_CDS=$(ViashDockerAutodetectMount "$VIASH_PAR_TR_CDS")
fi
if [ ! -z "$VIASH_PAR_IDS" ]; then
  VIASH_DIRECTORY_MOUNTS+=( "$(ViashDockerAutodetectMountArg "$VIASH_PAR_IDS")" )
  VIASH_PAR_IDS=$(ViashDockerAutodetectMount "$VIASH_PAR_IDS")
fi
if [ ! -z "$VIASH_PAR_NIDS" ]; then
  VIASH_DIRECTORY_MOUNTS+=( "$(ViashDockerAutodetectMountArg "$VIASH_PAR_NIDS")" )
  VIASH_PAR_NIDS=$(ViashDockerAutodetectMount "$VIASH_PAR_NIDS")
fi
if [ ! -z "$VIASH_PAR_SORT_BY" ]; then
  VIASH_DIRECTORY_MOUNTS+=( "$(ViashDockerAutodetectMountArg "$VIASH_PAR_SORT_BY")" )
  VIASH_PAR_SORT_BY=$(ViashDockerAutodetectMount "$VIASH_PAR_SORT_BY")
fi
if [ ! -z "$VIASH_PAR_DUPINFO" ]; then
  VIASH_DIRECTORY_MOUNTS+=( "$(ViashDockerAutodetectMountArg "$VIASH_PAR_DUPINFO")" )
  VIASH_PAR_DUPINFO=$(ViashDockerAutodetectMount "$VIASH_PAR_DUPINFO")
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-gffread-XXXXXX").sh
function clean_up {
  rm "\$tempscript"
}
function interrupt {
  echo -e "\nCTRL-C Pressed..."
  exit 1
}
trap clean_up EXIT
trap interrupt INT SIGINT
cat > "\$tempscript" << 'VIASHMAIN'
#!/bin/bash

## VIASH START
# The following code has been auto-generated by Viash.
$( if [ ! -z ${VIASH_PAR_INPUT+x} ]; then echo "${VIASH_PAR_INPUT}" | sed "s#'#'\"'\"'#g;s#.*#par_input='&'#" ; else echo "# par_input="; fi )
$( if [ ! -z ${VIASH_PAR_CHR_MAPPING+x} ]; then echo "${VIASH_PAR_CHR_MAPPING}" | sed "s#'#'\"'\"'#g;s#.*#par_chr_mapping='&'#" ; else echo "# par_chr_mapping="; fi )
$( if [ ! -z ${VIASH_PAR_SEQ_INFO+x} ]; then echo "${VIASH_PAR_SEQ_INFO}" | sed "s#'#'\"'\"'#g;s#.*#par_seq_info='&'#" ; else echo "# par_seq_info="; fi )
$( if [ ! -z ${VIASH_PAR_GENOME+x} ]; then echo "${VIASH_PAR_GENOME}" | sed "s#'#'\"'\"'#g;s#.*#par_genome='&'#" ; else echo "# par_genome="; fi )
$( if [ ! -z ${VIASH_PAR_OUTFILE+x} ]; then echo "${VIASH_PAR_OUTFILE}" | sed "s#'#'\"'\"'#g;s#.*#par_outfile='&'#" ; else echo "# par_outfile="; fi )
$( if [ ! -z ${VIASH_PAR_FORCE_EXONS+x} ]; then echo "${VIASH_PAR_FORCE_EXONS}" | sed "s#'#'\"'\"'#g;s#.*#par_force_exons='&'#" ; else echo "# par_force_exons="; fi )
$( if [ ! -z ${VIASH_PAR_GENE2EXON+x} ]; then echo "${VIASH_PAR_GENE2EXON}" | sed "s#'#'\"'\"'#g;s#.*#par_gene2exon='&'#" ; else echo "# par_gene2exon="; fi )
$( if [ ! -z ${VIASH_PAR_T_ADOPT+x} ]; then echo "${VIASH_PAR_T_ADOPT}" | sed "s#'#'\"'\"'#g;s#.*#par_t_adopt='&'#" ; else echo "# par_t_adopt="; fi )
$( if [ ! -z ${VIASH_PAR_DECODE+x} ]; then echo "${VIASH_PAR_DECODE}" | sed "s#'#'\"'\"'#g;s#.*#par_decode='&'#" ; else echo "# par_decode="; fi )
$( if [ ! -z ${VIASH_PAR_MERGE_EXONS+x} ]; then echo "${VIASH_PAR_MERGE_EXONS}" | sed "s#'#'\"'\"'#g;s#.*#par_merge_exons='&'#" ; else echo "# par_merge_exons="; fi )
$( if [ ! -z ${VIASH_PAR_JUNCTIONS+x} ]; then echo "${VIASH_PAR_JUNCTIONS}" | sed "s#'#'\"'\"'#g;s#.*#par_junctions='&'#" ; else echo "# par_junctions="; fi )
$( if [ ! -z ${VIASH_PAR_SPLICED_EXONS+x} ]; then echo "${VIASH_PAR_SPLICED_EXONS}" | sed "s#'#'\"'\"'#g;s#.*#par_spliced_exons='&'#" ; else echo "# par_spliced_exons="; fi )
$( if [ ! -z ${VIASH_PAR_W_ADD+x} ]; then echo "${VIASH_PAR_W_ADD}" | sed "s#'#'\"'\"'#g;s#.*#par_w_add='&'#" ; else echo "# par_w_add="; fi )
$( if [ ! -z ${VIASH_PAR_W_NOCDS+x} ]; then echo "${VIASH_PAR_W_NOCDS}" | sed "s#'#'\"'\"'#g;s#.*#par_w_nocds='&'#" ; else echo "# par_w_nocds="; fi )
$( if [ ! -z ${VIASH_PAR_SPLICED_CDS+x} ]; then echo "${VIASH_PAR_SPLICED_CDS}" | sed "s#'#'\"'\"'#g;s#.*#par_spliced_cds='&'#" ; else echo "# par_spliced_cds="; fi )
$( if [ ! -z ${VIASH_PAR_TR_CDS+x} ]; then echo "${VIASH_PAR_TR_CDS}" | sed "s#'#'\"'\"'#g;s#.*#par_tr_cds='&'#" ; else echo "# par_tr_cds="; fi )
$( if [ ! -z ${VIASH_PAR_W_COORDS+x} ]; then echo "${VIASH_PAR_W_COORDS}" | sed "s#'#'\"'\"'#g;s#.*#par_w_coords='&'#" ; else echo "# par_w_coords="; fi )
$( if [ ! -z ${VIASH_PAR_STOP_DOT+x} ]; then echo "${VIASH_PAR_STOP_DOT}" | sed "s#'#'\"'\"'#g;s#.*#par_stop_dot='&'#" ; else echo "# par_stop_dot="; fi )
$( if [ ! -z ${VIASH_PAR_ID_VERSION+x} ]; then echo "${VIASH_PAR_ID_VERSION}" | sed "s#'#'\"'\"'#g;s#.*#par_id_version='&'#" ; else echo "# par_id_version="; fi )
$( if [ ! -z ${VIASH_PAR_TRACKNAME+x} ]; then echo "${VIASH_PAR_TRACKNAME}" | sed "s#'#'\"'\"'#g;s#.*#par_trackname='&'#" ; else echo "# par_trackname="; fi )
$( if [ ! -z ${VIASH_PAR_GTF_OUTPUT+x} ]; then echo "${VIASH_PAR_GTF_OUTPUT}" | sed "s#'#'\"'\"'#g;s#.*#par_gtf_output='&'#" ; else echo "# par_gtf_output="; fi )
$( if [ ! -z ${VIASH_PAR_BED+x} ]; then echo "${VIASH_PAR_BED}" | sed "s#'#'\"'\"'#g;s#.*#par_bed='&'#" ; else echo "# par_bed="; fi )
$( if [ ! -z ${VIASH_PAR_TLF+x} ]; then echo "${VIASH_PAR_TLF}" | sed "s#'#'\"'\"'#g;s#.*#par_tlf='&'#" ; else echo "# par_tlf="; fi )
$( if [ ! -z ${VIASH_PAR_TABLE+x} ]; then echo "${VIASH_PAR_TABLE}" | sed "s#'#'\"'\"'#g;s#.*#par_table='&'#" ; else echo "# par_table="; fi )
$( if [ ! -z ${VIASH_PAR_EXPOSE_DUPS+x} ]; then echo "${VIASH_PAR_EXPOSE_DUPS}" | sed "s#'#'\"'\"'#g;s#.*#par_expose_dups='&'#" ; else echo "# par_expose_dups="; fi )
$( if [ ! -z ${VIASH_PAR_IDS+x} ]; then echo "${VIASH_PAR_IDS}" | sed "s#'#'\"'\"'#g;s#.*#par_ids='&'#" ; else echo "# par_ids="; fi )
$( if [ ! -z ${VIASH_PAR_NIDS+x} ]; then echo "${VIASH_PAR_NIDS}" | sed "s#'#'\"'\"'#g;s#.*#par_nids='&'#" ; else echo "# par_nids="; fi )
$( if [ ! -z ${VIASH_PAR_MAXINTRON+x} ]; then echo "${VIASH_PAR_MAXINTRON}" | sed "s#'#'\"'\"'#g;s#.*#par_maxintron='&'#" ; else echo "# par_maxintron="; fi )
$( if [ ! -z ${VIASH_PAR_MINLEN+x} ]; then echo "${VIASH_PAR_MINLEN}" | sed "s#'#'\"'\"'#g;s#.*#par_minlen='&'#" ; else echo "# par_minlen="; fi )
$( if [ ! -z ${VIASH_PAR_RANGE+x} ]; then echo "${VIASH_PAR_RANGE}" | sed "s#'#'\"'\"'#g;s#.*#par_range='&'#" ; else echo "# par_range="; fi )
$( if [ ! -z ${VIASH_PAR_STRICT_RANGE+x} ]; then echo "${VIASH_PAR_STRICT_RANGE}" | sed "s#'#'\"'\"'#g;s#.*#par_strict_range='&'#" ; else echo "# par_strict_range="; fi )
$( if [ ! -z ${VIASH_PAR_JMATCH+x} ]; then echo "${VIASH_PAR_JMATCH}" | sed "s#'#'\"'\"'#g;s#.*#par_jmatch='&'#" ; else echo "# par_jmatch="; fi )
$( if [ ! -z ${VIASH_PAR_NO_SINGLE_EXON+x} ]; then echo "${VIASH_PAR_NO_SINGLE_EXON}" | sed "s#'#'\"'\"'#g;s#.*#par_no_single_exon='&'#" ; else echo "# par_no_single_exon="; fi )
$( if [ ! -z ${VIASH_PAR_CODING+x} ]; then echo "${VIASH_PAR_CODING}" | sed "s#'#'\"'\"'#g;s#.*#par_coding='&'#" ; else echo "# par_coding="; fi )
$( if [ ! -z ${VIASH_PAR_NC+x} ]; then echo "${VIASH_PAR_NC}" | sed "s#'#'\"'\"'#g;s#.*#par_nc='&'#" ; else echo "# par_nc="; fi )
$( if [ ! -z ${VIASH_PAR_IGNORE_LOCUS+x} ]; then echo "${VIASH_PAR_IGNORE_LOCUS}" | sed "s#'#'\"'\"'#g;s#.*#par_ignore_locus='&'#" ; else echo "# par_ignore_locus="; fi )
$( if [ ! -z ${VIASH_PAR_DESCRIPTION+x} ]; then echo "${VIASH_PAR_DESCRIPTION}" | sed "s#'#'\"'\"'#g;s#.*#par_description='&'#" ; else echo "# par_description="; fi )
$( if [ ! -z ${VIASH_PAR_SORT_ALPHA+x} ]; then echo "${VIASH_PAR_SORT_ALPHA}" | sed "s#'#'\"'\"'#g;s#.*#par_sort_alpha='&'#" ; else echo "# par_sort_alpha="; fi )
$( if [ ! -z ${VIASH_PAR_SORT_BY+x} ]; then echo "${VIASH_PAR_SORT_BY}" | sed "s#'#'\"'\"'#g;s#.*#par_sort_by='&'#" ; else echo "# par_sort_by="; fi )
$( if [ ! -z ${VIASH_PAR_KEEP_ATTRS+x} ]; then echo "${VIASH_PAR_KEEP_ATTRS}" | sed "s#'#'\"'\"'#g;s#.*#par_keep_attrs='&'#" ; else echo "# par_keep_attrs="; fi )
$( if [ ! -z ${VIASH_PAR_KEEP_EXON_ATTRS+x} ]; then echo "${VIASH_PAR_KEEP_EXON_ATTRS}" | sed "s#'#'\"'\"'#g;s#.*#par_keep_exon_attrs='&'#" ; else echo "# par_keep_exon_attrs="; fi )
$( if [ ! -z ${VIASH_PAR_NO_EXON_ATTRS+x} ]; then echo "${VIASH_PAR_NO_EXON_ATTRS}" | sed "s#'#'\"'\"'#g;s#.*#par_no_exon_attrs='&'#" ; else echo "# par_no_exon_attrs="; fi )
$( if [ ! -z ${VIASH_PAR_ATTRS+x} ]; then echo "${VIASH_PAR_ATTRS}" | sed "s#'#'\"'\"'#g;s#.*#par_attrs='&'#" ; else echo "# par_attrs="; fi )
$( if [ ! -z ${VIASH_PAR_KEEP_GENES+x} ]; then echo "${VIASH_PAR_KEEP_GENES}" | sed "s#'#'\"'\"'#g;s#.*#par_keep_genes='&'#" ; else echo "# par_keep_genes="; fi )
$( if [ ! -z ${VIASH_PAR_KEEP_COMMENTS+x} ]; then echo "${VIASH_PAR_KEEP_COMMENTS}" | sed "s#'#'\"'\"'#g;s#.*#par_keep_comments='&'#" ; else echo "# par_keep_comments="; fi )
$( if [ ! -z ${VIASH_PAR_PROCESS_OTHER+x} ]; then echo "${VIASH_PAR_PROCESS_OTHER}" | sed "s#'#'\"'\"'#g;s#.*#par_process_other='&'#" ; else echo "# par_process_other="; fi )
$( if [ ! -z ${VIASH_PAR_RM_STOP_CODONS+x} ]; then echo "${VIASH_PAR_RM_STOP_CODONS}" | sed "s#'#'\"'\"'#g;s#.*#par_rm_stop_codons='&'#" ; else echo "# par_rm_stop_codons="; fi )
$( if [ ! -z ${VIASH_PAR_ADJ_CDS_START+x} ]; then echo "${VIASH_PAR_ADJ_CDS_START}" | sed "s#'#'\"'\"'#g;s#.*#par_adj_cds_start='&'#" ; else echo "# par_adj_cds_start="; fi )
$( if [ ! -z ${VIASH_PAR_OPPOSITE_STRAND+x} ]; then echo "${VIASH_PAR_OPPOSITE_STRAND}" | sed "s#'#'\"'\"'#g;s#.*#par_opposite_strand='&'#" ; else echo "# par_opposite_strand="; fi )
$( if [ ! -z ${VIASH_PAR_CODING_STATUS+x} ]; then echo "${VIASH_PAR_CODING_STATUS}" | sed "s#'#'\"'\"'#g;s#.*#par_coding_status='&'#" ; else echo "# par_coding_status="; fi )
$( if [ ! -z ${VIASH_PAR_ADD_HASCDS+x} ]; then echo "${VIASH_PAR_ADD_HASCDS}" | sed "s#'#'\"'\"'#g;s#.*#par_add_hasCDS='&'#" ; else echo "# par_add_hasCDS="; fi )
$( if [ ! -z ${VIASH_PAR_ADJ_STOP+x} ]; then echo "${VIASH_PAR_ADJ_STOP}" | sed "s#'#'\"'\"'#g;s#.*#par_adj_stop='&'#" ; else echo "# par_adj_stop="; fi )
$( if [ ! -z ${VIASH_PAR_RM_NONCANON+x} ]; then echo "${VIASH_PAR_RM_NONCANON}" | sed "s#'#'\"'\"'#g;s#.*#par_rm_noncanon='&'#" ; else echo "# par_rm_noncanon="; fi )
$( if [ ! -z ${VIASH_PAR_COMPLETE_CDS+x} ]; then echo "${VIASH_PAR_COMPLETE_CDS}" | sed "s#'#'\"'\"'#g;s#.*#par_complete_cds='&'#" ; else echo "# par_complete_cds="; fi )
$( if [ ! -z ${VIASH_PAR_NO_PSEUDO+x} ]; then echo "${VIASH_PAR_NO_PSEUDO}" | sed "s#'#'\"'\"'#g;s#.*#par_no_pseudo='&'#" ; else echo "# par_no_pseudo="; fi )
$( if [ ! -z ${VIASH_PAR_IN_BED+x} ]; then echo "${VIASH_PAR_IN_BED}" | sed "s#'#'\"'\"'#g;s#.*#par_in_bed='&'#" ; else echo "# par_in_bed="; fi )
$( if [ ! -z ${VIASH_PAR_IN_TLF+x} ]; then echo "${VIASH_PAR_IN_TLF}" | sed "s#'#'\"'\"'#g;s#.*#par_in_tlf='&'#" ; else echo "# par_in_tlf="; fi )
$( if [ ! -z ${VIASH_PAR_STREAM+x} ]; then echo "${VIASH_PAR_STREAM}" | sed "s#'#'\"'\"'#g;s#.*#par_stream='&'#" ; else echo "# par_stream="; fi )
$( if [ ! -z ${VIASH_PAR_MERGE+x} ]; then echo "${VIASH_PAR_MERGE}" | sed "s#'#'\"'\"'#g;s#.*#par_merge='&'#" ; else echo "# par_merge="; fi )
$( if [ ! -z ${VIASH_PAR_DUPINFO+x} ]; then echo "${VIASH_PAR_DUPINFO}" | sed "s#'#'\"'\"'#g;s#.*#par_dupinfo='&'#" ; else echo "# par_dupinfo="; fi )
$( if [ ! -z ${VIASH_PAR_CLUSTER_ONLY+x} ]; then echo "${VIASH_PAR_CLUSTER_ONLY}" | sed "s#'#'\"'\"'#g;s#.*#par_cluster_only='&'#" ; else echo "# par_cluster_only="; fi )
$( if [ ! -z ${VIASH_PAR_RM_REDUNDANT+x} ]; then echo "${VIASH_PAR_RM_REDUNDANT}" | sed "s#'#'\"'\"'#g;s#.*#par_rm_redundant='&'#" ; else echo "# par_rm_redundant="; fi )
$( if [ ! -z ${VIASH_PAR_NO_BOUNDARY+x} ]; then echo "${VIASH_PAR_NO_BOUNDARY}" | sed "s#'#'\"'\"'#g;s#.*#par_no_boundary='&'#" ; else echo "# par_no_boundary="; 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_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

# unset flags
unset_if_false=(
    par_coding
    par_strict_range
    par_no_single_exon
    par_no_exon_attrs
    par_nc
    par_ignore_locus
    par_description
    par_sort_alpha
    par_keep_genes
    par_keep_attrs
    par_keep_exon_attrs
    par_keep_comments
    par_process_other
    par_rm_stop_codons
    par_adj_cds_start
    par_opposite_strand
    par_coding_status
    par_add_hasCDS
    par_adj_stop
    par_rm_noncanon
    par_complete_cds
    par_no_pseudo
    par_in_bed
    par_in_tlf
    par_stream
    par_merge
    par_rm_redundant
    par_no_boundary
    par_no_overlap
    par_force_exons
    par_gene2exon
    par_t_adopt
    par_decode
    par_merge_exons
    par_junctions
    par_w_nocds
    par_tr_cds
    par_w_coords
    par_stop_dot
    par_id_version
    par_gtf_output
    par_bed
    par_tlf
    par_expose_dups
    par_cluster_only
)

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

# if par_table is not empty, replace ";" with ","
par_table=\$(echo "\$par_table" | tr ';' ',')

\$(which gffread) \\
    "\$par_input" \\
    \${par_chr_mapping:+-m "\$par_chr_mapping"} \\
    \${par_seq_info:+-s "\$par_seq_info"} \\
    -o "\$par_outfile" \\
    \${par_force_exons:+--force-exons} \\
    \${par_gene2exon:+--gene2exon} \\
    \${par_t_adopt:+--t-adopt} \\
    \${par_decode:+-D} \\
    \${par_merge_exons:+-Z} \\
    \${par_genome:+-g "\$par_genome"} \\
    \${par_junctions:+-j} \\
    \${par_spliced_exons:+-w "\$par_spliced_exons"} \\
    \${par_w_add:+--w-add "\$par_w_add"} \\
    \${par_w_nocds:+--w-nocds} \\
    \${par_spliced_cds:+-x "\$par_spliced_cds"} \\
    \${par_tr_cds:+-y "\$par_tr_cds"} \\
    \${par_w_coords:+-W} \\
    \${par_stop_dot:+-S} \\
    \${par_id_version:+-L} \\
    \${par_trackname:+-t "\$par_trackname"} \\
    \${par_gtf_output:+-T} \\
    \${par_bed:+--bed} \\
    \${par_tlf:+--tlf} \\
    \${par_table:+--table "\$par_table"} \\
    \${par_expose_dups:+-E} \\
    \${par_ids:+--ids "\$par_ids"} \\
    \${par_nids:+--nids "\$par_nids"} \\
    \${par_maxintron:+-i "\$par_maxintron"} \\
    \${par_minlen:+-l "\$par_minlen"} \\
    \${par_range:+-r "\$par_range"} \\
    \${par_strict_range:+-R} \\
    \${par_jmatch:+--jmatch "\$par_jmatch"} \\
    \${par_no_single_exon:+-U} \\
    \${par_coding:+-C} \\
    \${par_nc:+--nc} \\
    \${par_ignore_locus:+--ignore-locus} \\
    \${par_description:+-A} \\
    \${par_sort_alpha:+--sort-alpha} \\
    \${par_sort_by:+--sort-by "\$par_sort_by"} \\
    \${par_keep_attrs:+-F} \\
    \${par_keep_exon_attrs:+--keep-exon-attrs} \\
    \${par_no_exon_attrs:+-G} \\
    \${par_attrs:+--attrs "\$par_attrs"} \\
    \${par_keep_genes:+--keep-genes} \\
    \${par_keep_comments:+--keep-comments} \\
    \${par_process_other:+-O} \\
    \${par_rm_stop_codons:+-V} \\
    \${par_adj_cds_start:+-H} \\
    \${par_opposite_strand:+-B} \\
    \${par_coding_status:+-P} \\
    \${par_add_hasCDS:+--add-hasCDS} \\
    \${par_adj_stop:+--adj-stop} \\
    \${par_rm_noncanon:+-N} \\
    \${par_complete_cds:+-J} \\
    \${par_no_pseudo:+--no-pseudo} \\
    \${par_in_bed:+--in-bed} \\
    \${par_in_tlf:+--in-tlf} \\
    \${par_stream:+--stream} \\
    \${par_merge:+-M} \\
    \${par_dupinfo:+-d "\$par_dupinfo"} \\
    \${par_cluster_only:+--cluster-only} \\
    \${par_rm_redundant:+-K} \\
    \${par_no_boundary:+-Q} \\
    \${par_no_overlap:+-Y} 
VIASHMAIN
bash "\$tempscript" &
wait "\$!"

VIASHEOF


if [[ "$VIASH_ENGINE_TYPE" == "docker" ]]; then
  # strip viash automount from file paths
  
  if [ ! -z "$VIASH_PAR_INPUT" ]; then
    VIASH_PAR_INPUT=$(ViashDockerStripAutomount "$VIASH_PAR_INPUT")
  fi
  if [ ! -z "$VIASH_PAR_CHR_MAPPING" ]; then
    VIASH_PAR_CHR_MAPPING=$(ViashDockerStripAutomount "$VIASH_PAR_CHR_MAPPING")
  fi
  if [ ! -z "$VIASH_PAR_SEQ_INFO" ]; then
    VIASH_PAR_SEQ_INFO=$(ViashDockerStripAutomount "$VIASH_PAR_SEQ_INFO")
  fi
  if [ ! -z "$VIASH_PAR_GENOME" ]; then
    VIASH_PAR_GENOME=$(ViashDockerStripAutomount "$VIASH_PAR_GENOME")
  fi
  if [ ! -z "$VIASH_PAR_OUTFILE" ]; then
    VIASH_PAR_OUTFILE=$(ViashDockerStripAutomount "$VIASH_PAR_OUTFILE")
  fi
  if [ ! -z "$VIASH_PAR_SPLICED_EXONS" ]; then
    VIASH_PAR_SPLICED_EXONS=$(ViashDockerStripAutomount "$VIASH_PAR_SPLICED_EXONS")
  fi
  if [ ! -z "$VIASH_PAR_SPLICED_CDS" ]; then
    VIASH_PAR_SPLICED_CDS=$(ViashDockerStripAutomount "$VIASH_PAR_SPLICED_CDS")
  fi
  if [ ! -z "$VIASH_PAR_TR_CDS" ]; then
    VIASH_PAR_TR_CDS=$(ViashDockerStripAutomount "$VIASH_PAR_TR_CDS")
  fi
  if [ ! -z "$VIASH_PAR_IDS" ]; then
    VIASH_PAR_IDS=$(ViashDockerStripAutomount "$VIASH_PAR_IDS")
  fi
  if [ ! -z "$VIASH_PAR_NIDS" ]; then
    VIASH_PAR_NIDS=$(ViashDockerStripAutomount "$VIASH_PAR_NIDS")
  fi
  if [ ! -z "$VIASH_PAR_SORT_BY" ]; then
    VIASH_PAR_SORT_BY=$(ViashDockerStripAutomount "$VIASH_PAR_SORT_BY")
  fi
  if [ ! -z "$VIASH_PAR_DUPINFO" ]; then
    VIASH_PAR_DUPINFO=$(ViashDockerStripAutomount "$VIASH_PAR_DUPINFO")
  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_OUTFILE" ] && [ ! -e "$VIASH_PAR_OUTFILE" ]; then
  ViashError "Output file '$VIASH_PAR_OUTFILE' does not exist."
  exit 1
fi


exit 0
