Skip to content

Commit

Permalink
Add and update - picard/gatk4 - addorreplacereadgroups (nf-core#5302)
Browse files Browse the repository at this point in the history
* migrate picard_addorreplacereadgroups to nf-testand and add cram support

* remove unused code

* fix unstable checksums in tests

* remove crai and add meta 2 and 3

* update snap

* Duplicate as gatk4 module

* name conflict

---------

Co-authored-by: CMGG Cloud Team <[email protected]>
Co-authored-by: Matthias De Smet <[email protected]>
  • Loading branch information
3 people authored Mar 20, 2024
1 parent 4685ac9 commit c331b11
Show file tree
Hide file tree
Showing 18 changed files with 614 additions and 47 deletions.
7 changes: 7 additions & 0 deletions modules/nf-core/gatk4/addorreplacereadgroups/environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: gatk4_addorreplacereadgroups
channels:
- conda-forge
- bioconda
- defaults
dependencies:
- bioconda::gatk4=4.5.0.0
71 changes: 71 additions & 0 deletions modules/nf-core/gatk4/addorreplacereadgroups/main.nf
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
process GATK4_ADDORREPLACEREADGROUPS {
tag "$meta.id"
label 'process_low'

conda "${moduleDir}/environment.yml"
container "${ workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container ?
'https://depot.galaxyproject.org/singularity/gatk4:4.5.0.0--py36hdfd78af_0':
'biocontainers/gatk4:4.5.0.0--py36hdfd78af_0' }"

input:
tuple val(meta), path(bam)
tuple val(meta2), path(fasta)
tuple val(meta3), path(fasta_index)

output:
tuple val(meta), path("*.bam") , emit: bam, optional: true
tuple val(meta), path("*.bai") , emit: bai, optional: true
tuple val(meta), path("*.cram"), emit: cram, optional: true
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}"
def suffix = task.ext.suffix ?: "${bam.getExtension()}"
def reference = fasta ? "--REFERENCE_SEQUENCE ${fasta}" : ""
def create_index = ( suffix == "bam" )? "--CREATE_INDEX" : ""
def avail_mem = 3072
if (!task.memory) {
log.info '[GATK AddOrReplaceReadGroups] Available memory not known - defaulting to 3GB. Specify process memory requirements to change this.'
} else {
avail_mem = (task.memory.mega*0.8).intValue()
}

if ("$bam" == "${prefix}.${suffix}") error "Input and output names are the same, use \"task.ext.prefix\" to disambiguate!"

"""
gatk --java-options "-Xmx${avail_mem}M -XX:-UsePerfData" \\
AddOrReplaceReadGroups \\
$args \\
$reference \\
$create_index \\
--INPUT ${bam} \\
--OUTPUT ${prefix}.${suffix}
cat <<-END_VERSIONS > versions.yml
"${task.process}":
gatk4: \$(echo \$(gatk AddOrReplaceReadGroups --version 2>&1) | sed 's/^.*(GATK) v//; s/ .*\$//')
END_VERSIONS
"""

stub:
def prefix = task.ext.prefix ?: "${meta.id}"
def suffix = task.ext.suffix ?: "${bam.getExtension()}"
if ("$bam" == "${prefix}.${suffix}") error "Input and output names are the same, use \"task.ext.prefix\" to disambiguate!"
def create_index = ""
if (suffix == "bam") {
create_index = "touch ${prefix}.${suffix}.bai"
}
"""
touch ${prefix}.${suffix}
${create_index}
cat <<-END_VERSIONS > versions.yml
"${task.process}":
gatk4: \$(echo \$(gatk AddOrReplaceReadGroups --version 2>&1) | sed 's/^.*(GATK) v//; s/ .*\$//')
END_VERSIONS
"""
}
80 changes: 80 additions & 0 deletions modules/nf-core/gatk4/addorreplacereadgroups/meta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: gatk4_addorreplacereadgroups
description: Assigns all the reads in a file to a single new read-group
keywords:
- add
- replace
- read-group
- picard
- gatk
tools:
- gatk4:
description: |
Developed in the Data Sciences Platform at the Broad Institute, the toolkit offers a wide variety of tools
with a primary focus on variant discovery and genotyping. Its powerful processing engine
and high-performance computing features make it capable of taking on projects of any size.
homepage: https://gatk.broadinstitute.org/hc/en-us
documentation: https://gatk.broadinstitute.org/hc/en-us/categories/360002369672s
doi: 10.1158/1538-7445.AM2017-3590
licence: ["Apache-2.0"]
input:
- meta:
type: map
description: |
Groovy Map containing sample information
e.g. [ id:'test', single_end:false ]
- meta2:
type: map
description: |
Groovy Map containing sample information
e.g. [ id:'test', single_end:false ]
- meta3:
type: map
description: |
Groovy Map containing sample information
e.g. [ id:'test', single_end:false ]
- bam:
type: file
description: Input BAM file
pattern: "*.{bam}"
- fasta:
type: file
description: Reference genome file
pattern: "*.{fasta,fa,fasta.gz,fa.gz}"
- fasta_index:
type: file
description: Reference genome index file
pattern: "*.{fai,fasta.fai,fa.fai,fasta.gz.fai,fa.gz.fai}"
output:
- 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"
- bam:
type: file
description: Output BAM file
pattern: "*.{bam}"
- bai:
type: file
description: An optional BAM index file
pattern: "*.{bai}"
- cram:
type: file
description: Output CRAM file
pattern: "*.{cram}"
authors:
- "@sateeshperi"
- "@mjcipriano"
- "@hseabolt"
- "@cmatKhan"
- "@muffato"
maintainers:
- "@sateeshperi"
- "@mjcipriano"
- "@hseabolt"
- "@cmatKhan"
- "@muffato"
12 changes: 12 additions & 0 deletions modules/nf-core/gatk4/addorreplacereadgroups/tests/bam.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
process {
withName: 'GATK4_ADDORREPLACEREADGROUPS'{
ext.prefix = { "${meta.id}.replaced"}
ext.args = {[
"-LB ${meta.id}",
"-PL ILLUMINA",
"-PU bc1",
"-SM ${meta.id}"
].join(' ').trim()}
}

}
13 changes: 13 additions & 0 deletions modules/nf-core/gatk4/addorreplacereadgroups/tests/cram.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
process {
withName: 'GATK4_ADDORREPLACEREADGROUPS'{
ext.prefix = { "${meta.id}.replaced"}
ext.args = {[
"-LB ${meta.id}",
"-PL ILLUMINA",
"-PU bc1",
"-SM ${meta.id}"
].join(' ').trim()}
ext.suffix = { "cram" }
}

}
85 changes: 85 additions & 0 deletions modules/nf-core/gatk4/addorreplacereadgroups/tests/main.nf.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
nextflow_process {

name "Test Process GATK4_ADDORREPLACEREADGROUPS"
script "../main.nf"
process "GATK4_ADDORREPLACEREADGROUPS"

tag "modules"
tag "modules_nfcore"
tag "gatk4"
tag "gatk4/addorreplacereadgroups"

test("sarscov2 - bam") {
config "./bam.config"

when {
process {
"""
input[0] = [ [:], file(params.modules_testdata_base_path + 'genomics/sarscov2/illumina/bam/test.paired_end.sorted.bam', checkIfExists: true) ]
input[1] = [ [:], [] ]
input[2] = [ [:], [] ]
"""
}
}

then {
assertAll(
{ assert process.success },
{ assert snapshot(file(process.out.bam[0][1]).name).match("bam_name") },
{ assert snapshot(file(process.out.bai[0][1]).name).match("bai_name") },
)
}

}

test("homo_sapiens - cram") {
config "./cram.config"

when {
process {
"""
input[0] = [
[ id:'test' ], // meta map
[
file(params.modules_testdata_base_path + 'genomics/homo_sapiens/illumina/cram/test.paired_end.sorted.cram', checkIfExists: true), ]
]
input[1] = [ [:], file(params.modules_testdata_base_path + 'genomics/homo_sapiens/genome/genome.fasta', checkIfExists: true) ]
input[2] = [ [:], file(params.modules_testdata_base_path + 'genomics/homo_sapiens/genome/genome.fasta.fai', checkIfExists: true) ]
"""
}
}

then {
assertAll(
{ assert process.success },
{ assert snapshot(file(process.out.cram[0][1]).name).match("cram_name") },
{ assert snapshot(process.out.versions).match("versions") },
)
}

}

test("sarscov2 - bam - stub") {
config "./bam.config"
options "-stub"

when {
process {
"""
input[0] = [ [:], file(params.modules_testdata_base_path + 'genomics/sarscov2/illumina/bam/test.paired_end.sorted.bam', checkIfExists: true) ]
input[1] = [ [:], [] ]
input[2] = [ [:], [] ]
"""
}
}

then {
assertAll(
{ assert process.success },
{ assert snapshot(process.out).match() }
)
}

}

}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions modules/nf-core/gatk4/addorreplacereadgroups/tests/tags.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
gatk4/addorreplacereadgroups:
- "modules/nf-core/gatk4/addorreplacereadgroups/**"
Loading

0 comments on commit c331b11

Please sign in to comment.