Khmer normalizebymedian (#985)

* Templates for new module

* pe only test passing

* only_pe and only_se passing

* only_pe, only_se, mixed passes

* Multiple pe + se tc passes

* Passing args works

* Add 'interleaved' to description

* Fixed linting message

* Update modules/khmer/normalizebymedian/main.nf

Good point.

Co-authored-by: Daniel Straub <42973691+d4straub@users.noreply.github.com>

* Update meta.yml

Co-authored-by: Daniel Straub <42973691+d4straub@users.noreply.github.com>
This commit is contained in:
Daniel Lundin 2021-10-29 13:23:34 +02:00 committed by GitHub
parent ac1e6df076
commit 84cb78cc98
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 297 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,49 @@
// Import generic module functions
include { initOptions; saveFiles; getSoftwareName; getProcessName } from './functions'
params.options = [:]
options = initOptions(params.options)
process KHMER_NORMALIZEBYMEDIAN {
tag "${name}"
label 'process_long'
publishDir "${params.outdir}",
mode: params.publish_dir_mode,
saveAs: { filename -> saveFiles(filename:filename, options:params.options, publish_dir:getSoftwareName(task.process), meta:[:], publish_by_meta:[]) }
conda (params.enable_conda ? "bioconda::khmer=3.0.0a3" : null)
if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) {
container "https://depot.galaxyproject.org/singularity/khmer:3.0.0a3--py37haa7609a_2"
} else {
container "quay.io/biocontainers/khmer:3.0.0a3--py37haa7609a_2"
}
input:
path pe_reads
path se_reads
val name
output:
path "${name}.fastq.gz", emit: reads
path "versions.yml" , emit: versions
script:
pe_args = pe_reads ? "--paired" : ""
se_args = se_reads ? "--unpaired-reads ${se_reads}" : ""
files = pe_reads ? pe_reads : se_reads
"""
normalize-by-median.py \\
-M ${task.memory.toGiga()}e9 \\
--gzip ${options.args} \\
-o ${name}.fastq.gz \\
${pe_args} \\
${se_args} \\
${files}
cat <<-END_VERSIONS > versions.yml
${getProcessName(task.process)}:
${getSoftwareName(task.process)}: \$( normalize-by-median.py --version 2>&1 | grep ^khmer | sed 's/^khmer //' )
END_VERSIONS
"""
}

View file

@ -0,0 +1,39 @@
name: khmer_normalizebymedian
description: Module that calls normalize-by-median.py from khmer. The module can take a mix of paired end (interleaved) and single end reads. If both types are provided, only a single file with single ends is possible.
keywords:
- digital normalization
- khmer
tools:
- khmer:
description: khmer k-mer counting library
homepage: https://github.com/dib-lab/khmer
documentation: https://khmer.readthedocs.io/en/latest/
tool_dev_url: https://github.com/dib-lab/khmer
doi: "https://doi.org/10.12688/f1000research.6924.1"
licence: ['BSD License']
input:
- pe_reads:
type: files
description: Paired-end interleaved fastq files
pattern: "*.{fq,fastq}.gz"
- se_reads:
type: files
description: Single-end fastq files
pattern: "*.{fq,fastq}.gz"
- name:
type: string
description: filename for output file(s); ".fastq.gz" will be appended
output:
- versions:
type: file
description: File containing software versions
pattern: "versions.yml"
- reads:
type: file
description: Interleaved fastq files
pattern: "*.{fq,fastq}.gz"
authors:
- "@erikrikarddaniel"

View file

@ -629,6 +629,10 @@ kallistobustools/ref:
- modules/kallistobustools/ref/**
- tests/modules/kallistobustools/ref/**
khmer/normalizebymedian:
- modules/khmer/normalizebymedian/**
- tests/modules/khmer/normalizebymedian/**
kleborate:
- modules/kleborate/**
- tests/modules/kleborate/**

View file

@ -0,0 +1,85 @@
#!/usr/bin/env nextflow
nextflow.enable.dsl = 2
include { SEQTK_MERGEPE } from '../../../../modules/seqtk/mergepe/main.nf' addParams( options: [:] )
include { KHMER_NORMALIZEBYMEDIAN } from '../../../../modules/khmer/normalizebymedian/main.nf' addParams( options: [:] )
include { KHMER_NORMALIZEBYMEDIAN as KHMER_NORMALIZEBYMEDIAN_ARGS } from '../../../../modules/khmer/normalizebymedian/main.nf' addParams( options: [args: '-C 20 -k 32'] )
workflow test_khmer_normalizebymedian_only_pe {
pe_reads = [
[ id:'khmer_test', single_end:false ], // meta map
[
file(params.test_data['sarscov2']['illumina']['test_1_fastq_gz'], checkIfExists: true),
file(params.test_data['sarscov2']['illumina']['test_2_fastq_gz'], checkIfExists: true)
]
]
SEQTK_MERGEPE(pe_reads)
KHMER_NORMALIZEBYMEDIAN ( SEQTK_MERGEPE.out.reads.collect { it[1] }, [], 'only_pe' )
}
workflow test_khmer_normalizebymedian_only_se {
se_reads = [
file(params.test_data['sarscov2']['illumina']['test_1_fastq_gz'], checkIfExists: true),
file(params.test_data['sarscov2']['illumina']['test_2_fastq_gz'], checkIfExists: true)
]
KHMER_NORMALIZEBYMEDIAN ( [], se_reads, 'only_se' )
}
workflow test_khmer_normalizebymedian_mixed {
pe_reads = [
[ id:'khmer_test', single_end:false ], // meta map
[
file(params.test_data['sarscov2']['illumina']['test_1_fastq_gz'], checkIfExists: true),
file(params.test_data['sarscov2']['illumina']['test_2_fastq_gz'], checkIfExists: true)
]
]
se_reads = file(params.test_data['sarscov2']['illumina']['test_1_fastq_gz'], checkIfExists: true)
SEQTK_MERGEPE(pe_reads)
KHMER_NORMALIZEBYMEDIAN ( SEQTK_MERGEPE.out.reads.map { it[1] }, se_reads, 'mixed' )
}
workflow test_khmer_normalizebymedian_multiple_pe {
pe_reads = [
[ id:'khmer_test0', single_end:false ], // meta map
[
file(params.test_data['sarscov2']['illumina']['test_1_fastq_gz'], checkIfExists: true),
file(params.test_data['sarscov2']['illumina']['test_2_fastq_gz'], checkIfExists: true)
],
[ id:'khmer_test1', single_end:false ], // meta map
[
file(params.test_data['sarscov2']['illumina']['test_1_fastq_gz'], checkIfExists: true),
file(params.test_data['sarscov2']['illumina']['test_2_fastq_gz'], checkIfExists: true)
]
]
se_reads = file(params.test_data['sarscov2']['illumina']['test_1_fastq_gz'], checkIfExists: true)
SEQTK_MERGEPE(pe_reads)
KHMER_NORMALIZEBYMEDIAN ( SEQTK_MERGEPE.out.reads.collect { it[1] }, se_reads, 'multiple_pe' )
}
workflow test_khmer_normalizebymedian_args {
pe_reads = [
[ id:'khmer_test0', single_end:false ], // meta map
[
file(params.test_data['sarscov2']['illumina']['test_1_fastq_gz'], checkIfExists: true),
file(params.test_data['sarscov2']['illumina']['test_2_fastq_gz'], checkIfExists: true)
]
]
se_reads = file(params.test_data['sarscov2']['illumina']['test_1_fastq_gz'], checkIfExists: true)
SEQTK_MERGEPE(pe_reads)
KHMER_NORMALIZEBYMEDIAN_ARGS ( SEQTK_MERGEPE.out.reads.collect { it[1] }, se_reads, 'args' )
}

View file

@ -0,0 +1,42 @@
# nf-core modules create-test-yml khmer/normalizebymedian
- name: khmer normalizebymedian only pe reads
command: nextflow run ./tests/modules/khmer/normalizebymedian -entry test_khmer_normalizebymedian_only_pe -c tests/config/nextflow.config
tags:
- khmer
- khmer/normalizebymedian
files:
- path: output/khmer/only_pe.fastq.gz
# md5sum not stable even locally with docker (gzip done by tool)
#md5sum: 75e05f2e80cf4bd0b534d4b73f7c059c
- name: khmer normalizebymedian only se reads
command: nextflow run ./tests/modules/khmer/normalizebymedian -entry test_khmer_normalizebymedian_only_se -c tests/config/nextflow.config
tags:
- khmer
- khmer/normalizebymedian
files:
- path: output/khmer/only_se.fastq.gz
- name: khmer normalizebymedian mixed reads
command: nextflow run ./tests/modules/khmer/normalizebymedian -entry test_khmer_normalizebymedian_mixed -c tests/config/nextflow.config
tags:
- khmer
- khmer/normalizebymedian
files:
- path: output/khmer/mixed.fastq.gz
- name: khmer normalizebymedian multiple pe reads
command: nextflow run ./tests/modules/khmer/normalizebymedian -entry test_khmer_normalizebymedian_multiple_pe -c tests/config/nextflow.config
tags:
- khmer
- khmer/normalizebymedian
files:
- path: output/khmer/multiple_pe.fastq.gz
- name: khmer normalizebymedian args
command: nextflow run ./tests/modules/khmer/normalizebymedian -entry test_khmer_normalizebymedian_args -c tests/config/nextflow.config
tags:
- khmer
- khmer/normalizebymedian
files:
- path: output/khmer/args.fastq.gz