#!/usr/bin/env cwl-runner
class: CommandLineTool
cwlVersion: v1.2
label: "bwa index process"
doc: |
  "bwa index create process from predicted protein conding sequences for executing BWA-MEM process
  modified from https://github.com/common-workflow-library/bio-cwl-tools/blob/release/bwa/BWA-Index.cwl
  original script: https://github.com/RyoMameda/workflow/blob/main/05_mapping.sh
  original command: bwa index -p index_${f}_bwa ${f}.fna"

requirements:
  WorkReuse:
    enableReuse: true
  ShellCommandRequirement: {}

arguments:
  - shellQuote: false
    valueFrom: |
      mkdir -p $(inputs.index_bwa_dir_name)
      touch $(inputs.index_bwa_dir_name)/$(inputs.index_bwa_name) # create empty file
      bwa index -p $(inputs.index_bwa_dir_name)/$(inputs.index_bwa_name) $(inputs.input_fasta_file.path)

inputs:

  - id: index_bwa_dir_name
    type: string
    label: "index bwa dir name"
    doc: "index files will be contained in this directry"
    default: "index_bwa_dir"

  - id: index_bwa_name
    type: string
    label: "index bwa name"
    doc: "index files' name for BWA-MEM"
    default: "index_bwa"

  - id: input_fasta_file
    type: File
    label: "input dna fasta file"
    doc: "input predicted protein conding DNA sequences fasta file generated by prodigal process"
    default:
      class: File
      location: ../out/all_contigs_SRR27548858_dna.fasta

outputs:
  # - id: all-for-debugging
  #   type:
  #     type: array
  #     items: [File, Directory]
  #   outputBinding:
  #     glob: "*"

  - id: index_bwa_dir
    type: Directory
    label: "index bwa dir"
    doc: "index files will be contained in this directry"
    outputBinding:
      glob: "$(inputs.index_bwa_dir_name)"

  - id: index_bwa_files
    type: File
    label: "index bwa files"
    doc: "index files' name for BWA-MEM"
    outputBinding:
      glob: "$(inputs.index_bwa_dir_name)/$(inputs.index_bwa_name)"
    secondaryFiles:
      - .amb
      - .ann
      - .bwt
      - .pac
      - .sa
    

hints:
  - class: DockerRequirement
    dockerPull: quay.io/biocontainers/bwa:0.7.17--he4a0461_11

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