name: prepare_genome
namespace: workflows
description: |
  A subworkflow for preparing all the required genome references

argument_groups:
  - name: "Input"
    arguments:
      - name: "--fasta"
        type: file
        description: Path to FASTA genome file.
        required: true
      - name: "--gtf"
        type: file
        description: Path to GTF annotation file. This parameter is *mandatory* if --genome is not specified.
        required: false
      - name: "--gff"
        type: file
        description: Path to GFF3 annotation file. Required if "--gtf" is not specified.
        required: false
      - name: "--additional_fasta"
        type: file
        description: FASTA file to concatenate to genome FASTA file e.g. containing spike-in sequences.
      - name: "--transcript_fasta"
        type: file
        description: Path to FASTA transcriptome file.
      - name: "--gene_bed"
        type: file
        description: Path to BED file containing gene intervals. This will be created from the GTF file if not specified.
      - name: "--splicesites"
        type: file
        description: Splice sites file required for HISAT2.
      - name: "--skip_bbsplit"
        type: boolean
        description: Skip BBSplit for removal of non-reference genome reads.
      - name: "--bbsplit_fasta_list"
        type: file
        description: Path to comma-separated file containing a list of reference genomes to filter reads against with BBSplit. To use BBSplit, "--skip_bbsplit" must be explicitly set to "false". The file should contain 2 (comma separated) columns - short name and full path to reference genome(s)
      - name: "--star_index"
        type: file
        description: Path to directory or tar.gz archive for pre-built STAR index.
      - name: "--rsem_index"
        type: file
        description: Path to directory or tar.gz archive for pre-built RSEM index.
      - name: extra_rsem_prepare_reference_args
        type: string
        description: Extra arguments to pass to rsem-prepare-reference command in addition to defaults defined by the pipeline.
      - name: "--salmon_index"
        type: file
        description: Path to directory or tar.gz archive for pre-built Salmon index.
      - name: "--kallisto_index"
        type: file
        description: Path to directory or tar.gz archive for pre-built Kallisto index.
      # - name: "--hisat2_index"
      #   type: file
      #   description: Path to directory or tar.gz archive for pre-built HISAT2 index.
      - name: "--bbsplit_index"
        type: file
        description: Path to directory or tar.gz archive for pre-built BBSplit index.
      - name: "--pseudo_aligner_kmer_size"
        type: integer
        description: Kmer length passed to indexing step of pseudoaligners.
        default: 31
      - name: "--gencode"
        type: boolean
        description: Specify if the GTF annotation is in GENCODE format.
      - name: "--biotype"
        type: string
        description: Biotype value to use while appending entries to GTF file when additional fasta file is provided.
      - name: "--filter_gtf"
        type: boolean
        description: Whether to filter the GTF or not?
      - name: "--aligner"
        type: string
        description: Specifies the alignment algorithm to use - available options are 'star_salmon', 'star_rsem' and 'hisat2'. 
        choices: [star_salmon, star_rsem, hisat2]
        default: "star_salmon"
      - name: "--pseudo_aligner"
        type: string
        description: Specifies the pseudo aligner to use - available options are 'salmon'. Runs in addition to '--aligner'.
        choices: [salmon, kallisto]
        default: "salmon"
        
  - name: "Output"
    arguments:
      - name: "--fasta_uncompressed"
        type: file
        direction: output
        default: reference_genome.fasta
      - name: "--gtf_uncompressed"
        type: file
        direction: output
        default: gene_annotation.gtf
      - name: "--transcript_fasta_uncompressed"
        type: file
        direction: output
        default: transcriptome.fasta
      - name: "--gene_bed_uncompressed"
        type: file
        direction: output
        default: gene_annotation.bed
      - name: "--star_index_uncompressed"
        type: file
        direction: output
        description: Path to STAR index.
        default: STAR_index
      - name: "--rsem_index_uncompressed"
        type: file
        direction: output
        description: Path to directory or tar.gz archive for pre-built RSEM index.
        default: RSEM_index
      - name: "--salmon_index_uncompressed"
        type: file
        direction: output
        description: Path to Salmon index.
        default: Salmon_index
      - name: "--kallisto_index_uncompressed"
        type: file
        direction: output
        description: Path to Kallisto index.
        default: Kallisto_index
      # - name: "--hisat2_index_uncompressed"
      #   type: file
      #   direction: output
      #   description: Path to directory or tar.gz archive for pre-built HISAT2 index.
      - name: "--bbsplit_index_uncompressed"
        type: file
        direction: output
        description: Path to BBSplit index.
        default: BBSplit_index
      - name: "--chrom_sizes"
        type: file
        direction: output
        description: File containing chromosome lengths
        default: reference_genome.fasta.sizes
      - name: "--fai"
        type: file
        description: FASTA index file
        direction: output
        default: reference_genome.fasta.fai

resources:
  - type: nextflow_script
    path: main.nf
    entrypoint: run_wf
    
dependencies:
  - name: gunzip
  - name: gffread
    repository: biobox
  - name: cat_additional_fasta
  - name: gtf2bed
  - name: preprocess_transcripts_fasta
  - name: gtf_filter
  - name: rsem/rsem_prepare_reference
    repository: biobox
  - name: getchromsizes
  - name: untar
    repository: craftbox
  - name: star/star_genome_generate
    repository: biobox
  - name: bbmap_bbsplit
  - name: salmon/salmon_index
    repository: biobox
  - name: kallisto/kallisto_index

repositories:
  - name: biobox
    type: vsh
    repo: biobox
    tag: main
  - name: craftbox
    type: vsh
    repo: craftbox
    tag: main

runners: 
- type: executable
- type: nextflow
