-
Notifications
You must be signed in to change notification settings - Fork 424
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
169 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* ----------------------------------------------------- | ||
* 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" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// TODO Remove the module declaration | ||
nextflow.enable.dsl=2 | ||
|
||
// Import generic module functions | ||
include { initOptions; saveFiles; getSoftwareName } from './functions' | ||
|
||
// TODO nf-core: A module file SHOULD only define input and output files as command-line parameters. | ||
// All other parameters MUST be provided as a string i.e. "options.args" | ||
// where "params.options" is a Groovy Map that MUST be provided via the addParams section of the including workflow. | ||
// Any parameters that need to be evaluated in the context of a particular sample | ||
// e.g. single-end/paired-end data MUST also be defined and evaluated appropriately. | ||
|
||
params.options = [:] | ||
options = initOptions(params.options) | ||
|
||
process DEEPVARIANT { | ||
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::deepvariant=1.1.0" : null) | ||
if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) { | ||
container "https://depot.galaxyproject.org/singularity/deepvariant:1.1.0--py36hf3e76ba_2" | ||
} else { | ||
// TODO update the bioconda container to work with run_deepvariant.sh script | ||
// container "quay.io/biocontainers/deepvariant:1.1.0--py36hf3e76ba_2" | ||
container "google/deepvariant:1.1.0" | ||
} | ||
|
||
input: | ||
// TODO nf-core: Where applicable all sample-specific information e.g. "id", "single_end", "read_group" | ||
// MUST be provided as an input via a Groovy Map called "meta". | ||
// This information may not be required in some instances e.g. indexing reference genome files: | ||
// https://github.com/nf-core/modules/blob/master/software/bwa/index/main.nf | ||
tuple val(meta), path(fasta), path(fai) | ||
tuple val(meta), path(bam), path(bai) | ||
|
||
output: | ||
// TODO nf-core: Named file extensions MUST be emitted for ALL output channels | ||
tuple val(meta), path("*.vcf*"), emit: vcf | ||
path "*.version.txt" , emit: version | ||
|
||
script: | ||
def software = getSoftwareName(task.process) | ||
def prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}" | ||
""" | ||
/opt/deepvariant/bin/run_deepvariant \ | ||
--ref=${fasta} \ | ||
--reads=${bam} \ | ||
--output_vcf=${meta.id}.vcf.gz \ | ||
--output_gvcf=${meta.id}.g.vcf.gz \ | ||
${options.args} | ||
echo \$(/opt/deepvariant/bin/run_deepvariant --version) > ${software}.version.txt | ||
""" | ||
|
||
|
||
stub: | ||
|
||
def software = getSoftwareName(task.process) | ||
def prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}" | ||
""" | ||
echo "/opt/deepvariant/bin/run_deepvariant \ | ||
--ref=${fasta} \ | ||
--reads=${bam} \ | ||
--output_vcf=${meta.id}.vcf.gz \ | ||
--output_gvcf=${meta.id}.g.vcf.gz" | ||
echo "${options.args}" | ||
touch ${meta.id}.vcf.gz | ||
touch ${meta.id}.g.vcf.gz | ||
echo \$(/opt/deepvariant/bin/run_deepvariant --version) > ${software}.version.txt | ||
""" | ||
|
||
|
||
} | ||
|
||
|
||
workflow test { | ||
|
||
fasta_ch = Channel.of([[id: "GRCh38_no_alt_analysis_set"], | ||
"${launchDir}/data/GRCh38_no_alt_analysis_set.fasta", | ||
"${launchDir}/data/GRCh38_no_alt_analysis_set.fasta.fai"] | ||
) | ||
|
||
bam_ch = Channel.of([[id: "HG003.novaseq.pcr-free.35x.dedup.grch38_no_alt.chr20"], | ||
"${launchDir}/data/HG003.novaseq.pcr-free.35x.dedup.grch38_no_alt.chr20.bam", | ||
"${launchDir}/data/HG003.novaseq.pcr-free.35x.dedup.grch38_no_alt.chr20.bam.bai"] | ||
) | ||
|
||
|
||
DEEPVARIANT(fasta_ch, bam_ch) | ||
|
||
|
||
} |