Add dsh-bio export-segments module (#631)

Co-authored-by: Gregor Sturm <mail@gregor-sturm.de>
This commit is contained in:
Michael L Heuer 2021-08-17 08:53:41 -05:00 committed by GitHub
parent 6c633ef305
commit bc7b5b3a12
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 174 additions and 1 deletions

View file

@ -0,0 +1,68 @@
//
// 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()
}
//
// 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) {
if (!args.filename.endsWith('.version.txt')) {
def ioptions = initOptions(args.options)
def path_list = [ ioptions.publish_dir ?: args.publish_dir ]
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,40 @@
// Import generic module functions
include { initOptions; saveFiles; getSoftwareName } from './functions'
params.options = [:]
options = initOptions(params.options)
process DSHBIO_EXPORTSEGMENTS {
tag "${meta.id}"
label 'process_medium'
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::dsh-bio=2.0.5" : null)
if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) {
container "https://depot.galaxyproject.org/singularity/dsh-bio:2.0.5--hdfd78af_0"
} else {
container "quay.io/biocontainers/dsh-bio:2.0.5--hdfd78af_0"
}
input:
tuple val(meta), path(gfa)
output:
tuple val(meta), path("*.fa"), emit: fasta
path "*.version.txt" , emit: version
script:
def software = getSoftwareName(task.process)
def prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}"
"""
dsh-bio \\
export-segments \\
$options.args \\
-i $gfa \\
-o ${prefix}.fa
echo \$(dsh-bio --version 2>&1) | grep -o 'dsh-bio-tools .*' | cut -f2 -d ' ' > ${software}.version.txt
"""
}

View file

@ -0,0 +1,40 @@
name: dshbio_exportsegments
description: Export assembly segment sequences in GFA 1.0 format to FASTA format
keywords:
- gfa
- assembly
- segment
tools:
- dshbio:
description: |
Reads, features, variants, assemblies, alignments, genomic range trees, pangenome
graphs, and a bunch of random command line tools for bioinformatics. LGPL version 3
or later.
homepage: https://github.com/heuermh/dishevelled-bio
documentation: https://github.com/heuermh/dishevelled-bio
input:
- meta:
type: map
description: |
Groovy Map containing sample information
e.g. [ id:'test', single_end:false ]
- gfa:
type: file
description: Assembly segments in GFA 1.0 format
pattern: "*.{gfa}"
output:
- meta:
type: map
description: |
Groovy Map containing sample information
e.g. [ id:'test', single_end:false ]
- fasta:
type: file
description: Assembly segment sequences in FASTA format
pattern: "*.{fa}"
- version:
type: file
description: File containing software version
pattern: "*.{version.txt}"
authors:
- "@heuermh"

View file

@ -245,11 +245,15 @@ deeptools/plotprofile:
delly/call:
- modules/delly/call/**
- tests/modules/delly/call/**
dragonflye:
- modules/dragonflye/**
- tests/modules/dragonflye/**
dshbio/exportsegments:
- modules/dshbio/exportsegments/**
- tests/modules/dshbio/exportsegments/**
dshbio/filterbed:
- modules/dshbio/filterbed/**
- tests/modules/dshbio/filterbed/**

View file

@ -0,0 +1,13 @@
#!/usr/bin/env nextflow
nextflow.enable.dsl = 2
include { DSHBIO_EXPORTSEGMENTS } from '../../../../modules/dshbio/exportsegments/main.nf' addParams( options: [:] )
workflow test_dshbio_exportsegments {
input = [ [ id:'test' ], // meta map
[ file(params.test_data['sarscov2']['illumina']['assembly_gfa'], checkIfExists: true) ]
]
DSHBIO_EXPORTSEGMENTS ( input )
}

View file

@ -0,0 +1,8 @@
- name: dshbio exportsegments
command: nextflow run ./tests/modules/dshbio/exportsegments -entry test_dshbio_exportsegments -c tests/config/nextflow.config
tags:
- dshbio
- dshbio/exportsegments
files:
- path: ./output/dshbio/test.fa
md5sum: 19ed0b69970ed3fbb641c5c510ebef61