mirror of
https://github.com/MillironX/nf-core_modules.git
synced 2024-11-10 20:23:10 +00:00
add csvtk/concat module (#785)
* add csvtk/concat module * Update modules/csvtk/concat/main.nf Co-authored-by: Gregor Sturm <mail@gregor-sturm.de> * allow alternate delimiters * Update main.nf * Update modules/csvtk/concat/main.nf Co-authored-by: Harshil Patel <drpatelh@users.noreply.github.com> * Update modules/csvtk/concat/main.nf Co-authored-by: Harshil Patel <drpatelh@users.noreply.github.com> * Update modules/csvtk/concat/main.nf Co-authored-by: Harshil Patel <drpatelh@users.noreply.github.com> * Update modules/csvtk/concat/main.nf Co-authored-by: Harshil Patel <drpatelh@users.noreply.github.com> * Update modules/csvtk/concat/main.nf * Apply suggestions from code review Co-authored-by: Gregor Sturm <mail@gregor-sturm.de> Co-authored-by: Harshil Patel <drpatelh@users.noreply.github.com>
This commit is contained in:
parent
bb7beff497
commit
8179bab819
6 changed files with 210 additions and 0 deletions
78
modules/csvtk/concat/functions.nf
Normal file
78
modules/csvtk/concat/functions.nf
Normal 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"
|
||||
}
|
||||
}
|
49
modules/csvtk/concat/main.nf
Normal file
49
modules/csvtk/concat/main.nf
Normal file
|
@ -0,0 +1,49 @@
|
|||
// Import generic module functions
|
||||
include { initOptions; saveFiles; getSoftwareName; getProcessName } from './functions'
|
||||
|
||||
params.options = [:]
|
||||
options = initOptions(params.options)
|
||||
|
||||
process CSVTK_CONCAT {
|
||||
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::csvtk=0.23.0" : null)
|
||||
if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) {
|
||||
container "https://depot.galaxyproject.org/singularity/csvtk:0.23.0--h9ee0642_0"
|
||||
} else {
|
||||
container "quay.io/biocontainers/csvtk:0.23.0--h9ee0642_0"
|
||||
}
|
||||
|
||||
input:
|
||||
tuple val(meta), path(csv)
|
||||
val in_format
|
||||
val out_format
|
||||
|
||||
output:
|
||||
tuple val(meta), path("*.${out_format}"), emit: csv
|
||||
path "versions.yml" , emit: versions
|
||||
|
||||
script:
|
||||
def prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}"
|
||||
def delimiter = in_format == "tsv" ? "\t" : (in_format == "csv" ? "," : in_format)
|
||||
def out_delimiter = out_format == "tsv" ? "\t" : (out_format == "csv" ? "," : out_format)
|
||||
"""
|
||||
csvtk \\
|
||||
concat \\
|
||||
$options.args \\
|
||||
--num-cpus $task.cpus \\
|
||||
--delimiter "${delimiter}" \\
|
||||
--out-delimiter "${out_delimiter}" \\
|
||||
--out-file ${prefix}.${out_format} \\
|
||||
$csv
|
||||
|
||||
cat <<-END_VERSIONS > versions.yml
|
||||
${getProcessName(task.process)}:
|
||||
csvtk: \$(echo \$( csvtk version | sed -e "s/csvtk v//g" ))
|
||||
END_VERSIONS
|
||||
"""
|
||||
}
|
51
modules/csvtk/concat/meta.yml
Normal file
51
modules/csvtk/concat/meta.yml
Normal file
|
@ -0,0 +1,51 @@
|
|||
name: csvtk_concat
|
||||
description: Concatenate two or more CSV (or TSV) tables into a single table
|
||||
keywords:
|
||||
- concatenate
|
||||
- tsv
|
||||
- csv
|
||||
tools:
|
||||
- csvtk:
|
||||
description: A cross-platform, efficient, practical CSV/TSV toolkit
|
||||
homepage: http://bioinf.shenwei.me/csvtk
|
||||
documentation: http://bioinf.shenwei.me/csvtk
|
||||
tool_dev_url: https://github.com/shenwei356/csvtk
|
||||
doi: ""
|
||||
licence: ['MIT']
|
||||
|
||||
input:
|
||||
- meta:
|
||||
type: map
|
||||
description: |
|
||||
Groovy Map containing sample information
|
||||
e.g. [ id:'test', single_end:false ]
|
||||
- csv:
|
||||
type: file
|
||||
description: CSV/TSV formatted files
|
||||
pattern: "*.{csv,tsv}"
|
||||
- in_format:
|
||||
type: string
|
||||
description: Input format (csv, tab, or a delimiting character)
|
||||
pattern: "*"
|
||||
- out_format:
|
||||
type: string
|
||||
description: Output format (csv, tab, or a delimiting character)
|
||||
pattern: "*"
|
||||
|
||||
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: "version.yml"
|
||||
- csv:
|
||||
type: file
|
||||
description: Concatenated CSV/TSV file
|
||||
pattern: "*.{csv,tsv}"
|
||||
|
||||
authors:
|
||||
- "@rpetit3"
|
|
@ -266,6 +266,10 @@ cooler/dump:
|
|||
- modules/cooler/dump/**
|
||||
- tests/modules/cooler/dump/**
|
||||
|
||||
csvtk/concat:
|
||||
- modules/csvtk/concat/**
|
||||
- tests/modules/csvtk/concat/**
|
||||
|
||||
custom/dumpsoftwareversions:
|
||||
- modules/custom/dumpsoftwareversions/**
|
||||
- tests/modules/custom/dumpsoftwareversions/**
|
||||
|
|
20
tests/modules/csvtk/concat/main.nf
Normal file
20
tests/modules/csvtk/concat/main.nf
Normal file
|
@ -0,0 +1,20 @@
|
|||
#!/usr/bin/env nextflow
|
||||
|
||||
nextflow.enable.dsl = 2
|
||||
|
||||
include { CSVTK_CONCAT } from '../../../../modules/csvtk/concat/main.nf' addParams( options: [:] )
|
||||
|
||||
workflow test_csvtk_concat {
|
||||
|
||||
input = [
|
||||
[ id:'test' ], // meta map
|
||||
[ file("https://github.com/nf-core/test-datasets/raw/bacass/bacass_hybrid.csv", checkIfExists: true),
|
||||
file("https://github.com/nf-core/test-datasets/raw/bacass/bacass_long.csv", checkIfExists: true),
|
||||
file("https://github.com/nf-core/test-datasets/raw/bacass/bacass_short.csv", checkIfExists: true) ]
|
||||
]
|
||||
|
||||
in_format = "tsv"
|
||||
out_format = "csv"
|
||||
|
||||
CSVTK_CONCAT ( input, in_format, out_format )
|
||||
}
|
8
tests/modules/csvtk/concat/test.yml
Normal file
8
tests/modules/csvtk/concat/test.yml
Normal file
|
@ -0,0 +1,8 @@
|
|||
- name: csvtk concat
|
||||
command: nextflow run ./tests/modules/csvtk/concat -entry test_csvtk_concat -c tests/config/nextflow.config
|
||||
tags:
|
||||
- csvtk
|
||||
- csvtk/concat
|
||||
files:
|
||||
- path: output/csvtk/test.csv
|
||||
md5sum: 917fe5d857f04b58e0f49c384d167cec
|
Loading…
Reference in a new issue