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 <kadomu@gmail.com>

* Update tests/modules/ucsc/liftover/main.nf

Use test chain file

Co-authored-by: Jose Espinosa-Carrasco <kadomu@gmail.com>

* 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 <kadomu@gmail.com>
This commit is contained in:
Benjamin Wingfield 2021-10-21 17:04:15 +01:00 committed by GitHub
parent 4d89d6b2f0
commit 4ed5e4eff3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 200 additions and 0 deletions

View file

@ -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"
}
}

View file

@ -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
"""
}

View file

@ -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"

View file

@ -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/**

View file

@ -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"

View file

@ -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 )
}

View file

@ -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