From bdca0f17ea92b6290e458bbcef71544041d7b720 Mon Sep 17 00:00:00 2001 From: Dave Carlson Date: Mon, 13 May 2024 23:55:19 +0800 Subject: [PATCH] add bedops/gtf2bed (#4476) * add gt2bed main.nf * add meta.yml file * bug fixes and add tests * run prettier on yml files * replace meta.yml * prettier formatting * Update modules/nf-core/bedops/gtf2bed/main.nf Co-authored-by: Maxime U Garcia * Swap to nftest * Update snap --------- Co-authored-by: Maxime U Garcia Co-authored-by: Maxime U Garcia Co-authored-by: Simon Pearce <24893913+SPPearce@users.noreply.github.com> --- .../nf-core/bedops/gtf2bed/environment.yml | 7 ++ modules/nf-core/bedops/gtf2bed/main.nf | 49 +++++++++++++ modules/nf-core/bedops/gtf2bed/meta.yml | 38 +++++++++++ .../nf-core/bedops/gtf2bed/tests/main.nf.test | 56 +++++++++++++++ .../bedops/gtf2bed/tests/main.nf.test.snap | 68 +++++++++++++++++++ modules/nf-core/bedops/gtf2bed/tests/tags.yml | 2 + 6 files changed, 220 insertions(+) create mode 100644 modules/nf-core/bedops/gtf2bed/environment.yml create mode 100644 modules/nf-core/bedops/gtf2bed/main.nf create mode 100644 modules/nf-core/bedops/gtf2bed/meta.yml create mode 100644 modules/nf-core/bedops/gtf2bed/tests/main.nf.test create mode 100644 modules/nf-core/bedops/gtf2bed/tests/main.nf.test.snap create mode 100644 modules/nf-core/bedops/gtf2bed/tests/tags.yml diff --git a/modules/nf-core/bedops/gtf2bed/environment.yml b/modules/nf-core/bedops/gtf2bed/environment.yml new file mode 100644 index 00000000000..8aede242838 --- /dev/null +++ b/modules/nf-core/bedops/gtf2bed/environment.yml @@ -0,0 +1,7 @@ +name: "bedops_gtf2bed" +channels: + - conda-forge + - bioconda + - defaults +dependencies: + - "bioconda::bedops=2.4.41" diff --git a/modules/nf-core/bedops/gtf2bed/main.nf b/modules/nf-core/bedops/gtf2bed/main.nf new file mode 100644 index 00000000000..13a37b5cc85 --- /dev/null +++ b/modules/nf-core/bedops/gtf2bed/main.nf @@ -0,0 +1,49 @@ +process BEDOPS_GTF2BED { + tag "$gtf" + label 'process_low' + + conda "${moduleDir}/environment.yml" + container "${ workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container ? + 'https://depot.galaxyproject.org/singularity/bedops:2.4.41--h4ac6f70_2': + 'biocontainers/bedops:2.4.41--h4ac6f70_2' }" + + input: + tuple val(meta), path(gtf) + + output: + tuple val(meta), path('*.bed'), emit: bed + path "versions.yml" , emit: versions + + when: + task.ext.when == null || task.ext.when + + script: + def args = task.ext.args ?: '' + def prefix = task.ext.prefix ?: "${gtf.baseName}" + + """ + cat \\ + $gtf \\ + | gtf2bed \\ + $args \\ + --attribute-key=exon_id \\ + > ${prefix}.bed + + cat <<-END_VERSIONS > versions.yml + "${task.process}": + gtf2bed: \$(bedops --version | grep version | awk ' { print \$2 } ') + END_VERSIONS + """ + + stub: + def prefix = task.ext.prefix ?: "${gtf.baseName}" + """ + touch ${prefix}.bed + + cat <<-END_VERSIONS > versions.yml + "${task.process}": + gtf2bed: \$(bedops --version | grep version | awk ' { print \$2 } ') + END_VERSIONS + """ + +} diff --git a/modules/nf-core/bedops/gtf2bed/meta.yml b/modules/nf-core/bedops/gtf2bed/meta.yml new file mode 100644 index 00000000000..2646b74a2f8 --- /dev/null +++ b/modules/nf-core/bedops/gtf2bed/meta.yml @@ -0,0 +1,38 @@ +name: "bedops_gtf2bed" +description: Convert gtf format to bed format +keywords: + - gtf + - bed + - conversion +tools: + - gtf2bed: + description: The gtf2bed script converts 1-based, closed [start, end] Gene Transfer Format v2.2 (GTF2.2) to sorted, 0-based, half-open [start-1, end) extended BED-formatted data. + homepage: https://bedops.readthedocs.io/en/latest/content/reference/file-management/conversion/gtf2bed.html + documentation: https://bedops.readthedocs.io/en/latest/content/reference/file-management/conversion/gtf2bed.html + tool_dev_url: https://github.com/bedops/bedops + doi: 10.1093/bioinformatics/bts277 + licence: ["GPL v2"] + +input: + - meta: + type: map + description: | + Groovy Map containing sample information + e.g. `[ id:'sample1', single_end:false ]` + + - gtf: + type: file + description: A reference file in GTF format + pattern: "*.{gtf,gtf.gz}" + +output: + - bed: + type: file + description: A reference file in BED format + pattern: "*.{bed}" + - versions: + type: file + description: File containing software versions + pattern: "versions.yml" +authors: + - "@davidecarlson" diff --git a/modules/nf-core/bedops/gtf2bed/tests/main.nf.test b/modules/nf-core/bedops/gtf2bed/tests/main.nf.test new file mode 100644 index 00000000000..8dcc67f5760 --- /dev/null +++ b/modules/nf-core/bedops/gtf2bed/tests/main.nf.test @@ -0,0 +1,56 @@ +nextflow_process { + + name "Test Process BEDOPS_GTF2BED" + script "../main.nf" + process "BEDOPS_GTF2BED" + + tag "modules" + tag "modules_nfcore" + tag "bedops" + tag "bedops/gtf2bed" + + test("homo sapiens") { + + when { + process { + """ + input[0] = [[ id:'test' ], // meta map + file(params.test_data['homo_sapiens']['genome']['genome_gtf'], checkIfExists: true) + ] + """ + } + } + + then { + assertAll( + { assert process.success }, + { assert snapshot(process.out).match() } + ) + } + + } + + test("homo sapiens - stub") { + + options "-stub" + + when { + process { + """ + input[0] = [[ id:'test' ], // meta map + file(params.test_data['homo_sapiens']['genome']['genome_gtf'], checkIfExists: true) + ] + """ + } + } + + then { + assertAll( + { assert process.success }, + { assert snapshot(process.out).match() } + ) + } + + } + +} diff --git a/modules/nf-core/bedops/gtf2bed/tests/main.nf.test.snap b/modules/nf-core/bedops/gtf2bed/tests/main.nf.test.snap new file mode 100644 index 00000000000..9c9f905e43c --- /dev/null +++ b/modules/nf-core/bedops/gtf2bed/tests/main.nf.test.snap @@ -0,0 +1,68 @@ +{ + "homo sapiens": { + "content": [ + { + "0": [ + [ + { + "id": "test" + }, + "genome.bed:md5,783257789b0c59a1a5391f7f2b9ac08a" + ] + ], + "1": [ + "versions.yml:md5,fb301f89b7f040eedb8ea7edaaf05187" + ], + "bed": [ + [ + { + "id": "test" + }, + "genome.bed:md5,783257789b0c59a1a5391f7f2b9ac08a" + ] + ], + "versions": [ + "versions.yml:md5,fb301f89b7f040eedb8ea7edaaf05187" + ] + } + ], + "meta": { + "nf-test": "0.8.4", + "nextflow": "23.10.1" + }, + "timestamp": "2024-05-13T15:45:25.277799374" + }, + "homo sapiens - stub": { + "content": [ + { + "0": [ + [ + { + "id": "test" + }, + "genome.bed:md5,d41d8cd98f00b204e9800998ecf8427e" + ] + ], + "1": [ + "versions.yml:md5,fb301f89b7f040eedb8ea7edaaf05187" + ], + "bed": [ + [ + { + "id": "test" + }, + "genome.bed:md5,d41d8cd98f00b204e9800998ecf8427e" + ] + ], + "versions": [ + "versions.yml:md5,fb301f89b7f040eedb8ea7edaaf05187" + ] + } + ], + "meta": { + "nf-test": "0.8.4", + "nextflow": "23.10.1" + }, + "timestamp": "2024-05-13T15:45:34.937117692" + } +} \ No newline at end of file diff --git a/modules/nf-core/bedops/gtf2bed/tests/tags.yml b/modules/nf-core/bedops/gtf2bed/tests/tags.yml new file mode 100644 index 00000000000..215ef9a1711 --- /dev/null +++ b/modules/nf-core/bedops/gtf2bed/tests/tags.yml @@ -0,0 +1,2 @@ +bedops/gtf2bed: + - "modules/nf-core/bedops/gtf2bed/**"