module fastani (#695)

* initiate agrvate module

* remove todos [ci skip]

* initiate fastani draft [ci skip]

* clean stubs [ci skip]

* interim commit [ci skip]

* accomodate the batch/per-sample processing [ci skip]

* use the meta map [ci skip]

* run first test [ci skip]

* remove extra spaces [ci skip]

* change output file name [ci skip]

* update the expected output [ci skip]

* update the files used for test [ci skip]

* fix typo [ci skip]

* test passing [ci skip]

* update the description

* remove extra files

* accomodate CR suggestions [ci skip]

Co-authored-by: Harshil Patel <drpatelh@users.noreply.github.com>

* accomodate CR suggestions [ci skip]

Co-authored-by: Harshil Patel <drpatelh@users.noreply.github.com>

* accomodate CR suggestions [ci skip]

Co-authored-by: Harshil Patel <drpatelh@users.noreply.github.com>

* use meta map for batch analysis

* fix the tests

* rely upon tuples

* Apply suggestions from code review

* Update main.nf

Co-authored-by: Harshil Patel <drpatelh@users.noreply.github.com>
This commit is contained in:
Abhinav Sharma 2021-09-21 21:20:26 +02:00 committed by GitHub
parent 7830a4a80c
commit 0d53a34eed
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 187 additions and 0 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"
}
}
}

52
modules/fastani/main.nf Normal file
View file

@ -0,0 +1,52 @@
// Import generic module functions
include { initOptions; saveFiles; getSoftwareName } from './functions'
params.options = [:]
options = initOptions(params.options)
process FASTANI {
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::fastani=1.32" : null)
if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) {
container "https://depot.galaxyproject.org/singularity/fastani:1.32--he1c1bb9_0"
} else {
container "quay.io/biocontainers/fastani:1.32--he1c1bb9_0"
}
input:
tuple val(meta), path(query)
path reference
output:
tuple val(meta), path("*.ani.txt"), emit: ani
path "*.version.txt" , emit: version
script:
def software = getSoftwareName(task.process)
def prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}"
if (meta.batch_input) {
"""
fastANI \\
-ql $query \\
-rl $reference \\
-o ${prefix}.ani.txt
echo \$(fastANI --version 2>&1) | sed 's/version//;' > ${software}.version.txt
"""
} else {
"""
fastANI \\
-q $query \\
-r $reference \\
-o ${prefix}.ani.txt
echo \$(fastANI --version 2>&1) | sed 's/version//;' > ${software}.version.txt
"""
}
}

43
modules/fastani/meta.yml Normal file
View file

@ -0,0 +1,43 @@
name: fastani
description: write your description here
keywords:
- fastani
tools:
- fastani:
description: FastANI is developed for fast alignment-free computation of whole-genome Average Nucleotide Identity (ANI).
homepage: https://github.com/ParBLiSS/FastANI
documentation: https://github.com/ParBLiSS/FastANI
tool_dev_url: https://github.com/ParBLiSS/FastANI
doi: 10.1038/s41467-018-07641-9
licence: ['Apache-2.0']
input:
- meta:
type: map
description: |
Groovy Map containing sample information
e.g. [ id:'test', single_end:false ]
- query:
type: file
description: Fasta file(s) to be queried
pattern: "*.fasta"
- reference:
type: file
description: Fasta file(s) to be used as reference for the query
pattern: "*.fasta"
output:
- meta:
type: map
description: |
Groovy Map containing sample information
e.g. [ id:'test', single_end:false ]
- ani:
type: file
description: Results of the query
pattern: "*.ani.txt"
- version:
type: file
description: File containing software version
pattern: "*.{version.txt}"
authors:
- "@abhi18av"

View file

@ -318,6 +318,10 @@ expansionhunter:
- modules/expansionhunter/** - modules/expansionhunter/**
- tests/modules/expansionhunter/** - tests/modules/expansionhunter/**
fastani:
- modules/fastani/**
- tests/modules/fastani/**
fastp: fastp:
- modules/fastp/** - modules/fastp/**
- tests/modules/fastp/** - tests/modules/fastp/**

View file

@ -0,0 +1,13 @@
#!/usr/bin/env nextflow
nextflow.enable.dsl = 2
include { FASTANI } from '../../../modules/fastani/main.nf' addParams( options: [:] )
workflow test_fastani {
query = file(params.test_data['sarscov2']['genome']['genome_fasta'], checkIfExists: true)
reference = file(params.test_data['sarscov2']['illumina']['contigs_fasta'], checkIfExists: true)
FASTANI ( [[ id:'test' ], query], reference )
}

View file

@ -0,0 +1,7 @@
- name: fastani
command: nextflow run ./tests/modules/fastani -entry test_fastani -c tests/config/nextflow.config
tags:
- fastani
files:
- path: output/fastani/test.ani.txt
md5sum: 31d4f04e8cffe13080c86db3f9f3a589