Skip to content

Commit

Permalink
Added gt/gff3validator (nf-core#4718)
Browse files Browse the repository at this point in the history
* Added gt/gff3validator

* Make error handling a bit more intuitive

* Fixed a problem with info echo and simplified test assertions

---------

Co-authored-by: Leon Rauschning <[email protected]>
  • Loading branch information
GallVp and lrauschning authored Mar 19, 2024
1 parent 8ce34a4 commit 5ed10bd
Show file tree
Hide file tree
Showing 7 changed files with 331 additions and 0 deletions.
9 changes: 9 additions & 0 deletions modules/nf-core/gt/gff3validator/environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/nf-core/modules/master/modules/environment-schema.json
name: "gt_gff3validator"
channels:
- conda-forge
- bioconda
- defaults
dependencies:
- "bioconda::genometools-genometools=1.6.5"
61 changes: 61 additions & 0 deletions modules/nf-core/gt/gff3validator/main.nf
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
process GT_GFF3VALIDATOR {
tag "$meta.id"
label 'process_single'

conda "${moduleDir}/environment.yml"
container "${ workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container ?
'https://depot.galaxyproject.org/singularity/genometools-genometools:1.6.5--py310h3db02ab_0':
'biocontainers/genometools-genometools:1.6.5--py310h3db02ab_0' }"

input:
tuple val(meta), path(gff3)

output:
tuple val(meta), path('*.success.log') , emit: success_log , optional: true
tuple val(meta), path('*.error.log') , emit: error_log , optional: true
path "versions.yml" , emit: versions

when:
task.ext.when == null || task.ext.when

script:
def prefix = task.ext.prefix ?: "${meta.id}"
"""
gt \\
gff3validator \\
"$gff3" \\
> "${prefix}.stdout" \\
2> >(tee "${prefix}.stderr" >&2) \\
|| echo "Errors from gt-gff3validator printed to ${prefix}.error.log"
if grep -q "input is valid GFF3" "${prefix}.stdout"; then
echo "Validation successful..."
# emit stdout to the success output channel
mv \\
"${prefix}.stdout" \\
"${prefix}.success.log"
else
echo "Validation failed..."
# emit stderr to the error output channel
mv \\
"${prefix}.stderr" \\
"${prefix}.error.log"
fi
cat <<-END_VERSIONS > versions.yml
"${task.process}":
genometools: \$(gt --version | head -1 | sed 's/gt (GenomeTools) //')
END_VERSIONS
"""

stub:
def prefix = task.ext.prefix ?: "${meta.id}"
"""
touch "${prefix}.success.log"
cat <<-END_VERSIONS > versions.yml
"${task.process}":
genometools: \$(gt --version | head -1 | sed 's/gt (GenomeTools) //')
END_VERSIONS
"""
}
49 changes: 49 additions & 0 deletions modules/nf-core/gt/gff3validator/meta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/nf-core/modules/master/modules/meta-schema.json
name: "gt_gff3validator"
description: "GenomeTools gt-gff3validator utility to strictly validate a GFF3 file"
keywords:
- genome
- gff3
- annotation
- validation
tools:
- "gt":
description: "The GenomeTools genome analysis system"
homepage: "https://genometools.org/index.html"
documentation: "https://genometools.org/documentation.html"
tool_dev_url: "https://github.com/genometools/genometools"
doi: "10.1109/TCBB.2013.68"
licence: ["ISC"]
input:
- meta:
type: map
description: |
Groovy Map containing sample information
e.g. `[ id:'test' ]`
- gff3:
type: file
description: Input gff3 file
pattern: "*.{gff,gff3}"
output:
- meta:
type: map
description: |
Groovy Map containing sample information
e.g. `[ id:'test' ]`
- success_log:
type: file
description: Log file for successful validation
pattern: "*.success.log"
- error_log:
type: file
description: Log file for failed validation
pattern: "*.error.log"
- versions:
type: file
description: File containing software versions
pattern: "versions.yml"
authors:
- "@GallVp"
maintainers:
- "@GallVp"
98 changes: 98 additions & 0 deletions modules/nf-core/gt/gff3validator/tests/main.nf.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
nextflow_process {

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

tag "modules"
tag "modules_nfcore"
tag "gt"
tag "gt/gff3validator"
tag "gt/gff3"

test("sarscov2-gff3-valid") {

config './nextflow.config'

setup {
run("GT_GFF3") {
script "../../../../nf-core/gt/gff3"

process {
"""
input[0] = [
[ id:'test' ],
file(params.test_data['sarscov2']['genome']['genome_gff3'], checkIfExists: true)
]
"""
}
}
}

when {
process {
"""
input[0] = GT_GFF3.out.gt_gff3
"""
}
}

then {
assertAll(
{ assert process.success },
{ assert snapshot(process.out).match() },
{ assert path(process.out.success_log[0][1]).text.contains("input is valid GFF3") },
{ assert process.out.error_log == [] }
)
}

}

test("sarscov2-gff3-stub") {

options '-stub'

when {
process {
"""
input[0] = [
[ id:'test' ],
file(params.test_data['sarscov2']['genome']['genome_gff3'], checkIfExists: true)
]
"""
}
}

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

}

test("sarscov2-gff3-invalid") {

when {
process {
"""
input[0] = [
[ id:'test' ], // meta map
file(params.test_data['homo_sapiens']['genome']['genome_gff3'], checkIfExists: true)
]
"""
}
}

then {
assertAll(
{ assert process.success },
{ assert snapshot(process.out).match() },
{ assert process.out.success_log == [] },
{ assert path(process.out.error_log[0][1]).text.contains("gt gff3validator: error:") }
)
}

}
}
107 changes: 107 additions & 0 deletions modules/nf-core/gt/gff3validator/tests/main.nf.test.snap

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

5 changes: 5 additions & 0 deletions modules/nf-core/gt/gff3validator/tests/nextflow.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
process {
withName: GT_GFF3 {
ext.args = '-tidy -retainids'
}
}
2 changes: 2 additions & 0 deletions modules/nf-core/gt/gff3validator/tests/tags.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
gt/gff3validator:
- "modules/nf-core/gt/gff3validator/**"

0 comments on commit 5ed10bd

Please sign in to comment.