From db2192593795680d272b1e5cd9a1a13cd5d83f32 Mon Sep 17 00:00:00 2001 From: Alexander Peltzer Date: Thu, 28 Oct 2021 13:55:12 +0200 Subject: [PATCH] Initialized CM generator + mapper modules --- .../circularmapper/functions.nf | 68 ++++++++++++++++ modules/circularmapper/circularmapper/main.nf | 79 +++++++++++++++++++ .../circularmapper/circularmapper/meta.yml | 47 +++++++++++ modules/circularmapper/generator/functions.nf | 68 ++++++++++++++++ modules/circularmapper/generator/main.nf | 77 ++++++++++++++++++ modules/circularmapper/generator/meta.yml | 37 +++++++++ tests/config/pytest_modules.yml | 8 ++ .../circularmapper/circularmapper/main.nf | 13 +++ .../circularmapper/circularmapper/test.yml | 10 +++ .../modules/circularmapper/generator/main.nf | 12 +++ .../modules/circularmapper/generator/test.yml | 10 +++ 11 files changed, 429 insertions(+) create mode 100644 modules/circularmapper/circularmapper/functions.nf create mode 100644 modules/circularmapper/circularmapper/main.nf create mode 100644 modules/circularmapper/circularmapper/meta.yml create mode 100644 modules/circularmapper/generator/functions.nf create mode 100644 modules/circularmapper/generator/main.nf create mode 100644 modules/circularmapper/generator/meta.yml create mode 100644 tests/modules/circularmapper/circularmapper/main.nf create mode 100644 tests/modules/circularmapper/circularmapper/test.yml create mode 100644 tests/modules/circularmapper/generator/main.nf create mode 100644 tests/modules/circularmapper/generator/test.yml diff --git a/modules/circularmapper/circularmapper/functions.nf b/modules/circularmapper/circularmapper/functions.nf new file mode 100644 index 00000000..da9da093 --- /dev/null +++ b/modules/circularmapper/circularmapper/functions.nf @@ -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" + } + } +} diff --git a/modules/circularmapper/circularmapper/main.nf b/modules/circularmapper/circularmapper/main.nf new file mode 100644 index 00000000..b69a6127 --- /dev/null +++ b/modules/circularmapper/circularmapper/main.nf @@ -0,0 +1,79 @@ +// Import generic module functions +include { initOptions; saveFiles; getSoftwareName } from './functions' + +// TODO nf-core: If in doubt look at other nf-core/modules to see how we are doing things! :) +// https://github.com/nf-core/modules/tree/master/software +// You can also ask for help via your pull request or on the #modules channel on the nf-core Slack workspace: +// https://nf-co.re/join + +// 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. +// TODO nf-core: Software that can be piped together SHOULD be added to separate module files +// unless there is a run-time, storage advantage in implementing in this way +// e.g. it's ok to have a single module for bwa to output BAM instead of SAM: +// bwa mem | samtools view -B -T ref.fasta +// TODO nf-core: Optional inputs are not currently supported by Nextflow. However, using an empty +// list (`[]`) instead of a file can be used to work around this issue. + +params.options = [:] +options = initOptions(params.options) + +process CIRCULARMAPPER_CIRCULARMAPPER { + 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']) } + + // TODO nf-core: List required Conda package(s). + // Software MUST be pinned to channel (i.e. "bioconda"), version (i.e. "1.10"). + // For Conda, the build (i.e. "h9402c20_2") must be EXCLUDED to support installation on different operating systems. + // TODO nf-core: See section in main README for further information regarding finding and adding container addresses to the section below. + conda (params.enable_conda ? "bioconda::circularmapper=1.93.5" : null) + if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) { + container "https://depot.galaxyproject.org/singularity/circularmapper:1.93.5--h4a94de4_1" + } else { + container "quay.io/biocontainers/circularmapper:1.93.5--h4a94de4_1" + } + + 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 + // TODO nf-core: Where applicable please provide/convert compressed files as input/output + // e.g. "*.fastq.gz" and NOT "*.fastq", "*.bam" and NOT "*.sam" etc. + tuple val(meta), path(bam) + + output: + // TODO nf-core: Named file extensions MUST be emitted for ALL output channels + tuple val(meta), path("*.bam"), emit: bam + // TODO nf-core: List additional required output channels/values here + path "*.version.txt" , emit: version + + script: + def software = getSoftwareName(task.process) + def prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}" + // TODO nf-core: Where possible, a command MUST be provided to obtain the version number of the software e.g. 1.10 + // If the software is unable to output a version number on the command-line then it can be manually specified + // e.g. https://github.com/nf-core/modules/blob/master/software/homer/annotatepeaks/main.nf + // TODO nf-core: It MUST be possible to pass additional parameters to the tool as a command-line string via the "$options.args" variable + // TODO nf-core: If the tool supports multi-threading then you MUST provide the appropriate parameter + // using the Nextflow "task" variable e.g. "--threads $task.cpus" + // TODO nf-core: Please replace the example samtools command below with your module's command + // TODO nf-core: Please indent the command appropriately (4 spaces!!) to help with readability ;) + """ + samtools \\ + sort \\ + $options.args \\ + -@ $task.cpus \\ + -o ${prefix}.bam \\ + -T $prefix \\ + $bam + + echo \$(samtools --version 2>&1) | sed 's/^.*samtools //; s/Using.*\$//' > ${software}.version.txt + """ +} diff --git a/modules/circularmapper/circularmapper/meta.yml b/modules/circularmapper/circularmapper/meta.yml new file mode 100644 index 00000000..f9202888 --- /dev/null +++ b/modules/circularmapper/circularmapper/meta.yml @@ -0,0 +1,47 @@ +name: circularmapper_circularmapper +## TODO nf-core: Add a description of the module and list keywords +description: write your description here +keywords: + - sort +tools: + - circularmapper: + ## TODO nf-core: Add a description and other details for the software below + description: A method to improve mappings on circular genomes, using the BWA mapper. + homepage: None + documentation: None + tool_dev_url: None + doi: "" + licence: ['GPL v3'] + +## TODO nf-core: Add a description of all of the variables used as input +input: + - meta: + type: map + description: | + Groovy Map containing sample information + e.g. [ id:'test', single_end:false ] + ## TODO nf-core: Delete / customise this example input + - bam: + type: file + description: BAM/CRAM/SAM file + pattern: "*.{bam,cram,sam}" + +## TODO nf-core: Add a description of all of the variables used as output +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}" + ## TODO nf-core: Delete / customise this example output + - bam: + type: file + description: Sorted BAM/CRAM/SAM file + pattern: "*.{bam,cram,sam}" + +authors: + - "@apeltzer" diff --git a/modules/circularmapper/generator/functions.nf b/modules/circularmapper/generator/functions.nf new file mode 100644 index 00000000..da9da093 --- /dev/null +++ b/modules/circularmapper/generator/functions.nf @@ -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" + } + } +} diff --git a/modules/circularmapper/generator/main.nf b/modules/circularmapper/generator/main.nf new file mode 100644 index 00000000..3283ba9a --- /dev/null +++ b/modules/circularmapper/generator/main.nf @@ -0,0 +1,77 @@ +// Import generic module functions +include { initOptions; saveFiles; getSoftwareName } from './functions' + +// TODO nf-core: If in doubt look at other nf-core/modules to see how we are doing things! :) +// https://github.com/nf-core/modules/tree/master/software +// You can also ask for help via your pull request or on the #modules channel on the nf-core Slack workspace: +// https://nf-co.re/join + +// 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. +// TODO nf-core: Software that can be piped together SHOULD be added to separate module files +// unless there is a run-time, storage advantage in implementing in this way +// e.g. it's ok to have a single module for bwa to output BAM instead of SAM: +// bwa mem | samtools view -B -T ref.fasta +// TODO nf-core: Optional inputs are not currently supported by Nextflow. However, using an empty +// list (`[]`) instead of a file can be used to work around this issue. + +params.options = [:] +options = initOptions(params.options) + +process CIRCULARMAPPER_GENERATOR { + tag '$bam' + 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:[:], publish_by_meta:[]) } + + // TODO nf-core: List required Conda package(s). + // Software MUST be pinned to channel (i.e. "bioconda"), version (i.e. "1.10"). + // For Conda, the build (i.e. "h9402c20_2") must be EXCLUDED to support installation on different operating systems. + // TODO nf-core: See section in main README for further information regarding finding and adding container addresses to the section below. + conda (params.enable_conda ? "bioconda::circularmapper=1.93.5" : null) + if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) { + container "https://depot.galaxyproject.org/singularity/circularmapper:1.93.5--h4a94de4_1" + } else { + container "quay.io/biocontainers/circularmapper:1.93.5--h4a94de4_1" + } + + 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 + // TODO nf-core: Where applicable please provide/convert compressed files as input/output + // e.g. "*.fastq.gz" and NOT "*.fastq", "*.bam" and NOT "*.sam" etc. + path bam + + output: + // TODO nf-core: Named file extensions MUST be emitted for ALL output channels + path "*.bam", emit: bam + // TODO nf-core: List additional required output channels/values here + path "*.version.txt" , emit: version + + script: + def software = getSoftwareName(task.process) + + // TODO nf-core: Where possible, a command MUST be provided to obtain the version number of the software e.g. 1.10 + // If the software is unable to output a version number on the command-line then it can be manually specified + // e.g. https://github.com/nf-core/modules/blob/master/software/homer/annotatepeaks/main.nf + // TODO nf-core: It MUST be possible to pass additional parameters to the tool as a command-line string via the "$options.args" variable + // TODO nf-core: If the tool supports multi-threading then you MUST provide the appropriate parameter + // using the Nextflow "task" variable e.g. "--threads $task.cpus" + // TODO nf-core: Please replace the example samtools command below with your module's command + // TODO nf-core: Please indent the command appropriately (4 spaces!!) to help with readability ;) + """ + samtools \\ + sort \\ + $options.args \\ + -@ $task.cpus \\ + $bam + + echo \$(samtools --version 2>&1) | sed 's/^.*samtools //; s/Using.*\$//' > ${software}.version.txt + """ +} diff --git a/modules/circularmapper/generator/meta.yml b/modules/circularmapper/generator/meta.yml new file mode 100644 index 00000000..6cb7312c --- /dev/null +++ b/modules/circularmapper/generator/meta.yml @@ -0,0 +1,37 @@ +name: circularmapper_generator +## TODO nf-core: Add a description of the module and list keywords +description: write your description here +keywords: + - sort +tools: + - circularmapper: + ## TODO nf-core: Add a description and other details for the software below + description: A method to improve mappings on circular genomes, using the BWA mapper. + homepage: None + documentation: None + tool_dev_url: None + doi: "" + licence: ['GPL v3'] + +## TODO nf-core: Add a description of all of the variables used as input +input: + ## TODO nf-core: Delete / customise this example input + - bam: + type: file + description: BAM/CRAM/SAM file + pattern: "*.{bam,cram,sam}" + +## TODO nf-core: Add a description of all of the variables used as output +output: + - version: + type: file + description: File containing software version + pattern: "*.{version.txt}" + ## TODO nf-core: Delete / customise this example output + - bam: + type: file + description: Sorted BAM/CRAM/SAM file + pattern: "*.{bam,cram,sam}" + +authors: + - "@apeltzer" diff --git a/tests/config/pytest_modules.yml b/tests/config/pytest_modules.yml index c613ed80..5f7b4d15 100644 --- a/tests/config/pytest_modules.yml +++ b/tests/config/pytest_modules.yml @@ -270,6 +270,14 @@ chromap/index: - modules/chromap/index/** - tests/modules/chromap/index/** +circularmapper/circularmapper: + - modules/circularmapper/circularmapper/** + - tests/modules/circularmapper/circularmapper/** + +circularmapper/generator: + - modules/circularmapper/generator/** + - tests/modules/circularmapper/generator/** + cnvkit: - modules/cnvkit/** - tests/modules/cnvkit/** diff --git a/tests/modules/circularmapper/circularmapper/main.nf b/tests/modules/circularmapper/circularmapper/main.nf new file mode 100644 index 00000000..9912aa51 --- /dev/null +++ b/tests/modules/circularmapper/circularmapper/main.nf @@ -0,0 +1,13 @@ +#!/usr/bin/env nextflow + +nextflow.enable.dsl = 2 + +include { CIRCULARMAPPER_CIRCULARMAPPER } from '../../../../modules/circularmapper/circularmapper/main.nf' addParams( options: [:] ) + +workflow test_circularmapper_circularmapper { + + input = [ [ id:'test', single_end:false ], // meta map + file(params.test_data['sarscov2']['illumina']['test_paired_end_bam'], checkIfExists: true) ] + + CIRCULARMAPPER_CIRCULARMAPPER ( input ) +} diff --git a/tests/modules/circularmapper/circularmapper/test.yml b/tests/modules/circularmapper/circularmapper/test.yml new file mode 100644 index 00000000..cc530cff --- /dev/null +++ b/tests/modules/circularmapper/circularmapper/test.yml @@ -0,0 +1,10 @@ +## TODO nf-core: Please run the following command to build this file: +# nf-core modules create-test-yml circularmapper/circularmapper +- name: circularmapper circularmapper + command: nextflow run ./tests/modules/circularmapper/circularmapper -entry test_circularmapper_circularmapper -c tests/config/nextflow.config + tags: + - circularmapper + - circularmapper/circularmapper + files: + - path: output/circularmapper/test.bam + md5sum: e667c7caad0bc4b7ac383fd023c654fc diff --git a/tests/modules/circularmapper/generator/main.nf b/tests/modules/circularmapper/generator/main.nf new file mode 100644 index 00000000..f16f2809 --- /dev/null +++ b/tests/modules/circularmapper/generator/main.nf @@ -0,0 +1,12 @@ +#!/usr/bin/env nextflow + +nextflow.enable.dsl = 2 + +include { CIRCULARMAPPER_GENERATOR } from '../../../../modules/circularmapper/generator/main.nf' addParams( options: [:] ) + +workflow test_circularmapper_generator { + + input = file(params.test_data['sarscov2']['illumina']['test_single_end_bam'], checkIfExists: true) + + CIRCULARMAPPER_GENERATOR ( input ) +} diff --git a/tests/modules/circularmapper/generator/test.yml b/tests/modules/circularmapper/generator/test.yml new file mode 100644 index 00000000..909bbb0e --- /dev/null +++ b/tests/modules/circularmapper/generator/test.yml @@ -0,0 +1,10 @@ +## TODO nf-core: Please run the following command to build this file: +# nf-core modules create-test-yml circularmapper/generator +- name: circularmapper generator + command: nextflow run ./tests/modules/circularmapper/generator -entry test_circularmapper_generator -c tests/config/nextflow.config + tags: + - circularmapper + - circularmapper/generator + files: + - path: output/circularmapper/test.bam + md5sum: e667c7caad0bc4b7ac383fd023c654fc