Add Miniasm module (#962)

* add racon

* add miniasm module

* edit miniasm module

* edit miniasm module

* Update tests/modules/racon/main.nf

Co-authored-by: Daniel Straub <42973691+d4straub@users.noreply.github.com>

* Update tests/modules/racon/test.yml

Co-authored-by: Daniel Straub <42973691+d4straub@users.noreply.github.com>

* Update modules/miniasm/meta.yml

Co-authored-by: Daniel Straub <42973691+d4straub@users.noreply.github.com>

* Update main.nf

Add some spaces.

* Update meta.yml

Correct DOI

* Update main.nf

* Apply suggestions from code review

* Update tests/modules/miniasm/test.yml

Co-authored-by: Daniel Straub <42973691+d4straub@users.noreply.github.com>
Co-authored-by: Sébastien Guizard <sguizard@ed.ac.uk>
Co-authored-by: Harshil Patel <drpatelh@users.noreply.github.com>
This commit is contained in:
avantonder 2021-11-15 17:50:56 +00:00 committed by GitHub
parent 466b964b37
commit 527ccdb419
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 205 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"
}
}

48
modules/miniasm/main.nf Normal file
View file

@ -0,0 +1,48 @@
// Import generic module functions
include { initOptions; saveFiles; getSoftwareName; getProcessName } from './functions'
params.options = [:]
options = initOptions(params.options)
process MINIASM {
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), meta:meta, publish_by_meta:['id']) }
conda (params.enable_conda ? "bioconda::miniasm=0.3_r179" : null)
if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) {
container "https://depot.galaxyproject.org/singularity/miniasm:0.3_r179--h5bf99c6_2"
} else {
container "quay.io/biocontainers/miniasm:0.3_r179--h5bf99c6_2"
}
input:
tuple val(meta), path(reads), path(paf)
output:
tuple val(meta), path("*.gfa.gz") , emit: gfa
tuple val(meta), path("*.fasta.gz"), emit: assembly
path "versions.yml" , emit: versions
script:
def prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}"
"""
miniasm \\
$options.args \\
-f $reads \\
$paf > \\
${prefix}.gfa
awk '/^S/{print ">"\$2"\\n"\$3}' "${prefix}.gfa" | fold > ${prefix}.fasta
gzip -n ${prefix}.gfa
gzip -n ${prefix}.fasta
cat <<-END_VERSIONS > versions.yml
${getProcessName(task.process)}:
${getSoftwareName(task.process)}: \$( miniasm -V 2>&1 )
END_VERSIONS
"""
}

51
modules/miniasm/meta.yml Normal file
View file

@ -0,0 +1,51 @@
name: miniasm
description: A very fast OLC-based de novo assembler for noisy long reads
keywords:
- assembly
- pacbio
- nanopore
tools:
- miniasm:
description: Ultrafast de novo assembly for long noisy reads (though having no consensus step)
homepage: https://github.com/lh3/miniasm
documentation: https://github.com/lh3/miniasm
tool_dev_url: https://github.com/lh3/miniasm
doi: "10.1093/bioinformatics/btw152"
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 PacBio/ONT FastQ files.
pattern: "*.{fastq,fastq.gz,fq,fq.gz}"
- paf:
type: file
description: Alignment in PAF format
pattern: "*{.paf,.paf.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"
- gfa:
type: file
description: Assembly graph
pattern: "*.gfa.gz"
- assembly:
type: file
description: Genome assembly
pattern: "*.fasta.gz"
authors:
- "@avantonder"

View file

@ -862,6 +862,10 @@ minia:
- modules/minia/** - modules/minia/**
- tests/modules/minia/** - tests/modules/minia/**
miniasm:
- modules/miniasm/**
- tests/modules/miniasm/**
minimap2/align: minimap2/align:
- modules/minimap2/align/** - modules/minimap2/align/**
- tests/modules/minimap2/align/** - tests/modules/minimap2/align/**

View file

@ -0,0 +1,15 @@
#!/usr/bin/env nextflow
nextflow.enable.dsl = 2
include { MINIASM } from '../../../modules/miniasm/main.nf' addParams( options: [suffix:'.assembly'] )
workflow test_miniasm {
input = [ [ id:'test', single_end:true ], // meta map
file(params.test_data['bacteroides_fragilis']['nanopore']['test_fastq_gz'], checkIfExists: true),
file(params.test_data['bacteroides_fragilis']['nanopore']['overlap_paf'], checkIfExists: true)
]
MINIASM ( input )
}

View file

@ -0,0 +1,9 @@
- name: miniasm test_miniasm
command: nextflow run tests/modules/miniasm -entry test_miniasm -c tests/config/nextflow.config
tags:
- miniasm
files:
- path: output/miniasm/test.assembly.gfa.gz
md5sum: c68e4c2b64338d1c0f5b79b32934da14
- path: output/miniasm/test.assembly.fasta.gz
md5sum: d2f78ae618c02744e7a57bf4706ab8b4