new module: rasusa (#413)

* new module: rasusa

* Removed blank line in software/rasusa/main

* updated code as per reviewcomments

* removed blank line as failed for lint

* updated as per review comments

* Apply suggestions from code review

Co-authored-by: Harshil Patel <drpatelh@users.noreply.github.com>
This commit is contained in:
Thanh Lee 2021-04-09 13:10:32 +01:00 committed by GitHub
parent ca776e76a2
commit 5a59e61052
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 182 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"
}
}
}

43
software/rasusa/main.nf Normal file
View file

@ -0,0 +1,43 @@
// Import generic module functions
include { initOptions; saveFiles; getSoftwareName } from './functions'
params.options = [:]
options = initOptions(params.options)
process RASUSA {
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), publish_id:meta.id) }
conda (params.enable_conda ? "bioconda::rasusa=0.3.0" : null)
if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) {
container "https://depot.galaxyproject.org/singularity/rasusa:0.3.0--h779adbc_1"
} else {
container "quay.io/biocontainers/rasusa:0.3.0--h779adbc_1"
}
input:
tuple val(meta), path(reads)
val depth_cutoff
val genome_size
output:
tuple val(meta), path('*.fastq.gz'), emit: reads
path '*.version.txt' , emit: version
script:
def software = getSoftwareName(task.process)
def prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}"
def output = meta.single_end ? "--output ${prefix}.fastq.gz" : "--output ${prefix}_1.fastq.gz ${prefix}_2.fastq.gz"
"""
rasusa \\
$options.args \\
--coverage $depth_cutoff \\
--genome-size $genome_size \\
--input $reads \\
$output
echo \$(rasusa --version 2>&1) | sed -e "s/rasusa //g" > ${software}.version.txt
"""
}

48
software/rasusa/meta.yml Normal file
View file

@ -0,0 +1,48 @@
name: rasusa
description: Randomly subsample sequencing reads to a specified coverage
keywords:
- coverage
- depth
- subsampling
tools:
- rasusa:
description: Randomly subsample sequencing reads to a specified coverage
homepage: https://github.com/mbhall88/rasusa
documentation: https://github.com/mbhall88/rasusa/blob/master/README.md
tool_dev_url: https://github.com/mbhall88/rasusa
doi: "10.5281/zenodo.3731394"
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 paired-end FastQ files
- depth_cutoff:
type: integer
description: Depth of coverage cutoff
- genome_size:
type: string
description: Genome size of the species
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}"
- reads:
type: file
description: Reads with subsampled coverage
pattern: "*.fastq.gz"
authors:
- "@thanhleviet"

View file

@ -386,6 +386,10 @@ quast:
- software/quast/**
- tests/software/quast/**
rasusa:
- software/rasusa/**
- tests/software/rasusa/**
rapidnj:
- software/rapidnj/**
- tests/software/rapidnj/**

View file

@ -0,0 +1,18 @@
#!/usr/bin/env nextflow
nextflow.enable.dsl = 2
include { RASUSA } from '../../../software/rasusa/main.nf' addParams( options: ['suffix':'_100X'])
workflow test_rasusa {
input = [ [ id:'test', single_end:false], // meta map
[ file(params.test_data['sarscov2']['illumina']['test_1_fastq_gz'], checkIfExists: true),
file(params.test_data['sarscov2']['illumina']['test_2_fastq_gz'], checkIfExists: true)
]
]
depth_cutoff = 100
genome_size = "1000000b"
RASUSA ( input, depth_cutoff, genome_size )
}

View file

@ -0,0 +1,9 @@
- name: rasusa test_rasusa
command: nextflow run tests/software/rasusa -entry test_rasusa -c tests/config/nextflow.config
tags:
- rasusa
files:
- path: output/rasusa/test_100X_1.fastq.gz
md5sum: b9d6f0bef1ef0c21576330d882a7edbb
- path: output/rasusa/test_100X_2.fastq.gz
md5sum: 479bc4cdce2511a9af219e6c39db8d30