#!/usr/bin/env bash

# rsem_calculate_expression add_bases2fastq
# 
# 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.

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="rsem_calculate_expression"
VIASH_META_FUNCTIONALITY_NAME="rsem_calculate_expression"
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 "rsem_calculate_expression add_bases2fastq"
  echo ""
  echo "Calculate expression with RSEM."
  echo ""
  echo "Input:"
  echo "    --id"
  echo "        type: string"
  echo "        Sample ID."
  echo ""
  echo "    --strandedness"
  echo "        type: string"
  echo "        choices: [ forward, reverse, unstranded ]"
  echo "        Sample strand-specificity. Must be one of unstranded, forward, reverse"
  echo ""
  echo "    --paired"
  echo "        type: boolean_true"
  echo "        Paired-end reads or not?"
  echo ""
  echo "    --input"
  echo "        type: file, multiple values allowed, file must exist"
  echo "        Input reads for quantification."
  echo ""
  echo "    --index"
  echo "        type: file"
  echo "        RSEM index."
  echo ""
  echo "    --extra_args"
  echo "        type: string"
  echo "        Extra rsem-calculate-expression arguments in addition to the examples."
  echo ""
  echo "Output:"
  echo "    --counts_gene"
  echo "        type: file, output, file must exist"
  echo "        example: \$id.genes.results"
  echo "        Expression counts on gene level"
  echo ""
  echo "    --counts_transcripts"
  echo "        type: file, output, file must exist"
  echo "        example: \$id.isoforms.results"
  echo "        Expression counts on transcript level"
  echo ""
  echo "    --stat"
  echo "        type: file, output, file must exist"
  echo "        example: \$id.stat"
  echo "        RSEM statistics"
  echo ""
  echo "    --logs"
  echo "        type: file, output, file must exist"
  echo "        example: \$id.log"
  echo "        RSEM logs"
  echo ""
  echo "    --bam_star"
  echo "        type: file, output, file must exist"
  echo "        example: \$id.STAR.genome.bam"
  echo "        BAM file generated by STAR (optional)"
  echo ""
  echo "    --bam_genome"
  echo "        type: file, output, file must exist"
  echo "        example: \$id.genome.bam"
  echo "        Genome BAM file (optional)"
  echo ""
  echo "    --bam_transcript"
  echo "        type: file, output, file must exist"
  echo "        example: \$id.transcript.bam"
  echo "        Transcript BAM file (optional)"
  echo ""
  echo "    --sort_bam_by_read_name"
  echo "        type: boolean_true"
  echo "        Sort BAM file aligned under transcript coordidate by read name. Setting"
  echo "        this option on will produce"
  echo "        deterministic maximum likelihood estimations from independent runs. Note"
  echo "        that sorting will take long"
  echo "        time and lots of memory."
  echo ""
  echo "    --no_bam_output"
  echo "        type: boolean_true"
  echo "        Do not output any BAM file."
  echo ""
  echo "    --sampling_for_bam"
  echo "        type: boolean_true"
  echo "        When RSEM generates a BAM file, instead of outputting all alignments a"
  echo "        read has with their posterior"
  echo "        probabilities, one alignment is sampled according to the posterior"
  echo "        probabilities. The sampling procedure"
  echo "        includes the alignment to the \"noise\" transcript, which does not appear"
  echo "        in the BAM file. Only the"
  echo "        sampled alignment has a weight of 1. All other alignments have weight 0."
  echo "        If the \"noise\" transcript is"
  echo "        sampled, all alignments appeared in the BAM file should have weight 0."
  echo ""
  echo "    --output_genome_bam"
  echo "        type: boolean_true"
  echo "        Generate a BAM file, 'sample_name.genome.bam', with alignments mapped to"
  echo "        genomic coordinates and"
  echo "        annotated with their posterior probabilities. In addition, RSEM will"
  echo "        call samtools (included in RSEM"
  echo "        package) to sort and index the bam file. 'sample_name.genome.sorted.bam'"
  echo "        and 'sample_name.genome.sorted.bam.bai'"
  echo "        will be generated."
  echo ""
  echo "    --sort_bam_by_coordinate"
  echo "        type: boolean_true"
  echo "        Sort RSEM generated transcript and genome BAM files by coordinates and"
  echo "        build associated indices."
  echo ""
  echo "Basic Options:"
  echo "    --no_qualities"
  echo "        type: boolean_true"
  echo "        Input reads do not contain quality scores."
  echo ""
  echo "    --alignments"
  echo "        type: boolean_true"
  echo "        Input file contains alignments in SAM/BAM/CRAM format. The exact file"
  echo "        format will be determined"
  echo "        automatically."
  echo ""
  echo "    --fai"
  echo "        type: file, file must exist"
  echo "        If the header section of input alignment file does not contain reference"
  echo "        sequence information,"
  echo "        this option should be turned on. <file> is a FAI format file containing"
  echo "        each reference sequence's"
  echo "        name and length. Please refer to the SAM official website for the"
  echo "        details of FAI format."
  echo ""
  echo "    --bowtie2"
  echo "        type: boolean_true"
  echo "        Use Bowtie 2 instead of Bowtie to align reads. Since currently RSEM does"
  echo "        not handle indel, local"
  echo "        and discordant alignments, the Bowtie2 parameters are set in a way to"
  echo "        avoid those alignments. In"
  echo "        particular, we use options '--sensitive --dpad 0 --gbar 99999999 --mp"
  echo "        1,1 --np 1 --score_min L,0,-0.1'"
  echo "        by default. The last parameter of '--score_min', '-0.1', is the negative"
  echo "        of maximum mismatch rate."
  echo "        This rate can be set by option '--bowtie2_mismatch_rate'. If reads are"
  echo "        paired-end, we additionally"
  echo "        use options '--no_mixed' and '--no_discordant'."
  echo ""
  echo "    --star"
  echo "        type: boolean_true"
  echo "        Use STAR to align reads. Alignment parameters are from ENCODE3's"
  echo "        STAR-RSEM pipeline. To save"
  echo "        computational time and memory resources, STAR's Output BAM file is"
  echo "        unsorted. It is stored in RSEM's"
  echo "        temporary directory with name as 'sample_name.bam'. Each STAR job will"
  echo "        have its own private copy of"
  echo "        the genome in memory."
  echo ""
  echo "    --hisat2_hca"
  echo "        type: boolean_true"
  echo "        Use HISAT2 to align reads to the transcriptome according to Human Cell"
  echo "        Atlast."
  echo ""
  echo "    --append_names"
  echo "        type: boolean_true"
  echo "        If gene_name/transcript_name is available, append it to the end of"
  echo "        gene_id/transcript_id (separated"
  echo "        by '_') in files 'sample_name.isoforms.results' and"
  echo "        'sample_name.genes.results'."
  echo ""
  echo "    --seed"
  echo "        type: integer"
  echo "        Set the seed for the random number generators used in calculating"
  echo "        posterior mean estimates and"
  echo "        credibility intervals. The seed must be a non-negative 32 bit integer."
  echo ""
  echo "    --single_cell_prior"
  echo "        type: boolean_true"
  echo "        By default, RSEM uses Dirichlet(1) as the prior to calculate posterior"
  echo "        mean estimates and credibility"
  echo "        intervals. However, much less genes are expressed in single cell RNA-Seq"
  echo "        data. Thus, if you want to"
  echo "        compute posterior mean estimates and/or credibility intervals and you"
  echo "        have single-cell RNA-Seq data,"
  echo "        you are recommended to turn on this option. Then RSEM will use"
  echo "        Dirichlet(0.1) as the prior which"
  echo "        encourage the sparsity of the expression levels."
  echo ""
  echo "    --calc_pme"
  echo "        type: boolean_true"
  echo "        Run RSEM's collapsed Gibbs sampler to calculate posterior mean"
  echo "        estimates."
  echo ""
  echo "    --calc_ci"
  echo "        type: boolean_true"
  echo "        Calculate 95% credibility intervals and posterior mean estimates. The"
  echo "        credibility level can be"
  echo "        changed by setting '--ci_credibility_level'."
  echo ""
  echo "    -q, --quiet"
  echo "        type: boolean_true"
  echo "        Suppress the output of logging information."
  echo ""
  echo "Aligner Options:"
  echo "    --seed_length"
  echo "        type: integer"
  echo "        example: 25"
  echo "        Seed length used by the read aligner. Providing the correct value is"
  echo "        important for RSEM. If RSEM"
  echo "        runs Bowtie, it uses this value for Bowtie's seed length parameter. Any"
  echo "        read with its or at least"
  echo "        one of its mates' (for paired-end reads) length less than this value"
  echo "        will be ignored. If the"
  echo "        references are not added poly(A) tails, the minimum allowed value is 5,"
  echo "        otherwise, the minimum"
  echo "        allowed value is 25. Note that this script will only check if the value"
  echo "        >= 5 and give a warning"
  echo "        message if the value < 25 but >= 5. (Default: 25)"
  echo ""
  echo "    --phred64_quals"
  echo "        type: boolean_true"
  echo "        Input quality scores are encoded as Phred+64 (default for GA Pipeline"
  echo "        ver. >= 1.3). This option is"
  echo "        used by Bowtie, Bowtie 2 and HISAT2. Otherwise, quality score will be"
  echo "        encoded as Phred+33. (Default: false)"
  echo ""
  echo "    --solexa_quals"
  echo "        type: boolean_true"
  echo "        Input quality scores are solexa encoded (from GA Pipeline ver. < 1.3)."
  echo "        This option is used by"
  echo "        Bowtie, Bowtie 2 and HISAT2. Otherwise, quality score will be encoded as"
  echo "        Phred+33. (Default: false)"
  echo ""
  echo "    --bowtie_n"
  echo "        type: integer"
  echo "        example: 2"
  echo "        choices: [ 0, 1, 2, 3 ]"
  echo "        (Bowtie parameter) max # of mismatches in the seed. (Range: 0-3,"
  echo "        Default: 2)"
  echo ""
  echo "    --bowtie_e"
  echo "        type: integer"
  echo "        example: 99999999"
  echo "        (Bowtie parameter) max sum of mismatch quality scores across the"
  echo "        alignment. (Default: 99999999)"
  echo ""
  echo "    --bowtie_m"
  echo "        type: integer"
  echo "        example: 200"
  echo "        (Bowtie parameter) suppress all alignments for a read if > <int> valid"
  echo "        alignments exist. (Default: 200)"
  echo ""
  echo "    --bowtie_chunkmbs"
  echo "        type: integer"
  echo "        example: 0"
  echo "        (Bowtie parameter) memory allocated for best first alignment calculation"
  echo "        (Default: 0 - use Bowtie's default)"
  echo ""
  echo "    --bowtie2_mismatch_rate"
  echo "        type: double"
  echo "        example: 0.1"
  echo "        (Bowtie 2 parameter) The maximum mismatch rate allowed. (Default: 0.1)"
  echo ""
  echo "    --bowtie2_k"
  echo "        type: integer"
  echo "        example: 200"
  echo "        (Bowtie 2 parameter) Find up to <int> alignments per read. (Default:"
  echo "        200)"
  echo ""
  echo "    --bowtie2_sensitivity_level"
  echo "        type: string"
  echo "        example: sensitive"
  echo "        choices: [ very_fast, fast, sensitive, very_sensitive ]"
  echo "        (Bowtie 2 parameter) Set Bowtie 2's preset options in --end-to-end mode."
  echo "        This option controls how"
  echo "        hard Bowtie 2 tries to find alignments. <string> must be one of"
  echo "        \"very_fast\", \"fast\", \"sensitive\""
  echo "        and \"very_sensitive\". The four candidates correspond to Bowtie 2's"
  echo "        \"--very-fast\", \"--fast\","
  echo "        \"--sensitive\" and \"--very-sensitive\" options. (Default: \"sensitive\" -"
  echo "        use Bowtie 2's default)"
  echo ""
  echo "    --star_gzipped_read_file"
  echo "        type: boolean_true"
  echo "        Input read file(s) is compressed by gzip. (Default: false)"
  echo ""
  echo "    --star_bzipped_read_file"
  echo "        type: boolean_true"
  echo "        Input read file(s) is compressed by bzip2. (Default: false)"
  echo ""
  echo "    --star_output_genome_bam"
  echo "        type: boolean_true"
  echo "        Save the BAM file from STAR alignment under genomic coordinate to"
  echo "        'sample_name.STAR.genome.bam'."
  echo "        This file is NOT sorted by genomic coordinate. In this file, according"
  echo "        to STAR's manual, 'paired"
  echo "        ends of an alignment are always adjacent, and multiple alignments of a"
  echo "        read are adjacent as well'."
  echo "        (Default: false)"
  echo ""
  echo "Advanced Options:"
  echo "    --tag"
  echo "        type: string"
  echo "        example:"
  echo "        The name of the optional field used in the SAM input for identifying a"
  echo "        read with too many valid"
  echo "        alignments. The field should have the format <tagName>:i:<value>, where"
  echo "        a <value> bigger than 0"
  echo "        indicates a read with too many alignments. (Default: \"\")"
  echo ""
  echo "    --fragment_length_min"
  echo "        type: integer"
  echo "        example: 1"
  echo "        Minimum read/insert length allowed. This is also the value for the"
  echo "        Bowtie/Bowtie2 -I option."
  echo "        (Default: 1)"
  echo ""
  echo "    --fragment_length_max"
  echo "        type: integer"
  echo "        example: 1000"
  echo "        Maximum read/insert length allowed. This is also the value for the"
  echo "        Bowtie/Bowtie 2 -X option."
  echo "        (Default: 1000)"
  echo ""
  echo "    --fragment_length_mean"
  echo "        type: integer"
  echo "        example: -1"
  echo "        (single-end data only) The mean of the fragment length distribution,"
  echo "        which is assumed to be a"
  echo "        Gaussian. (Default: -1, which disables use of the fragment length"
  echo "        distribution)"
  echo ""
  echo "    --gragment_length_sd"
  echo "        type: double"
  echo "        example: 0.0"
  echo "        (single-end data only) The standard deviation of the fragment length"
  echo "        distribution, which is"
  echo "        assumed to be a Gaussian. (Default: 0, which assumes that all fragments"
  echo "        are of the same length,"
  echo "        given by the rounded value of --fragment_length_mean)."
  echo ""
  echo "    --estimate_rspd"
  echo "        type: boolean_true"
  echo "        Set this option if you want to estimate the read start position"
  echo "        distribution (RSPD) from data."
  echo "        Otherwise, RSEM will use a uniform RSPD."
  echo ""
  echo "    --num_rspd_bins"
  echo "        type: integer"
  echo "        example: 20"
  echo "        Number of bins in the RSPD. Only relevant when '--estimate_rspd' is"
  echo "        specified. Use of the default"
  echo "        setting is recommended. (Default: 20)"
  echo ""
  echo "    --gibbs_burnin"
  echo "        type: integer"
  echo "        example: 200"
  echo "        The number of burn-in rounds for RSEM's Gibbs sampler. Each round passes"
  echo "        over the entire data set"
  echo "        once. If RSEM can use multiple threads, multiple Gibbs samplers will"
  echo "        start at the same time and all"
  echo "        samplers share the same burn-in number. (Default: 200)"
  echo ""
  echo "    --gibbs_number_of_samples"
  echo "        type: integer"
  echo "        example: 1000"
  echo "        The total number of count vectors RSEM will collect from its Gibbs"
  echo "        samplers. (Default: 1000)"
  echo ""
  echo "    --gibbs_sampling_gap"
  echo "        type: integer"
  echo "        example: 1"
  echo "        The number of rounds between two succinct count vectors RSEM collects."
  echo "        If the count vector after"
  echo "        round N is collected, the count vector after round N + <int> will also"
  echo "        be collected. (Default: 1)"
  echo ""
  echo "    --ci_credibility_level"
  echo "        type: double"
  echo "        example: 0.95"
  echo "        The credibility level for credibility intervals. (Default: 0.95)"
  echo ""
  echo "    --ci_number_of_samples_per_count_vector"
  echo "        type: integer"
  echo "        example: 50"
  echo "        The number of read generating probability vectors sampled per sampled"
  echo "        count vector. The crebility"
  echo "        intervals are calculated by first sampling P(C | D) and then sampling"
  echo "        P(Theta | C) for each sampled"
  echo "        count vector. This option controls how many Theta vectors are sampled"
  echo "        per sampled count vector."
  echo "        (Default: 50)"
  echo ""
  echo "    --keep_intermediate_files"
  echo "        type: boolean_true"
  echo "        Keep temporary files generated by RSEM. RSEM creates a temporary"
  echo "        directory, 'sample_name.temp',"
  echo "        into which it puts all intermediate output files. If this directory"
  echo "        already exists, RSEM overwrites"
  echo "        all files generated by previous RSEM runs inside of it. By default,"
  echo "        after RSEM finishes, the"
  echo "        temporary directory is deleted. Set this option to prevent the deletion"
  echo "        of this directory and the"
  echo "        intermediate files inside of it."
  echo ""
  echo "    --temporary_folder"
  echo "        type: string"
  echo "        example: sample_name.temp"
  echo "        Set where to put the temporary files generated by RSEM. If the folder"
  echo "        specified does not exist,"
  echo "        RSEM will try to create it. (Default: sample_name.temp)"
  echo ""
  echo "    --time"
  echo "        type: boolean_true"
  echo "        Output time consumed by each step of RSEM to 'sample_name.time'."
  echo ""
  echo "Prior-Enhanced RSEM Options:"
  echo "    --run_pRSEM"
  echo "        type: boolean_true"
  echo "        Running prior-enhanced RSEM (pRSEM). Prior parameters, i.e. isoform's"
  echo "        initial pseudo-count for"
  echo "        RSEM's Gibbs sampling, will be learned from input RNA-seq data and an"
  echo "        external data set. When pRSEM"
  echo "        needs and only needs ChIP-seq peak information to partition isoforms"
  echo "        (e.g. in pRSEM's default"
  echo "        partition model), either ChIP-seq peak file (with the"
  echo "        '--chipseq_peak_file' option) or ChIP-seq"
  echo "        FASTQ files for target and input and the path for Bowtie executables are"
  echo "        required (with the"
  echo "        '--chipseq_target_read_files <string>', '--chipseq_control_read_files"
  echo "        <string>', and '--bowtie_path"
  echo "        <path> options), otherwise, ChIP-seq FASTQ files for target and control"
  echo "        and the path to Bowtie"
  echo "        executables are required."
  echo ""
  echo "    --chipseq_peak_file"
  echo "        type: file, file must exist"
  echo "        Full path to a ChIP-seq peak file in ENCODE's narrowPeak, i.e. BED6+4,"
  echo "        format. This file is used"
  echo "        when running prior-enhanced RSEM in the default two-partition model. It"
  echo "        partitions isoforms by"
  echo "        whether they have ChIP-seq overlapping with their transcription start"
  echo "        site region or not. Each"
  echo "        partition will have its own prior parameter learned from a training set."
  echo "        This file can be either"
  echo "        gzipped or ungzipped."
  echo ""
  echo "    --chipseq_target_read_files"
  echo "        type: file, file must exist"
  echo "        Comma-separated full path of FASTQ read file(s) for ChIP-seq target."
  echo "        This option is used when running"
  echo "        prior-enhanced RSEM. It provides information to calculate ChIP-seq peaks"
  echo "        and signals. The file(s)"
  echo "        can be either ungzipped or gzipped with a suffix '.gz' or '.gzip'. The"
  echo "        options '--bowtie_path <path>'"
  echo "        and '--chipseq_control_read_files <string>' must be defined when this"
  echo "        option is specified."
  echo ""
  echo "    --chipseq_control_read_files"
  echo "        type: file, file must exist"
  echo "        Comma-separated full path of FASTQ read file(s) for ChIP-seq conrol."
  echo "        This option is used when running"
  echo "        prior-enhanced RSEM. It provides information to call ChIP-seq peaks. The"
  echo "        file(s) can be either"
  echo "        ungzipped or gzipped with a suffix '.gz' or '.gzip'. The options"
  echo "        '--bowtie_path <path>' and"
  echo "        '--chipseq_target_read_files <string>' must be defined when this option"
  echo "        is specified."
  echo ""
  echo "    --chipseq_read_files_multi_targets"
  echo "        type: file, file must exist"
  echo "        Comma-separated full path of FASTQ read files for multiple ChIP-seq"
  echo "        targets. This option is used when"
  echo "        running prior-enhanced RSEM, where prior is learned from multiple"
  echo "        complementary data sets. It provides"
  echo "        information to calculate ChIP-seq signals. All files can be either"
  echo "        ungzipped or gzipped with a suffix"
  echo "        '.gz' or '.gzip'. When this option is specified, the option"
  echo "        '--bowtie_path <path>' must be defined and"
  echo "        the option '--partition_model <string>' will be set to 'cmb_lgt'"
  echo "        automatically."
  echo ""
  echo "    --chipseq_bed_files_multi_targets"
  echo "        type: file, file must exist"
  echo "        Comma-separated full path of BED files for multiple ChIP-seq targets."
  echo "        This option is used when running"
  echo "        prior-enhanced RSEM, where prior is learned from multiple complementary"
  echo "        data sets. It provides information"
  echo "        of ChIP-seq signals and must have at least the first six BED columns."
  echo "        All files can be either ungzipped"
  echo "        or gzipped with a suffix '.gz' or '.gzip'. When this option is"
  echo "        specified, the option '--partition_model"
  echo "        <string>' will be set to 'cmb_lgt' automatically."
  echo ""
  echo "    --cap_stacked_chipseq_reads"
  echo "        type: boolean_true"
  echo "        Keep a maximum number of ChIP-seq reads that aligned to the same genomic"
  echo "        interval. This option is used"
  echo "        when running prior-enhanced RSEM, where prior is learned from multiple"
  echo "        complementary data sets. This"
  echo "        option is only in use when either '--chipseq_read_files_multi_targets"
  echo "        <string>' or"
  echo "        '--chipseq_bed_files_multi_targets <string>' is specified."
  echo ""
  echo "    --n_max_stacked_chipseq_reads"
  echo "        type: integer"
  echo "        The maximum number of stacked ChIP-seq reads to keep. This option is"
  echo "        used when running prior-enhanced"
  echo "        RSEM, where prior is learned from multiple complementary data sets. This"
  echo "        option is only in use when the"
  echo "        option '--cap_stacked_chipseq_reads' is set."
  echo ""
  echo "    --partition_model"
  echo "        type: string"
  echo "        example: pk"
  echo "        A keyword to specify the partition model used by prior-enhanced RSEM. It"
  echo "        must be one of the following"
  echo "        keywords:"
  echo "        * pk"
  echo "        * pk_lgtnopk"
  echo "        * lm3, lm4, lm5, or lm6"
  echo "        * nopk_lm2pk, nopk_lm3pk, nopk_lm4pk, or nopk_lm5pk"
  echo "        * pk_lm2nopk, pk_lm3nopk, pk_lm4nopk, or pk_lm5nopk"
  echo "        * cmb_lgt"
  echo "        Parameters for all the above models are learned from a training set. For"
  echo "        detailed explanations, please"
  echo "        see prior-enhanced RSEM's paper. (Default: 'pk')"
}

# 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 ubuntu:22.04
ENTRYPOINT []
RUN apt-get update && \
  DEBIAN_FRONTEND=noninteractive apt-get install -y build-essential gcc g++ make wget zlib1g-dev unzip && \
  rm -rf /var/lib/apt/lists/*

ENV STAR_VERSION=2.7.11b
ENV RSEM_VERSION=1.3.3
RUN apt-get update && \
apt-get clean && \
wget --no-check-certificate https://github.com/alexdobin/STAR/archive/refs/tags/2.7.11a.zip && \
unzip 2.7.11a.zip && \
cp STAR-2.7.11a/bin/Linux_x86_64_static/STAR /usr/local/bin  && \
cd && \
wget --no-check-certificate https://github.com/deweylab/RSEM/archive/refs/tags/v1.3.3.zip && \
unzip v1.3.3.zip && \
cd RSEM-1.3.3 && \
make && \
make install

RUN echo "RSEM: `rsem-calculate-expression --version | sed -e 's/Current version: RSEM v//g'`" > /var/software_versions.txt && \
echo "STAR: `STAR --version`" >> /var/software_versions.txt && \
echo "bowtie2: `bowtie2 --version | grep -oP '\d+\.\d+\.\d+'`" >> /var/software_versions.txt && \
echo "bowtie: `bowtie --version | grep -oP 'bowtie-align-s version \K\d+\.\d+\.\d+'`" >> /var/software_versions.txt && \
echo "HISAT2: `hisat2 --version | grep -oP 'hisat2-align-s version \K\d+\.\d+\.\d+'`" >> /var/software_versions.txt

LABEL org.opencontainers.image.description="Companion container for running component rsem rsem_calculate_expression"
LABEL org.opencontainers.image.created="2024-11-26T11:31:27Z"
LABEL org.opencontainers.image.source="https://github.com/deweylab/RSEM"
LABEL org.opencontainers.image.revision="57cdff4c714136520441e853a5a746118427c65c"
LABEL org.opencontainers.image.version="add_bases2fastq"

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 "rsem_calculate_expression add_bases2fastq"
            exit
            ;;
        --id)
            [ -n "$VIASH_PAR_ID" ] && ViashError Bad arguments for option \'--id\': \'$VIASH_PAR_ID\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_ID="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --id. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --id=*)
            [ -n "$VIASH_PAR_ID" ] && ViashError Bad arguments for option \'--id=*\': \'$VIASH_PAR_ID\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_ID=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --strandedness)
            [ -n "$VIASH_PAR_STRANDEDNESS" ] && ViashError Bad arguments for option \'--strandedness\': \'$VIASH_PAR_STRANDEDNESS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_STRANDEDNESS="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --strandedness. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --strandedness=*)
            [ -n "$VIASH_PAR_STRANDEDNESS" ] && ViashError Bad arguments for option \'--strandedness=*\': \'$VIASH_PAR_STRANDEDNESS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_STRANDEDNESS=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --paired)
            [ -n "$VIASH_PAR_PAIRED" ] && ViashError Bad arguments for option \'--paired\': \'$VIASH_PAR_PAIRED\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_PAIRED=true
            shift 1
            ;;
        --input)
            if [ -z "$VIASH_PAR_INPUT" ]; then
              VIASH_PAR_INPUT="$2"
            else
              VIASH_PAR_INPUT="$VIASH_PAR_INPUT;""$2"
            fi
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --input. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --input=*)
            if [ -z "$VIASH_PAR_INPUT" ]; then
              VIASH_PAR_INPUT=$(ViashRemoveFlags "$1")
            else
              VIASH_PAR_INPUT="$VIASH_PAR_INPUT;"$(ViashRemoveFlags "$1")
            fi
            shift 1
            ;;
        --index)
            [ -n "$VIASH_PAR_INDEX" ] && ViashError Bad arguments for option \'--index\': \'$VIASH_PAR_INDEX\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_INDEX="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --index. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --index=*)
            [ -n "$VIASH_PAR_INDEX" ] && ViashError Bad arguments for option \'--index=*\': \'$VIASH_PAR_INDEX\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_INDEX=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --extra_args)
            [ -n "$VIASH_PAR_EXTRA_ARGS" ] && ViashError Bad arguments for option \'--extra_args\': \'$VIASH_PAR_EXTRA_ARGS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_EXTRA_ARGS="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --extra_args. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --extra_args=*)
            [ -n "$VIASH_PAR_EXTRA_ARGS" ] && ViashError Bad arguments for option \'--extra_args=*\': \'$VIASH_PAR_EXTRA_ARGS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_EXTRA_ARGS=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --counts_gene)
            [ -n "$VIASH_PAR_COUNTS_GENE" ] && ViashError Bad arguments for option \'--counts_gene\': \'$VIASH_PAR_COUNTS_GENE\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_COUNTS_GENE="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --counts_gene. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --counts_gene=*)
            [ -n "$VIASH_PAR_COUNTS_GENE" ] && ViashError Bad arguments for option \'--counts_gene=*\': \'$VIASH_PAR_COUNTS_GENE\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_COUNTS_GENE=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --counts_transcripts)
            [ -n "$VIASH_PAR_COUNTS_TRANSCRIPTS" ] && ViashError Bad arguments for option \'--counts_transcripts\': \'$VIASH_PAR_COUNTS_TRANSCRIPTS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_COUNTS_TRANSCRIPTS="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --counts_transcripts. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --counts_transcripts=*)
            [ -n "$VIASH_PAR_COUNTS_TRANSCRIPTS" ] && ViashError Bad arguments for option \'--counts_transcripts=*\': \'$VIASH_PAR_COUNTS_TRANSCRIPTS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_COUNTS_TRANSCRIPTS=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --stat)
            [ -n "$VIASH_PAR_STAT" ] && ViashError Bad arguments for option \'--stat\': \'$VIASH_PAR_STAT\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_STAT="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --stat. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --stat=*)
            [ -n "$VIASH_PAR_STAT" ] && ViashError Bad arguments for option \'--stat=*\': \'$VIASH_PAR_STAT\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_STAT=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --logs)
            [ -n "$VIASH_PAR_LOGS" ] && ViashError Bad arguments for option \'--logs\': \'$VIASH_PAR_LOGS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_LOGS="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --logs. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --logs=*)
            [ -n "$VIASH_PAR_LOGS" ] && ViashError Bad arguments for option \'--logs=*\': \'$VIASH_PAR_LOGS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_LOGS=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --bam_star)
            [ -n "$VIASH_PAR_BAM_STAR" ] && ViashError Bad arguments for option \'--bam_star\': \'$VIASH_PAR_BAM_STAR\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_BAM_STAR="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --bam_star. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --bam_star=*)
            [ -n "$VIASH_PAR_BAM_STAR" ] && ViashError Bad arguments for option \'--bam_star=*\': \'$VIASH_PAR_BAM_STAR\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_BAM_STAR=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --bam_genome)
            [ -n "$VIASH_PAR_BAM_GENOME" ] && ViashError Bad arguments for option \'--bam_genome\': \'$VIASH_PAR_BAM_GENOME\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_BAM_GENOME="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --bam_genome. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --bam_genome=*)
            [ -n "$VIASH_PAR_BAM_GENOME" ] && ViashError Bad arguments for option \'--bam_genome=*\': \'$VIASH_PAR_BAM_GENOME\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_BAM_GENOME=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --bam_transcript)
            [ -n "$VIASH_PAR_BAM_TRANSCRIPT" ] && ViashError Bad arguments for option \'--bam_transcript\': \'$VIASH_PAR_BAM_TRANSCRIPT\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_BAM_TRANSCRIPT="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --bam_transcript. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --bam_transcript=*)
            [ -n "$VIASH_PAR_BAM_TRANSCRIPT" ] && ViashError Bad arguments for option \'--bam_transcript=*\': \'$VIASH_PAR_BAM_TRANSCRIPT\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_BAM_TRANSCRIPT=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --sort_bam_by_read_name)
            [ -n "$VIASH_PAR_SORT_BAM_BY_READ_NAME" ] && ViashError Bad arguments for option \'--sort_bam_by_read_name\': \'$VIASH_PAR_SORT_BAM_BY_READ_NAME\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_SORT_BAM_BY_READ_NAME=true
            shift 1
            ;;
        --no_bam_output)
            [ -n "$VIASH_PAR_NO_BAM_OUTPUT" ] && ViashError Bad arguments for option \'--no_bam_output\': \'$VIASH_PAR_NO_BAM_OUTPUT\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_NO_BAM_OUTPUT=true
            shift 1
            ;;
        --sampling_for_bam)
            [ -n "$VIASH_PAR_SAMPLING_FOR_BAM" ] && ViashError Bad arguments for option \'--sampling_for_bam\': \'$VIASH_PAR_SAMPLING_FOR_BAM\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_SAMPLING_FOR_BAM=true
            shift 1
            ;;
        --output_genome_bam)
            [ -n "$VIASH_PAR_OUTPUT_GENOME_BAM" ] && ViashError Bad arguments for option \'--output_genome_bam\': \'$VIASH_PAR_OUTPUT_GENOME_BAM\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_OUTPUT_GENOME_BAM=true
            shift 1
            ;;
        --sort_bam_by_coordinate)
            [ -n "$VIASH_PAR_SORT_BAM_BY_COORDINATE" ] && ViashError Bad arguments for option \'--sort_bam_by_coordinate\': \'$VIASH_PAR_SORT_BAM_BY_COORDINATE\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_SORT_BAM_BY_COORDINATE=true
            shift 1
            ;;
        --no_qualities)
            [ -n "$VIASH_PAR_NO_QUALITIES" ] && ViashError Bad arguments for option \'--no_qualities\': \'$VIASH_PAR_NO_QUALITIES\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_NO_QUALITIES=true
            shift 1
            ;;
        --alignments)
            [ -n "$VIASH_PAR_ALIGNMENTS" ] && ViashError Bad arguments for option \'--alignments\': \'$VIASH_PAR_ALIGNMENTS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_ALIGNMENTS=true
            shift 1
            ;;
        --fai)
            [ -n "$VIASH_PAR_FAI" ] && ViashError Bad arguments for option \'--fai\': \'$VIASH_PAR_FAI\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_FAI="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --fai. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --fai=*)
            [ -n "$VIASH_PAR_FAI" ] && ViashError Bad arguments for option \'--fai=*\': \'$VIASH_PAR_FAI\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_FAI=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --bowtie2)
            [ -n "$VIASH_PAR_BOWTIE2" ] && ViashError Bad arguments for option \'--bowtie2\': \'$VIASH_PAR_BOWTIE2\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_BOWTIE2=true
            shift 1
            ;;
        --star)
            [ -n "$VIASH_PAR_STAR" ] && ViashError Bad arguments for option \'--star\': \'$VIASH_PAR_STAR\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_STAR=true
            shift 1
            ;;
        --hisat2_hca)
            [ -n "$VIASH_PAR_HISAT2_HCA" ] && ViashError Bad arguments for option \'--hisat2_hca\': \'$VIASH_PAR_HISAT2_HCA\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_HISAT2_HCA=true
            shift 1
            ;;
        --append_names)
            [ -n "$VIASH_PAR_APPEND_NAMES" ] && ViashError Bad arguments for option \'--append_names\': \'$VIASH_PAR_APPEND_NAMES\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_APPEND_NAMES=true
            shift 1
            ;;
        --seed)
            [ -n "$VIASH_PAR_SEED" ] && ViashError Bad arguments for option \'--seed\': \'$VIASH_PAR_SEED\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_SEED="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --seed. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --seed=*)
            [ -n "$VIASH_PAR_SEED" ] && ViashError Bad arguments for option \'--seed=*\': \'$VIASH_PAR_SEED\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_SEED=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --single_cell_prior)
            [ -n "$VIASH_PAR_SINGLE_CELL_PRIOR" ] && ViashError Bad arguments for option \'--single_cell_prior\': \'$VIASH_PAR_SINGLE_CELL_PRIOR\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_SINGLE_CELL_PRIOR=true
            shift 1
            ;;
        --calc_pme)
            [ -n "$VIASH_PAR_CALC_PME" ] && ViashError Bad arguments for option \'--calc_pme\': \'$VIASH_PAR_CALC_PME\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_CALC_PME=true
            shift 1
            ;;
        --calc_ci)
            [ -n "$VIASH_PAR_CALC_CI" ] && ViashError Bad arguments for option \'--calc_ci\': \'$VIASH_PAR_CALC_CI\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_CALC_CI=true
            shift 1
            ;;
        --quiet)
            [ -n "$VIASH_PAR_QUIET" ] && ViashError Bad arguments for option \'--quiet\': \'$VIASH_PAR_QUIET\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_QUIET=true
            shift 1
            ;;
        -q)
            [ -n "$VIASH_PAR_QUIET" ] && ViashError Bad arguments for option \'-q\': \'$VIASH_PAR_QUIET\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_QUIET=true
            shift 1
            ;;
        --seed_length)
            [ -n "$VIASH_PAR_SEED_LENGTH" ] && ViashError Bad arguments for option \'--seed_length\': \'$VIASH_PAR_SEED_LENGTH\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_SEED_LENGTH="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --seed_length. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --seed_length=*)
            [ -n "$VIASH_PAR_SEED_LENGTH" ] && ViashError Bad arguments for option \'--seed_length=*\': \'$VIASH_PAR_SEED_LENGTH\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_SEED_LENGTH=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --phred64_quals)
            [ -n "$VIASH_PAR_PHRED64_QUALS" ] && ViashError Bad arguments for option \'--phred64_quals\': \'$VIASH_PAR_PHRED64_QUALS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_PHRED64_QUALS=true
            shift 1
            ;;
        --solexa_quals)
            [ -n "$VIASH_PAR_SOLEXA_QUALS" ] && ViashError Bad arguments for option \'--solexa_quals\': \'$VIASH_PAR_SOLEXA_QUALS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_SOLEXA_QUALS=true
            shift 1
            ;;
        --bowtie_n)
            [ -n "$VIASH_PAR_BOWTIE_N" ] && ViashError Bad arguments for option \'--bowtie_n\': \'$VIASH_PAR_BOWTIE_N\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_BOWTIE_N="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --bowtie_n. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --bowtie_n=*)
            [ -n "$VIASH_PAR_BOWTIE_N" ] && ViashError Bad arguments for option \'--bowtie_n=*\': \'$VIASH_PAR_BOWTIE_N\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_BOWTIE_N=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --bowtie_e)
            [ -n "$VIASH_PAR_BOWTIE_E" ] && ViashError Bad arguments for option \'--bowtie_e\': \'$VIASH_PAR_BOWTIE_E\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_BOWTIE_E="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --bowtie_e. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --bowtie_e=*)
            [ -n "$VIASH_PAR_BOWTIE_E" ] && ViashError Bad arguments for option \'--bowtie_e=*\': \'$VIASH_PAR_BOWTIE_E\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_BOWTIE_E=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --bowtie_m)
            [ -n "$VIASH_PAR_BOWTIE_M" ] && ViashError Bad arguments for option \'--bowtie_m\': \'$VIASH_PAR_BOWTIE_M\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_BOWTIE_M="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --bowtie_m. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --bowtie_m=*)
            [ -n "$VIASH_PAR_BOWTIE_M" ] && ViashError Bad arguments for option \'--bowtie_m=*\': \'$VIASH_PAR_BOWTIE_M\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_BOWTIE_M=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --bowtie_chunkmbs)
            [ -n "$VIASH_PAR_BOWTIE_CHUNKMBS" ] && ViashError Bad arguments for option \'--bowtie_chunkmbs\': \'$VIASH_PAR_BOWTIE_CHUNKMBS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_BOWTIE_CHUNKMBS="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --bowtie_chunkmbs. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --bowtie_chunkmbs=*)
            [ -n "$VIASH_PAR_BOWTIE_CHUNKMBS" ] && ViashError Bad arguments for option \'--bowtie_chunkmbs=*\': \'$VIASH_PAR_BOWTIE_CHUNKMBS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_BOWTIE_CHUNKMBS=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --bowtie2_mismatch_rate)
            [ -n "$VIASH_PAR_BOWTIE2_MISMATCH_RATE" ] && ViashError Bad arguments for option \'--bowtie2_mismatch_rate\': \'$VIASH_PAR_BOWTIE2_MISMATCH_RATE\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_BOWTIE2_MISMATCH_RATE="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --bowtie2_mismatch_rate. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --bowtie2_mismatch_rate=*)
            [ -n "$VIASH_PAR_BOWTIE2_MISMATCH_RATE" ] && ViashError Bad arguments for option \'--bowtie2_mismatch_rate=*\': \'$VIASH_PAR_BOWTIE2_MISMATCH_RATE\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_BOWTIE2_MISMATCH_RATE=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --bowtie2_k)
            [ -n "$VIASH_PAR_BOWTIE2_K" ] && ViashError Bad arguments for option \'--bowtie2_k\': \'$VIASH_PAR_BOWTIE2_K\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_BOWTIE2_K="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --bowtie2_k. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --bowtie2_k=*)
            [ -n "$VIASH_PAR_BOWTIE2_K" ] && ViashError Bad arguments for option \'--bowtie2_k=*\': \'$VIASH_PAR_BOWTIE2_K\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_BOWTIE2_K=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --bowtie2_sensitivity_level)
            [ -n "$VIASH_PAR_BOWTIE2_SENSITIVITY_LEVEL" ] && ViashError Bad arguments for option \'--bowtie2_sensitivity_level\': \'$VIASH_PAR_BOWTIE2_SENSITIVITY_LEVEL\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_BOWTIE2_SENSITIVITY_LEVEL="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --bowtie2_sensitivity_level. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --bowtie2_sensitivity_level=*)
            [ -n "$VIASH_PAR_BOWTIE2_SENSITIVITY_LEVEL" ] && ViashError Bad arguments for option \'--bowtie2_sensitivity_level=*\': \'$VIASH_PAR_BOWTIE2_SENSITIVITY_LEVEL\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_BOWTIE2_SENSITIVITY_LEVEL=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --star_gzipped_read_file)
            [ -n "$VIASH_PAR_STAR_GZIPPED_READ_FILE" ] && ViashError Bad arguments for option \'--star_gzipped_read_file\': \'$VIASH_PAR_STAR_GZIPPED_READ_FILE\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_STAR_GZIPPED_READ_FILE=true
            shift 1
            ;;
        --star_bzipped_read_file)
            [ -n "$VIASH_PAR_STAR_BZIPPED_READ_FILE" ] && ViashError Bad arguments for option \'--star_bzipped_read_file\': \'$VIASH_PAR_STAR_BZIPPED_READ_FILE\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_STAR_BZIPPED_READ_FILE=true
            shift 1
            ;;
        --star_output_genome_bam)
            [ -n "$VIASH_PAR_STAR_OUTPUT_GENOME_BAM" ] && ViashError Bad arguments for option \'--star_output_genome_bam\': \'$VIASH_PAR_STAR_OUTPUT_GENOME_BAM\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_STAR_OUTPUT_GENOME_BAM=true
            shift 1
            ;;
        --tag)
            [ -n "$VIASH_PAR_TAG" ] && ViashError Bad arguments for option \'--tag\': \'$VIASH_PAR_TAG\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_TAG="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --tag. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --tag=*)
            [ -n "$VIASH_PAR_TAG" ] && ViashError Bad arguments for option \'--tag=*\': \'$VIASH_PAR_TAG\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_TAG=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --fragment_length_min)
            [ -n "$VIASH_PAR_FRAGMENT_LENGTH_MIN" ] && ViashError Bad arguments for option \'--fragment_length_min\': \'$VIASH_PAR_FRAGMENT_LENGTH_MIN\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_FRAGMENT_LENGTH_MIN="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --fragment_length_min. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --fragment_length_min=*)
            [ -n "$VIASH_PAR_FRAGMENT_LENGTH_MIN" ] && ViashError Bad arguments for option \'--fragment_length_min=*\': \'$VIASH_PAR_FRAGMENT_LENGTH_MIN\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_FRAGMENT_LENGTH_MIN=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --fragment_length_max)
            [ -n "$VIASH_PAR_FRAGMENT_LENGTH_MAX" ] && ViashError Bad arguments for option \'--fragment_length_max\': \'$VIASH_PAR_FRAGMENT_LENGTH_MAX\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_FRAGMENT_LENGTH_MAX="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --fragment_length_max. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --fragment_length_max=*)
            [ -n "$VIASH_PAR_FRAGMENT_LENGTH_MAX" ] && ViashError Bad arguments for option \'--fragment_length_max=*\': \'$VIASH_PAR_FRAGMENT_LENGTH_MAX\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_FRAGMENT_LENGTH_MAX=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --fragment_length_mean)
            [ -n "$VIASH_PAR_FRAGMENT_LENGTH_MEAN" ] && ViashError Bad arguments for option \'--fragment_length_mean\': \'$VIASH_PAR_FRAGMENT_LENGTH_MEAN\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_FRAGMENT_LENGTH_MEAN="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --fragment_length_mean. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --fragment_length_mean=*)
            [ -n "$VIASH_PAR_FRAGMENT_LENGTH_MEAN" ] && ViashError Bad arguments for option \'--fragment_length_mean=*\': \'$VIASH_PAR_FRAGMENT_LENGTH_MEAN\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_FRAGMENT_LENGTH_MEAN=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --gragment_length_sd)
            [ -n "$VIASH_PAR_GRAGMENT_LENGTH_SD" ] && ViashError Bad arguments for option \'--gragment_length_sd\': \'$VIASH_PAR_GRAGMENT_LENGTH_SD\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_GRAGMENT_LENGTH_SD="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --gragment_length_sd. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --gragment_length_sd=*)
            [ -n "$VIASH_PAR_GRAGMENT_LENGTH_SD" ] && ViashError Bad arguments for option \'--gragment_length_sd=*\': \'$VIASH_PAR_GRAGMENT_LENGTH_SD\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_GRAGMENT_LENGTH_SD=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --estimate_rspd)
            [ -n "$VIASH_PAR_ESTIMATE_RSPD" ] && ViashError Bad arguments for option \'--estimate_rspd\': \'$VIASH_PAR_ESTIMATE_RSPD\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_ESTIMATE_RSPD=true
            shift 1
            ;;
        --num_rspd_bins)
            [ -n "$VIASH_PAR_NUM_RSPD_BINS" ] && ViashError Bad arguments for option \'--num_rspd_bins\': \'$VIASH_PAR_NUM_RSPD_BINS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_NUM_RSPD_BINS="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --num_rspd_bins. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --num_rspd_bins=*)
            [ -n "$VIASH_PAR_NUM_RSPD_BINS" ] && ViashError Bad arguments for option \'--num_rspd_bins=*\': \'$VIASH_PAR_NUM_RSPD_BINS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_NUM_RSPD_BINS=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --gibbs_burnin)
            [ -n "$VIASH_PAR_GIBBS_BURNIN" ] && ViashError Bad arguments for option \'--gibbs_burnin\': \'$VIASH_PAR_GIBBS_BURNIN\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_GIBBS_BURNIN="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --gibbs_burnin. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --gibbs_burnin=*)
            [ -n "$VIASH_PAR_GIBBS_BURNIN" ] && ViashError Bad arguments for option \'--gibbs_burnin=*\': \'$VIASH_PAR_GIBBS_BURNIN\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_GIBBS_BURNIN=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --gibbs_number_of_samples)
            [ -n "$VIASH_PAR_GIBBS_NUMBER_OF_SAMPLES" ] && ViashError Bad arguments for option \'--gibbs_number_of_samples\': \'$VIASH_PAR_GIBBS_NUMBER_OF_SAMPLES\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_GIBBS_NUMBER_OF_SAMPLES="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --gibbs_number_of_samples. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --gibbs_number_of_samples=*)
            [ -n "$VIASH_PAR_GIBBS_NUMBER_OF_SAMPLES" ] && ViashError Bad arguments for option \'--gibbs_number_of_samples=*\': \'$VIASH_PAR_GIBBS_NUMBER_OF_SAMPLES\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_GIBBS_NUMBER_OF_SAMPLES=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --gibbs_sampling_gap)
            [ -n "$VIASH_PAR_GIBBS_SAMPLING_GAP" ] && ViashError Bad arguments for option \'--gibbs_sampling_gap\': \'$VIASH_PAR_GIBBS_SAMPLING_GAP\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_GIBBS_SAMPLING_GAP="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --gibbs_sampling_gap. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --gibbs_sampling_gap=*)
            [ -n "$VIASH_PAR_GIBBS_SAMPLING_GAP" ] && ViashError Bad arguments for option \'--gibbs_sampling_gap=*\': \'$VIASH_PAR_GIBBS_SAMPLING_GAP\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_GIBBS_SAMPLING_GAP=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --ci_credibility_level)
            [ -n "$VIASH_PAR_CI_CREDIBILITY_LEVEL" ] && ViashError Bad arguments for option \'--ci_credibility_level\': \'$VIASH_PAR_CI_CREDIBILITY_LEVEL\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_CI_CREDIBILITY_LEVEL="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --ci_credibility_level. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --ci_credibility_level=*)
            [ -n "$VIASH_PAR_CI_CREDIBILITY_LEVEL" ] && ViashError Bad arguments for option \'--ci_credibility_level=*\': \'$VIASH_PAR_CI_CREDIBILITY_LEVEL\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_CI_CREDIBILITY_LEVEL=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --ci_number_of_samples_per_count_vector)
            [ -n "$VIASH_PAR_CI_NUMBER_OF_SAMPLES_PER_COUNT_VECTOR" ] && ViashError Bad arguments for option \'--ci_number_of_samples_per_count_vector\': \'$VIASH_PAR_CI_NUMBER_OF_SAMPLES_PER_COUNT_VECTOR\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_CI_NUMBER_OF_SAMPLES_PER_COUNT_VECTOR="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --ci_number_of_samples_per_count_vector. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --ci_number_of_samples_per_count_vector=*)
            [ -n "$VIASH_PAR_CI_NUMBER_OF_SAMPLES_PER_COUNT_VECTOR" ] && ViashError Bad arguments for option \'--ci_number_of_samples_per_count_vector=*\': \'$VIASH_PAR_CI_NUMBER_OF_SAMPLES_PER_COUNT_VECTOR\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_CI_NUMBER_OF_SAMPLES_PER_COUNT_VECTOR=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --keep_intermediate_files)
            [ -n "$VIASH_PAR_KEEP_INTERMEDIATE_FILES" ] && ViashError Bad arguments for option \'--keep_intermediate_files\': \'$VIASH_PAR_KEEP_INTERMEDIATE_FILES\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_KEEP_INTERMEDIATE_FILES=true
            shift 1
            ;;
        --temporary_folder)
            [ -n "$VIASH_PAR_TEMPORARY_FOLDER" ] && ViashError Bad arguments for option \'--temporary_folder\': \'$VIASH_PAR_TEMPORARY_FOLDER\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_TEMPORARY_FOLDER="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --temporary_folder. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --temporary_folder=*)
            [ -n "$VIASH_PAR_TEMPORARY_FOLDER" ] && ViashError Bad arguments for option \'--temporary_folder=*\': \'$VIASH_PAR_TEMPORARY_FOLDER\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_TEMPORARY_FOLDER=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --time)
            [ -n "$VIASH_PAR_TIME" ] && ViashError Bad arguments for option \'--time\': \'$VIASH_PAR_TIME\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_TIME=true
            shift 1
            ;;
        --run_pRSEM)
            [ -n "$VIASH_PAR_RUN_PRSEM" ] && ViashError Bad arguments for option \'--run_pRSEM\': \'$VIASH_PAR_RUN_PRSEM\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_RUN_PRSEM=true
            shift 1
            ;;
        --chipseq_peak_file)
            [ -n "$VIASH_PAR_CHIPSEQ_PEAK_FILE" ] && ViashError Bad arguments for option \'--chipseq_peak_file\': \'$VIASH_PAR_CHIPSEQ_PEAK_FILE\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_CHIPSEQ_PEAK_FILE="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --chipseq_peak_file. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --chipseq_peak_file=*)
            [ -n "$VIASH_PAR_CHIPSEQ_PEAK_FILE" ] && ViashError Bad arguments for option \'--chipseq_peak_file=*\': \'$VIASH_PAR_CHIPSEQ_PEAK_FILE\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_CHIPSEQ_PEAK_FILE=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --chipseq_target_read_files)
            [ -n "$VIASH_PAR_CHIPSEQ_TARGET_READ_FILES" ] && ViashError Bad arguments for option \'--chipseq_target_read_files\': \'$VIASH_PAR_CHIPSEQ_TARGET_READ_FILES\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_CHIPSEQ_TARGET_READ_FILES="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --chipseq_target_read_files. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --chipseq_target_read_files=*)
            [ -n "$VIASH_PAR_CHIPSEQ_TARGET_READ_FILES" ] && ViashError Bad arguments for option \'--chipseq_target_read_files=*\': \'$VIASH_PAR_CHIPSEQ_TARGET_READ_FILES\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_CHIPSEQ_TARGET_READ_FILES=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --chipseq_control_read_files)
            [ -n "$VIASH_PAR_CHIPSEQ_CONTROL_READ_FILES" ] && ViashError Bad arguments for option \'--chipseq_control_read_files\': \'$VIASH_PAR_CHIPSEQ_CONTROL_READ_FILES\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_CHIPSEQ_CONTROL_READ_FILES="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --chipseq_control_read_files. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --chipseq_control_read_files=*)
            [ -n "$VIASH_PAR_CHIPSEQ_CONTROL_READ_FILES" ] && ViashError Bad arguments for option \'--chipseq_control_read_files=*\': \'$VIASH_PAR_CHIPSEQ_CONTROL_READ_FILES\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_CHIPSEQ_CONTROL_READ_FILES=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --chipseq_read_files_multi_targets)
            [ -n "$VIASH_PAR_CHIPSEQ_READ_FILES_MULTI_TARGETS" ] && ViashError Bad arguments for option \'--chipseq_read_files_multi_targets\': \'$VIASH_PAR_CHIPSEQ_READ_FILES_MULTI_TARGETS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_CHIPSEQ_READ_FILES_MULTI_TARGETS="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --chipseq_read_files_multi_targets. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --chipseq_read_files_multi_targets=*)
            [ -n "$VIASH_PAR_CHIPSEQ_READ_FILES_MULTI_TARGETS" ] && ViashError Bad arguments for option \'--chipseq_read_files_multi_targets=*\': \'$VIASH_PAR_CHIPSEQ_READ_FILES_MULTI_TARGETS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_CHIPSEQ_READ_FILES_MULTI_TARGETS=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --chipseq_bed_files_multi_targets)
            [ -n "$VIASH_PAR_CHIPSEQ_BED_FILES_MULTI_TARGETS" ] && ViashError Bad arguments for option \'--chipseq_bed_files_multi_targets\': \'$VIASH_PAR_CHIPSEQ_BED_FILES_MULTI_TARGETS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_CHIPSEQ_BED_FILES_MULTI_TARGETS="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --chipseq_bed_files_multi_targets. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --chipseq_bed_files_multi_targets=*)
            [ -n "$VIASH_PAR_CHIPSEQ_BED_FILES_MULTI_TARGETS" ] && ViashError Bad arguments for option \'--chipseq_bed_files_multi_targets=*\': \'$VIASH_PAR_CHIPSEQ_BED_FILES_MULTI_TARGETS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_CHIPSEQ_BED_FILES_MULTI_TARGETS=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --cap_stacked_chipseq_reads)
            [ -n "$VIASH_PAR_CAP_STACKED_CHIPSEQ_READS" ] && ViashError Bad arguments for option \'--cap_stacked_chipseq_reads\': \'$VIASH_PAR_CAP_STACKED_CHIPSEQ_READS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_CAP_STACKED_CHIPSEQ_READS=true
            shift 1
            ;;
        --n_max_stacked_chipseq_reads)
            [ -n "$VIASH_PAR_N_MAX_STACKED_CHIPSEQ_READS" ] && ViashError Bad arguments for option \'--n_max_stacked_chipseq_reads\': \'$VIASH_PAR_N_MAX_STACKED_CHIPSEQ_READS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_N_MAX_STACKED_CHIPSEQ_READS="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --n_max_stacked_chipseq_reads. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --n_max_stacked_chipseq_reads=*)
            [ -n "$VIASH_PAR_N_MAX_STACKED_CHIPSEQ_READS" ] && ViashError Bad arguments for option \'--n_max_stacked_chipseq_reads=*\': \'$VIASH_PAR_N_MAX_STACKED_CHIPSEQ_READS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_N_MAX_STACKED_CHIPSEQ_READS=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        --partition_model)
            [ -n "$VIASH_PAR_PARTITION_MODEL" ] && ViashError Bad arguments for option \'--partition_model\': \'$VIASH_PAR_PARTITION_MODEL\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_PARTITION_MODEL="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to --partition_model. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        --partition_model=*)
            [ -n "$VIASH_PAR_PARTITION_MODEL" ] && ViashError Bad arguments for option \'--partition_model=*\': \'$VIASH_PAR_PARTITION_MODEL\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_PAR_PARTITION_MODEL=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        ---engine)
            VIASH_ENGINE_ID="$2"
            shift 2
            ;;
        ---engine=*)
            VIASH_ENGINE_ID="$(ViashRemoveFlags "$1")"
            shift 1
            ;;
        ---setup)
            VIASH_MODE='setup'
            VIASH_SETUP_STRATEGY="$2"
            shift 2
            ;;
        ---setup=*)
            VIASH_MODE='setup'
            VIASH_SETUP_STRATEGY="$(ViashRemoveFlags "$1")"
            shift 1
            ;;
        ---dockerfile)
            VIASH_MODE='dockerfile'
            shift 1
            ;;
        ---docker_run_args)
            VIASH_DOCKER_RUN_ARGS+=("$2")
            shift 2
            ;;
        ---docker_run_args=*)
            VIASH_DOCKER_RUN_ARGS+=("$(ViashRemoveFlags "$1")")
            shift 1
            ;;
        ---docker_image_id)
            VIASH_MODE='docker_image_id'
            shift 1
            ;;
        ---debug)
            VIASH_MODE='debug'
            shift 1
            ;;
        ---cpus)
            [ -n "$VIASH_META_CPUS" ] && ViashError Bad arguments for option \'---cpus\': \'$VIASH_META_CPUS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_META_CPUS="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to ---cpus. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        ---cpus=*)
            [ -n "$VIASH_META_CPUS" ] && ViashError Bad arguments for option \'---cpus=*\': \'$VIASH_META_CPUS\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_META_CPUS=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        ---memory)
            [ -n "$VIASH_META_MEMORY" ] && ViashError Bad arguments for option \'---memory\': \'$VIASH_META_MEMORY\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_META_MEMORY="$2"
            [ $# -lt 2 ] && ViashError Not enough arguments passed to ---memory. Use "--help" to get more information on the parameters. && exit 1
            shift 2
            ;;
        ---memory=*)
            [ -n "$VIASH_META_MEMORY" ] && ViashError Bad arguments for option \'---memory=*\': \'$VIASH_META_MEMORY\' \& \'$2\' - you should provide exactly one argument for this option. && exit 1
            VIASH_META_MEMORY=$(ViashRemoveFlags "$1")
            shift 1
            ;;
        *)  # positional arg or unknown option
            # since the positional args will be eval'd, can we always quote, instead of using ViashQuote
            VIASH_POSITIONAL_ARGS="$VIASH_POSITIONAL_ARGS '$1'"
            [[ $1 == -* ]] && ViashWarning $1 looks like a parameter but is not a defined parameter and will instead be treated as a positional argument. Use "--help" to get more information on the parameters.
            shift # past argument
            ;;
    esac
done

# parse positional parameters
eval set -- $VIASH_POSITIONAL_ARGS


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

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

  # determine docker image id
  if [[ "$VIASH_ENGINE_ID" == 'docker' ]]; then
    VIASH_DOCKER_IMAGE_ID='images.viash-hub.com/vsh/biobox/rsem/rsem_calculate_expression:add_bases2fastq'
  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_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_PAIRED+x} ]; then
  VIASH_PAR_PAIRED="false"
fi
if [ -z ${VIASH_PAR_SORT_BAM_BY_READ_NAME+x} ]; then
  VIASH_PAR_SORT_BAM_BY_READ_NAME="false"
fi
if [ -z ${VIASH_PAR_NO_BAM_OUTPUT+x} ]; then
  VIASH_PAR_NO_BAM_OUTPUT="false"
fi
if [ -z ${VIASH_PAR_SAMPLING_FOR_BAM+x} ]; then
  VIASH_PAR_SAMPLING_FOR_BAM="false"
fi
if [ -z ${VIASH_PAR_OUTPUT_GENOME_BAM+x} ]; then
  VIASH_PAR_OUTPUT_GENOME_BAM="false"
fi
if [ -z ${VIASH_PAR_SORT_BAM_BY_COORDINATE+x} ]; then
  VIASH_PAR_SORT_BAM_BY_COORDINATE="false"
fi
if [ -z ${VIASH_PAR_NO_QUALITIES+x} ]; then
  VIASH_PAR_NO_QUALITIES="false"
fi
if [ -z ${VIASH_PAR_ALIGNMENTS+x} ]; then
  VIASH_PAR_ALIGNMENTS="false"
fi
if [ -z ${VIASH_PAR_BOWTIE2+x} ]; then
  VIASH_PAR_BOWTIE2="false"
fi
if [ -z ${VIASH_PAR_STAR+x} ]; then
  VIASH_PAR_STAR="false"
fi
if [ -z ${VIASH_PAR_HISAT2_HCA+x} ]; then
  VIASH_PAR_HISAT2_HCA="false"
fi
if [ -z ${VIASH_PAR_APPEND_NAMES+x} ]; then
  VIASH_PAR_APPEND_NAMES="false"
fi
if [ -z ${VIASH_PAR_SINGLE_CELL_PRIOR+x} ]; then
  VIASH_PAR_SINGLE_CELL_PRIOR="false"
fi
if [ -z ${VIASH_PAR_CALC_PME+x} ]; then
  VIASH_PAR_CALC_PME="false"
fi
if [ -z ${VIASH_PAR_CALC_CI+x} ]; then
  VIASH_PAR_CALC_CI="false"
fi
if [ -z ${VIASH_PAR_QUIET+x} ]; then
  VIASH_PAR_QUIET="false"
fi
if [ -z ${VIASH_PAR_PHRED64_QUALS+x} ]; then
  VIASH_PAR_PHRED64_QUALS="false"
fi
if [ -z ${VIASH_PAR_SOLEXA_QUALS+x} ]; then
  VIASH_PAR_SOLEXA_QUALS="false"
fi
if [ -z ${VIASH_PAR_STAR_GZIPPED_READ_FILE+x} ]; then
  VIASH_PAR_STAR_GZIPPED_READ_FILE="false"
fi
if [ -z ${VIASH_PAR_STAR_BZIPPED_READ_FILE+x} ]; then
  VIASH_PAR_STAR_BZIPPED_READ_FILE="false"
fi
if [ -z ${VIASH_PAR_STAR_OUTPUT_GENOME_BAM+x} ]; then
  VIASH_PAR_STAR_OUTPUT_GENOME_BAM="false"
fi
if [ -z ${VIASH_PAR_ESTIMATE_RSPD+x} ]; then
  VIASH_PAR_ESTIMATE_RSPD="false"
fi
if [ -z ${VIASH_PAR_KEEP_INTERMEDIATE_FILES+x} ]; then
  VIASH_PAR_KEEP_INTERMEDIATE_FILES="false"
fi
if [ -z ${VIASH_PAR_TIME+x} ]; then
  VIASH_PAR_TIME="false"
fi
if [ -z ${VIASH_PAR_RUN_PRSEM+x} ]; then
  VIASH_PAR_RUN_PRSEM="false"
fi
if [ -z ${VIASH_PAR_CAP_STACKED_CHIPSEQ_READS+x} ]; then
  VIASH_PAR_CAP_STACKED_CHIPSEQ_READS="false"
fi

# check whether required files exist
if [ ! -z "$VIASH_PAR_INPUT" ]; then
  IFS=';'
  set -f
  for file in $VIASH_PAR_INPUT; do
    unset IFS
    if [ ! -e "$file" ]; then
      ViashError "Input file '$file' does not exist."
      exit 1
    fi
  done
  set +f
fi
if [ ! -z "$VIASH_PAR_FAI" ] && [ ! -e "$VIASH_PAR_FAI" ]; then
  ViashError "Input file '$VIASH_PAR_FAI' does not exist."
  exit 1
fi
if [ ! -z "$VIASH_PAR_CHIPSEQ_PEAK_FILE" ] && [ ! -e "$VIASH_PAR_CHIPSEQ_PEAK_FILE" ]; then
  ViashError "Input file '$VIASH_PAR_CHIPSEQ_PEAK_FILE' does not exist."
  exit 1
fi
if [ ! -z "$VIASH_PAR_CHIPSEQ_TARGET_READ_FILES" ] && [ ! -e "$VIASH_PAR_CHIPSEQ_TARGET_READ_FILES" ]; then
  ViashError "Input file '$VIASH_PAR_CHIPSEQ_TARGET_READ_FILES' does not exist."
  exit 1
fi
if [ ! -z "$VIASH_PAR_CHIPSEQ_CONTROL_READ_FILES" ] && [ ! -e "$VIASH_PAR_CHIPSEQ_CONTROL_READ_FILES" ]; then
  ViashError "Input file '$VIASH_PAR_CHIPSEQ_CONTROL_READ_FILES' does not exist."
  exit 1
fi
if [ ! -z "$VIASH_PAR_CHIPSEQ_READ_FILES_MULTI_TARGETS" ] && [ ! -e "$VIASH_PAR_CHIPSEQ_READ_FILES_MULTI_TARGETS" ]; then
  ViashError "Input file '$VIASH_PAR_CHIPSEQ_READ_FILES_MULTI_TARGETS' does not exist."
  exit 1
fi
if [ ! -z "$VIASH_PAR_CHIPSEQ_BED_FILES_MULTI_TARGETS" ] && [ ! -e "$VIASH_PAR_CHIPSEQ_BED_FILES_MULTI_TARGETS" ]; then
  ViashError "Input file '$VIASH_PAR_CHIPSEQ_BED_FILES_MULTI_TARGETS' does not exist."
  exit 1
fi

# check whether parameters values are of the right type
if [[ -n "$VIASH_PAR_PAIRED" ]]; then
  if ! [[ "$VIASH_PAR_PAIRED" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--paired' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_SORT_BAM_BY_READ_NAME" ]]; then
  if ! [[ "$VIASH_PAR_SORT_BAM_BY_READ_NAME" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--sort_bam_by_read_name' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_NO_BAM_OUTPUT" ]]; then
  if ! [[ "$VIASH_PAR_NO_BAM_OUTPUT" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--no_bam_output' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_SAMPLING_FOR_BAM" ]]; then
  if ! [[ "$VIASH_PAR_SAMPLING_FOR_BAM" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--sampling_for_bam' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_OUTPUT_GENOME_BAM" ]]; then
  if ! [[ "$VIASH_PAR_OUTPUT_GENOME_BAM" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--output_genome_bam' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_SORT_BAM_BY_COORDINATE" ]]; then
  if ! [[ "$VIASH_PAR_SORT_BAM_BY_COORDINATE" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--sort_bam_by_coordinate' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_NO_QUALITIES" ]]; then
  if ! [[ "$VIASH_PAR_NO_QUALITIES" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--no_qualities' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_ALIGNMENTS" ]]; then
  if ! [[ "$VIASH_PAR_ALIGNMENTS" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--alignments' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_BOWTIE2" ]]; then
  if ! [[ "$VIASH_PAR_BOWTIE2" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--bowtie2' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_STAR" ]]; then
  if ! [[ "$VIASH_PAR_STAR" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--star' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_HISAT2_HCA" ]]; then
  if ! [[ "$VIASH_PAR_HISAT2_HCA" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--hisat2_hca' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_APPEND_NAMES" ]]; then
  if ! [[ "$VIASH_PAR_APPEND_NAMES" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--append_names' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_SEED" ]]; then
  if ! [[ "$VIASH_PAR_SEED" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError '--seed' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_SINGLE_CELL_PRIOR" ]]; then
  if ! [[ "$VIASH_PAR_SINGLE_CELL_PRIOR" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--single_cell_prior' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_CALC_PME" ]]; then
  if ! [[ "$VIASH_PAR_CALC_PME" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--calc_pme' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_CALC_CI" ]]; then
  if ! [[ "$VIASH_PAR_CALC_CI" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--calc_ci' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_QUIET" ]]; then
  if ! [[ "$VIASH_PAR_QUIET" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--quiet' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_SEED_LENGTH" ]]; then
  if ! [[ "$VIASH_PAR_SEED_LENGTH" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError '--seed_length' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_PHRED64_QUALS" ]]; then
  if ! [[ "$VIASH_PAR_PHRED64_QUALS" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--phred64_quals' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_SOLEXA_QUALS" ]]; then
  if ! [[ "$VIASH_PAR_SOLEXA_QUALS" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--solexa_quals' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_BOWTIE_N" ]]; then
  if ! [[ "$VIASH_PAR_BOWTIE_N" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError '--bowtie_n' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_BOWTIE_E" ]]; then
  if ! [[ "$VIASH_PAR_BOWTIE_E" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError '--bowtie_e' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_BOWTIE_M" ]]; then
  if ! [[ "$VIASH_PAR_BOWTIE_M" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError '--bowtie_m' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_BOWTIE_CHUNKMBS" ]]; then
  if ! [[ "$VIASH_PAR_BOWTIE_CHUNKMBS" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError '--bowtie_chunkmbs' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_BOWTIE2_MISMATCH_RATE" ]]; then
  if ! [[ "$VIASH_PAR_BOWTIE2_MISMATCH_RATE" =~ ^[-+]?(\.[0-9]+|[0-9]+(\.[0-9]*)?)([eE][-+]?[0-9]+)?$ ]]; then
    ViashError '--bowtie2_mismatch_rate' has to be a double. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_BOWTIE2_K" ]]; then
  if ! [[ "$VIASH_PAR_BOWTIE2_K" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError '--bowtie2_k' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_STAR_GZIPPED_READ_FILE" ]]; then
  if ! [[ "$VIASH_PAR_STAR_GZIPPED_READ_FILE" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--star_gzipped_read_file' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_STAR_BZIPPED_READ_FILE" ]]; then
  if ! [[ "$VIASH_PAR_STAR_BZIPPED_READ_FILE" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--star_bzipped_read_file' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_STAR_OUTPUT_GENOME_BAM" ]]; then
  if ! [[ "$VIASH_PAR_STAR_OUTPUT_GENOME_BAM" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--star_output_genome_bam' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_FRAGMENT_LENGTH_MIN" ]]; then
  if ! [[ "$VIASH_PAR_FRAGMENT_LENGTH_MIN" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError '--fragment_length_min' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_FRAGMENT_LENGTH_MAX" ]]; then
  if ! [[ "$VIASH_PAR_FRAGMENT_LENGTH_MAX" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError '--fragment_length_max' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_FRAGMENT_LENGTH_MEAN" ]]; then
  if ! [[ "$VIASH_PAR_FRAGMENT_LENGTH_MEAN" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError '--fragment_length_mean' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_GRAGMENT_LENGTH_SD" ]]; then
  if ! [[ "$VIASH_PAR_GRAGMENT_LENGTH_SD" =~ ^[-+]?(\.[0-9]+|[0-9]+(\.[0-9]*)?)([eE][-+]?[0-9]+)?$ ]]; then
    ViashError '--gragment_length_sd' has to be a double. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_ESTIMATE_RSPD" ]]; then
  if ! [[ "$VIASH_PAR_ESTIMATE_RSPD" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--estimate_rspd' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_NUM_RSPD_BINS" ]]; then
  if ! [[ "$VIASH_PAR_NUM_RSPD_BINS" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError '--num_rspd_bins' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_GIBBS_BURNIN" ]]; then
  if ! [[ "$VIASH_PAR_GIBBS_BURNIN" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError '--gibbs_burnin' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_GIBBS_NUMBER_OF_SAMPLES" ]]; then
  if ! [[ "$VIASH_PAR_GIBBS_NUMBER_OF_SAMPLES" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError '--gibbs_number_of_samples' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_GIBBS_SAMPLING_GAP" ]]; then
  if ! [[ "$VIASH_PAR_GIBBS_SAMPLING_GAP" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError '--gibbs_sampling_gap' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_CI_CREDIBILITY_LEVEL" ]]; then
  if ! [[ "$VIASH_PAR_CI_CREDIBILITY_LEVEL" =~ ^[-+]?(\.[0-9]+|[0-9]+(\.[0-9]*)?)([eE][-+]?[0-9]+)?$ ]]; then
    ViashError '--ci_credibility_level' has to be a double. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_CI_NUMBER_OF_SAMPLES_PER_COUNT_VECTOR" ]]; then
  if ! [[ "$VIASH_PAR_CI_NUMBER_OF_SAMPLES_PER_COUNT_VECTOR" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError '--ci_number_of_samples_per_count_vector' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_KEEP_INTERMEDIATE_FILES" ]]; then
  if ! [[ "$VIASH_PAR_KEEP_INTERMEDIATE_FILES" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--keep_intermediate_files' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_TIME" ]]; then
  if ! [[ "$VIASH_PAR_TIME" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--time' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_RUN_PRSEM" ]]; then
  if ! [[ "$VIASH_PAR_RUN_PRSEM" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--run_pRSEM' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_CAP_STACKED_CHIPSEQ_READS" ]]; then
  if ! [[ "$VIASH_PAR_CAP_STACKED_CHIPSEQ_READS" =~ ^(true|True|TRUE|false|False|FALSE|yes|Yes|YES|no|No|NO)$ ]]; then
    ViashError '--cap_stacked_chipseq_reads' has to be a boolean_true. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_PAR_N_MAX_STACKED_CHIPSEQ_READS" ]]; then
  if ! [[ "$VIASH_PAR_N_MAX_STACKED_CHIPSEQ_READS" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError '--n_max_stacked_chipseq_reads' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_META_CPUS" ]]; then
  if ! [[ "$VIASH_META_CPUS" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError 'cpus' has to be an integer. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_META_MEMORY_B" ]]; then
  if ! [[ "$VIASH_META_MEMORY_B" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError 'memory_b' has to be a long. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_META_MEMORY_KB" ]]; then
  if ! [[ "$VIASH_META_MEMORY_KB" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError 'memory_kb' has to be a long. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_META_MEMORY_MB" ]]; then
  if ! [[ "$VIASH_META_MEMORY_MB" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError 'memory_mb' has to be a long. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_META_MEMORY_GB" ]]; then
  if ! [[ "$VIASH_META_MEMORY_GB" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError 'memory_gb' has to be a long. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_META_MEMORY_TB" ]]; then
  if ! [[ "$VIASH_META_MEMORY_TB" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError 'memory_tb' has to be a long. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_META_MEMORY_PB" ]]; then
  if ! [[ "$VIASH_META_MEMORY_PB" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError 'memory_pb' has to be a long. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_META_MEMORY_KIB" ]]; then
  if ! [[ "$VIASH_META_MEMORY_KIB" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError 'memory_kib' has to be a long. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_META_MEMORY_MIB" ]]; then
  if ! [[ "$VIASH_META_MEMORY_MIB" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError 'memory_mib' has to be a long. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_META_MEMORY_GIB" ]]; then
  if ! [[ "$VIASH_META_MEMORY_GIB" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError 'memory_gib' has to be a long. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_META_MEMORY_TIB" ]]; then
  if ! [[ "$VIASH_META_MEMORY_TIB" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError 'memory_tib' has to be a long. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi
if [[ -n "$VIASH_META_MEMORY_PIB" ]]; then
  if ! [[ "$VIASH_META_MEMORY_PIB" =~ ^[-+]?[0-9]+$ ]]; then
    ViashError 'memory_pib' has to be a long. Use "--help" to get more information on the parameters.
    exit 1
  fi
fi

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

if [ ! -z "$VIASH_PAR_BOWTIE_N" ]; then
  VIASH_PAR_BOWTIE_N_CHOICES=("0;1;2;3")
  IFS=';'
  set -f
  if ! [[ ";${VIASH_PAR_BOWTIE_N_CHOICES[*]};" =~ ";$VIASH_PAR_BOWTIE_N;" ]]; then
    ViashError '--bowtie_n' specified value of \'$VIASH_PAR_BOWTIE_N\' is not in the list of allowed values. Use "--help" to get more information on the parameters.
    exit 1
  fi
  set +f
  unset IFS
fi

if [ ! -z "$VIASH_PAR_BOWTIE2_SENSITIVITY_LEVEL" ]; then
  VIASH_PAR_BOWTIE2_SENSITIVITY_LEVEL_CHOICES=("very_fast;fast;sensitive;very_sensitive")
  IFS=';'
  set -f
  if ! [[ ";${VIASH_PAR_BOWTIE2_SENSITIVITY_LEVEL_CHOICES[*]};" =~ ";$VIASH_PAR_BOWTIE2_SENSITIVITY_LEVEL;" ]]; then
    ViashError '--bowtie2_sensitivity_level' specified value of \'$VIASH_PAR_BOWTIE2_SENSITIVITY_LEVEL\' is not in the list of allowed values. Use "--help" to get more information on the parameters.
    exit 1
  fi
  set +f
  unset IFS
fi

# create parent directories of output files, if so desired
if [ ! -z "$VIASH_PAR_COUNTS_GENE" ] && [ ! -d "$(dirname "$VIASH_PAR_COUNTS_GENE")" ]; then
  mkdir -p "$(dirname "$VIASH_PAR_COUNTS_GENE")"
fi
if [ ! -z "$VIASH_PAR_COUNTS_TRANSCRIPTS" ] && [ ! -d "$(dirname "$VIASH_PAR_COUNTS_TRANSCRIPTS")" ]; then
  mkdir -p "$(dirname "$VIASH_PAR_COUNTS_TRANSCRIPTS")"
fi
if [ ! -z "$VIASH_PAR_STAT" ] && [ ! -d "$(dirname "$VIASH_PAR_STAT")" ]; then
  mkdir -p "$(dirname "$VIASH_PAR_STAT")"
fi
if [ ! -z "$VIASH_PAR_LOGS" ] && [ ! -d "$(dirname "$VIASH_PAR_LOGS")" ]; then
  mkdir -p "$(dirname "$VIASH_PAR_LOGS")"
fi
if [ ! -z "$VIASH_PAR_BAM_STAR" ] && [ ! -d "$(dirname "$VIASH_PAR_BAM_STAR")" ]; then
  mkdir -p "$(dirname "$VIASH_PAR_BAM_STAR")"
fi
if [ ! -z "$VIASH_PAR_BAM_GENOME" ] && [ ! -d "$(dirname "$VIASH_PAR_BAM_GENOME")" ]; then
  mkdir -p "$(dirname "$VIASH_PAR_BAM_GENOME")"
fi
if [ ! -z "$VIASH_PAR_BAM_TRANSCRIPT" ] && [ ! -d "$(dirname "$VIASH_PAR_BAM_TRANSCRIPT")" ]; then
  mkdir -p "$(dirname "$VIASH_PAR_BAM_TRANSCRIPT")"
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_TEST_INPUT=()
  IFS=';'
  for var in $VIASH_PAR_INPUT; do
    unset IFS
    VIASH_DIRECTORY_MOUNTS+=( "$(ViashDockerAutodetectMountArg "$var")" )
    var=$(ViashDockerAutodetectMount "$var")
    VIASH_TEST_INPUT+=( "$var" )
  done
  VIASH_PAR_INPUT=$(IFS=';' ; echo "${VIASH_TEST_INPUT[*]}")
fi
if [ ! -z "$VIASH_PAR_INDEX" ]; then
  VIASH_DIRECTORY_MOUNTS+=( "$(ViashDockerAutodetectMountArg "$VIASH_PAR_INDEX")" )
  VIASH_PAR_INDEX=$(ViashDockerAutodetectMount "$VIASH_PAR_INDEX")
fi
if [ ! -z "$VIASH_PAR_COUNTS_GENE" ]; then
  VIASH_DIRECTORY_MOUNTS+=( "$(ViashDockerAutodetectMountArg "$VIASH_PAR_COUNTS_GENE")" )
  VIASH_PAR_COUNTS_GENE=$(ViashDockerAutodetectMount "$VIASH_PAR_COUNTS_GENE")
  VIASH_CHOWN_VARS+=( "$VIASH_PAR_COUNTS_GENE" )
fi
if [ ! -z "$VIASH_PAR_COUNTS_TRANSCRIPTS" ]; then
  VIASH_DIRECTORY_MOUNTS+=( "$(ViashDockerAutodetectMountArg "$VIASH_PAR_COUNTS_TRANSCRIPTS")" )
  VIASH_PAR_COUNTS_TRANSCRIPTS=$(ViashDockerAutodetectMount "$VIASH_PAR_COUNTS_TRANSCRIPTS")
  VIASH_CHOWN_VARS+=( "$VIASH_PAR_COUNTS_TRANSCRIPTS" )
fi
if [ ! -z "$VIASH_PAR_STAT" ]; then
  VIASH_DIRECTORY_MOUNTS+=( "$(ViashDockerAutodetectMountArg "$VIASH_PAR_STAT")" )
  VIASH_PAR_STAT=$(ViashDockerAutodetectMount "$VIASH_PAR_STAT")
  VIASH_CHOWN_VARS+=( "$VIASH_PAR_STAT" )
fi
if [ ! -z "$VIASH_PAR_LOGS" ]; then
  VIASH_DIRECTORY_MOUNTS+=( "$(ViashDockerAutodetectMountArg "$VIASH_PAR_LOGS")" )
  VIASH_PAR_LOGS=$(ViashDockerAutodetectMount "$VIASH_PAR_LOGS")
  VIASH_CHOWN_VARS+=( "$VIASH_PAR_LOGS" )
fi
if [ ! -z "$VIASH_PAR_BAM_STAR" ]; then
  VIASH_DIRECTORY_MOUNTS+=( "$(ViashDockerAutodetectMountArg "$VIASH_PAR_BAM_STAR")" )
  VIASH_PAR_BAM_STAR=$(ViashDockerAutodetectMount "$VIASH_PAR_BAM_STAR")
  VIASH_CHOWN_VARS+=( "$VIASH_PAR_BAM_STAR" )
fi
if [ ! -z "$VIASH_PAR_BAM_GENOME" ]; then
  VIASH_DIRECTORY_MOUNTS+=( "$(ViashDockerAutodetectMountArg "$VIASH_PAR_BAM_GENOME")" )
  VIASH_PAR_BAM_GENOME=$(ViashDockerAutodetectMount "$VIASH_PAR_BAM_GENOME")
  VIASH_CHOWN_VARS+=( "$VIASH_PAR_BAM_GENOME" )
fi
if [ ! -z "$VIASH_PAR_BAM_TRANSCRIPT" ]; then
  VIASH_DIRECTORY_MOUNTS+=( "$(ViashDockerAutodetectMountArg "$VIASH_PAR_BAM_TRANSCRIPT")" )
  VIASH_PAR_BAM_TRANSCRIPT=$(ViashDockerAutodetectMount "$VIASH_PAR_BAM_TRANSCRIPT")
  VIASH_CHOWN_VARS+=( "$VIASH_PAR_BAM_TRANSCRIPT" )
fi
if [ ! -z "$VIASH_PAR_FAI" ]; then
  VIASH_DIRECTORY_MOUNTS+=( "$(ViashDockerAutodetectMountArg "$VIASH_PAR_FAI")" )
  VIASH_PAR_FAI=$(ViashDockerAutodetectMount "$VIASH_PAR_FAI")
fi
if [ ! -z "$VIASH_PAR_CHIPSEQ_PEAK_FILE" ]; then
  VIASH_DIRECTORY_MOUNTS+=( "$(ViashDockerAutodetectMountArg "$VIASH_PAR_CHIPSEQ_PEAK_FILE")" )
  VIASH_PAR_CHIPSEQ_PEAK_FILE=$(ViashDockerAutodetectMount "$VIASH_PAR_CHIPSEQ_PEAK_FILE")
fi
if [ ! -z "$VIASH_PAR_CHIPSEQ_TARGET_READ_FILES" ]; then
  VIASH_DIRECTORY_MOUNTS+=( "$(ViashDockerAutodetectMountArg "$VIASH_PAR_CHIPSEQ_TARGET_READ_FILES")" )
  VIASH_PAR_CHIPSEQ_TARGET_READ_FILES=$(ViashDockerAutodetectMount "$VIASH_PAR_CHIPSEQ_TARGET_READ_FILES")
fi
if [ ! -z "$VIASH_PAR_CHIPSEQ_CONTROL_READ_FILES" ]; then
  VIASH_DIRECTORY_MOUNTS+=( "$(ViashDockerAutodetectMountArg "$VIASH_PAR_CHIPSEQ_CONTROL_READ_FILES")" )
  VIASH_PAR_CHIPSEQ_CONTROL_READ_FILES=$(ViashDockerAutodetectMount "$VIASH_PAR_CHIPSEQ_CONTROL_READ_FILES")
fi
if [ ! -z "$VIASH_PAR_CHIPSEQ_READ_FILES_MULTI_TARGETS" ]; then
  VIASH_DIRECTORY_MOUNTS+=( "$(ViashDockerAutodetectMountArg "$VIASH_PAR_CHIPSEQ_READ_FILES_MULTI_TARGETS")" )
  VIASH_PAR_CHIPSEQ_READ_FILES_MULTI_TARGETS=$(ViashDockerAutodetectMount "$VIASH_PAR_CHIPSEQ_READ_FILES_MULTI_TARGETS")
fi
if [ ! -z "$VIASH_PAR_CHIPSEQ_BED_FILES_MULTI_TARGETS" ]; then
  VIASH_DIRECTORY_MOUNTS+=( "$(ViashDockerAutodetectMountArg "$VIASH_PAR_CHIPSEQ_BED_FILES_MULTI_TARGETS")" )
  VIASH_PAR_CHIPSEQ_BED_FILES_MULTI_TARGETS=$(ViashDockerAutodetectMount "$VIASH_PAR_CHIPSEQ_BED_FILES_MULTI_TARGETS")
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-rsem_calculate_expression-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_ID+x} ]; then echo "${VIASH_PAR_ID}" | sed "s#'#'\"'\"'#g;s#.*#par_id='&'#" ; else echo "# par_id="; fi )
$( if [ ! -z ${VIASH_PAR_STRANDEDNESS+x} ]; then echo "${VIASH_PAR_STRANDEDNESS}" | sed "s#'#'\"'\"'#g;s#.*#par_strandedness='&'#" ; else echo "# par_strandedness="; fi )
$( if [ ! -z ${VIASH_PAR_PAIRED+x} ]; then echo "${VIASH_PAR_PAIRED}" | sed "s#'#'\"'\"'#g;s#.*#par_paired='&'#" ; else echo "# par_paired="; fi )
$( if [ ! -z ${VIASH_PAR_INPUT+x} ]; then echo "${VIASH_PAR_INPUT}" | sed "s#'#'\"'\"'#g;s#.*#par_input='&'#" ; else echo "# par_input="; fi )
$( if [ ! -z ${VIASH_PAR_INDEX+x} ]; then echo "${VIASH_PAR_INDEX}" | sed "s#'#'\"'\"'#g;s#.*#par_index='&'#" ; else echo "# par_index="; fi )
$( if [ ! -z ${VIASH_PAR_EXTRA_ARGS+x} ]; then echo "${VIASH_PAR_EXTRA_ARGS}" | sed "s#'#'\"'\"'#g;s#.*#par_extra_args='&'#" ; else echo "# par_extra_args="; fi )
$( if [ ! -z ${VIASH_PAR_COUNTS_GENE+x} ]; then echo "${VIASH_PAR_COUNTS_GENE}" | sed "s#'#'\"'\"'#g;s#.*#par_counts_gene='&'#" ; else echo "# par_counts_gene="; fi )
$( if [ ! -z ${VIASH_PAR_COUNTS_TRANSCRIPTS+x} ]; then echo "${VIASH_PAR_COUNTS_TRANSCRIPTS}" | sed "s#'#'\"'\"'#g;s#.*#par_counts_transcripts='&'#" ; else echo "# par_counts_transcripts="; fi )
$( if [ ! -z ${VIASH_PAR_STAT+x} ]; then echo "${VIASH_PAR_STAT}" | sed "s#'#'\"'\"'#g;s#.*#par_stat='&'#" ; else echo "# par_stat="; fi )
$( if [ ! -z ${VIASH_PAR_LOGS+x} ]; then echo "${VIASH_PAR_LOGS}" | sed "s#'#'\"'\"'#g;s#.*#par_logs='&'#" ; else echo "# par_logs="; fi )
$( if [ ! -z ${VIASH_PAR_BAM_STAR+x} ]; then echo "${VIASH_PAR_BAM_STAR}" | sed "s#'#'\"'\"'#g;s#.*#par_bam_star='&'#" ; else echo "# par_bam_star="; fi )
$( if [ ! -z ${VIASH_PAR_BAM_GENOME+x} ]; then echo "${VIASH_PAR_BAM_GENOME}" | sed "s#'#'\"'\"'#g;s#.*#par_bam_genome='&'#" ; else echo "# par_bam_genome="; fi )
$( if [ ! -z ${VIASH_PAR_BAM_TRANSCRIPT+x} ]; then echo "${VIASH_PAR_BAM_TRANSCRIPT}" | sed "s#'#'\"'\"'#g;s#.*#par_bam_transcript='&'#" ; else echo "# par_bam_transcript="; fi )
$( if [ ! -z ${VIASH_PAR_SORT_BAM_BY_READ_NAME+x} ]; then echo "${VIASH_PAR_SORT_BAM_BY_READ_NAME}" | sed "s#'#'\"'\"'#g;s#.*#par_sort_bam_by_read_name='&'#" ; else echo "# par_sort_bam_by_read_name="; fi )
$( if [ ! -z ${VIASH_PAR_NO_BAM_OUTPUT+x} ]; then echo "${VIASH_PAR_NO_BAM_OUTPUT}" | sed "s#'#'\"'\"'#g;s#.*#par_no_bam_output='&'#" ; else echo "# par_no_bam_output="; fi )
$( if [ ! -z ${VIASH_PAR_SAMPLING_FOR_BAM+x} ]; then echo "${VIASH_PAR_SAMPLING_FOR_BAM}" | sed "s#'#'\"'\"'#g;s#.*#par_sampling_for_bam='&'#" ; else echo "# par_sampling_for_bam="; fi )
$( if [ ! -z ${VIASH_PAR_OUTPUT_GENOME_BAM+x} ]; then echo "${VIASH_PAR_OUTPUT_GENOME_BAM}" | sed "s#'#'\"'\"'#g;s#.*#par_output_genome_bam='&'#" ; else echo "# par_output_genome_bam="; fi )
$( if [ ! -z ${VIASH_PAR_SORT_BAM_BY_COORDINATE+x} ]; then echo "${VIASH_PAR_SORT_BAM_BY_COORDINATE}" | sed "s#'#'\"'\"'#g;s#.*#par_sort_bam_by_coordinate='&'#" ; else echo "# par_sort_bam_by_coordinate="; fi )
$( if [ ! -z ${VIASH_PAR_NO_QUALITIES+x} ]; then echo "${VIASH_PAR_NO_QUALITIES}" | sed "s#'#'\"'\"'#g;s#.*#par_no_qualities='&'#" ; else echo "# par_no_qualities="; fi )
$( if [ ! -z ${VIASH_PAR_ALIGNMENTS+x} ]; then echo "${VIASH_PAR_ALIGNMENTS}" | sed "s#'#'\"'\"'#g;s#.*#par_alignments='&'#" ; else echo "# par_alignments="; fi )
$( if [ ! -z ${VIASH_PAR_FAI+x} ]; then echo "${VIASH_PAR_FAI}" | sed "s#'#'\"'\"'#g;s#.*#par_fai='&'#" ; else echo "# par_fai="; fi )
$( if [ ! -z ${VIASH_PAR_BOWTIE2+x} ]; then echo "${VIASH_PAR_BOWTIE2}" | sed "s#'#'\"'\"'#g;s#.*#par_bowtie2='&'#" ; else echo "# par_bowtie2="; fi )
$( if [ ! -z ${VIASH_PAR_STAR+x} ]; then echo "${VIASH_PAR_STAR}" | sed "s#'#'\"'\"'#g;s#.*#par_star='&'#" ; else echo "# par_star="; fi )
$( if [ ! -z ${VIASH_PAR_HISAT2_HCA+x} ]; then echo "${VIASH_PAR_HISAT2_HCA}" | sed "s#'#'\"'\"'#g;s#.*#par_hisat2_hca='&'#" ; else echo "# par_hisat2_hca="; fi )
$( if [ ! -z ${VIASH_PAR_APPEND_NAMES+x} ]; then echo "${VIASH_PAR_APPEND_NAMES}" | sed "s#'#'\"'\"'#g;s#.*#par_append_names='&'#" ; else echo "# par_append_names="; fi )
$( if [ ! -z ${VIASH_PAR_SEED+x} ]; then echo "${VIASH_PAR_SEED}" | sed "s#'#'\"'\"'#g;s#.*#par_seed='&'#" ; else echo "# par_seed="; fi )
$( if [ ! -z ${VIASH_PAR_SINGLE_CELL_PRIOR+x} ]; then echo "${VIASH_PAR_SINGLE_CELL_PRIOR}" | sed "s#'#'\"'\"'#g;s#.*#par_single_cell_prior='&'#" ; else echo "# par_single_cell_prior="; fi )
$( if [ ! -z ${VIASH_PAR_CALC_PME+x} ]; then echo "${VIASH_PAR_CALC_PME}" | sed "s#'#'\"'\"'#g;s#.*#par_calc_pme='&'#" ; else echo "# par_calc_pme="; fi )
$( if [ ! -z ${VIASH_PAR_CALC_CI+x} ]; then echo "${VIASH_PAR_CALC_CI}" | sed "s#'#'\"'\"'#g;s#.*#par_calc_ci='&'#" ; else echo "# par_calc_ci="; fi )
$( if [ ! -z ${VIASH_PAR_QUIET+x} ]; then echo "${VIASH_PAR_QUIET}" | sed "s#'#'\"'\"'#g;s#.*#par_quiet='&'#" ; else echo "# par_quiet="; fi )
$( if [ ! -z ${VIASH_PAR_SEED_LENGTH+x} ]; then echo "${VIASH_PAR_SEED_LENGTH}" | sed "s#'#'\"'\"'#g;s#.*#par_seed_length='&'#" ; else echo "# par_seed_length="; fi )
$( if [ ! -z ${VIASH_PAR_PHRED64_QUALS+x} ]; then echo "${VIASH_PAR_PHRED64_QUALS}" | sed "s#'#'\"'\"'#g;s#.*#par_phred64_quals='&'#" ; else echo "# par_phred64_quals="; fi )
$( if [ ! -z ${VIASH_PAR_SOLEXA_QUALS+x} ]; then echo "${VIASH_PAR_SOLEXA_QUALS}" | sed "s#'#'\"'\"'#g;s#.*#par_solexa_quals='&'#" ; else echo "# par_solexa_quals="; fi )
$( if [ ! -z ${VIASH_PAR_BOWTIE_N+x} ]; then echo "${VIASH_PAR_BOWTIE_N}" | sed "s#'#'\"'\"'#g;s#.*#par_bowtie_n='&'#" ; else echo "# par_bowtie_n="; fi )
$( if [ ! -z ${VIASH_PAR_BOWTIE_E+x} ]; then echo "${VIASH_PAR_BOWTIE_E}" | sed "s#'#'\"'\"'#g;s#.*#par_bowtie_e='&'#" ; else echo "# par_bowtie_e="; fi )
$( if [ ! -z ${VIASH_PAR_BOWTIE_M+x} ]; then echo "${VIASH_PAR_BOWTIE_M}" | sed "s#'#'\"'\"'#g;s#.*#par_bowtie_m='&'#" ; else echo "# par_bowtie_m="; fi )
$( if [ ! -z ${VIASH_PAR_BOWTIE_CHUNKMBS+x} ]; then echo "${VIASH_PAR_BOWTIE_CHUNKMBS}" | sed "s#'#'\"'\"'#g;s#.*#par_bowtie_chunkmbs='&'#" ; else echo "# par_bowtie_chunkmbs="; fi )
$( if [ ! -z ${VIASH_PAR_BOWTIE2_MISMATCH_RATE+x} ]; then echo "${VIASH_PAR_BOWTIE2_MISMATCH_RATE}" | sed "s#'#'\"'\"'#g;s#.*#par_bowtie2_mismatch_rate='&'#" ; else echo "# par_bowtie2_mismatch_rate="; fi )
$( if [ ! -z ${VIASH_PAR_BOWTIE2_K+x} ]; then echo "${VIASH_PAR_BOWTIE2_K}" | sed "s#'#'\"'\"'#g;s#.*#par_bowtie2_k='&'#" ; else echo "# par_bowtie2_k="; fi )
$( if [ ! -z ${VIASH_PAR_BOWTIE2_SENSITIVITY_LEVEL+x} ]; then echo "${VIASH_PAR_BOWTIE2_SENSITIVITY_LEVEL}" | sed "s#'#'\"'\"'#g;s#.*#par_bowtie2_sensitivity_level='&'#" ; else echo "# par_bowtie2_sensitivity_level="; fi )
$( if [ ! -z ${VIASH_PAR_STAR_GZIPPED_READ_FILE+x} ]; then echo "${VIASH_PAR_STAR_GZIPPED_READ_FILE}" | sed "s#'#'\"'\"'#g;s#.*#par_star_gzipped_read_file='&'#" ; else echo "# par_star_gzipped_read_file="; fi )
$( if [ ! -z ${VIASH_PAR_STAR_BZIPPED_READ_FILE+x} ]; then echo "${VIASH_PAR_STAR_BZIPPED_READ_FILE}" | sed "s#'#'\"'\"'#g;s#.*#par_star_bzipped_read_file='&'#" ; else echo "# par_star_bzipped_read_file="; fi )
$( if [ ! -z ${VIASH_PAR_STAR_OUTPUT_GENOME_BAM+x} ]; then echo "${VIASH_PAR_STAR_OUTPUT_GENOME_BAM}" | sed "s#'#'\"'\"'#g;s#.*#par_star_output_genome_bam='&'#" ; else echo "# par_star_output_genome_bam="; fi )
$( if [ ! -z ${VIASH_PAR_TAG+x} ]; then echo "${VIASH_PAR_TAG}" | sed "s#'#'\"'\"'#g;s#.*#par_tag='&'#" ; else echo "# par_tag="; fi )
$( if [ ! -z ${VIASH_PAR_FRAGMENT_LENGTH_MIN+x} ]; then echo "${VIASH_PAR_FRAGMENT_LENGTH_MIN}" | sed "s#'#'\"'\"'#g;s#.*#par_fragment_length_min='&'#" ; else echo "# par_fragment_length_min="; fi )
$( if [ ! -z ${VIASH_PAR_FRAGMENT_LENGTH_MAX+x} ]; then echo "${VIASH_PAR_FRAGMENT_LENGTH_MAX}" | sed "s#'#'\"'\"'#g;s#.*#par_fragment_length_max='&'#" ; else echo "# par_fragment_length_max="; fi )
$( if [ ! -z ${VIASH_PAR_FRAGMENT_LENGTH_MEAN+x} ]; then echo "${VIASH_PAR_FRAGMENT_LENGTH_MEAN}" | sed "s#'#'\"'\"'#g;s#.*#par_fragment_length_mean='&'#" ; else echo "# par_fragment_length_mean="; fi )
$( if [ ! -z ${VIASH_PAR_GRAGMENT_LENGTH_SD+x} ]; then echo "${VIASH_PAR_GRAGMENT_LENGTH_SD}" | sed "s#'#'\"'\"'#g;s#.*#par_gragment_length_sd='&'#" ; else echo "# par_gragment_length_sd="; fi )
$( if [ ! -z ${VIASH_PAR_ESTIMATE_RSPD+x} ]; then echo "${VIASH_PAR_ESTIMATE_RSPD}" | sed "s#'#'\"'\"'#g;s#.*#par_estimate_rspd='&'#" ; else echo "# par_estimate_rspd="; fi )
$( if [ ! -z ${VIASH_PAR_NUM_RSPD_BINS+x} ]; then echo "${VIASH_PAR_NUM_RSPD_BINS}" | sed "s#'#'\"'\"'#g;s#.*#par_num_rspd_bins='&'#" ; else echo "# par_num_rspd_bins="; fi )
$( if [ ! -z ${VIASH_PAR_GIBBS_BURNIN+x} ]; then echo "${VIASH_PAR_GIBBS_BURNIN}" | sed "s#'#'\"'\"'#g;s#.*#par_gibbs_burnin='&'#" ; else echo "# par_gibbs_burnin="; fi )
$( if [ ! -z ${VIASH_PAR_GIBBS_NUMBER_OF_SAMPLES+x} ]; then echo "${VIASH_PAR_GIBBS_NUMBER_OF_SAMPLES}" | sed "s#'#'\"'\"'#g;s#.*#par_gibbs_number_of_samples='&'#" ; else echo "# par_gibbs_number_of_samples="; fi )
$( if [ ! -z ${VIASH_PAR_GIBBS_SAMPLING_GAP+x} ]; then echo "${VIASH_PAR_GIBBS_SAMPLING_GAP}" | sed "s#'#'\"'\"'#g;s#.*#par_gibbs_sampling_gap='&'#" ; else echo "# par_gibbs_sampling_gap="; fi )
$( if [ ! -z ${VIASH_PAR_CI_CREDIBILITY_LEVEL+x} ]; then echo "${VIASH_PAR_CI_CREDIBILITY_LEVEL}" | sed "s#'#'\"'\"'#g;s#.*#par_ci_credibility_level='&'#" ; else echo "# par_ci_credibility_level="; fi )
$( if [ ! -z ${VIASH_PAR_CI_NUMBER_OF_SAMPLES_PER_COUNT_VECTOR+x} ]; then echo "${VIASH_PAR_CI_NUMBER_OF_SAMPLES_PER_COUNT_VECTOR}" | sed "s#'#'\"'\"'#g;s#.*#par_ci_number_of_samples_per_count_vector='&'#" ; else echo "# par_ci_number_of_samples_per_count_vector="; fi )
$( if [ ! -z ${VIASH_PAR_KEEP_INTERMEDIATE_FILES+x} ]; then echo "${VIASH_PAR_KEEP_INTERMEDIATE_FILES}" | sed "s#'#'\"'\"'#g;s#.*#par_keep_intermediate_files='&'#" ; else echo "# par_keep_intermediate_files="; fi )
$( if [ ! -z ${VIASH_PAR_TEMPORARY_FOLDER+x} ]; then echo "${VIASH_PAR_TEMPORARY_FOLDER}" | sed "s#'#'\"'\"'#g;s#.*#par_temporary_folder='&'#" ; else echo "# par_temporary_folder="; fi )
$( if [ ! -z ${VIASH_PAR_TIME+x} ]; then echo "${VIASH_PAR_TIME}" | sed "s#'#'\"'\"'#g;s#.*#par_time='&'#" ; else echo "# par_time="; fi )
$( if [ ! -z ${VIASH_PAR_RUN_PRSEM+x} ]; then echo "${VIASH_PAR_RUN_PRSEM}" | sed "s#'#'\"'\"'#g;s#.*#par_run_pRSEM='&'#" ; else echo "# par_run_pRSEM="; fi )
$( if [ ! -z ${VIASH_PAR_CHIPSEQ_PEAK_FILE+x} ]; then echo "${VIASH_PAR_CHIPSEQ_PEAK_FILE}" | sed "s#'#'\"'\"'#g;s#.*#par_chipseq_peak_file='&'#" ; else echo "# par_chipseq_peak_file="; fi )
$( if [ ! -z ${VIASH_PAR_CHIPSEQ_TARGET_READ_FILES+x} ]; then echo "${VIASH_PAR_CHIPSEQ_TARGET_READ_FILES}" | sed "s#'#'\"'\"'#g;s#.*#par_chipseq_target_read_files='&'#" ; else echo "# par_chipseq_target_read_files="; fi )
$( if [ ! -z ${VIASH_PAR_CHIPSEQ_CONTROL_READ_FILES+x} ]; then echo "${VIASH_PAR_CHIPSEQ_CONTROL_READ_FILES}" | sed "s#'#'\"'\"'#g;s#.*#par_chipseq_control_read_files='&'#" ; else echo "# par_chipseq_control_read_files="; fi )
$( if [ ! -z ${VIASH_PAR_CHIPSEQ_READ_FILES_MULTI_TARGETS+x} ]; then echo "${VIASH_PAR_CHIPSEQ_READ_FILES_MULTI_TARGETS}" | sed "s#'#'\"'\"'#g;s#.*#par_chipseq_read_files_multi_targets='&'#" ; else echo "# par_chipseq_read_files_multi_targets="; fi )
$( if [ ! -z ${VIASH_PAR_CHIPSEQ_BED_FILES_MULTI_TARGETS+x} ]; then echo "${VIASH_PAR_CHIPSEQ_BED_FILES_MULTI_TARGETS}" | sed "s#'#'\"'\"'#g;s#.*#par_chipseq_bed_files_multi_targets='&'#" ; else echo "# par_chipseq_bed_files_multi_targets="; fi )
$( if [ ! -z ${VIASH_PAR_CAP_STACKED_CHIPSEQ_READS+x} ]; then echo "${VIASH_PAR_CAP_STACKED_CHIPSEQ_READS}" | sed "s#'#'\"'\"'#g;s#.*#par_cap_stacked_chipseq_reads='&'#" ; else echo "# par_cap_stacked_chipseq_reads="; fi )
$( if [ ! -z ${VIASH_PAR_N_MAX_STACKED_CHIPSEQ_READS+x} ]; then echo "${VIASH_PAR_N_MAX_STACKED_CHIPSEQ_READS}" | sed "s#'#'\"'\"'#g;s#.*#par_n_max_stacked_chipseq_reads='&'#" ; else echo "# par_n_max_stacked_chipseq_reads="; fi )
$( if [ ! -z ${VIASH_PAR_PARTITION_MODEL+x} ]; then echo "${VIASH_PAR_PARTITION_MODEL}" | sed "s#'#'\"'\"'#g;s#.*#par_partition_model='&'#" ; else echo "# par_partition_model="; fi )
$( if [ ! -z ${VIASH_META_NAME+x} ]; then echo "${VIASH_META_NAME}" | sed "s#'#'\"'\"'#g;s#.*#meta_name='&'#" ; else echo "# meta_name="; fi )
$( if [ ! -z ${VIASH_META_FUNCTIONALITY_NAME+x} ]; then echo "${VIASH_META_FUNCTIONALITY_NAME}" | sed "s#'#'\"'\"'#g;s#.*#meta_functionality_name='&'#" ; else echo "# meta_functionality_name="; fi )
$( if [ ! -z ${VIASH_META_RESOURCES_DIR+x} ]; then echo "${VIASH_META_RESOURCES_DIR}" | sed "s#'#'\"'\"'#g;s#.*#meta_resources_dir='&'#" ; else echo "# meta_resources_dir="; fi )
$( if [ ! -z ${VIASH_META_EXECUTABLE+x} ]; then echo "${VIASH_META_EXECUTABLE}" | sed "s#'#'\"'\"'#g;s#.*#meta_executable='&'#" ; else echo "# meta_executable="; fi )
$( if [ ! -z ${VIASH_META_CONFIG+x} ]; then echo "${VIASH_META_CONFIG}" | sed "s#'#'\"'\"'#g;s#.*#meta_config='&'#" ; else echo "# meta_config="; fi )
$( if [ ! -z ${VIASH_META_TEMP_DIR+x} ]; then echo "${VIASH_META_TEMP_DIR}" | sed "s#'#'\"'\"'#g;s#.*#meta_temp_dir='&'#" ; else echo "# meta_temp_dir="; fi )
$( if [ ! -z ${VIASH_META_CPUS+x} ]; then echo "${VIASH_META_CPUS}" | sed "s#'#'\"'\"'#g;s#.*#meta_cpus='&'#" ; else echo "# meta_cpus="; fi )
$( if [ ! -z ${VIASH_META_MEMORY_B+x} ]; then echo "${VIASH_META_MEMORY_B}" | sed "s#'#'\"'\"'#g;s#.*#meta_memory_b='&'#" ; else echo "# meta_memory_b="; fi )
$( if [ ! -z ${VIASH_META_MEMORY_KB+x} ]; then echo "${VIASH_META_MEMORY_KB}" | sed "s#'#'\"'\"'#g;s#.*#meta_memory_kb='&'#" ; else echo "# meta_memory_kb="; fi )
$( if [ ! -z ${VIASH_META_MEMORY_MB+x} ]; then echo "${VIASH_META_MEMORY_MB}" | sed "s#'#'\"'\"'#g;s#.*#meta_memory_mb='&'#" ; else echo "# meta_memory_mb="; fi )
$( if [ ! -z ${VIASH_META_MEMORY_GB+x} ]; then echo "${VIASH_META_MEMORY_GB}" | sed "s#'#'\"'\"'#g;s#.*#meta_memory_gb='&'#" ; else echo "# meta_memory_gb="; fi )
$( if [ ! -z ${VIASH_META_MEMORY_TB+x} ]; then echo "${VIASH_META_MEMORY_TB}" | sed "s#'#'\"'\"'#g;s#.*#meta_memory_tb='&'#" ; else echo "# meta_memory_tb="; fi )
$( if [ ! -z ${VIASH_META_MEMORY_PB+x} ]; then echo "${VIASH_META_MEMORY_PB}" | sed "s#'#'\"'\"'#g;s#.*#meta_memory_pb='&'#" ; else echo "# meta_memory_pb="; fi )
$( if [ ! -z ${VIASH_META_MEMORY_KIB+x} ]; then echo "${VIASH_META_MEMORY_KIB}" | sed "s#'#'\"'\"'#g;s#.*#meta_memory_kib='&'#" ; else echo "# meta_memory_kib="; fi )
$( if [ ! -z ${VIASH_META_MEMORY_MIB+x} ]; then echo "${VIASH_META_MEMORY_MIB}" | sed "s#'#'\"'\"'#g;s#.*#meta_memory_mib='&'#" ; else echo "# meta_memory_mib="; fi )
$( if [ ! -z ${VIASH_META_MEMORY_GIB+x} ]; then echo "${VIASH_META_MEMORY_GIB}" | sed "s#'#'\"'\"'#g;s#.*#meta_memory_gib='&'#" ; else echo "# meta_memory_gib="; fi )
$( if [ ! -z ${VIASH_META_MEMORY_TIB+x} ]; then echo "${VIASH_META_MEMORY_TIB}" | sed "s#'#'\"'\"'#g;s#.*#meta_memory_tib='&'#" ; else echo "# meta_memory_tib="; fi )
$( if [ ! -z ${VIASH_META_MEMORY_PIB+x} ]; then echo "${VIASH_META_MEMORY_PIB}" | sed "s#'#'\"'\"'#g;s#.*#meta_memory_pib='&'#" ; else echo "# meta_memory_pib="; fi )

## VIASH END

set -eo pipefail

if [ "\$par_strandedness" == 'forward' ]; then
    strandedness='--strandedness forward'
elif [ "\$par_strandedness" == 'reverse' ]; then
    strandedness="--strandedness reverse"
else
    strandedness=''
fi

IFS=";" read -ra input <<< \$par_input

INDEX=\$(find -L \$par_index -name "*.grp" | sed 's/\\.grp\$//')

unset_if_false=( par_paired par_quiet par_no_bam_output par_sampling_for_bam par_no_qualities 
                 par_alignments par_bowtie2 par_star par_hisat2_hca par_append_names 
                 par_single_cell_prior par_calc_pme par_calc_ci par_phred64_quals 
                 par_solexa_quals par_star_gzipped_read_file par_star_bzipped_read_file 
                 par_star_output_genome_bam par_estimate_rspd par_keep_intermediate_files 
                 par_time par_run_pRSEM par_cap_stacked_chipseq_reads par_sort_bam_by_read_name par_sort_bam_by_coordinate )

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

rsem-calculate-expression \\
    \${par_quiet:+-q} \\
    \${par_no_bam_output:+--no-bam-output} \\
    \${par_sampling_for_bam:+--sampling-for-bam} \\
    \${par_no_qualities:+--no-qualities} \\
    \${par_alignments:+--alignments} \\
    \${par_bowtie2:+--bowtie2} \\
    \${par_star:+--star} \\
    \${par_hisat2_hca:+--hisat2-hca} \\
    \${par_append_names:+--append-names} \\
    \${par_single_cell_prior:+--single-cell-prior} \\
    \${par_calc_pme:+--calc-pme} \\
    \${par_calc_ci:+--calc-ci} \\
    \${par_phred64_quals:+--phred64-quals} \\
    \${par_solexa_quals:+--solexa-quals} \\
    \${par_star_gzipped_read_file:+--star-gzipped-read-file} \\
    \${par_star_bzipped_read_file:+--star-bzipped-read-file} \\
    \${par_star_output_genome_bam:+--star-output-genome-bam} \\
    \${par_estimate_rspd:+--estimate-rspd} \\
    \${par_keep_intermediate_files:+--keep-intermediate-files} \\
    \${par_time:+--time} \\
    \${par_run_pRSEM:+--run-pRSEM} \\
    \${par_cap_stacked_chipseq_reads:+--cap-stacked-chipseq-reads} \\
    \${par_sort_bam_by_read_name:+--sort-bam-by-read-name} \\
    \${par_sort_bam_by_coordinate:+--sort-bam-by-coordinate} \\
    \${par_fai:+--fai "\$par_fai"} \\
    \${par_seed:+--seed "\$par_seed"} \\
    \${par_seed_length:+--seed-length "\$par_seed_length"} \\
    \${par_bowtie_n:+--bowtie-n "\$par_bowtie_n"} \\
    \${par_bowtie_e:+--bowtie-e "\$par_bowtie_e"} \\
    \${par_bowtie_m:+--bowtie-m "\$par_bowtie_m"} \\
    \${par_bowtie_chunkmbs:+--bowtie-chunkmbs "\$par_bowtie_chunkmbs"} \\
    \${par_bowtie2_mismatch_rate:+--bowtie2-mismatch-rate "\$par_bowtie2_mismatch_rate"} \\
    \${par_bowtie2_k:+--bowtie2-k "\$par_bowtie2_k"} \\
    \${par_bowtie2_sensitivity_level:+--bowtie2-sensitivity-level "\$par_bowtie2_sensitivity_level"} \\
    \${par_tag:+--tag "\$par_tag"} \\
    \${par_fragment_length_min:+--fragment-length-min "\$par_fragment_length_min"} \\
    \${par_fragment_length_max:+--fragment-length-max "\$par_fragment_length_max"} \\
    \${par_fragment_length_mean:+--fragment-length-mean "\$par_fragment_length_mean"} \\
    \${par_fragment_length_sd:+--fragment-length-sd "\$par_fragment_length_sd"} \\
    \${par_num_rspd_bins:+--num-rspd-bins "\$par_num_rspd_bins"} \\
    \${par_gibbs_burnin:+--gibbs-burnin "\$par_gibbs_burnin"} \\
    \${par_gibbs_number_of_samples:+--gibbs-number-of-samples "\$par_gibbs_number_of_samples"} \\
    \${par_gibbs_sampling_gap:+--gibbs-sampling-gap "\$par_gibbs_sampling_gap"} \\
    \${par_ci_credibility_level:+--ci-credibility-level "\$par_ci_credibility_level"} \\
    \${par_ci_number_of_samples_per_count_vector:+--ci-number-of-samples-per-count-vector "\$par_ci_number_of_samples_per_count_vector"} \\
    \${par_temporary_folder:+--temporary-folder "\$par_temporary_folder"} \\
    \${par_chipseq_peak_file:+--chipseq-peak-file "\$par_chipseq_peak_file"} \\
    \${par_chipseq_target_read_files:+--chipseq-target-read-files "\$par_chipseq_target_read_files"} \\
    \${par_chipseq_control_read_files:+--chipseq-control-read-files "\$par_chipseq_control_read_files"} \\
    \${par_chipseq_read_files_multi_targets:+--chipseq-read-files-multi-targets "\$par_chipseq_read_files_multi_targets"} \\
    \${par_chipseq_bed_files_multi_targets:+--chipseq-bed-files-multi-targets "\$par_chipseq_bed_files_multi_targets"} \\
    \${par_n_max_stacked_chipseq_reads:+--n-max-stacked-chipseq-reads "\$par_n_max_stacked_chipseq_reads"} \\
    \${par_partition_model:+--partition-model "\$par_partition_model"} \\
    \$strandedness \\
    \${par_paired:+--paired-end} \\
    \${input[*]} \\
    \$INDEX \\
    \$par_id
   
[[ -f "\${par_id}.genes.results" ]] && mv "\${par_id}.genes.results" \$par_counts_gene
[[ -f "\${par_id}.isoforms.results" ]] && mv "\${par_id}.isoforms.results" \$par_counts_transcripts
[[ -d "\${par_id}.stat" ]] && mv "\${par_id}.stat" \$par_stat
[[ -f "\${par_id}.log" ]] && mv "\${par_id}.log" \$par_logs
[[ -f "\${par_id}.STAR.genome.bam" ]] && mv "\${par_id}.STAR.genome.bam" \$par_bam_star
[[ -f "\${par_id}.genome.bam" ]] && mv "\${par_id}.genome.bam" \$par_bam_genome
[[ -f "\${par_id}.transcript.bam" ]] && mv "\${par_id}.transcript.bam" \$par_bam_transcript
VIASHMAIN
bash "\$tempscript" &
wait "\$!"

VIASHEOF


if [[ "$VIASH_ENGINE_TYPE" == "docker" ]]; then
  # strip viash automount from file paths
  
  if [ ! -z "$VIASH_PAR_INPUT" ]; then
    unset VIASH_TEST_INPUT
    IFS=';'
    for var in $VIASH_PAR_INPUT; do
      unset IFS
      if [ -z "$VIASH_TEST_INPUT" ]; then
      VIASH_TEST_INPUT="$(ViashDockerStripAutomount "$var")"
    else
      VIASH_TEST_INPUT="$VIASH_TEST_INPUT;""$(ViashDockerStripAutomount "$var")"
    fi
    done
    VIASH_PAR_INPUT="$VIASH_TEST_INPUT"
  fi
  if [ ! -z "$VIASH_PAR_INDEX" ]; then
    VIASH_PAR_INDEX=$(ViashDockerStripAutomount "$VIASH_PAR_INDEX")
  fi
  if [ ! -z "$VIASH_PAR_COUNTS_GENE" ]; then
    VIASH_PAR_COUNTS_GENE=$(ViashDockerStripAutomount "$VIASH_PAR_COUNTS_GENE")
  fi
  if [ ! -z "$VIASH_PAR_COUNTS_TRANSCRIPTS" ]; then
    VIASH_PAR_COUNTS_TRANSCRIPTS=$(ViashDockerStripAutomount "$VIASH_PAR_COUNTS_TRANSCRIPTS")
  fi
  if [ ! -z "$VIASH_PAR_STAT" ]; then
    VIASH_PAR_STAT=$(ViashDockerStripAutomount "$VIASH_PAR_STAT")
  fi
  if [ ! -z "$VIASH_PAR_LOGS" ]; then
    VIASH_PAR_LOGS=$(ViashDockerStripAutomount "$VIASH_PAR_LOGS")
  fi
  if [ ! -z "$VIASH_PAR_BAM_STAR" ]; then
    VIASH_PAR_BAM_STAR=$(ViashDockerStripAutomount "$VIASH_PAR_BAM_STAR")
  fi
  if [ ! -z "$VIASH_PAR_BAM_GENOME" ]; then
    VIASH_PAR_BAM_GENOME=$(ViashDockerStripAutomount "$VIASH_PAR_BAM_GENOME")
  fi
  if [ ! -z "$VIASH_PAR_BAM_TRANSCRIPT" ]; then
    VIASH_PAR_BAM_TRANSCRIPT=$(ViashDockerStripAutomount "$VIASH_PAR_BAM_TRANSCRIPT")
  fi
  if [ ! -z "$VIASH_PAR_FAI" ]; then
    VIASH_PAR_FAI=$(ViashDockerStripAutomount "$VIASH_PAR_FAI")
  fi
  if [ ! -z "$VIASH_PAR_CHIPSEQ_PEAK_FILE" ]; then
    VIASH_PAR_CHIPSEQ_PEAK_FILE=$(ViashDockerStripAutomount "$VIASH_PAR_CHIPSEQ_PEAK_FILE")
  fi
  if [ ! -z "$VIASH_PAR_CHIPSEQ_TARGET_READ_FILES" ]; then
    VIASH_PAR_CHIPSEQ_TARGET_READ_FILES=$(ViashDockerStripAutomount "$VIASH_PAR_CHIPSEQ_TARGET_READ_FILES")
  fi
  if [ ! -z "$VIASH_PAR_CHIPSEQ_CONTROL_READ_FILES" ]; then
    VIASH_PAR_CHIPSEQ_CONTROL_READ_FILES=$(ViashDockerStripAutomount "$VIASH_PAR_CHIPSEQ_CONTROL_READ_FILES")
  fi
  if [ ! -z "$VIASH_PAR_CHIPSEQ_READ_FILES_MULTI_TARGETS" ]; then
    VIASH_PAR_CHIPSEQ_READ_FILES_MULTI_TARGETS=$(ViashDockerStripAutomount "$VIASH_PAR_CHIPSEQ_READ_FILES_MULTI_TARGETS")
  fi
  if [ ! -z "$VIASH_PAR_CHIPSEQ_BED_FILES_MULTI_TARGETS" ]; then
    VIASH_PAR_CHIPSEQ_BED_FILES_MULTI_TARGETS=$(ViashDockerStripAutomount "$VIASH_PAR_CHIPSEQ_BED_FILES_MULTI_TARGETS")
  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_COUNTS_GENE" ] && [ ! -e "$VIASH_PAR_COUNTS_GENE" ]; then
  ViashError "Output file '$VIASH_PAR_COUNTS_GENE' does not exist."
  exit 1
fi
if [ ! -z "$VIASH_PAR_COUNTS_TRANSCRIPTS" ] && [ ! -e "$VIASH_PAR_COUNTS_TRANSCRIPTS" ]; then
  ViashError "Output file '$VIASH_PAR_COUNTS_TRANSCRIPTS' does not exist."
  exit 1
fi
if [ ! -z "$VIASH_PAR_STAT" ] && [ ! -e "$VIASH_PAR_STAT" ]; then
  ViashError "Output file '$VIASH_PAR_STAT' does not exist."
  exit 1
fi
if [ ! -z "$VIASH_PAR_LOGS" ] && [ ! -e "$VIASH_PAR_LOGS" ]; then
  ViashError "Output file '$VIASH_PAR_LOGS' does not exist."
  exit 1
fi
if [ ! -z "$VIASH_PAR_BAM_STAR" ] && [ ! -e "$VIASH_PAR_BAM_STAR" ]; then
  ViashError "Output file '$VIASH_PAR_BAM_STAR' does not exist."
  exit 1
fi
if [ ! -z "$VIASH_PAR_BAM_GENOME" ] && [ ! -e "$VIASH_PAR_BAM_GENOME" ]; then
  ViashError "Output file '$VIASH_PAR_BAM_GENOME' does not exist."
  exit 1
fi
if [ ! -z "$VIASH_PAR_BAM_TRANSCRIPT" ] && [ ! -e "$VIASH_PAR_BAM_TRANSCRIPT" ]; then
  ViashError "Output file '$VIASH_PAR_BAM_TRANSCRIPT' does not exist."
  exit 1
fi


exit 0
