Adding unicycler module (#307)

* Adding unicycler module

* Do not forget to change default keywords on meta.yml
This commit is contained in:
Jose Espinosa-Carrasco 2021-03-22 18:14:24 +01:00 committed by GitHub
parent bed31cd9b4
commit cfa8f64c4f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 213 additions and 0 deletions

View file

@ -0,0 +1,60 @@
/*
* -----------------------------------------------------
* 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_id = args.publish_by_id ?: false
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_id) {
path_list.add(args.publish_id)
}
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,47 @@
// Import generic module functions
include { initOptions; saveFiles; getSoftwareName } from './functions'
params.options = [:]
options = initOptions(params.options)
process UNICYCLER {
tag "$meta.id"
label 'process_high'
publishDir "${params.outdir}",
mode: params.publish_dir_mode,
saveAs: { filename -> saveFiles(filename:filename, options:params.options, publish_dir:getSoftwareName(task.process), publish_id:meta.id) }
conda (params.enable_conda ? 'bioconda::unicycler=0.4.8' : null)
if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) {
container "https://depot.galaxyproject.org/singularity/unicycler:0.4.8--py38h8162308_3"
} else {
container "quay.io/biocontainers/unicycler:0.4.8--py38h8162308_3"
}
input:
tuple val(meta), path(reads)
output:
tuple val(meta), path('*.scaffolds.fa'), emit: scaffolds
tuple val(meta), path('*.assembly.gfa'), emit: gfa
tuple val(meta), path('*.log') , emit: log
path '*.version.txt' , emit: version
script:
def software = getSoftwareName(task.process)
def prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}"
def input_reads = meta.single_end ? "-s $reads" : "-1 ${reads[0]} -2 ${reads[1]}"
"""
unicycler \\
--threads $task.cpus \\
$options.args \\
$input_reads \\
--out ./
mv assembly.fasta ${prefix}.scaffolds.fa
mv assembly.gfa ${prefix}.assembly.gfa
mv unicycler.log ${prefix}.unicycler.log
echo \$(unicycler --version 2>&1) | sed 's/^.*Unicycler v//; s/ .*\$//' > ${software}.version.txt
"""
}

View file

@ -0,0 +1,55 @@
name: unicycler
description: Assembles bacterial genomes
keywords:
- genome
- assembly
- genome assembler
- small genome
tools:
- unicycler:
description: Hybrid assembly pipeline for bacterial genomes
homepage: https://github.com/rrwick/Unicycler
documentation: https://github.com/rrwick/Unicycler
tool_dev_url: https://github.com/rrwick/Unicycler
doi: 10.1371/journal.pcbi.1005595
licence: ['GPL v3']
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.
output:
- meta:
type: map
description: |
Groovy Map containing sample information
e.g. [ id:'test', single_end:false ]
- version:
type: file
description: File containing software version
pattern: "*.{version.txt}"
- scaffolds:
type: file
description: Fasta file containing scaffolds
pattern: "*.{scaffolds.fa}"
- gfa:
type: file
description: gfa file containing assembly
pattern: "*.{assembly.gfa}"
- log:
type: file
description: unicycler log file
pattern: "*.{log}"
- version:
type: file
description: File containing software version
pattern: "*.{version.txt}"
authors:
- "@JoseEspinosa"
- "@drpatelh"

View file

@ -372,6 +372,10 @@ ucsc_bedgraphtobigwig:
- software/ucsc/bedgraphtobigwig/**
- tests/software/ucsc/bedgraphtobigwig/**
unicycler:
- software/unicycler/**
- tests/software/unicycler/**
untar:
- software/untar/**
- tests/software/untar/**

View file

@ -0,0 +1,24 @@
#!/usr/bin/env nextflow
nextflow.enable.dsl = 2
include { UNICYCLER } from '../../../software/unicycler/main.nf' addParams( options: [:] )
workflow test_unicycler_single_end {
def input = []
input = [ [ id:'test', single_end:true ], // meta map
[ file("${launchDir}/tests/data/generic/fastq/test_R1.fastq.gz", checkIfExists: true) ] ]
UNICYCLER ( input )
}
workflow test_unicycler_paired_end {
def input = []
input = [ [ id:'test', single_end:false ], // meta map
[ file("${launchDir}/tests/data/generic/fastq/test_R1.fastq.gz", checkIfExists: true),
file("${launchDir}/tests/data/generic/fastq/test_R2.fastq.gz", checkIfExists: true) ] ]
UNICYCLER ( input )
}

View file

@ -0,0 +1,23 @@
- name: unicycler single-end
command: nextflow run ./tests/software/unicycler -entry test_unicycler_single_end -c tests/config/nextflow.config
tags:
- unicycler
- unicycler_single_end
files:
- path: output/unicycler/test.scaffolds.fa
- path: output/unicycler/test.assembly.gfa
- path: output/unicycler/test.unicycler.log
contains:
- "Assembly complete"
- name: unicycler paired-end
command: nextflow run ./tests/software/unicycler -entry test_unicycler_paired_end -c tests/config/nextflow.config
tags:
- unicycler
- unicycler_paired_end
files:
- path: output/unicycler/test.scaffolds.fa
- path: output/unicycler/test.assembly.gfa
- path: output/unicycler/test.unicycler.log
contains:
- "Assembly complete"