mirror of
https://github.com/MillironX/nf-core_modules.git
synced 2024-12-22 19:18:17 +00:00
Add kraken2 run module (#266)
* Add kraken2 run module * Add kraken2 run module * Add coronavirus kraken2 db * Adding kraken2 run tests * Update software/kraken2/run/meta.yml Co-authored-by: Harshil Patel <drpatelh@users.noreply.github.com> * Fixing files commited by mistake * Remove params for meta.yml Co-authored-by: Harshil Patel <drpatelh@users.noreply.github.com>
This commit is contained in:
parent
1845db4043
commit
313241749c
10 changed files with 289 additions and 0 deletions
59
software/functions.nf
Normal file
59
software/functions.nf
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
/*
|
||||||
|
* -----------------------------------------------------
|
||||||
|
* 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.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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
59
software/kraken2/run/functions.nf
Normal file
59
software/kraken2/run/functions.nf
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
/*
|
||||||
|
* -----------------------------------------------------
|
||||||
|
* 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.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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
52
software/kraken2/run/main.nf
Normal file
52
software/kraken2/run/main.nf
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
// Import generic module functions
|
||||||
|
include { initOptions; saveFiles; getSoftwareName } from './functions'
|
||||||
|
|
||||||
|
params.options = [:]
|
||||||
|
def options = initOptions(params.options)
|
||||||
|
|
||||||
|
process KRAKEN2_RUN {
|
||||||
|
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::kraken2=2.1.1' : null)
|
||||||
|
if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) {
|
||||||
|
container 'https://depot.galaxyproject.org/singularity/kraken2:2.1.1--pl526hc9558a2_0'
|
||||||
|
} else {
|
||||||
|
container 'quay.io/biocontainers/kraken2:2.1.1--pl526hc9558a2_0'
|
||||||
|
}
|
||||||
|
|
||||||
|
input:
|
||||||
|
tuple val(meta), path(reads)
|
||||||
|
path db
|
||||||
|
|
||||||
|
output:
|
||||||
|
tuple val(meta), path('*classified*') , emit: classified
|
||||||
|
tuple val(meta), path('*unclassified*'), emit: unclassified
|
||||||
|
tuple val(meta), path('*report.txt') , emit: txt
|
||||||
|
path '*.version.txt' , emit: version
|
||||||
|
|
||||||
|
script:
|
||||||
|
def software = getSoftwareName(task.process)
|
||||||
|
def prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}"
|
||||||
|
def paired = meta.single_end ? "" : "--paired"
|
||||||
|
def classified = meta.single_end ? "${prefix}.classified.fastq" : "${prefix}.classified#.fastq"
|
||||||
|
def unclassified = meta.single_end ? "${prefix}.unclassified.fastq" : "${prefix}.unclassified#.fastq"
|
||||||
|
"""
|
||||||
|
kraken2 \\
|
||||||
|
--db $db \\
|
||||||
|
--threads $task.cpus \\
|
||||||
|
--unclassified-out $unclassified \\
|
||||||
|
--classified-out $classified \\
|
||||||
|
--report ${prefix}.kraken2.report.txt \\
|
||||||
|
--gzip-compressed \\
|
||||||
|
$paired \\
|
||||||
|
$options.args \\
|
||||||
|
$reads
|
||||||
|
|
||||||
|
gzip *.fastq
|
||||||
|
echo \$(kraken2 --version 2>&1) | sed 's/^.*Kraken version //; s/ .*\$//' > ${software}.version.txt
|
||||||
|
"""
|
||||||
|
}
|
59
software/kraken2/run/meta.yml
Normal file
59
software/kraken2/run/meta.yml
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
name: kraken2_run
|
||||||
|
description: Classifies metagenomic sequence data
|
||||||
|
keywords:
|
||||||
|
- classify
|
||||||
|
- metagenomics
|
||||||
|
- fastq
|
||||||
|
- db
|
||||||
|
tools:
|
||||||
|
- kraken2:
|
||||||
|
description: |
|
||||||
|
Kraken2 is a taxonomic sequence classifier that assigns taxonomic labels to sequence reads
|
||||||
|
homepage: https://ccb.jhu.edu/software/kraken2/
|
||||||
|
documentation: https://github.com/DerrickWood/kraken2/wiki/Manual
|
||||||
|
doi: 10.1186/s13059-019-1891-0
|
||||||
|
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.
|
||||||
|
- db:
|
||||||
|
type: directory
|
||||||
|
description: Kraken2 database
|
||||||
|
output:
|
||||||
|
- meta:
|
||||||
|
type: map
|
||||||
|
description: |
|
||||||
|
Groovy Map containing sample information
|
||||||
|
e.g. [ id:'test', single_end:false ]
|
||||||
|
- classified:
|
||||||
|
type: file
|
||||||
|
description: |
|
||||||
|
Reads classified to belong to any of the taxa
|
||||||
|
on the Kraken2 database.
|
||||||
|
pattern: "*{fastq.gz}"
|
||||||
|
- unclassified:
|
||||||
|
type: file
|
||||||
|
description: |
|
||||||
|
Reads not classified to belong to any of the taxa
|
||||||
|
on the Kraken2 database.
|
||||||
|
pattern: "*{fastq.gz}"
|
||||||
|
- txt:
|
||||||
|
type: file
|
||||||
|
description: |
|
||||||
|
Kraken2 report containing stats about classified
|
||||||
|
and not classifed reads.
|
||||||
|
pattern: "*.{report.txt}"
|
||||||
|
- version:
|
||||||
|
type: file
|
||||||
|
description: File containing software version
|
||||||
|
pattern: "*.{version.txt}"
|
||||||
|
authors:
|
||||||
|
- "@joseespinosa"
|
||||||
|
- "@drpatelh"
|
|
@ -180,6 +180,10 @@ ivar_variants:
|
||||||
- software/ivar/variants/**
|
- software/ivar/variants/**
|
||||||
- tests/software/ivar/variants/**
|
- tests/software/ivar/variants/**
|
||||||
|
|
||||||
|
kraken2_run:
|
||||||
|
- software/kraken2/run/**
|
||||||
|
- tests/software/kraken2/run/**
|
||||||
|
|
||||||
methyldackel_extract:
|
methyldackel_extract:
|
||||||
- software/methyldackel/extract/**
|
- software/methyldackel/extract/**
|
||||||
- tests/software/methyldackel/extract/**
|
- tests/software/methyldackel/extract/**
|
||||||
|
|
BIN
tests/data/genomics/sarscov2/db/kraken2/hash.k2d
Normal file
BIN
tests/data/genomics/sarscov2/db/kraken2/hash.k2d
Normal file
Binary file not shown.
BIN
tests/data/genomics/sarscov2/db/kraken2/opts.k2d
Normal file
BIN
tests/data/genomics/sarscov2/db/kraken2/opts.k2d
Normal file
Binary file not shown.
BIN
tests/data/genomics/sarscov2/db/kraken2/taxo.k2d
Normal file
BIN
tests/data/genomics/sarscov2/db/kraken2/taxo.k2d
Normal file
Binary file not shown.
25
tests/software/kraken2/run/main.nf
Normal file
25
tests/software/kraken2/run/main.nf
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
#!/usr/bin/env nextflow
|
||||||
|
|
||||||
|
nextflow.enable.dsl = 2
|
||||||
|
|
||||||
|
include { KRAKEN2_RUN } from '../../../../software/kraken2/run/main.nf' addParams( options: [:] )
|
||||||
|
|
||||||
|
workflow test_kraken2_run_single_end {
|
||||||
|
def input = []
|
||||||
|
input = [ [ id:'test', single_end:true ], // meta map
|
||||||
|
file("${launchDir}/tests/data/genomics/sarscov2/fastq/test_1.fastq.gz", checkIfExists: true) ]
|
||||||
|
|
||||||
|
db = [ file("${launchDir}/tests/data/genomics/sarscov2/db/kraken2", checkIfExists: true) ]
|
||||||
|
|
||||||
|
KRAKEN2_RUN ( input, db )
|
||||||
|
}
|
||||||
|
|
||||||
|
workflow test_kraken2_run_paired_end {
|
||||||
|
def input, db = []
|
||||||
|
input = [ [ id:'test', single_end:false ], // meta map
|
||||||
|
file("${launchDir}/tests/data/genomics/sarscov2/fastq/test_*.fastq.gz", checkIfExists: true) ]
|
||||||
|
|
||||||
|
db = [ file("${launchDir}/tests/data/genomics/sarscov2/db/kraken2", checkIfExists: true) ]
|
||||||
|
|
||||||
|
KRAKEN2_RUN ( input, db )
|
||||||
|
}
|
31
tests/software/kraken2/run/test.yml
Normal file
31
tests/software/kraken2/run/test.yml
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
- name: kraken2 run single-end
|
||||||
|
command: nextflow run ./tests/software/kraken2/run -entry test_kraken2_run_single_end -c tests/config/nextflow.config
|
||||||
|
tags:
|
||||||
|
- kraken2
|
||||||
|
- kraken2_run
|
||||||
|
- kraken2_run_single_end
|
||||||
|
files:
|
||||||
|
- path: output/kraken2/test.classified.fastq.gz
|
||||||
|
should_exist: true
|
||||||
|
- path: output/kraken2/test.unclassified.fastq.gz
|
||||||
|
should_exist: true
|
||||||
|
- path: output/kraken2/test.kraken2.report.txt
|
||||||
|
md5sum: 4227755fe40478b8d7dc8634b489761e
|
||||||
|
|
||||||
|
- name: kraken2 run paired-end
|
||||||
|
command: nextflow run ./tests/software/kraken2/run -entry test_kraken2_run_paired_end -c tests/config/nextflow.config
|
||||||
|
tags:
|
||||||
|
- kraken2
|
||||||
|
- kraken2_run
|
||||||
|
- kraken2_run_paired_end
|
||||||
|
files:
|
||||||
|
- path: output/kraken2/test.classified_1.fastq.gz
|
||||||
|
should_exist: true
|
||||||
|
- path: output/kraken2/test.classified_2.fastq.gz
|
||||||
|
should_exist: true
|
||||||
|
- path: output/kraken2/test.unclassified_1.fastq.gz
|
||||||
|
should_exist: true
|
||||||
|
- path: output/kraken2/test.unclassified_2.fastq.gz
|
||||||
|
should_exist: true
|
||||||
|
- path: output/kraken2/test.kraken2.report.txt
|
||||||
|
md5sum: 5fb165fd0bdf920ff6cf6f734371a4cf
|
Loading…
Reference in a new issue