Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maxulysse committed Jan 31, 2025
1 parent ee48616 commit 03f001f
Show file tree
Hide file tree
Showing 5 changed files with 239 additions and 1 deletion.
23 changes: 22 additions & 1 deletion subworkflows/local/utils_references/main.nf
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
// JUST TO TEST THE SUBWORKFLOW

workflow UTILS_REFERENCES {
take:
references
param_file
param_value
attribute_file
attribute_value
basepath

main:
// GIVING up writing a test for the functions, so writing a subworkflow to test it
references_file = extract_references_file(references, param_file, attribute_file, basepath)
references_value = extract_references_value(references, param_value, attribute_value)

emit:
references_file
references_value
}

/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
FUNCTIONS TO EXTRACT REFERENCES FILES OR VALUES FROM THE REFERENCES YAML OR PARAMS
Expand All @@ -8,7 +29,7 @@ def extract_references_file(references, param, attribute, basepath) {
return references
.map { meta, _readme ->
if (param || meta[attribute]) {
[meta.subMap(['id']), file(param ?: meta[attribute].replace('${params.igenomes_base}', basepath))]
[meta.subMap(['id']), file(param ?: meta[attribute].replace('${params.igenomes_base}', basepath), checkIfExists: true)]
}
else {
null
Expand Down
14 changes: 14 additions & 0 deletions subworkflows/local/utils_references/meta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/nf-core/modules/master/subworkflows/yaml-schema.json
name: "utils_references"
description: Functionality for dealing with references that may be useful for any Nextflow pipeline
keywords:
- utility
- pipeline
- references
components: []
input: []
output: []
authors:
- "@maxulysse"
maintainers:
- "@maxulysse"
57 changes: 57 additions & 0 deletions subworkflows/local/utils_references/tests/main.function.nf.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@

nextflow_function {

name "Test Functions"
script "../main.nf"

test("extract_references_file - without params") {

function "extract_references_file"

when {
function {
"""
input[0] = Channel.of([[
genome:'GRCh38_chr22',
id:'GRCh38_chr22',
species:'Homo_sapiens',
fasta:'\${params.igenomes_base}/Homo_sapiens/nf-core/references/testdata.GRCh38_chr22/Sequence/WholeGenomeFasta/genome.fasta',
], []])
input[1] = []
input[2] = 'fasta'
input[3] = 's3://nf-core-references/test_data/'
"""
}
}

then {
assert function.success
assert snapshot(function.result).match()
}
}

test("extract_references_value - without params") {

function "extract_references_value"

when {
function {
"""
input[0] = Channel.of([[
genome:'GRCh38_chr22',
id:'GRCh38_chr22',
species:'Homo_sapiens',
fasta:'\${params.igenomes_base}/Homo_sapiens/nf-core/references/testdata.GRCh38_chr22/Sequence/WholeGenomeFasta/genome.fasta',
], []])
input[1] = []
input[2] = 'species'
"""
}
}

then {
assert function.success
assert snapshot(function.result).match()
}
}
}
58 changes: 58 additions & 0 deletions subworkflows/local/utils_references/tests/main.nf.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
nextflow_workflow {

name "Test Workflow UTILS_REFERENCES"
script "../main.nf"
workflow "UTILS_REFERENCES"

test("Without params") {

when {
workflow {
"""
input[0] = Channel.of([[
genome:'GRCh38_chr22',
id:'GRCh38_chr22',
species:'Homo_sapiens',
fasta:'\${params.igenomes_base}/Homo_sapiens/nf-core/references/testdata.GRCh38_chr22/Sequence/WholeGenomeFasta/genome.fasta',
], []])
input[1] = []
input[2] = []
input[3] = 'fasta'
input[4] = 'species'
input[5] = 's3://nf-core-references/test_data/'
"""
}
}

then {
assert workflow.success
assert snapshot(workflow.out).match()
}
}

test("With params") {

when {
workflow {
"""
input[0] = Channel.of([[
genome:'GRCh38_chr22',
id:'GRCh38_chr22',
species:'Homo_sapiens',
fasta:'\${params.igenomes_base}/Homo_sapiens/nf-core/references/testdata.GRCh38_chr22/Sequence/WholeGenomeFasta/genome.fasta',
], []])
input[1] = 'https://raw.githubusercontent.com/nf-core/test-datasets/modules/data/genomics/homo_sapiens/genome/genome.fasta'
input[2] = 'WBCel235'
input[3] = 'fasta'
input[4] = 'species'
input[5] = 's3://nf-core-references/test_data/'
"""
}
}

then {
assert workflow.success
assert snapshot(workflow.out).match()
}
}
}
88 changes: 88 additions & 0 deletions subworkflows/local/utils_references/tests/main.nf.test.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
{
"Without params": {
"content": [
{
"0": [
[
{
"id": "GRCh38_chr22"
},
"/nf-core-references/test_data/Homo_sapiens/nf-core/references/testdata.GRCh38_chr22/Sequence/WholeGenomeFasta/genome.fasta"
]
],
"1": [
[
{
"id": "GRCh38_chr22"
},
"Homo_sapiens"
]
],
"references_file": [
[
{
"id": "GRCh38_chr22"
},
"/nf-core-references/test_data/Homo_sapiens/nf-core/references/testdata.GRCh38_chr22/Sequence/WholeGenomeFasta/genome.fasta"
]
],
"references_value": [
[
{
"id": "GRCh38_chr22"
},
"Homo_sapiens"
]
]
}
],
"meta": {
"nf-test": "0.9.2",
"nextflow": "24.10.4"
},
"timestamp": "2025-01-31T13:12:57.867733238"
},
"With params": {
"content": [
{
"0": [
[
{
"id": "GRCh38_chr22"
},
"/nf-core/test-datasets/modules/data/genomics/homo_sapiens/genome/genome.fasta"
]
],
"1": [
[
{
"id": "GRCh38_chr22"
},
"WBCel235"
]
],
"references_file": [
[
{
"id": "GRCh38_chr22"
},
"/nf-core/test-datasets/modules/data/genomics/homo_sapiens/genome/genome.fasta"
]
],
"references_value": [
[
{
"id": "GRCh38_chr22"
},
"WBCel235"
]
]
}
],
"meta": {
"nf-test": "0.9.2",
"nextflow": "24.10.4"
},
"timestamp": "2025-01-31T13:13:08.097955852"
}
}

0 comments on commit 03f001f

Please sign in to comment.