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

fix optional cram support in modules and migrate to nf-test #5329

Merged
merged 12 commits into from
Mar 21, 2024
3 changes: 2 additions & 1 deletion modules/nf-core/gatk4/estimatelibrarycomplexity/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ process GATK4_ESTIMATELIBRARYCOMPLEXITY {
def args = task.ext.args ?: ''
def prefix = task.ext.prefix ?: "${meta.id}"
def input_list = input.collect(){"--INPUT $it"}.join(" ")
def reference = fasta ? "--REFERENCE_SEQUENCE ${fasta}" : ""

def avail_mem = 3072
if (!task.memory) {
Expand All @@ -36,7 +37,7 @@ process GATK4_ESTIMATELIBRARYCOMPLEXITY {
EstimateLibraryComplexity \\
$input_list \\
--OUTPUT ${prefix}.metrics \\
--REFERENCE_SEQUENCE ${fasta} \\
$reference \\
--TMP_DIR . \\
$args

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

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

tag "modules"
tag "modules_nfcore"
tag "gatk4"
tag "gatk4/estimatelibrarycomplexity"

test("homo_sapiens - bam") {

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

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

}

test("homo_sapiens - cram") {

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

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

}

test("sarscov2 - bam - stub") {

options "-stub"

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

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

}

}

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
gatk4/estimatelibrarycomplexity:
- "modules/nf-core/gatk4/estimatelibrarycomplexity/**"
19 changes: 6 additions & 13 deletions modules/nf-core/picard/addorreplacereadgroups/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ process PICARD_ADDORREPLACEREADGROUPS {
'biocontainers/picard:3.1.1--hdfd78af_0' }"

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

Expand All @@ -24,26 +24,24 @@ process PICARD_ADDORREPLACEREADGROUPS {
script:
def args = task.ext.args ?: ''
def prefix = task.ext.prefix ?: "${meta.id}"
def suffix = task.ext.suffix ?: "${bam.getExtension()}"
def suffix = task.ext.suffix ?: "${reads.getExtension()}"
def reference = fasta ? "--REFERENCE_SEQUENCE ${fasta}" : ""
def create_index = ( suffix == "bam" )? "--CREATE_INDEX" : ""
tomiles marked this conversation as resolved.
Show resolved Hide resolved
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}.${suffix}") error "Input and output names are the same, use \"task.ext.prefix\" to disambiguate!"
if ("$reads" == "${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} \\
--INPUT ${reads} \\
--OUTPUT ${prefix}.${suffix}

cat <<-END_VERSIONS > versions.yml
Expand All @@ -54,15 +52,10 @@ process PICARD_ADDORREPLACEREADGROUPS {

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

cat <<-END_VERSIONS > versions.yml
"${task.process}":
Expand Down
6 changes: 3 additions & 3 deletions modules/nf-core/picard/addorreplacereadgroups/meta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ input:
description: |
Groovy Map containing sample information
e.g. [ id:'test', single_end:false ]
- bam:
- reads:
type: file
description: Input BAM file
pattern: "*.{bam}"
description: Sequence reads file, can be SAM/BAM/CRAM format
pattern: "*.{bam,cram,sam}"
- fasta:
type: file
description: Reference genome file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ process {
withName: 'PICARD_ADDORREPLACEREADGROUPS'{
ext.prefix = { "${meta.id}.replaced"}
ext.args = {[
"--CREATE_INDEX",
"-LB ${meta.id}",
"-PL ILLUMINA",
"-PU bc1",
Expand Down
15 changes: 11 additions & 4 deletions modules/nf-core/picard/addorreplacereadgroups/tests/main.nf.test
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ nextflow_process {
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") },
{ assert snapshot(
file(process.out.bam[0][1]).name,
file(process.out.bai[0][1]).name,
process.out.versions
).match()
},
)
}

Expand All @@ -53,8 +57,11 @@ nextflow_process {
then {
assertAll(
{ assert process.success },
{ assert snapshot(file(process.out.cram[0][1]).name).match("cram_name") },
{ assert snapshot(process.out.versions).match("versions") },
{ assert snapshot(
file(process.out.cram[0][1]).name,
process.out.versions
).match()
},
)
}

Expand Down

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

Loading
Loading