add ismapper module (#773)

* add ismapper module

* Update main.nf

* Update main.nf

* Update meta.yml

* Apply suggestions from code review

Co-authored-by: Harshil Patel <drpatelh@users.noreply.github.com>
This commit is contained in:
Robert A. Petit III 2021-10-05 14:55:41 -06:00 committed by GitHub
parent 8179bab819
commit 8d04c34934
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 221 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"
}
}

44
modules/ismapper/main.nf Normal file
View file

@ -0,0 +1,44 @@
// Import generic module functions
include { initOptions; saveFiles; getSoftwareName; getProcessName } from './functions'
params.options = [:]
options = initOptions(params.options)
process ISMAPPER {
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::ismapper=2.0.2" : null)
if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) {
container "https://depot.galaxyproject.org/singularity/ismapper:2.0.2--pyhdfd78af_1"
} else {
container "quay.io/biocontainers/ismapper:2.0.2--pyhdfd78af_1"
}
input:
tuple val(meta), path(reads), path(reference), path(query)
output:
tuple val(meta), path("results/*"), emit: results
path "versions.yml" , emit: versions
script:
def prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}"
"""
ismap \\
$options.args \\
--t $task.cpus \\
--output_dir results \\
--queries $query \\
--reference $reference \\
--reads $reads
cat <<-END_VERSIONS > versions.yml
${getProcessName(task.process)}:
${getSoftwareName(task.process)}: \$( echo \$( ismap --version 2>&1 ) | sed 's/^.*ismap //' )
END_VERSIONS
"""
}

50
modules/ismapper/meta.yml Normal file
View file

@ -0,0 +1,50 @@
name: ismapper
description: Identify insertion sites positions in bacterial genomes
keywords:
- fastq
- insertion sequences
tools:
- ismapper:
description: A mapping-based tool for identification of the site and orientation of IS insertions in bacterial genomes.
homepage: https://github.com/jhawkey/IS_mapper
documentation: https://github.com/jhawkey/IS_mapper
tool_dev_url: https://github.com/jhawkey/IS_mapper
doi: "https://doi.org/10.1186/s12864-015-1860-2"
licence: ['BSD']
input:
- meta:
type: map
description: |
Groovy Map containing sample information
e.g. [ id:'test', single_end:false ]
- reads:
type: file
description: A set of paired-end FASTQ files
pattern: "*.{fastq.gz,fq.gz}"
- reference:
type: file
description: Reference genome in GenBank format
pattern: "*.{gbk}"
- query:
type: file
description: Insertion sequences to query in FASTA format
pattern: "*.{fasta,fa}"
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"
- results:
type: directory
description: Directory containing ISMapper result files
pattern: "*/*"
authors:
- "@rpetit3"

View file

@ -521,6 +521,10 @@ iqtree:
- modules/iqtree/** - modules/iqtree/**
- tests/modules/iqtree/** - tests/modules/iqtree/**
ismapper:
- modules/ismapper/**
- tests/modules/ismapper/**
ivar/consensus: ivar/consensus:
- modules/ivar/consensus/** - modules/ivar/consensus/**
- tests/modules/ivar/consensus/** - tests/modules/ivar/consensus/**

View file

@ -0,0 +1,18 @@
#!/usr/bin/env nextflow
nextflow.enable.dsl = 2
include { ISMAPPER } from '../../../modules/ismapper/main.nf' addParams( options: [:] )
workflow test_ismapper {
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) ],
file("https://github.com/jhawkey/IS_mapper/raw/master/test/inputs/S_suis_P17.gbk", checkIfExists: true),
file("https://github.com/jhawkey/IS_mapper/raw/master/test/inputs/ISSsu3.fasta", checkIfExists: true)
]
ISMAPPER ( input )
}

View file

@ -0,0 +1,27 @@
- name: ismapper test_ismapper
command: nextflow run tests/modules/ismapper -entry test_ismapper -c tests/config/nextflow.config
tags:
- ismapper
files:
- path: output/ismapper/results/test/ISSsu3/test_ISSsu3_left_final.fastq
md5sum: d41d8cd98f00b204e9800998ecf8427e
- path: output/ismapper/results/test/ISSsu3/test_ISSsu3_right_final.fastq
md5sum: d41d8cd98f00b204e9800998ecf8427e
- path: output/ismapper/results/test/ISSsu3/test__AM946016.1_closest.bed
md5sum: d41d8cd98f00b204e9800998ecf8427e
- path: output/ismapper/results/test/ISSsu3/test__AM946016.1_intersect.bed
md5sum: d41d8cd98f00b204e9800998ecf8427e
- path: output/ismapper/results/test/ISSsu3/test__AM946016.1_table.txt
md5sum: 9e05cda3990cb841db2bfb6e6e04a1f5
- path: output/ismapper/results/test/ISSsu3/test_left_AM946016.1_finalcov.bed
md5sum: d41d8cd98f00b204e9800998ecf8427e
- path: output/ismapper/results/test/ISSsu3/test_left_AM946016.1_merged.sorted.bed
md5sum: d41d8cd98f00b204e9800998ecf8427e
- path: output/ismapper/results/test/ISSsu3/test_left_AM946016.1_unpaired.bed
md5sum: d41d8cd98f00b204e9800998ecf8427e
- path: output/ismapper/results/test/ISSsu3/test_right_AM946016.1_finalcov.bed
md5sum: d41d8cd98f00b204e9800998ecf8427e
- path: output/ismapper/results/test/ISSsu3/test_right_AM946016.1_merged.sorted.bed
md5sum: d41d8cd98f00b204e9800998ecf8427e
- path: output/ismapper/results/test/ISSsu3/test_right_AM946016.1_unpaired.bed
md5sum: d41d8cd98f00b204e9800998ecf8427e