name: parallel_map
description: |
  Map wells in batch, using STAR
  Spliced Transcripts Alignment to a Reference (C) Alexander Dobin
  https://github.com/alexdobin/STAR
authors:
  - __merge__: /src/base/authors/dries_schaumont.yaml
    roles: [ maintainer ]
  - __merge__: /src/base/authors/toni_verbeiren.yaml
    roles: [ author, maintainer ]
requirements:
  commands:
    - STAR
    - file
    - parallel
argument_groups:
  - name: Input arguments
    arguments:
    - name: "--input_r1"
      description: |
        Input FASTQ files for the forward reads. All FASTQ file names must start with the prefix '{well_id}_R1', where
        'well_id' can be found as the sequence identifier in the barcodes FASTA file (see 'barcodesFasta' argument).
        For each FASTQ file, a matching FASTQ file for the reverse reads must be provided to the 'input_r2' argument,
        meaning that their 'well_id' prefix must match. The number of items provided for 'input_r1' must be equal
        to the number of items for 'input_r2'.
      type: file
      required: true
      multiple: true
    - name: "--input_r2"
      description: |
        Input FASTQ files for the reverse reads. All FASTQ file names must start with the prefix '{well_id}_R2', where
        'well_id' can be found as the sequence identifier in the barcodes FASTA file (see 'barcodesFasta' argument).
        For each FASTQ file, a matching FASTQ file for the reverse reads must be provided to the 'input_r1' argument,
        meaning that their 'well_id' prefix must match. The number of items provided for 'input_r1' must be equal
        to the number of items for 'input_r2'.
      type: file
      required: true
      multiple: true
    - name: "--genomeDir"
      description: |
        Reference genome to match to. Can be generated from genomic FASTA sequences and a genome annotation
        by using STAR with '--runMode genomeGenerate'.
      type: file
      required: true
    - name: "--barcodesFasta"
      type: file
      required: true
      description: |
        FASTA file where each entry specifies a unique barcode sequence present at the start of the forward input reads
        (input_r1). The IDs of each barcode (the start of the FASTA headers up until the first whitespace character) must
        match with the start of one input FASTQ pair.
  - name: Barcode arguments
    arguments:
    - name: "--umiLength"
      type: integer
      required: true
      description: |
        Length of the Unique Molecular Identifiers (UMI). The UMI are expected to be located after the barcodes in the
        forwards reads.
    - name: "--limitBAMsortRAM"
      type: string
      default: "10000000000"
  - name: Runtime arguments
    arguments:
    - name: "--runThreadN"
      description: "Number of threads to use for a single STAR execution."
      type: integer
      default: 1
  - name: Output arguments
    arguments:
    - name: "--output"
      type: file
      description: |
          A list of output folders which are the result of using STAR to map each input FASTQ pair STAR to the reference genome.
          The order of the items DO NOT match with the order of the entries in the barcodes FASTA file or the input FASTQ pairs. 
      required: true
      multiple: true
      direction: output
      default: './*'
    - name: "--joblog"
      type: file
      description: Where to store the log file listing all the jobs.
      required: false
      direction: output
      default: "execution_log.txt"

resources:
- type: bash_script
  path: script.sh
- path: STAR

test_resources:
  - type: bash_script
    path: test.sh

engines:
  - type: docker
    image: debian:stable-slim
    setup:
      - type: apt
        packages:
          - procps
          - wget
          - automake
          - make
          - gcc
          - g++
          - zlib1g-dev
          - parallel
          - file
          - seqkit
      - type: docker
        build_args:
          - STAR_V=2.7.6a
        env:
          - STAR_SOURCE="https://github.com/alexdobin/STAR/archive/refs/tags/$STAR_V.tar.gz"
          - STAR_TARGET="/app/star-$STAR_V.tar.gz"
          - STAR_INSTALL_DIR="/app/STAR-$STAR_V"
          - STAR_BINARY=STAR
        copy:
          - STAR /usr/local/bin/$STAR_BINARY
runners:
  - type: executable
  - type: nextflow
