#!/usr/bin/env cwl-runner

cwlVersion: v1.2
class: Workflow
requirements:
   - class: StepInputExpressionRequirement
   - class: InlineJavascriptRequirement
   - class: MultipleInputFeatureRequirement
   - class: ScatterFeatureRequirement

label: Genome assembly workflow
doc: Workflow for genome assembly working with pacbio and illumina data

inputs:
  prefix_id:
    type: string
    default: "DNAsample"
  metagenomics:
    type: boolean?
    doc: this flag is required for metagenomic sample data
    label: metagenomics sample
  isolate:
    type: boolean?
    doc: this flag is highly recommended for high-coverage isolate and multi-cell data
    label: high-coverage mode
  pacbio_reads:
    type: File[]?
    doc: file with PacBio reads locally
    label: pacbio reads
  forward_reads:
    type: File[]
    doc: forward sequence file locally
    label: forward reads
  reverse_reads:
    type: File[]
    doc: reverse sequence file locally
    label: reverse reads
  threads:
    type: int?
    doc: number of threads to use for computational processes
    label: number of threads
    default: 2
  memory:
    type: int?
    doc: maximum memory usage in megabytes
    label: maximum memory usage in megabytes
    default: 4000

steps:
#  fastqc:
#    run: ../fastqc/fastqc.cwl
#    in:
#      fastqs: 
#        source: [forward_reads, reverse_reads]
#        linkMerge: merge_flattened
#        pickValue: all_non_null
#    out: [output]
############################
  fastp:
    run: ../fastp/fastp.cwl
    scatter: [forward_reads, reverse_reads]
    scatterMethod: dotproduct
    in:
      prefix: prefix_id
      forward_reads: forward_reads
      reverse_reads: reverse_reads
      threads: threads
    out: [out_forward_reads, out_reverse_reads, html_report, json_report]
############################
  spades:
   run: ../assembly/spades.cwl
   in:
    forward_reads: fastp/out_forward_reads
    reverse_reads: fastp/out_reverse_reads
    pacbio_reads: pacbio_reads
    metagenomics: metagenomics
    memory: memory
    threads: threads
    isolate: isolate
   out: [contigs, scaffolds, assembly_graph, contigs_assembly_graph, scaffolds_assembly_graph, contigs_before_rr, params, log, internal_config, internal_dataset]
############################
#  fastqc_files_to_folder:
#    run: ../expressions/files_to_folder.cwl
#    in:
#      files: 
#        source: [fastqc/output]
#      folder: 
#        default: "1_QualityControl"
#    out:
#      [results]
############################  
  fastp_files_to_folder:
    run: ../expressions/files_to_folder.cwl
    in:
      files: 
        source: [fastp/out_forward_reads, fastp/out_reverse_reads, fastp/html_report, fastp/json_report]
        linkMerge: merge_flattened
        pickValue: all_non_null
      folder: 
        default: "2_Filtering"
    out:
      [results]
############################
  spades_files_to_folder:
    run: ../expressions/files_to_folder.cwl
    in:
      files: 
        source: [spades/contigs, spades/scaffolds, spades/assembly_graph, spades/contigs_assembly_graph, spades/scaffolds_assembly_graph, spades/contigs_before_rr, spades/params, spades/log, spades/internal_config, spades/internal_dataset]
      folder: 
        default: "3_Assembly"
    out:
      [results]
############################

outputs:
#  files_to_folder_fastqc:
#    type: Directory
#    outputSource: fastqc_files_to_folder/results
  files_to_folder_fastp:
    type: Directory
    outputSource: fastp_files_to_folder/results
  files_to_folder_spades:
    type: Directory
    outputSource: spades_files_to_folder/results
  # Optional use for further workflows?
  scaffolds:
    type: File
    outputSource: spades/scaffolds
    
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/Apache-2.0 
s:copyrightHolder: "UNLOCK - Unlocking Microbial Potential"


$namespaces:
  s: https://schema.org/
  edam: http://edamontology.org/

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