From 4ed5e4eff30922a1ba998441760d1f3537ca96b8 Mon Sep 17 00:00:00 2001 From: Benjamin Wingfield Date: Thu, 21 Oct 2021 17:04:15 +0100 Subject: [PATCH] New module: ucsc/liftover (#868) * add liftOver module * add liftover module tests * fix getProcessName * fix tests * fix out of date function * version numbers should be numeric * drop versions.yml from test.yml * Update modules/ucsc/liftover/main.nf Remove software name variable Co-authored-by: Jose Espinosa-Carrasco * Update tests/modules/ucsc/liftover/main.nf Use test chain file Co-authored-by: Jose Espinosa-Carrasco * add genome_chain_gz to test data config * update md5sum for new chain test data * Fix indentation in file declaration Co-authored-by: Jose Espinosa-Carrasco --- modules/ucsc/liftover/functions.nf | 78 ++++++++++++++++++++++++++++ modules/ucsc/liftover/main.nf | 48 +++++++++++++++++ modules/ucsc/liftover/meta.yml | 45 ++++++++++++++++ tests/config/pytest_modules.yml | 4 ++ tests/config/test_data.config | 1 + tests/modules/ucsc/liftover/main.nf | 14 +++++ tests/modules/ucsc/liftover/test.yml | 10 ++++ 7 files changed, 200 insertions(+) create mode 100644 modules/ucsc/liftover/functions.nf create mode 100644 modules/ucsc/liftover/main.nf create mode 100644 modules/ucsc/liftover/meta.yml create mode 100644 tests/modules/ucsc/liftover/main.nf create mode 100644 tests/modules/ucsc/liftover/test.yml diff --git a/modules/ucsc/liftover/functions.nf b/modules/ucsc/liftover/functions.nf new file mode 100644 index 00000000..85628ee0 --- /dev/null +++ b/modules/ucsc/liftover/functions.nf @@ -0,0 +1,78 @@ +// +// 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() +} + +// +// Extract name of module from process name using $task.process +// +def getProcessName(task_process) { + return task_process.tokenize(':')[-1] +} + +// +// 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.args3 = args.args3 ?: '' + options.publish_by_meta = args.publish_by_meta ?: [] + 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) { + def ioptions = initOptions(args.options) + def path_list = [ ioptions.publish_dir ?: args.publish_dir ] + + // Do not publish versions.yml unless running from pytest workflow + if (args.filename.equals('versions.yml') && !System.getenv("NF_CORE_MODULES_TEST")) { + return null + } + if (ioptions.publish_by_meta) { + def key_list = ioptions.publish_by_meta instanceof List ? ioptions.publish_by_meta : args.publish_by_meta + for (key in key_list) { + if (args.meta && key instanceof String) { + def path = key + if (args.meta.containsKey(key)) { + path = args.meta[key] instanceof Boolean ? "${key}_${args.meta[key]}".toString() : args.meta[key] + } + path = path instanceof String ? path : '' + path_list.add(path) + } + } + } + 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/modules/ucsc/liftover/main.nf b/modules/ucsc/liftover/main.nf new file mode 100644 index 00000000..3739a1e5 --- /dev/null +++ b/modules/ucsc/liftover/main.nf @@ -0,0 +1,48 @@ +// Import generic module functions +include { initOptions; saveFiles; getSoftwareName; getProcessName } from './functions' + +params.options = [:] +options = initOptions(params.options) + +def VERSION = '377' + +process UCSC_LIFTOVER { + tag "$meta.id" + label 'process_low' + publishDir "${params.outdir}", + mode: params.publish_dir_mode, + saveAs: { filename -> saveFiles(filename:filename, options:params.options, publish_dir:getSoftwareName(task.process), meta:meta, publish_by_meta:['id']) } + + conda (params.enable_conda ? "bioconda::ucsc-liftover=377" : null) + if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) { + container "https://depot.galaxyproject.org/singularity/ucsc-liftover:377--h0b8a92a_3" + } else { + container "quay.io/biocontainers/ucsc-liftover:377--h0b8a92a_3" + } + + input: + tuple val(meta), path(bed) + path(chain) + + output: + tuple val(meta), path("*.lifted.bed") , emit: lifted + tuple val(meta), path("*.unlifted.bed"), emit: unlifted + path "versions.yml" , emit: versions + + script: + def prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}" + + """ + liftOver \\ + $options.args \ + $bed \\ + $chain \\ + ${prefix}.lifted.bed \\ + ${prefix}.unlifted.bed + + cat <<-END_VERSIONS > versions.yml + ${getProcessName(task.process)}: + ${getSoftwareName(task.process)}: \$(echo "$VERSION") + END_VERSIONS + """ +} diff --git a/modules/ucsc/liftover/meta.yml b/modules/ucsc/liftover/meta.yml new file mode 100644 index 00000000..5c2febdc --- /dev/null +++ b/modules/ucsc/liftover/meta.yml @@ -0,0 +1,45 @@ +name: ucsc_liftover +description: convert between genome builds +keywords: + - liftOver +tools: + - ucsc: + description: Move annotations from one assembly to another + homepage: http://hgdownload.cse.ucsc.edu/admin/exe/ + documentation: None + tool_dev_url: None + doi: "" + licence: ['varies; see http://genome.ucsc.edu/license'] + +input: + - meta: + type: map + description: | + Groovy Map containing sample information + e.g. [ id:'test', single_end:false ] + - bed: + type: file + description: Browser Extensible Data (BED) file + pattern: "*.{bed}" + +output: + - meta: + type: map + description: | + Groovy Map containing sample information + e.g. [ id:'test', single_end:false ] + - version: + type: file + description: File containing software version + pattern: "versions.yml" + - lifted: + type: file + description: BED file containing successfully lifted variants + pattern: "*.{lifted.bed}" + - unlifted: + type: file + description: BED file containing variants that couldn't be lifted + pattern: "*.{unlifted.bed}" + +authors: + - "@nebfield" diff --git a/tests/config/pytest_modules.yml b/tests/config/pytest_modules.yml index 8f030bd8..99eb271c 100644 --- a/tests/config/pytest_modules.yml +++ b/tests/config/pytest_modules.yml @@ -1075,6 +1075,10 @@ ucsc/bigwigaverageoverbed: - modules/ucsc/bigwigaverageoverbed/** - tests/modules/ucsc/bigwigaverageoverbed/** +ucsc/liftover: + - modules/ucsc/liftover/** + - tests/modules/ucsc/liftover/** + ucsc/wigtobigwig: - modules/ucsc/wigtobigwig/** - tests/modules/ucsc/wigtobigwig/** diff --git a/tests/config/test_data.config b/tests/config/test_data.config index 744282cc..3c0308a0 100644 --- a/tests/config/test_data.config +++ b/tests/config/test_data.config @@ -109,6 +109,7 @@ params { genome_bed_gz_tbi = "${test_data_dir}/genomics/homo_sapiens/genome/genome.bed.gz.tbi" transcriptome_fasta = "${test_data_dir}/genomics/homo_sapiens/genome/transcriptome.fasta" genome2_fasta = "${test_data_dir}/genomics/homo_sapiens/genome/genome2.fasta" + genome_chain_gz = "${test_data_dir}/genomics/homo_sapiens/genome/genome.chain.gz" dbsnp_146_hg38_vcf_gz = "${test_data_dir}/genomics/homo_sapiens/genome/vcf/dbsnp_146.hg38.vcf.gz" dbsnp_146_hg38_vcf_gz_tbi = "${test_data_dir}/genomics/homo_sapiens/genome/vcf/dbsnp_146.hg38.vcf.gz.tbi" diff --git a/tests/modules/ucsc/liftover/main.nf b/tests/modules/ucsc/liftover/main.nf new file mode 100644 index 00000000..9670759a --- /dev/null +++ b/tests/modules/ucsc/liftover/main.nf @@ -0,0 +1,14 @@ +#!/usr/bin/env nextflow + +nextflow.enable.dsl = 2 + +include { UCSC_LIFTOVER } from '../../../../modules/ucsc/liftover/main.nf' addParams( options: [:] ) + +workflow test_ucsc_liftover { + + input = [ [ id:'test', single_end:false ], // meta map + file(params.test_data['homo_sapiens']['genome']['genome_bed'], checkIfExists: true)] + chain = file(params.test_data['homo_sapiens']['genome']['genome_chain_gz'], checkIfExists: true) + + UCSC_LIFTOVER ( input, chain ) +} diff --git a/tests/modules/ucsc/liftover/test.yml b/tests/modules/ucsc/liftover/test.yml new file mode 100644 index 00000000..74df6512 --- /dev/null +++ b/tests/modules/ucsc/liftover/test.yml @@ -0,0 +1,10 @@ +- name: ucsc liftover test_ucsc_liftover + command: nextflow run tests/modules/ucsc/liftover -entry test_ucsc_liftover -c tests/config/nextflow.config + tags: + - ucsc + - ucsc/liftover + files: + - path: output/ucsc/test.lifted.bed + md5sum: fd5878470257a8a0edeaa8b9374bd520 + - path: output/ucsc/test.unlifted.bed + md5sum: d41d8cd98f00b204e9800998ecf8427e