Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add and update - picard/gatk4 - addorreplacereadgroups #5302

Merged
merged 9 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions modules/nf-core/picard/addorreplacereadgroups/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,43 @@ process PICARD_ADDORREPLACEREADGROUPS {

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
tuple val(meta), path("*.bai"), emit: bai, optional: true
path "versions.yml" , emit: versions
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
tuple val(meta), path("*.crai"), emit: crai, 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 '[Picard 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}.bam") error "Input and output names are the same, use \"task.ext.prefix\" to disambiguate!"
if ("$bam" == "${prefix}.${suffix}") error "Input and output names are the same, use \"task.ext.prefix\" to disambiguate!"

"""
picard \\
-Xmx${avail_mem}M \\
AddOrReplaceReadGroups \\
$args \\
$reference \\
$create_index \\
--INPUT ${bam} \\
--OUTPUT ${prefix}.bam
--OUTPUT ${prefix}.${suffix}

cat <<-END_VERSIONS > versions.yml
"${task.process}":
Expand All @@ -46,10 +55,15 @@ process PICARD_ADDORREPLACEREADGROUPS {

stub:
def prefix = task.ext.prefix ?: "${meta.id}"

if ("$bam" == "${prefix}.bam") error "Input and output names are the same, use \"task.ext.prefix\" to disambiguate!"
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}.bam
touch ${prefix}.${suffix}
${create_index}

cat <<-END_VERSIONS > versions.yml
"${task.process}":
Expand Down
18 changes: 17 additions & 1 deletion modules/nf-core/picard/addorreplacereadgroups/meta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ input:
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
Expand All @@ -40,8 +48,16 @@ output:
pattern: "*.{bam}"
- bai:
type: file
description: BAM index file
description: An optional BAM index file
pattern: "*.{bai}"
- cram:
type: file
description: Output CRAM file
pattern: "*.{cram}"
- crai:
type: file
description: An optional CRAM index file
pattern: "*.{crai}"
authors:
- "@sateeshperi"
- "@mjcipriano"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
process {

publishDir = { "${params.outdir}/${task.process.tokenize(':')[-1].tokenize('_')[0].toLowerCase()}" }

withName: 'PICARD_ADDORREPLACEREADGROUPS'{
ext.prefix = { "${meta.id}.replaced"}
ext.args = {[
Expand All @@ -11,4 +8,5 @@ process {
"-SM ${meta.id}"
].join(' ').trim()}
}

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

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

nextflow_process {

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

tag "modules"
tag "modules_nfcore"
tag "picard"
tag "picard/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() }
)
}

}

}
105 changes: 105 additions & 0 deletions modules/nf-core/picard/addorreplacereadgroups/tests/main.nf.test.snap

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/picard/addorreplacereadgroups/tests/tags.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
picard/addorreplacereadgroups:
- "modules/nf-core/picard/addorreplacereadgroups/**"
3 changes: 0 additions & 3 deletions tests/config/pytest_modules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1573,9 +1573,6 @@ phispy:
phyloflash:
- modules/nf-core/phyloflash/**
- tests/modules/nf-core/phyloflash/**
picard/addorreplacereadgroups:
- modules/nf-core/picard/addorreplacereadgroups/**
- tests/modules/nf-core/picard/addorreplacereadgroups/**
picard/bedtointervallist:
- modules/nf-core/picard/bedtointervallist/**
- tests/modules/nf-core/picard/bedtointervallist/**
Expand Down
15 changes: 0 additions & 15 deletions tests/modules/nf-core/picard/addorreplacereadgroups/main.nf

This file was deleted.

17 changes: 0 additions & 17 deletions tests/modules/nf-core/picard/addorreplacereadgroups/test.yml

This file was deleted.

Loading