New module seqtk/mergepe (#951)

* First step into creating a seqtk/mergepe module to interleave fastQ input

* First rewrite of main.nf to make the module perform the desired (interleave/merge of pe reads) task

* Modifications to test the new seqtk/mergepe module.

* Improving the seqtk/mergepe module to output single end reads as well, and making sure tests work

* Modified so that gzip uses -n and that single read entries are symlinked with ln -s instead of copied, therefore updated test.yml as well.

* Fix trailing whitespaces

Co-authored-by: Daniel Lundin <daniel.lundin@lnu.se>
This commit is contained in:
emnilsson 2021-10-28 16:53:33 +02:00 committed by GitHub
parent fd1189c2f5
commit 9402595711
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 223 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,53 @@
// Import generic module functions
include { initOptions; saveFiles; getSoftwareName; getProcessName } from './functions'
params.options = [:]
options = initOptions(params.options)
process SEQTK_MERGEPE {
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::seqtk=1.3" : null)
if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) {
container "https://depot.galaxyproject.org/singularity/seqtk:1.3--h5bf99c6_3"
} else {
container "quay.io/biocontainers/seqtk:1.3--h5bf99c6_3"
}
input:
tuple val(meta), path(reads)
output:
tuple val(meta), path("*.fastq.gz"), emit: reads
path "versions.yml" , emit: versions
script:
def prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}"
if (meta.single_end) {
"""
ln -s ${reads} ${prefix}.fastq.gz
cat <<-END_VERSIONS > versions.yml
${getProcessName(task.process)}:
${getSoftwareName(task.process)}: \$(echo \$(seqtk 2>&1) | sed 's/^.*Version: //; s/ .*\$//')
END_VERSIONS
"""
} else {
"""
seqtk \\
mergepe \\
$options.args \\
${reads} \\
| gzip -n >> ${prefix}.fastq.gz
cat <<-END_VERSIONS > versions.yml
${getProcessName(task.process)}:
${getSoftwareName(task.process)}: \$(echo \$(seqtk 2>&1) | sed 's/^.*Version: //; s/ .*\$//')
END_VERSIONS
"""
}
}

View file

@ -0,0 +1,40 @@
name: seqtk_mergepe
description: Interleave pair-end reads from FastQ files
keywords:
- interleave
tools:
- seqtk:
description: Seqtk is a fast and lightweight tool for processing sequences in the FASTA or FASTQ format. Seqtk mergepe command merges pair-end reads into one interleaved file.
homepage: https://github.com/lh3/seqtk
documentation: https://docs.csc.fi/apps/seqtk/
tool_dev_url: https://github.com/lh3/seqtk
licence: ['MIT']
input:
- meta:
type: map
description: |
Groovy Map containing sample information
e.g. [ id:'test', single_end:false ]
- reads:
type: file
description: List of input FastQ files of size 1 and 2 for single-end and paired-end data,respectively.
pattern: "*.{fastq.gz}"
output:
- meta:
type: map
description: |
Groovy Map containing sample information
e.g. [ id:'test', single_end:false ]
- versions:
type: file
description: File containing software versions
pattern: "versions.yml"
- reads:
type: file
description: If single-end reads, the output is the same as the input, 1 FastQ file for each read. If pair-end reads, the read pairs will be interleaved and output as 1 FastQ file for each read pair.
pattern: "*.{fastq.gz}"
authors:
- "@emnilsson"

View file

@ -1023,6 +1023,10 @@ seacr/callpeak:
- modules/seacr/callpeak/** - modules/seacr/callpeak/**
- tests/modules/seacr/callpeak/** - tests/modules/seacr/callpeak/**
seqtk/mergepe:
- modules/seqtk/mergepe/**
- tests/modules/seqtk/mergepe/**
seqkit/split2: seqkit/split2:
- modules/seqkit/split2/** - modules/seqkit/split2/**
- tests/modules/seqkit/split2/** - tests/modules/seqkit/split2/**

View file

@ -0,0 +1,31 @@
#!/usr/bin/env nextflow
nextflow.enable.dsl = 2
include { SEQTK_MERGEPE } from '../../../../modules/seqtk/mergepe/main.nf' addParams( options: [ 'suffix':'.processed' ] )
//
// Test with single-end data
//
workflow test_seqtk_mergepe_single_end {
input = [ [ id:'test', single_end:true ], // meta map
file(params.test_data['sarscov2']['illumina']['test_1_fastq_gz'], checkIfExists: true) ]
SEQTK_MERGEPE ( input )
}
//
// Test with paired-end data
//
workflow test_seqtk_mergepe_paired_end {
input = [ [ id:'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 ( input )
}

View file

@ -0,0 +1,17 @@
- name: seqtk mergepe test_seqtk_mergepe_single_end
command: nextflow run tests/modules/seqtk/mergepe -entry test_seqtk_mergepe_single_end -c tests/config/nextflow.config
tags:
- seqtk/mergepe
- seqtk
files:
- path: output/seqtk/test.processed.fastq.gz
md5sum: e325ef7deb4023447a1f074e285761af
- name: seqtk mergepe test_seqtk_mergepe_paired_end
command: nextflow run tests/modules/seqtk/mergepe -entry test_seqtk_mergepe_paired_end -c tests/config/nextflow.config
tags:
- seqtk/mergepe
- seqtk
files:
- path: output/seqtk/test.processed.fastq.gz
md5sum: 3f094ef62d9bfe06aa25174a06bc7d04