From c1ac3fbb592b8e19bd66110fbe77bd47785cce6d Mon Sep 17 00:00:00 2001
From: James Fellows Yates <jfy133@gmail.com>
Date: Tue, 31 May 2022 20:13:48 +0200
Subject: [PATCH 1/8] Skeleton

---
 modules/gatk/realignertargetcreator/main.nf   | 75 +++++++++++++++++++
 modules/gatk/realignertargetcreator/meta.yml  | 51 +++++++++++++
 tests/config/pytest_modules.yml               |  4 +
 .../gatk/realignertargetcreator/main.nf       | 15 ++++
 .../realignertargetcreator/nextflow.config    |  5 ++
 .../gatk/realignertargetcreator/test.yml      | 14 ++++
 6 files changed, 164 insertions(+)
 create mode 100644 modules/gatk/realignertargetcreator/main.nf
 create mode 100644 modules/gatk/realignertargetcreator/meta.yml
 create mode 100644 tests/modules/gatk/realignertargetcreator/main.nf
 create mode 100644 tests/modules/gatk/realignertargetcreator/nextflow.config
 create mode 100644 tests/modules/gatk/realignertargetcreator/test.yml

diff --git a/modules/gatk/realignertargetcreator/main.nf b/modules/gatk/realignertargetcreator/main.nf
new file mode 100644
index 00000000..59dee1a8
--- /dev/null
+++ b/modules/gatk/realignertargetcreator/main.nf
@@ -0,0 +1,75 @@
+// TODO nf-core: If in doubt look at other nf-core/modules to see how we are doing things! :)
+//               https://github.com/nf-core/modules/tree/master/modules
+//               You can also ask for help via your pull request or on the #modules channel on the nf-core Slack workspace:
+//               https://nf-co.re/join
+// TODO nf-core: A module file SHOULD only define input and output files as command-line parameters.
+//               All other parameters MUST be provided using the "task.ext" directive, see here:
+//               https://www.nextflow.io/docs/latest/process.html#ext
+//               where "task.ext" is a string.
+//               Any parameters that need to be evaluated in the context of a particular sample
+//               e.g. single-end/paired-end data MUST also be defined and evaluated appropriately.
+// TODO nf-core: Software that can be piped together SHOULD be added to separate module files
+//               unless there is a run-time, storage advantage in implementing in this way
+//               e.g. it's ok to have a single module for bwa to output BAM instead of SAM:
+//                 bwa mem | samtools view -B -T ref.fasta
+// TODO nf-core: Optional inputs are not currently supported by Nextflow. However, using an empty
+//               list (`[]`) instead of a file can be used to work around this issue.
+
+process GATK_REALIGNERTARGETCREATOR {
+    tag "$meta.id"
+    label 'process_low'
+
+    // TODO nf-core: List required Conda package(s).
+    //               Software MUST be pinned to channel (i.e. "bioconda"), version (i.e. "1.10").
+    //               For Conda, the build (i.e. "h9402c20_2") must be EXCLUDED to support installation on different operating systems.
+    // TODO nf-core: See section in main README for further information regarding finding and adding container addresses to the section below.
+    conda (params.enable_conda ? "bioconda::gatk=3.8" : null)
+    container "${ workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container ?
+        'https://depot.galaxyproject.org/singularity/gatk:3.8--hdfd78af_11':
+        'quay.io/biocontainers/gatk:3.8--hdfd78af_11' }"
+
+    input:
+    // TODO nf-core: Where applicable all sample-specific information e.g. "id", "single_end", "read_group"
+    //               MUST be provided as an input via a Groovy Map called "meta".
+    //               This information may not be required in some instances e.g. indexing reference genome files:
+    //               https://github.com/nf-core/modules/blob/master/modules/bwa/index/main.nf
+    // TODO nf-core: Where applicable please provide/convert compressed files as input/output
+    //               e.g. "*.fastq.gz" and NOT "*.fastq", "*.bam" and NOT "*.sam" etc.
+    tuple val(meta), path(bam)
+
+    output:
+    // TODO nf-core: Named file extensions MUST be emitted for ALL output channels
+    tuple val(meta), path("*.bam"), emit: bam
+    // TODO nf-core: List additional required output channels/values here
+    path "versions.yml"           , emit: versions
+
+    when:
+    task.ext.when == null || task.ext.when
+
+    script:
+    def args = task.ext.args ?: ''
+    def prefix = task.ext.prefix ?: "${meta.id}"
+    // TODO nf-core: Where possible, a command MUST be provided to obtain the version number of the software e.g. 1.10
+    //               If the software is unable to output a version number on the command-line then it can be manually specified
+    //               e.g. https://github.com/nf-core/modules/blob/master/modules/homer/annotatepeaks/main.nf
+    //               Each software used MUST provide the software name and version number in the YAML version file (versions.yml)
+    // TODO nf-core: It MUST be possible to pass additional parameters to the tool as a command-line string via the "task.ext.args" directive
+    // TODO nf-core: If the tool supports multi-threading then you MUST provide the appropriate parameter
+    //               using the Nextflow "task" variable e.g. "--threads $task.cpus"
+    // TODO nf-core: Please replace the example samtools command below with your module's command
+    // TODO nf-core: Please indent the command appropriately (4 spaces!!) to help with readability ;)
+    """
+    samtools \\
+        sort \\
+        $args \\
+        -@ $task.cpus \\
+        -o ${prefix}.bam \\
+        -T $prefix \\
+        $bam
+
+    cat <<-END_VERSIONS > versions.yml
+    "${task.process}":
+        gatk: \$(echo \$(samtools --version 2>&1) | sed 's/^.*samtools //; s/Using.*\$//' ))
+    END_VERSIONS
+    """
+}
diff --git a/modules/gatk/realignertargetcreator/meta.yml b/modules/gatk/realignertargetcreator/meta.yml
new file mode 100644
index 00000000..a33db8f1
--- /dev/null
+++ b/modules/gatk/realignertargetcreator/meta.yml
@@ -0,0 +1,51 @@
+name: "gatk_realignertargetcreator"
+## TODO nf-core: Add a description of the module and list keywords
+description: write your description here
+keywords:
+  - sort
+tools:
+  - "gatk":
+      ## TODO nf-core: Add a description and other details for the software below
+      description: "The full Genome Analysis Toolkit (GATK) framework, license restricted."
+      homepage: "None"
+      documentation: "None"
+      tool_dev_url: "None"
+      doi: ""
+      licence: "['https://software.broadinstitute.org/gatk/download/licensing', 'https://www.broadinstitute.org/gatk/about/#licensing', 'BSD']"
+
+## TODO nf-core: Add a description of all of the variables used as input
+input:
+  # Only when we have meta
+  - meta:
+      type: map
+      description: |
+        Groovy Map containing sample information
+        e.g. [ id:'test', single_end:false ]
+  # 
+  ## TODO nf-core: Delete / customise this example input
+  - bam:
+      type: file
+      description: BAM/CRAM/SAM file
+      pattern: "*.{bam,cram,sam}"
+
+## TODO nf-core: Add a description of all of the variables used as output
+output:
+  #Only when we have meta
+  - meta:
+      type: map
+      description: |
+        Groovy Map containing sample information
+        e.g. [ id:'test', single_end:false ]
+  # 
+  - versions:
+      type: file
+      description: File containing software versions
+      pattern: "versions.yml"
+  ## TODO nf-core: Delete / customise this example output
+  - bam:
+      type: file
+      description: Sorted BAM/CRAM/SAM file
+      pattern: "*.{bam,cram,sam}"
+
+authors:
+  - "@jfy133"
diff --git a/tests/config/pytest_modules.yml b/tests/config/pytest_modules.yml
index 3ff58b5c..80dcb9ec 100644
--- a/tests/config/pytest_modules.yml
+++ b/tests/config/pytest_modules.yml
@@ -715,6 +715,10 @@ gamma/gamma:
   - modules/gamma/gamma/**
   - tests/modules/gamma/gamma/**
 
+gatk/realignertargetcreator:
+  - modules/gatk/realignertargetcreator/**
+  - tests/modules/gatk/realignertargetcreator/**
+
 gatk4/applybqsr:
   - modules/gatk4/applybqsr/**
   - tests/modules/gatk4/applybqsr/**
diff --git a/tests/modules/gatk/realignertargetcreator/main.nf b/tests/modules/gatk/realignertargetcreator/main.nf
new file mode 100644
index 00000000..63908069
--- /dev/null
+++ b/tests/modules/gatk/realignertargetcreator/main.nf
@@ -0,0 +1,15 @@
+#!/usr/bin/env nextflow
+
+nextflow.enable.dsl = 2
+
+include { GATK_REALIGNERTARGETCREATOR } from '../../../../modules/gatk/realignertargetcreator/main.nf'
+
+workflow test_gatk_realignertargetcreator {
+    
+    input = [
+        [ id:'test', single_end:false ], // meta map
+        file(params.test_data['sarscov2']['illumina']['test_paired_end_bam'], checkIfExists: true)
+    ]
+
+    GATK_REALIGNERTARGETCREATOR ( input )
+}
diff --git a/tests/modules/gatk/realignertargetcreator/nextflow.config b/tests/modules/gatk/realignertargetcreator/nextflow.config
new file mode 100644
index 00000000..50f50a7a
--- /dev/null
+++ b/tests/modules/gatk/realignertargetcreator/nextflow.config
@@ -0,0 +1,5 @@
+process {
+
+    publishDir = { "${params.outdir}/${task.process.tokenize(':')[-1].tokenize('_')[0].toLowerCase()}" }
+    
+}
\ No newline at end of file
diff --git a/tests/modules/gatk/realignertargetcreator/test.yml b/tests/modules/gatk/realignertargetcreator/test.yml
new file mode 100644
index 00000000..a45fbb93
--- /dev/null
+++ b/tests/modules/gatk/realignertargetcreator/test.yml
@@ -0,0 +1,14 @@
+## TODO nf-core: Please run the following command to build this file:
+#                nf-core modules create-test-yml gatk/realignertargetcreator
+- name: "gatk realignertargetcreator"
+  command: nextflow run ./tests/modules/gatk/realignertargetcreator -entry test_gatk_realignertargetcreator -c ./tests/config/nextflow.config -c ./tests/modules/gatk/realignertargetcreator/nextflow.config
+  tags:
+    - "gatk"
+    #
+    - "gatk/realignertargetcreator"
+    #
+  files:
+    - path: "output/gatk/test.bam"
+      md5sum: e667c7caad0bc4b7ac383fd023c654fc
+    - path: output/gatk/versions.yml
+      md5sum: a01fe51bc4c6a3a6226fbf77b2c7cf3b

From d39ba08e02b78001f851b737bc832203a60dc7f1 Mon Sep 17 00:00:00 2001
From: James Fellows Yates <jfy133@gmail.com>
Date: Tue, 31 May 2022 20:19:49 +0200
Subject: [PATCH 2/8] Prepare main module code

---
 modules/gatk/realignertargetcreator/main.nf | 64 ++++++---------------
 1 file changed, 16 insertions(+), 48 deletions(-)

diff --git a/modules/gatk/realignertargetcreator/main.nf b/modules/gatk/realignertargetcreator/main.nf
index 59dee1a8..76ac2dd7 100644
--- a/modules/gatk/realignertargetcreator/main.nf
+++ b/modules/gatk/realignertargetcreator/main.nf
@@ -1,46 +1,19 @@
-// TODO nf-core: If in doubt look at other nf-core/modules to see how we are doing things! :)
-//               https://github.com/nf-core/modules/tree/master/modules
-//               You can also ask for help via your pull request or on the #modules channel on the nf-core Slack workspace:
-//               https://nf-co.re/join
-// TODO nf-core: A module file SHOULD only define input and output files as command-line parameters.
-//               All other parameters MUST be provided using the "task.ext" directive, see here:
-//               https://www.nextflow.io/docs/latest/process.html#ext
-//               where "task.ext" is a string.
-//               Any parameters that need to be evaluated in the context of a particular sample
-//               e.g. single-end/paired-end data MUST also be defined and evaluated appropriately.
-// TODO nf-core: Software that can be piped together SHOULD be added to separate module files
-//               unless there is a run-time, storage advantage in implementing in this way
-//               e.g. it's ok to have a single module for bwa to output BAM instead of SAM:
-//                 bwa mem | samtools view -B -T ref.fasta
-// TODO nf-core: Optional inputs are not currently supported by Nextflow. However, using an empty
-//               list (`[]`) instead of a file can be used to work around this issue.
-
 process GATK_REALIGNERTARGETCREATOR {
     tag "$meta.id"
     label 'process_low'
 
-    // TODO nf-core: List required Conda package(s).
-    //               Software MUST be pinned to channel (i.e. "bioconda"), version (i.e. "1.10").
-    //               For Conda, the build (i.e. "h9402c20_2") must be EXCLUDED to support installation on different operating systems.
-    // TODO nf-core: See section in main README for further information regarding finding and adding container addresses to the section below.
-    conda (params.enable_conda ? "bioconda::gatk=3.8" : null)
+    conda (params.enable_conda ? "bioconda::gatk=3.5" : null)
     container "${ workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container ?
-        'https://depot.galaxyproject.org/singularity/gatk:3.8--hdfd78af_11':
-        'quay.io/biocontainers/gatk:3.8--hdfd78af_11' }"
+        'https://depot.galaxyproject.org/singularity/gatk:3.5--hdfd78af_11':
+        'quay.io/biocontainers/gatk:3.5--hdfd78af_11' }"
 
     input:
-    // TODO nf-core: Where applicable all sample-specific information e.g. "id", "single_end", "read_group"
-    //               MUST be provided as an input via a Groovy Map called "meta".
-    //               This information may not be required in some instances e.g. indexing reference genome files:
-    //               https://github.com/nf-core/modules/blob/master/modules/bwa/index/main.nf
-    // TODO nf-core: Where applicable please provide/convert compressed files as input/output
-    //               e.g. "*.fastq.gz" and NOT "*.fastq", "*.bam" and NOT "*.sam" etc.
     tuple val(meta), path(bam)
+    tuple val(meta), path(reference)
+    tuple val(meta), path(known_vcf)
 
     output:
-    // TODO nf-core: Named file extensions MUST be emitted for ALL output channels
     tuple val(meta), path("*.bam"), emit: bam
-    // TODO nf-core: List additional required output channels/values here
     path "versions.yml"           , emit: versions
 
     when:
@@ -49,27 +22,22 @@ process GATK_REALIGNERTARGETCREATOR {
     script:
     def args = task.ext.args ?: ''
     def prefix = task.ext.prefix ?: "${meta.id}"
-    // TODO nf-core: Where possible, a command MUST be provided to obtain the version number of the software e.g. 1.10
-    //               If the software is unable to output a version number on the command-line then it can be manually specified
-    //               e.g. https://github.com/nf-core/modules/blob/master/modules/homer/annotatepeaks/main.nf
-    //               Each software used MUST provide the software name and version number in the YAML version file (versions.yml)
-    // TODO nf-core: It MUST be possible to pass additional parameters to the tool as a command-line string via the "task.ext.args" directive
-    // TODO nf-core: If the tool supports multi-threading then you MUST provide the appropriate parameter
-    //               using the Nextflow "task" variable e.g. "--threads $task.cpus"
-    // TODO nf-core: Please replace the example samtools command below with your module's command
-    // TODO nf-core: Please indent the command appropriately (4 spaces!!) to help with readability ;)
+    def known = known_vcf ? "-known ${known_vcf}" ? ""
+    if ("$bam" == "${prefix}.bam") error "Input and output names are the same, set prefix in module configuration to disambiguate!"
+
     """
-    samtools \\
-        sort \\
-        $args \\
-        -@ $task.cpus \\
+    gatk3 \\
+        -T RealigerTargetCreator \\
+        -nt ${task.cpus}
+        -I ${bam} \\
+        -R ${reference} \\
         -o ${prefix}.bam \\
-        -T $prefix \\
-        $bam
+        ${known} \\
+        $args
 
     cat <<-END_VERSIONS > versions.yml
     "${task.process}":
-        gatk: \$(echo \$(samtools --version 2>&1) | sed 's/^.*samtools //; s/Using.*\$//' ))
+        gatk: \$(echo \$(gatk3 --version))
     END_VERSIONS
     """
 }

From 7633d7816b10d8bd1fb97a748ee1006dd0ea5d09 Mon Sep 17 00:00:00 2001
From: James Fellows Yates <jfy133@gmail.com>
Date: Tue, 31 May 2022 20:35:54 +0200
Subject: [PATCH 3/8] Add GATK(3)/realignertargetcreator

---
 modules/gatk/realignertargetcreator/main.nf   | 20 +++----
 modules/gatk/realignertargetcreator/meta.yml  | 57 ++++++++++++-------
 .../gatk/realignertargetcreator/main.nf       | 12 +++-
 .../gatk/realignertargetcreator/test.yml      | 18 ++----
 4 files changed, 60 insertions(+), 47 deletions(-)

diff --git a/modules/gatk/realignertargetcreator/main.nf b/modules/gatk/realignertargetcreator/main.nf
index 76ac2dd7..e3a03a5f 100644
--- a/modules/gatk/realignertargetcreator/main.nf
+++ b/modules/gatk/realignertargetcreator/main.nf
@@ -8,13 +8,13 @@ process GATK_REALIGNERTARGETCREATOR {
         'quay.io/biocontainers/gatk:3.5--hdfd78af_11' }"
 
     input:
-    tuple val(meta), path(bam)
-    tuple val(meta), path(reference)
-    tuple val(meta), path(known_vcf)
+    tuple val(meta), path(bam), path(bai)
+    tuple path(fasta), path(fasta_fai), path(fasta_dict)
+    path(known_vcf)
 
     output:
-    tuple val(meta), path("*.bam"), emit: bam
-    path "versions.yml"           , emit: versions
+    tuple val(meta), path("*.intervals"), emit: intervals
+    path "versions.yml"                 , emit: versions
 
     when:
     task.ext.when == null || task.ext.when
@@ -22,16 +22,16 @@ process GATK_REALIGNERTARGETCREATOR {
     script:
     def args = task.ext.args ?: ''
     def prefix = task.ext.prefix ?: "${meta.id}"
-    def known = known_vcf ? "-known ${known_vcf}" ? ""
+    def known = known_vcf ? "-known ${known_vcf}" : ""
     if ("$bam" == "${prefix}.bam") error "Input and output names are the same, set prefix in module configuration to disambiguate!"
 
     """
     gatk3 \\
-        -T RealigerTargetCreator \\
-        -nt ${task.cpus}
+        -T RealignerTargetCreator \\
+        -nt ${task.cpus} \\
         -I ${bam} \\
-        -R ${reference} \\
-        -o ${prefix}.bam \\
+        -R ${fasta} \\
+        -o ${prefix}.intervals \\
         ${known} \\
         $args
 
diff --git a/modules/gatk/realignertargetcreator/meta.yml b/modules/gatk/realignertargetcreator/meta.yml
index a33db8f1..70df7b78 100644
--- a/modules/gatk/realignertargetcreator/meta.yml
+++ b/modules/gatk/realignertargetcreator/meta.yml
@@ -1,51 +1,64 @@
 name: "gatk_realignertargetcreator"
-## TODO nf-core: Add a description of the module and list keywords
-description: write your description here
+description: Generates a list of locations that should be considered for local realignment prior genotyping.
 keywords:
-  - sort
+  - bam
+  - vcf
+  - variant calling
+  - indel
+  - realignment
+  - targets
 tools:
   - "gatk":
-      ## TODO nf-core: Add a description and other details for the software below
       description: "The full Genome Analysis Toolkit (GATK) framework, license restricted."
-      homepage: "None"
-      documentation: "None"
-      tool_dev_url: "None"
-      doi: ""
-      licence: "['https://software.broadinstitute.org/gatk/download/licensing', 'https://www.broadinstitute.org/gatk/about/#licensing', 'BSD']"
+      homepage: "https://gatk.broadinstitute.org/hc/en-us"
+      documentation: "https://github.com/broadinstitute/gatk-docs"
+      licence: "['https://software.broadinstitute.org/gatk/download/licensing', 'BSD', 'https://www.broadinstitute.org/gatk/about/#licensing']"
 
-## TODO nf-core: Add a description of all of the variables used as input
 input:
-  # Only when we have meta
   - meta:
       type: map
       description: |
         Groovy Map containing sample information
         e.g. [ id:'test', single_end:false ]
-  # 
-  ## TODO nf-core: Delete / customise this example input
   - bam:
       type: file
-      description: BAM/CRAM/SAM file
-      pattern: "*.{bam,cram,sam}"
+      description: Sorted and indexed BAM/CRAM/SAM file
+      pattern: "*.bam"
+  - bai:
+      type: file
+      description: BAM index file
+      pattern: "*.bai"
+  - fasta:
+      type: file
+      description: Reference file used to generate BAM file
+      pattern: ".{fasta,fa,fna}"
+  - fasta_fai:
+      type: file
+      description: Index of reference file used to generate BAM file
+      pattern: ".fai"
+  - dict:
+      type: file
+      description: GATK dict file for reference
+      pattern: ".dict"
+  - known_vcf:
+      type: file
+      description: Optional input VCF file(s) with known indels
+      pattern: ".vcf"
 
-## TODO nf-core: Add a description of all of the variables used as output
 output:
-  #Only when we have meta
   - meta:
       type: map
       description: |
         Groovy Map containing sample information
         e.g. [ id:'test', single_end:false ]
-  # 
   - versions:
       type: file
       description: File containing software versions
       pattern: "versions.yml"
-  ## TODO nf-core: Delete / customise this example output
-  - bam:
+  - intervals:
       type: file
-      description: Sorted BAM/CRAM/SAM file
-      pattern: "*.{bam,cram,sam}"
+      description: File containg intervals that represent sites of extant and potential indels.
+      pattern: "*.intervals"
 
 authors:
   - "@jfy133"
diff --git a/tests/modules/gatk/realignertargetcreator/main.nf b/tests/modules/gatk/realignertargetcreator/main.nf
index 63908069..02e62d93 100644
--- a/tests/modules/gatk/realignertargetcreator/main.nf
+++ b/tests/modules/gatk/realignertargetcreator/main.nf
@@ -5,11 +5,17 @@ nextflow.enable.dsl = 2
 include { GATK_REALIGNERTARGETCREATOR } from '../../../../modules/gatk/realignertargetcreator/main.nf'
 
 workflow test_gatk_realignertargetcreator {
-    
+
     input = [
         [ id:'test', single_end:false ], // meta map
-        file(params.test_data['sarscov2']['illumina']['test_paired_end_bam'], checkIfExists: true)
+        file(params.test_data['sarscov2']['illumina']['test_paired_end_sorted_bam'], checkIfExists: true),
+        file(params.test_data['sarscov2']['illumina']['test_paired_end_sorted_bam_bai'], checkIfExists: true)
+    ]
+    reference = [
+        file(params.test_data['sarscov2']['genome']['genome_fasta'], checkIfExists: true),
+        file(params.test_data['sarscov2']['genome']['genome_fasta_fai'], checkIfExists: true),
+        file(params.test_data['sarscov2']['genome']['genome_dict'], checkIfExists: true),
     ]
 
-    GATK_REALIGNERTARGETCREATOR ( input )
+    GATK_REALIGNERTARGETCREATOR ( input, reference, [] )
 }
diff --git a/tests/modules/gatk/realignertargetcreator/test.yml b/tests/modules/gatk/realignertargetcreator/test.yml
index a45fbb93..0e247013 100644
--- a/tests/modules/gatk/realignertargetcreator/test.yml
+++ b/tests/modules/gatk/realignertargetcreator/test.yml
@@ -1,14 +1,8 @@
-## TODO nf-core: Please run the following command to build this file:
-#                nf-core modules create-test-yml gatk/realignertargetcreator
-- name: "gatk realignertargetcreator"
-  command: nextflow run ./tests/modules/gatk/realignertargetcreator -entry test_gatk_realignertargetcreator -c ./tests/config/nextflow.config -c ./tests/modules/gatk/realignertargetcreator/nextflow.config
+- name: gatk realignertargetcreator test_gatk_realignertargetcreator
+  command: nextflow run ./tests/modules/gatk/realignertargetcreator -entry test_gatk_realignertargetcreator -c ./tests/config/nextflow.config  -c ./tests/modules/gatk/realignertargetcreator/nextflow.config
   tags:
-    - "gatk"
-    #
-    - "gatk/realignertargetcreator"
-    #
+    - gatk
+    - gatk/realignertargetcreator
   files:
-    - path: "output/gatk/test.bam"
-      md5sum: e667c7caad0bc4b7ac383fd023c654fc
-    - path: output/gatk/versions.yml
-      md5sum: a01fe51bc4c6a3a6226fbf77b2c7cf3b
+    - path: output/gatk/test.intervals
+      md5sum: 7aa7a1b235a510e6591e262382086bf8

From 14c63f9ccc50735464e963c558424efde668f164 Mon Sep 17 00:00:00 2001
From: James Fellows Yates <jfy133@gmail.com>
Date: Thu, 2 Jun 2022 20:24:14 +0200
Subject: [PATCH 4/8] Changes after review

---
 modules/gatk/realignertargetcreator/main.nf  | 14 ++++++++++++--
 modules/gatk/realignertargetcreator/meta.yml |  6 +++---
 2 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/modules/gatk/realignertargetcreator/main.nf b/modules/gatk/realignertargetcreator/main.nf
index e3a03a5f..866ff8a5 100644
--- a/modules/gatk/realignertargetcreator/main.nf
+++ b/modules/gatk/realignertargetcreator/main.nf
@@ -8,8 +8,10 @@ process GATK_REALIGNERTARGETCREATOR {
         'quay.io/biocontainers/gatk:3.5--hdfd78af_11' }"
 
     input:
-    tuple val(meta), path(bam), path(bai)
-    tuple path(fasta), path(fasta_fai), path(fasta_dict)
+    tuple val(meta), path(input), path(index)
+    path path(fasta)
+    path(fai)
+    path(dict)
     path(known_vcf)
 
     output:
@@ -25,8 +27,16 @@ process GATK_REALIGNERTARGETCREATOR {
     def known = known_vcf ? "-known ${known_vcf}" : ""
     if ("$bam" == "${prefix}.bam") error "Input and output names are the same, set prefix in module configuration to disambiguate!"
 
+    def avail_mem = 3
+    if (!task.memory) {
+        log.info '[GATK HaplotypeCaller] Available memory not known - defaulting to 3GB. Specify process memory requirements to change this.'
+    } else {
+        avail_mem = task.memory.giga
+    }
+
     """
     gatk3 \\
+        -Xmx${avail_mem}g \\
         -T RealignerTargetCreator \\
         -nt ${task.cpus} \\
         -I ${bam} \\
diff --git a/modules/gatk/realignertargetcreator/meta.yml b/modules/gatk/realignertargetcreator/meta.yml
index 70df7b78..c49d2a8d 100644
--- a/modules/gatk/realignertargetcreator/meta.yml
+++ b/modules/gatk/realignertargetcreator/meta.yml
@@ -20,11 +20,11 @@ input:
       description: |
         Groovy Map containing sample information
         e.g. [ id:'test', single_end:false ]
-  - bam:
+  - input:
       type: file
       description: Sorted and indexed BAM/CRAM/SAM file
       pattern: "*.bam"
-  - bai:
+  - index:
       type: file
       description: BAM index file
       pattern: "*.bai"
@@ -32,7 +32,7 @@ input:
       type: file
       description: Reference file used to generate BAM file
       pattern: ".{fasta,fa,fna}"
-  - fasta_fai:
+  - fai:
       type: file
       description: Index of reference file used to generate BAM file
       pattern: ".fai"

From 43ef3841d1249aa20793b783bb961f568af2b8a4 Mon Sep 17 00:00:00 2001
From: "James A. Fellows Yates" <jfy133@gmail.com>
Date: Thu, 2 Jun 2022 20:25:12 +0200
Subject: [PATCH 5/8] remove duplciate path

---
 modules/gatk/realignertargetcreator/main.nf | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/modules/gatk/realignertargetcreator/main.nf b/modules/gatk/realignertargetcreator/main.nf
index 866ff8a5..7454430c 100644
--- a/modules/gatk/realignertargetcreator/main.nf
+++ b/modules/gatk/realignertargetcreator/main.nf
@@ -9,7 +9,7 @@ process GATK_REALIGNERTARGETCREATOR {
 
     input:
     tuple val(meta), path(input), path(index)
-    path path(fasta)
+    path(fasta)
     path(fai)
     path(dict)
     path(known_vcf)

From b1edcc6e94124fc7f2473655268f6d72b12d7209 Mon Sep 17 00:00:00 2001
From: "James A. Fellows Yates" <jfy133@gmail.com>
Date: Thu, 2 Jun 2022 20:26:09 +0200
Subject: [PATCH 6/8] Update modules/gatk/realignertargetcreator/main.nf

---
 modules/gatk/realignertargetcreator/main.nf | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/modules/gatk/realignertargetcreator/main.nf b/modules/gatk/realignertargetcreator/main.nf
index 7454430c..96b8806c 100644
--- a/modules/gatk/realignertargetcreator/main.nf
+++ b/modules/gatk/realignertargetcreator/main.nf
@@ -29,7 +29,7 @@ process GATK_REALIGNERTARGETCREATOR {
 
     def avail_mem = 3
     if (!task.memory) {
-        log.info '[GATK HaplotypeCaller] Available memory not known - defaulting to 3GB. Specify process memory requirements to change this.'
+        log.info '[GATK RealignerTargetCreator] Available memory not known - defaulting to 3GB. Specify process memory requirements to change this.'
     } else {
         avail_mem = task.memory.giga
     }

From c469a2b35ed2e2948c9d3cbde5672143086b7e35 Mon Sep 17 00:00:00 2001
From: James Fellows Yates <jfy133@gmail.com>
Date: Thu, 2 Jun 2022 20:32:00 +0200
Subject: [PATCH 7/8] Fux tests

---
 modules/gatk/realignertargetcreator/main.nf   |  6 +++---
 .../gatk/realignertargetcreator/main.nf       | 19 ++++++++-----------
 2 files changed, 11 insertions(+), 14 deletions(-)

diff --git a/modules/gatk/realignertargetcreator/main.nf b/modules/gatk/realignertargetcreator/main.nf
index 866ff8a5..e356c826 100644
--- a/modules/gatk/realignertargetcreator/main.nf
+++ b/modules/gatk/realignertargetcreator/main.nf
@@ -9,7 +9,7 @@ process GATK_REALIGNERTARGETCREATOR {
 
     input:
     tuple val(meta), path(input), path(index)
-    path path(fasta)
+    path(fasta)
     path(fai)
     path(dict)
     path(known_vcf)
@@ -25,7 +25,7 @@ process GATK_REALIGNERTARGETCREATOR {
     def args = task.ext.args ?: ''
     def prefix = task.ext.prefix ?: "${meta.id}"
     def known = known_vcf ? "-known ${known_vcf}" : ""
-    if ("$bam" == "${prefix}.bam") error "Input and output names are the same, set prefix in module configuration to disambiguate!"
+    if ("$input" == "${prefix}.bam") error "Input and output names are the same, set prefix in module configuration to disambiguate!"
 
     def avail_mem = 3
     if (!task.memory) {
@@ -39,7 +39,7 @@ process GATK_REALIGNERTARGETCREATOR {
         -Xmx${avail_mem}g \\
         -T RealignerTargetCreator \\
         -nt ${task.cpus} \\
-        -I ${bam} \\
+        -I ${input} \\
         -R ${fasta} \\
         -o ${prefix}.intervals \\
         ${known} \\
diff --git a/tests/modules/gatk/realignertargetcreator/main.nf b/tests/modules/gatk/realignertargetcreator/main.nf
index 02e62d93..4b9f8eff 100644
--- a/tests/modules/gatk/realignertargetcreator/main.nf
+++ b/tests/modules/gatk/realignertargetcreator/main.nf
@@ -6,16 +6,13 @@ include { GATK_REALIGNERTARGETCREATOR } from '../../../../modules/gatk/realigner
 
 workflow test_gatk_realignertargetcreator {
 
-    input = [
-        [ id:'test', single_end:false ], // meta map
-        file(params.test_data['sarscov2']['illumina']['test_paired_end_sorted_bam'], checkIfExists: true),
-        file(params.test_data['sarscov2']['illumina']['test_paired_end_sorted_bam_bai'], checkIfExists: true)
-    ]
-    reference = [
-        file(params.test_data['sarscov2']['genome']['genome_fasta'], checkIfExists: true),
-        file(params.test_data['sarscov2']['genome']['genome_fasta_fai'], checkIfExists: true),
-        file(params.test_data['sarscov2']['genome']['genome_dict'], checkIfExists: true),
-    ]
+    input     = [ [ id:'test' ], // meta map
+                  file(params.test_data['sarscov2']['illumina']['test_paired_end_sorted_bam'], checkIfExists: true),
+                  file(params.test_data['sarscov2']['illumina']['test_paired_end_sorted_bam_bai'], checkIfExists: true),
+                ]
+    fasta = file(params.test_data['sarscov2']['genome']['genome_fasta'], checkIfExists: true)
+    fai   = file(params.test_data['sarscov2']['genome']['genome_fasta_fai'], checkIfExists: true)
+    dict  = file(params.test_data['sarscov2']['genome']['genome_dict'], checkIfExists: true)
 
-    GATK_REALIGNERTARGETCREATOR ( input, reference, [] )
+    GATK_REALIGNERTARGETCREATOR ( input, fasta, fai, dict, [] )
 }

From 0d087b4890e080394c3c0fd5971d4e3364841380 Mon Sep 17 00:00:00 2001
From: "James A. Fellows Yates" <jfy133@gmail.com>
Date: Fri, 3 Jun 2022 21:33:54 +0200
Subject: [PATCH 8/8] Update modules/gatk/realignertargetcreator/main.nf

---
 modules/gatk/realignertargetcreator/main.nf | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/modules/gatk/realignertargetcreator/main.nf b/modules/gatk/realignertargetcreator/main.nf
index 5d2da4b3..ba6a2592 100644
--- a/modules/gatk/realignertargetcreator/main.nf
+++ b/modules/gatk/realignertargetcreator/main.nf
@@ -9,10 +9,10 @@ process GATK_REALIGNERTARGETCREATOR {
 
     input:
     tuple val(meta), path(input), path(index)
-    path(fasta)
-    path(fai)
-    path(dict)
-    path(known_vcf)
+    path fasta
+    path fai
+    path dict
+    path known_vcf
 
     output:
     tuple val(meta), path("*.intervals"), emit: intervals