#!/usr/bin/env cwl-runner

cwlVersion: v1.2
class: CommandLineTool

label: "spades genomic assembler"

doc: |
    Runs the spades assembler using a dataset file

requirements:
  InlineJavascriptRequirement: {}
  InitialWorkDirRequirement:
    listing:
      - entryname: spades.json
        entry: |-
          [
            {
              orientation: "fr",
              type: "paired-end",
              right reads: $( inputs.forward_reads.map( function(x) {return  x.path} ) ),
              left reads: $( inputs.reverse_reads.map( function(x) {return  x.path} ) )
            }
            
            ${
              var pacbio=""
                if (inputs.pacbio_reads != null) {
                 pacbio+=',{ type: "pacbio", single reads: ["' + inputs.pacbio_reads.map( function(x) {return  x.path} ).join('","') + '"] }' 
              }
              return pacbio;
            }
          ]

baseCommand: ["/unlock/infrastructure/binaries/SPAdes-3.14.1-Linux/bin/spades.py", "--dataset", "spades.json"]

arguments:
  - valueFrom: $(runtime.outdir)/output
    prefix: -o
  - valueFrom: $(inputs.memory / 1000)
    prefix: --memory

inputs:
  isolate:
    type: boolean?
    doc: this flag is highly recommended for high-coverage isolate and multi-cell data
    label: high-coverage mode
    inputBinding:
      prefix: --isolate
  metagenomics:
    type: boolean?
    doc: this flag is required for metagenomic sample data
    label: metagenomics sample
    inputBinding:
      prefix: --meta
  biosyntheticSPAdes:
    type: boolean?
    doc: this flag is required for biosyntheticSPAdes mode
    label: biosynthetic spades mode
    inputBinding:
      prefix: --bio
  rna:
    type: boolean?
    doc: this flag is required for RNA-Seq data
    label: rnaseq data
    inputBinding:
      prefix: --rna
  plasmid:
    type: boolean?
    doc: runs plasmidSPAdes pipeline for plasmid detection
    label: plasmid spades run
    inputBinding:
      prefix: --plasmid
  IonTorrent:
    type: boolean?
    doc: this flag is required for IonTorrent data
    label: iontorrent data
    inputBinding:
      prefix: --iontorrent
  forward_reads:
    type: File[]
    #format: edam:format_1930  # FASTQ
    doc: The file containing the forward reads
    label: Forward reads
  reverse_reads:
    type: File[]
    #format: edam:format_1930  # FASTQ
    doc: The file containing the reverse reads
    label: Reverse reads
  pacbio_reads:
    type: File[]?
    #format: edam:format_1930  # FASTQ
    doc: file with PacBio reads
    label: pacbio reads
  threads:
    type: int
    doc: number of threads to use
    label: threads
    inputBinding:
      prefix: --threads
  memory:
    type: int
    doc: Memory used in megabytes

outputs:
  # stdout: stdout
  # stderr: stderr
  # json:
  #   type: File
  #   outputBinding:
  #     glob: spades.json
  contigs:
    type: File
    format: edam:format_1929  # FASTA
    outputBinding:
      glob: output/contigs.fasta

  scaffolds:
    type: File
    format: edam:format_1929  # FASTA
    outputBinding:
      glob: output/scaffolds.fasta

  assembly_graph:
    type: File
    #format: edam:format_TBD  # FASTG
    outputBinding:
      glob: output/assembly_graph.fastg

  contigs_assembly_paths:
    type: File
    outputBinding:
      glob: output/contigs.paths

  scaffolds_assembly_paths:
    type: File
    outputBinding:
      glob: output/scaffolds.paths

  contigs_before_rr:
    label: contigs before repeat resolution
    type: File
    format: edam:format_1929  # FASTA
    outputBinding:
      glob: output/before_rr.fasta

  params:
    label: information about SPAdes parameters in this run
    type: File
    format: iana:text/plain
    outputBinding:
      glob: output/params.txt

  log:
    label: SPAdes log
    type: File
    format: iana:text/plain
    outputBinding:
      glob: output/spades.log

  internal_config:
    label: internal configuration file
    type: File
    format: text/plain
    outputBinding:
      glob: output/dataset.info

  internal_dataset:
    label: internal YAML data set file
    type: File
    outputBinding:
      glob: output/input_dataset.yaml

s:author:
  - class: s:Person
    s:identifier: https://orcid.org/0000-0001-8172-8981
    s:email: mailto:jasper.koehorst@wur.nl
    s:name: Jasper Koehorst
  - class: s:Person
    s:identifier: https://orcid.org/0000-0001-9524-5964
    s:email: mailto:bart.nijsse@wur.nl
    s:name: Bart Nijsse

s:citation: https://m-unlock.nl
s:codeRepository: https://gitlab.com/m-unlock/cwl
s:dateCreated: "2020-00-00"
s:license: https://spdx.org/licenses/CC0-1.0.html 
s:copyrightHolder: "UNLOCK - Unlocking Microbial Potential"


$namespaces:
 edam: http://edamontology.org/
 iana: https://www.iana.org/assignments/media-types/
 s: http://schema.org/

$schemas:
 - http://edamontology.org/EDAM_1.16.owl