From af3bc225c03b880e85c5aff7aa655e3ed7008b8b Mon Sep 17 00:00:00 2001 From: Yuk Kei Wan <41866052+yuukiiwa@users.noreply.github.com> Date: Wed, 24 Mar 2021 12:55:49 +0800 Subject: [PATCH] ucsc_bed12tobigbed (previous pull request had conflicts) (#302) * Add files via upload * Add files via upload * Add files via upload * Add files via upload * Update pytest_software.yml * Update main.nf * fix linting error * Delete test.yml * Create functions.nf * Update main.nf * change test data * revert to !>=20.11.0-edge --- software/ucsc/bed12tobigbed/functions.nf | 59 +++++++++++++++++++++ software/ucsc/bed12tobigbed/main.nf | 41 ++++++++++++++ tests/config/pytest_software.yml | 4 ++ tests/data/generic/sizes/test.sizes | 1 + tests/data/genomics/sarscov2/bed/test.bed12 | 4 ++ tests/software/ucsc/bed12tobigbed/main.nf | 15 ++++++ tests/software/ucsc/bed12tobigbed/test.yml | 7 +++ 7 files changed, 131 insertions(+) create mode 100644 software/ucsc/bed12tobigbed/functions.nf create mode 100644 software/ucsc/bed12tobigbed/main.nf create mode 100644 tests/data/generic/sizes/test.sizes create mode 100644 tests/data/genomics/sarscov2/bed/test.bed12 create mode 100644 tests/software/ucsc/bed12tobigbed/main.nf create mode 100644 tests/software/ucsc/bed12tobigbed/test.yml diff --git a/software/ucsc/bed12tobigbed/functions.nf b/software/ucsc/bed12tobigbed/functions.nf new file mode 100644 index 00000000..d25eea86 --- /dev/null +++ b/software/ucsc/bed12tobigbed/functions.nf @@ -0,0 +1,59 @@ +/* + * ----------------------------------------------------- + * Utility functions used in nf-core DSL2 module files + * ----------------------------------------------------- + */ + +/* + * Extract name of software tool from process name using $task.process + */ +def getSoftwareName(task_process) { + return task_process.tokenize(':')[-1].tokenize('_')[0].toLowerCase() +} + +/* + * Function to initialise default values and to generate a Groovy Map of available options for nf-core modules + */ +def initOptions(Map args) { + def Map options = [:] + options.args = args.args ?: '' + options.args2 = args.args2 ?: '' + options.publish_by_id = args.publish_by_id ?: false + options.publish_dir = args.publish_dir ?: '' + options.publish_files = args.publish_files + options.suffix = args.suffix ?: '' + return options +} + +/* + * Tidy up and join elements of a list to return a path string + */ +def getPathFromList(path_list) { + def paths = path_list.findAll { item -> !item?.trim().isEmpty() } // Remove empty entries + paths = paths.collect { it.trim().replaceAll("^[/]+|[/]+\$", "") } // Trim whitespace and trailing slashes + return paths.join('/') +} + +/* + * Function to save/publish module results + */ +def saveFiles(Map args) { + if (!args.filename.endsWith('.version.txt')) { + def ioptions = initOptions(args.options) + def path_list = [ ioptions.publish_dir ?: args.publish_dir ] + if (ioptions.publish_by_id) { + path_list.add(args.publish_id) + } + if (ioptions.publish_files instanceof Map) { + for (ext in ioptions.publish_files) { + if (args.filename.endsWith(ext.key)) { + def ext_list = path_list.collect() + ext_list.add(ext.value) + return "${getPathFromList(ext_list)}/$args.filename" + } + } + } else if (ioptions.publish_files == null) { + return "${getPathFromList(path_list)}/$args.filename" + } + } +} diff --git a/software/ucsc/bed12tobigbed/main.nf b/software/ucsc/bed12tobigbed/main.nf new file mode 100644 index 00000000..3b7a35bb --- /dev/null +++ b/software/ucsc/bed12tobigbed/main.nf @@ -0,0 +1,41 @@ +// Import generic module functions +include { initOptions; saveFiles; getSoftwareName } from './functions' + +params.options = [:] +def options = initOptions(params.options) + +def VERSION = '377' + +process UCSC_BED12TOBIGBED { + tag "$meta.id" + label 'process_medium' + publishDir "${params.outdir}", + mode: params.publish_dir_mode, + saveAs: { filename -> saveFiles(filename:filename, options:params.options, publish_dir:getSoftwareName(task.process), publish_id:meta.id) } + + conda (params.enable_conda ? "bioconda::ucsc-bedtobigbed=377" : null) + if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) { + container "https://depot.galaxyproject.org/singularity/ucsc-bedtobigbed:377--h446ed27_1" + } else { + container "quay.io/biocontainers/ucsc-bedtobigbed:377--h446ed27_1" + } + + input: + tuple val(meta), path(bed) + path sizes + + output: + tuple val(meta), path("*.bigBed"), emit: bigbed + path "*.version.txt" , emit: version + + script: + def software = getSoftwareName(task.process) + def prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}" + """ + bedToBigBed \\ + $bed \\ + $sizes \\ + ${prefix}.bigBed + echo $VERSION > ${software}.version.txt + """ +} diff --git a/tests/config/pytest_software.yml b/tests/config/pytest_software.yml index 52df14ff..6398b5cb 100755 --- a/tests/config/pytest_software.yml +++ b/tests/config/pytest_software.yml @@ -415,6 +415,10 @@ trimgalore: - software/trimgalore/** - tests/software/trimgalore/** +ucsc_bed12tobigbed: + - software/ucsc/bed12tobigbed/** + - tests/software/ucsc/bed12tobigbed/** + ucsc_bedgraphtobigwig: - software/ucsc/bedgraphtobigwig/** - tests/software/ucsc/bedgraphtobigwig/** diff --git a/tests/data/generic/sizes/test.sizes b/tests/data/generic/sizes/test.sizes new file mode 100644 index 00000000..319e9e27 --- /dev/null +++ b/tests/data/generic/sizes/test.sizes @@ -0,0 +1 @@ +chr7 159138663 diff --git a/tests/data/genomics/sarscov2/bed/test.bed12 b/tests/data/genomics/sarscov2/bed/test.bed12 new file mode 100644 index 00000000..33a46951 --- /dev/null +++ b/tests/data/genomics/sarscov2/bed/test.bed12 @@ -0,0 +1,4 @@ +MT192765.1 1242 1264 nCoV-2019_5_LEFT 1 + 1242 1264 0 2 10,12, 0,10, +MT192765.1 1573 1595 nCoV-2019_6_LEFT 2 + 1573 1595 0 2 7,15, 0,7, +MT192765.1 1623 1651 nCoV-2019_5_RIGHT 1 - 1623 1651 0 2 14,14, 0,14, +MT192765.1 1942 1964 nCoV-2019_6_RIGHT 2 - 1942 1964 0 2 11,11 0,11, diff --git a/tests/software/ucsc/bed12tobigbed/main.nf b/tests/software/ucsc/bed12tobigbed/main.nf new file mode 100644 index 00000000..380ba6cc --- /dev/null +++ b/tests/software/ucsc/bed12tobigbed/main.nf @@ -0,0 +1,15 @@ +#!/usr/bin/env nextflow + +nextflow.enable.dsl = 2 + +include { UCSC_BED12TOBIGBED } from '../../../../software/ucsc/bed12tobigbed/main.nf' addParams( options: [:] ) + +workflow test_ucsc_bed12tobigbed { + + def input = [] + input = [ [ id: 'test' ], // meta map + [ file("${launchDir}/tests/data/genomics/sarscov2/bed/test.bed12", checkIfExists: true )] ] + sizes = file("${launchDir}/tests/data/genomics/sarscov2/general/test.genome.sizes", checkIfExists: true) + + UCSC_BED12TOBIGBED ( input, sizes ) +} diff --git a/tests/software/ucsc/bed12tobigbed/test.yml b/tests/software/ucsc/bed12tobigbed/test.yml new file mode 100644 index 00000000..58641edf --- /dev/null +++ b/tests/software/ucsc/bed12tobigbed/test.yml @@ -0,0 +1,7 @@ +- name: ucsc bed12tobigbed + command: nextflow run ./tests/software/ucsc/bed12tobigbed -entry test_ucsc_bed12tobigbed -c tests/config/nextflow.config + tags: + - ucsc_bed12tobigbed + files: + - path: output/ucsc/test.bigBed + md5sum: 98cf0d0baa3ae5a330c80afbb8bc2b18