Skip to content

Commit

Permalink
Replace switch with else-if in utils_nfcore_pipeline (#7168)
Browse files Browse the repository at this point in the history
I also added some tests to check that the function works as expected.
  • Loading branch information
robsyme authored Dec 6, 2024
1 parent c33544d commit 51ae540
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 15 deletions.
28 changes: 13 additions & 15 deletions subworkflows/nf-core/utils_nfcore_pipeline/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -206,22 +206,20 @@ def logColours(monochrome_logs=true) {
// Return a single report from an object that may be a Path or List
//
def getSingleReport(multiqc_reports) {
switch (multiqc_reports) {
case Path:
return multiqc_reports
case List:
switch (multiqc_reports.size()) {
case 0:
log.warn("[${workflow.manifest.name}] No reports found from process 'MULTIQC'")
return null
case 1:
return multiqc_reports.first()
default:
log.warn("[${workflow.manifest.name}] Found multiple reports from process 'MULTIQC', will use only one")
return multiqc_reports.first()
}
default:
if (multiqc_reports instanceof Path) {
return multiqc_reports
} else if (multiqc_reports instanceof List) {
if (multiqc_reports.size() == 0) {
log.warn("[${workflow.manifest.name}] No reports found from process 'MULTIQC'")
return null
} else if (multiqc_reports.size() == 1) {
return multiqc_reports.first()
} else {
log.warn("[${workflow.manifest.name}] Found multiple reports from process 'MULTIQC', will use only one")
return multiqc_reports.first()
}
} else {
return null
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,48 @@ nextflow_function {
)
}
}

test("Test Function getSingleReport with a single file") {
function "getSingleReport"

when {
function {
"""
input[0] = file(params.modules_testdata_base_path + '/generic/tsv/test.tsv', checkIfExists: true)
"""
}
}

then {
assertAll(
{ assert function.success },
{ assert function.result.contains("test.tsv") }
)
}
}

test("Test Function getSingleReport with multiple files") {
function "getSingleReport"

when {
function {
"""
input[0] = [
file(params.modules_testdata_base_path + '/generic/tsv/test.tsv', checkIfExists: true),
file(params.modules_testdata_base_path + '/generic/tsv/network.tsv', checkIfExists: true),
file(params.modules_testdata_base_path + '/generic/tsv/expression.tsv', checkIfExists: true)
]
"""
}
}

then {
assertAll(
{ assert function.success },
{ assert function.result.contains("test.tsv") },
{ assert !function.result.contains("network.tsv") },
{ assert !function.result.contains("expression.tsv") }
)
}
}
}

0 comments on commit 51ae540

Please sign in to comment.