add paraclu (#909)

* add paraclu

* remove TODOs

* add min_cluster as input parameter, remove option parameters

* add tool_dev_url
This commit is contained in:
Matthias Hörtenhuber 2021-10-27 15:48:49 +02:00 committed by GitHub
parent f47c27edfb
commit b552958341
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 194 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"
}
}

45
modules/paraclu/main.nf Normal file
View file

@ -0,0 +1,45 @@
// Import generic module functions
include { initOptions; saveFiles; getSoftwareName; getProcessName } from './functions'
params.options = [:]
options = initOptions(params.options)
process PARACLU {
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::paraclu=10" : null)
if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) {
container "https://depot.galaxyproject.org/singularity/paraclu%3A10--h9a82719_1"
} else {
container "quay.io/biocontainers/paraclu:10--h9a82719_1"
}
input:
tuple val(meta), path(bed)
val(min_cluster)
output:
tuple val(meta), path("*.bed"), emit: bed
path "versions.yml" , emit: versions
script:
def prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}"
def VERSION=10
"""
awk -F "\t" '{print\$1"\t"\$6"\t"\$2"\t"\$5}' < $bed > ${bed}_4P
sort -k1,1 -k3n ${bed}_4P > ${bed}_4Ps
paraclu $min_cluster ${bed}_4Ps > ${prefix}.clustered
paraclu-cut ${prefix}.clustered > ${prefix}.clustered.simplified
awk -F '\t' '{print \$1"\t"\$3"\t"\$4"\t"\$1":"\$3".."\$4","\$2"\t"\$6"\t"\$2}' ${prefix}.clustered.simplified > ${prefix}.clustered.simplified.bed
cat <<-END_VERSIONS > versions.yml
${getProcessName(task.process)}:
${getSoftwareName(task.process)}: $VERSION
END_VERSIONS
"""
}

45
modules/paraclu/meta.yml Normal file
View file

@ -0,0 +1,45 @@
name: paraclu
description: Paraclu finds clusters in data attached to sequences.
keywords:
- sort
tools:
- paraclu:
description: Paraclu finds clusters in data attached to sequences.
homepage: https://gitlab.com/mcfrith/paraclu
documentation: https://gitlab.com/mcfrith/paraclu
tool_dev_url: https://gitlab.com/mcfrith/paraclu
doi: ""
licence: ['GPL v3-or-later']
input:
- meta:
type: map
description: |
Groovy Map containing sample information
e.g. [ id:'test', single_end:false ]
- bed:
type: file
description: BED file
pattern: "*.bed"
- min_cluster:
type: integer
description: Minimum size of cluster
pattern: "*.bed"
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"
- bed:
type: file
description: clustered BED file
pattern: "*.bed"
authors:
- "@mashehu"

View file

@ -791,6 +791,10 @@ pangolin:
- modules/pangolin/** - modules/pangolin/**
- tests/modules/pangolin/** - tests/modules/pangolin/**
paraclu:
- modules/paraclu/**
- tests/modules/paraclu/**
pbbam/pbmerge: pbbam/pbmerge:
- modules/pbbam/pbmerge/** - modules/pbbam/pbmerge/**
- tests/modules/pbbam/pbmerge/** - tests/modules/pbbam/pbmerge/**

View file

@ -0,0 +1,15 @@
#!/usr/bin/env nextflow
nextflow.enable.dsl = 2
include { PARACLU } from '../../../modules/paraclu/main.nf' addParams( options: [:] )
workflow test_paraclu {
input = [[ id:'test' ], // meta map
file(params.test_data['sarscov2']['genome']['test_bed'], checkIfExists: true)
]
min_cluster = 30
PARACLU ( input, min_cluster )
}

View file

@ -0,0 +1,7 @@
- name: paraclu test_paraclu
command: nextflow run tests/modules/paraclu -entry test_paraclu -c tests/config/nextflow.config
tags:
- paraclu
files:
- path: output/paraclu/test.clustered.simplified.bed
md5sum: d41d8cd98f00b204e9800998ecf8427e