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 nftests custom modules #7201

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
6 changes: 3 additions & 3 deletions modules/nf-core/cnvkit/export/tests/main.nf.test.snap
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@
"id": "test",
"single_end": false
},
"test.vcf:md5,0a0b4a00192be12f67bb895888026f00"
"test.vcf:md5,07fa974547dae22ff2af4b043466c12d"
]
],
"1": [
Expand All @@ -230,7 +230,7 @@
"id": "test",
"single_end": false
},
"test.vcf:md5,0a0b4a00192be12f67bb895888026f00"
"test.vcf:md5,07fa974547dae22ff2af4b043466c12d"
]
],
"versions": [
Expand All @@ -242,6 +242,6 @@
"nf-test": "0.9.2",
"nextflow": "24.10.3"
},
"timestamp": "2024-12-18T17:51:27.269813231"
"timestamp": "2024-12-20T21:13:12.582014142"
}
}
21 changes: 17 additions & 4 deletions modules/nf-core/custom/matrixfilter/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ process CUSTOM_MATRIXFILTER {
tag "$meta"
label 'process_single'
conda "${moduleDir}/environment.yml"
container "${ workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container ?
'https://depot.galaxyproject.org/singularity/r-base:4.2.1' :
'biocontainers/r-base:4.2.1' }"
container "${workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container
? 'https://community-cr-prod.seqera.io/docker/registry/v2/blobs/sha256/48/483e9d9b3b07e5658792d579e230ad40ed18daf7b9ebfb4323c08570f92fd1d5/data'
: 'community.wave.seqera.io/library/r-base:4.2.1--b0b5476e2e7a0872'}"

input:
tuple val(meta), path(abundance)
Expand All @@ -13,7 +13,7 @@ process CUSTOM_MATRIXFILTER {
output:
tuple val(meta), path("*.filtered.tsv") , emit: filtered
tuple val(meta), path("*.tests.tsv") , emit: tests
tuple val(meta), path("R_sessionInfo.log") , emit: session_info
tuple val(meta), path("*R_sessionInfo.log") , emit: session_info
path "versions.yml" , emit: versions

when:
Expand All @@ -27,4 +27,17 @@ process CUSTOM_MATRIXFILTER {
// (new variables defined here don't seem to be available in templates, so
// we have to access $task directly)
template 'matrixfilter.R'
nschcolnicov marked this conversation as resolved.
Show resolved Hide resolved

stub:
def prefix = task.ext.prefix ?: "${meta.id}"
"""
touch ${prefix}.filtered.tsv
touch ${prefix}.tests.tsv
touch ${prefix}.R_sessionInfo.log

cat <<-END_VERSIONS > versions.yml
"${task.process}":
r-base: \$(echo \$(R --version 2>&1) | sed 's/^.*R version //; s/ .*\$//')
END_VERSIONS
"""
}
2 changes: 1 addition & 1 deletion modules/nf-core/custom/matrixfilter/meta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ output:
description: |
Groovy Map containing information on experiment.
e.g. [ id:'test' ]
- R_sessionInfo.log:
- "*R_sessionInfo.log":
nschcolnicov marked this conversation as resolved.
Show resolved Hide resolved
type: file
description: Log file containing R session information
pattern: "*.log"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ keep <- apply(boolean_matrix, 1, all)
# Write out the matrix retaining the specified rows and re-prepending the
# column with the feature identifiers

prefix = ifelse('$task.ext.prefix' == 'null', '', '$task.ext.prefix')
prefix = ifelse('$task.ext.prefix' == 'null', '$meta.id', '$task.ext.prefix')

write.table(
data.frame(rownames(abundance_matrix)[keep], abundance_matrix[keep,,drop = FALSE]),
Expand Down
92 changes: 92 additions & 0 deletions modules/nf-core/custom/matrixfilter/tests/main.nf.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
nextflow_process {

name "Test Process CUSTOM_MATRIXFILTER"
script "../main.nf"
process "CUSTOM_MATRIXFILTER"
config "./nextflow.config"
tag "modules"
tag "modules_nfcore"
tag "custom_matrixfilter"
tag "custom"
tag "custom/matrixfilter"

test("test_custom_matrixfilter") {

when {
params {
observations_id_col = 'sample'
filtering_min_samples = 1.0
filtering_min_abundance = 10
filtering_min_proportion = null
filtering_grouping_var = null
filtering_min_proportion_not_na = 0.5
filtering_min_samples_not_na = null

module_args = [
"--sample_id_col \"${params.observations_id_col}\"",
"--minimum_samples ${params.filtering_min_samples}",
"--minimum_abundance ${params.filtering_min_abundance}",
(params.filtering_min_proportion ? "--minimum_proportion ${params.filtering_min_proportion}" : ''),
(params.filtering_grouping_var ? "--grouping_variable \"${params.filtering_grouping_var}\"" : ''),
(params.filtering_min_proportion_not_na ? "--minimum_proportion_not_na \"${params.filtering_min_proportion_not_na}\"" : ''),
(params.filtering_min_samples_not_na ? "--minimum_samples_not_na \"${params.filtering_min_samples_not_na}\"" : '')
].join(' ').trim()
}
process {
"""
input[0] = [ [id:"test"], file("https://github.com/nf-core/test-datasets/raw/refs/heads/differentialabundance/modules_testdata/SRP254919.salmon.merged.gene_counts.top1000cov.assay.tsv",checkIfExists: true) ]
input[1] = [ [id:"test"], file("https://github.com/nf-core/test-datasets/raw/refs/heads/differentialabundance/modules_testdata/SRP254919.samplesheet.sample_metadata.tsv",checkIfExists: true) ]
"""

}
}

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

test("test_custom_matrixfilter - stub") {

options "-stub"

when {
params {
observations_id_col = 'sample'
filtering_min_samples = 1.0
filtering_min_abundance = 10
filtering_min_proportion = null
filtering_grouping_var = null
filtering_min_proportion_not_na = 0.5
filtering_min_samples_not_na = null
module_args = [
"--sample_id_col \"${params.observations_id_col}\"",
"--minimum_samples ${params.filtering_min_samples}",
"--minimum_abundance ${params.filtering_min_abundance}",
(params.filtering_min_proportion ? "--minimum_proportion ${params.filtering_min_proportion}" : ''),
(params.filtering_grouping_var ? "--grouping_variable \"${params.filtering_grouping_var}\"" : ''),
(params.filtering_min_proportion_not_na ? "--minimum_proportion_not_na \"${params.filtering_min_proportion_not_na}\"" : ''),
(params.filtering_min_samples_not_na ? "--minimum_samples_not_na \"${params.filtering_min_samples_not_na}\"" : '')
].join(' ').trim()
}
process {
"""
input[0] = [ [id:"test"], file("https://github.com/nf-core/test-datasets/raw/refs/heads/differentialabundance/modules_testdata/SRP254919.salmon.merged.gene_counts.top1000cov.assay.tsv",checkIfExists: true) ]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more (small) thing - I would ask you to update your links so that they follow the convention and look like this:

file(params.modules_testdata_base_path + 'genomics/sarscov2/illumina/vcf/test.vcf.gz', checkIfExists: true)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That also means that all the test-datasets that you need must be present on the modules branch of the test-datasets repository. I know that there will be some restructuring around the test-datasets so maybe it makes sense to have them present there so they do not get lost and the tests stop working. I can review a PR over at the test-datasets repo when you add them.

input[1] = [ [id:"test"], file("https://github.com/nf-core/test-datasets/raw/refs/heads/differentialabundance/modules_testdata/SRP254919.samplesheet.sample_metadata.tsv",checkIfExists: true) ]
"""
}
}

then {
assertAll (
{ assert process.success },
{ assert snapshot(process.out).match() }
)
}
}
}
95 changes: 95 additions & 0 deletions modules/nf-core/custom/matrixfilter/tests/main.nf.test.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
{
"test_custom_matrixfilter": {
"content": [
[
[
{
"id": "test"
},
"test.filtered.tsv:md5,ecc3ca4c6538f9248dce844108474a66"
]
],
[
[
{
"id": "test"
},
"test.tests.tsv:md5,9a0f14988df8c1b8975039eed91b85e2"
]
],
[
"versions.yml:md5,275e382be9ca5bdd30ff5d6fc4340616"
]
],
"meta": {
"nf-test": "0.9.2",
"nextflow": "24.10.2"
},
"timestamp": "2024-12-13T21:21:11.862199262"
},
nschcolnicov marked this conversation as resolved.
Show resolved Hide resolved
"test_custom_matrixfilter - stub": {
"content": [
{
"0": [
[
{
"id": "test"
},
"test.filtered.tsv:md5,d41d8cd98f00b204e9800998ecf8427e"
]
],
"1": [
[
{
"id": "test"
},
"test.tests.tsv:md5,d41d8cd98f00b204e9800998ecf8427e"
]
],
"2": [
[
{
"id": "test"
},
"test.R_sessionInfo.log:md5,d41d8cd98f00b204e9800998ecf8427e"
]
],
"3": [
"versions.yml:md5,275e382be9ca5bdd30ff5d6fc4340616"
],
"filtered": [
[
{
"id": "test"
},
"test.filtered.tsv:md5,d41d8cd98f00b204e9800998ecf8427e"
]
],
"session_info": [
[
{
"id": "test"
},
"test.R_sessionInfo.log:md5,d41d8cd98f00b204e9800998ecf8427e"
]
],
"tests": [
[
{
"id": "test"
},
"test.tests.tsv:md5,d41d8cd98f00b204e9800998ecf8427e"
]
],
"versions": [
"versions.yml:md5,275e382be9ca5bdd30ff5d6fc4340616"
]
}
],
"meta": {
"nf-test": "0.9.2",
"nextflow": "24.10.2"
},
"timestamp": "2024-12-13T21:22:31.144793503"
}
}
3 changes: 3 additions & 0 deletions modules/nf-core/custom/matrixfilter/tests/nextflow.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
process {
ext.args = params.module_args
}
13 changes: 12 additions & 1 deletion modules/nf-core/custom/tabulartogseacls/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,18 @@ process CUSTOM_TABULARTOGSEACLS {

cat <<-END_VERSIONS > versions.yml
"${task.process}":
bash: \$(echo \$(bash --version | grep -Eo 'version [[:alnum:].]+' | sed 's/version //'))
awk: \$(mawk -W version | head -n 1 | awk '{print \$2}')
END_VERSIONS
"""

stub:
def prefix = task.ext.prefix ?: "${meta.id}"
"""
touch ${prefix}.cls
cat <<-END_VERSIONS > versions.yml
"${task.process}":
awk: \$(mawk -W version | head -n 1 | awk '{print \$2}')
END_VERSIONS
"""

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

name "Test Process CUSTOM_TABULARTOGSEACLS"
script "../main.nf"
process "CUSTOM_TABULARTOGSEACLS"
config "./nextflow.config"
tag "modules"
tag "modules_nfcore"
tag "custom_tabulartogseacls"
tag "custom"
tag "custom/tabulartogseacls"

test("test_custom_tabulartogseacls") {

when {
params {
module_args = [ "separator": "\t", "variable": "treatment" ]
}
process {
"""
input[0] = [ [id:'treatment_mCherry_hND6_sample_number', variable:'treatment', reference:'mCherry', target:'hND6', blocking:'sample_number'], file("https://github.com/nf-core/test-datasets/raw/refs/heads/differentialabundance/modules_testdata/SRP254919.samplesheet.sample_metadata.tsv",checkIfExists: true) ]
"""

}
}

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

test("test_custom_tabulartogseacls - stub") {

options "-stub"

when {
params {
module_args = { [ "separator": "\t", "variable": "treatment" ] }
}
process {
"""
input[0] = [ [id:'treatment_mCherry_hND6_sample_number', variable:'treatment', reference:'mCherry', target:'hND6', blocking:'sample_number'], file("https://github.com/nf-core/test-datasets/raw/refs/heads/differentialabundance/modules_testdata/SRP254919.samplesheet.sample_metadata.tsv",checkIfExists: true) ]
"""
}
}

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