#!/usr/bin/env cwl-runner
cwlVersion: v1.2
class: Workflow
label: "Subworkflow for Annotation"
doc: |
  "Subworkflow for Metagenome Annotation
  This subworkflow is for annotation of predicted protein coding sequences.
  "

requirements:
  SubworkflowFeatureRequirement: {}
  WorkReuse:
    enableReuse: true


inputs:
############## Common Parameters in this subworkflow ##############
  - id: SW_THREADS
    type: int
    label: "threads"
    doc: "number of threads to use in this subworkflow"
    default: 16

  - id: SW_EVALUE
    type: float
    label: "evalue"
    doc: "E-value threshold of BLASTP (diamond) and BLASTN alignment"
    default: 0.1


############## Parameters for BLASTN rRNA index creation and alignment (/Worlkflow/blastn_rRNA_ssw.cwl) ##############
  - id: SW_BLASTN_rRNA_FASTA_FILE1
    type: File
    label: "SILVA_138.1_LSUParc_tax_silva"
    doc: "SILVA_138.1_LSUParc_tax_silva"
    default:
      class: File
      location: ../Data/SILVA_138.1_LSUParc_tax_silva.fasta.gz
  
  - id: SW_BLASTN_rRNA_FASTA_FILE2
    type: File
    label: "SILVA_138.1_SSUParc_tax_silva"
    doc: "SILVA_138.1_SSUParc_tax_silva"
    default:
      class: File
      location: ../Data/SILVA_138.1_SSUParc_tax_silva.fasta.gz

  - id: SW_PRODIGAL_RESULT_DNA_FASTA_FILE
    type: File
    label: "input fasta file (nucleotide sequence generated by prodigal process)"
    doc: "predicted protein coding sequences produced by Prodigal process"
    default:
      class: File
      location: ../out/all_contigs_SRR27548858_dna.fasta

  - id: SW_PRODIGAL_RESULT_PROTEIN_FASTA_FILE
    type: File
    label: "predicted protein coding sequences produced by Prodigal process"
    doc: "predicted protein coding sequences produced by Prodigal process"
    default:
      class: File
      location: ../out/all_contigs_SRR27548858_protein.fasta

############## Parameters for diamond index creation and alignment (/Worlkflow/diamond_protein_ssw.cwl) ##############
  - id: SW_DIAMOND_INDEX_FILE
    type: File
    label: "Protein fasta file for diamond index"
    doc: "Protein fasta file for diamond index"
    default:
      class: File
      location: ../Data/uniprot_sprot.fasta


############## Parameters for GTF file creation (/Tools/12_faablast2gtf4tpm.cwl) ##############
  - id: SW_OUTPUT_GTF_FILE_NAME
    type: string
    label: "Output GTF file name"
    doc: "Output GTF file name"
    default: "all_contigs_SRR27548858_annotation.gtf"



############## Workflow steps ##############
steps:
  - id: PROCESS_BLASTN_rRNA
    run: ./blastn_rRNA_ssw.cwl
    label: "BLASTN rRNA annotation process"
    in:
      BLASTN_rRNA_FASTA_FILE1: SW_BLASTN_rRNA_FASTA_FILE1
      BLASTN_rRNA_FASTA_FILE2: SW_BLASTN_rRNA_FASTA_FILE2
      # BLASTN_rRNA_INDEX_DIR_NAME1: default
      # BLASTN_rRNA_INDEX_DIR_NAME2: default
      THREADS: SW_THREADS
      INPUT_FASTA_FILE: SW_PRODIGAL_RESULT_DNA_FASTA_FILE
      # OUTPUT_FILE_NAME1: default
      # OUTPUT_FILE_NAME2: default
      # MAX_TARGET_SEQS: default
      EVALUE: SW_EVALUE
      PRODIGAL_RESULT_PROTEIN_FASTA_FILE: SW_PRODIGAL_RESULT_PROTEIN_FASTA_FILE
    
    out: [BLASTN_rRNA_concat_file, FILTERED_rRNA_PROTEIN_FASTA_FILE]


  - id: PROCESS_DIAMOND_PROTEIN
    run: ./diamond_protein_ssw.cwl
    in:
      THREADS: SW_THREADS
      DIAMOND_INDEX_FILE: SW_DIAMOND_INDEX_FILE
      # DIAMOND_INDEX_NAME: default
      # DIAMOND_OUTPUT_FILE_NAME: default
      DIAMOND_FILTERED_RRNA_PROTEIN_FASTA_FILE: PROCESS_BLASTN_rRNA/FILTERED_rRNA_PROTEIN_FASTA_FILE # previous step output
      DIAMOND_EVALUE: SW_EVALUE
    
    out: [DIAMOND_ALIGNMENT_FILE, DIAMOND_TOPLIST_FILE, DIAMOND_FILTERED_FILE]


  - id: PROCESS_GTF_CREATION
    run: ../Tools/12_faablast2gtf4tpm.cwl
    in:
      # custom_script: default
      prodigal_result_protein_fasta_file: SW_PRODIGAL_RESULT_PROTEIN_FASTA_FILE
      blastn_result_rRNA_list_file: PROCESS_BLASTN_rRNA/BLASTN_rRNA_concat_file
      diamond_result_protein_list_file: PROCESS_DIAMOND_PROTEIN/DIAMOND_ALIGNMENT_FILE
      output_gtf_file_name: SW_OUTPUT_GTF_FILE_NAME
    
    out: [output_gtf_file]


outputs:
  - id: OUTPUT_GTF_FILE
    type: File
    label: "Output GTF file"
    doc: "Output GTF file"
    outputSource: PROCESS_GTF_CREATION/output_gtf_file

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


      

