From f62196a4a6254b05eaee9d882d1ca9afc4a02f7c Mon Sep 17 00:00:00 2001 From: MaxUlysse Date: Wed, 24 Feb 2021 15:59:10 +0100 Subject: [PATCH] feat: add tiddit_sv module --- .github/filters.yml | 4 ++ software/tiddit/sv/functions.nf | 59 +++++++++++++++++++++++++ software/tiddit/sv/main.nf | 45 ++++++++++++++++++++ software/tiddit/sv/meta.yml | 71 +++++++++++++++++++++++++++++++ tests/data/dummy/dummy_file2.txt | 0 tests/software/tiddit/sv/main.nf | 30 +++++++++++++ tests/software/tiddit/sv/test.yml | 27 ++++++++++++ 7 files changed, 236 insertions(+) create mode 100644 software/tiddit/sv/functions.nf create mode 100644 software/tiddit/sv/main.nf create mode 100644 software/tiddit/sv/meta.yml create mode 100644 tests/data/dummy/dummy_file2.txt create mode 100644 tests/software/tiddit/sv/main.nf create mode 100644 tests/software/tiddit/sv/test.yml diff --git a/.github/filters.yml b/.github/filters.yml index 72d5e782..f639aee1 100644 --- a/.github/filters.yml +++ b/.github/filters.yml @@ -273,6 +273,10 @@ tabix_tabix: - software/tabix/tabix/** - tests/software/tabix/tabix/** +tiddit_sv: + - software/tiddit/sv/** + - tests/software/tiddit/sv/** + tool_subtool: - software/TOOL/SUBTOOL/** - tests/software/TOOL/SUBTOOL/** diff --git a/software/tiddit/sv/functions.nf b/software/tiddit/sv/functions.nf new file mode 100644 index 00000000..d25eea86 --- /dev/null +++ b/software/tiddit/sv/functions.nf @@ -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" + } + } +} diff --git a/software/tiddit/sv/main.nf b/software/tiddit/sv/main.nf new file mode 100644 index 00000000..f8ea3e74 --- /dev/null +++ b/software/tiddit/sv/main.nf @@ -0,0 +1,45 @@ +// Import generic module functions +include { initOptions; saveFiles; getSoftwareName } from './functions' + +params.options = [:] +def options = initOptions(params.options) + +process TIDDIT_SV { + 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), publish_id:meta.id) } + + conda (params.enable_conda ? "bioconda::tiddit=2.12.1" : null) + if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) { + container "https://depot.galaxyproject.org/singularity/tiddit:2.12.1--py38h1773678_0" + } else { + container "quay.io/biocontainers/tiddit:2.12.1--py38h1773678_0" + } + + input: + tuple val(meta), path(bam) + path fasta + path fai + + output: + tuple val(meta), path("*.vcf"), emit: vcf + tuple val(meta), path("*.ploidy.tab"), emit: ploidy + tuple val(meta), path("*.signals.tab"), emit: signals + path "*.version.txt", emit: version + + script: + def software = getSoftwareName(task.process) + def output = options.suffix ? "${meta.id}.${options.suffix}" : "${meta.id}" + def reference = fasta == "dummy_file.txt" ? "--ref $fasta" : "" + """ + tiddit \\ + --sv $options.args \\ + --bam $bam \\ + $reference \\ + -o $output + + echo \$(tiddit -h 2>&1) | sed 's/^.*Version: //; s/(.*\$//' > ${software}.version.txt + """ +} diff --git a/software/tiddit/sv/meta.yml b/software/tiddit/sv/meta.yml new file mode 100644 index 00000000..0ecd809b --- /dev/null +++ b/software/tiddit/sv/meta.yml @@ -0,0 +1,71 @@ +name: tiddit_sv +description: Identify chromosomal rearrangements. +keywords: + - structural + - variants + - vcf +tools: + - sv: + description: Search for structural variants. + homepage: https://github.com/SciLifeLab/TIDDIT + documentation: https://github.com/SciLifeLab/TIDDIT/blob/master/README.md + doi: 10.12688/f1000research.11168.1 +params: + - outdir: + type: string + description: | + The pipeline's output directory. By default, the module will + output files into `$params.outdir/` + - publish_dir_mode: + type: string + description: | + Value for the Nextflow `publishDir` mode parameter. + Available: symlink, rellink, link, copy, copyNoFollow, move. + - enable_conda: + type: boolean + description: | + Run the module with Conda using the software specified + via the `conda` directive + - singularity_pull_docker_container: + type: boolean + description: | + Instead of directly downloading Singularity images for use with Singularity, + force the workflow to pull and convert Docker containers instead. +input: + - meta: + type: map + description: | + Groovy Map containing sample information + e.g. [ id:'test', single_end:false ] + - fasta: + type: file + description: Input FASTA file + pattern: "*.{fasta,fa}" + - fai: + type: file + description: FASTA index file + pattern: "*.{fai}" +output: + - meta: + type: map + description: | + Groovy Map containing sample information + e.g. [ id:'test', single_end:false ] + - vcf: + type: file + description: vcf + pattern: "*.{vcf}" + - ploidy: + type: file + description: tab + pattern: "*.{ploidy.tab}" + - signals: + type: file + description: tab + pattern: "*.{signals.tab}" + - version: + type: file + description: File containing software version + pattern: "*.{version.txt}" +authors: + - "@maxulysse" diff --git a/tests/data/dummy/dummy_file2.txt b/tests/data/dummy/dummy_file2.txt new file mode 100644 index 00000000..e69de29b diff --git a/tests/software/tiddit/sv/main.nf b/tests/software/tiddit/sv/main.nf new file mode 100644 index 00000000..97e2af3c --- /dev/null +++ b/tests/software/tiddit/sv/main.nf @@ -0,0 +1,30 @@ +#!/usr/bin/env nextflow + +nextflow.enable.dsl = 2 + +include { TIDDIT_SV } from '../../../../software/tiddit/sv/main.nf' addParams( options: [:] ) +include { SAMTOOLS_FAIDX } from '../../../../software/samtools/faidx/main.nf' addParams( options: [:] ) + +workflow test_tiddit_sv { + def input = [] + def fasta = file("${launchDir}/tests/data/fasta/E_coli/NC_010473.fa", checkIfExists: true) + + input = [ [ id:'test' ], // meta map + [ file("${launchDir}/tests/data/bam/test.paired_end.sorted.bam", checkIfExists: true) ] ] + + SAMTOOLS_FAIDX ( fasta ) + + TIDDIT_SV ( input, fasta, SAMTOOLS_FAIDX.out.fai ) +} + +workflow test_tiddit_sv_no_ref { + def input = [] + def dummy_file = file("${launchDir}/tests/data/dummy/dummy_file.txt", checkIfExists: true) + def dummy_file2 = file("${launchDir}/tests/data/dummy/dummy_file2.txt", checkIfExists: true) + + input = [ [ id:'test' ], // meta map + [ file("${launchDir}/tests/data/bam/test.paired_end.sorted.bam", checkIfExists: true) ] ] + + + TIDDIT_SV ( input, dummy_file, dummy_file2 ) +} \ No newline at end of file diff --git a/tests/software/tiddit/sv/test.yml b/tests/software/tiddit/sv/test.yml new file mode 100644 index 00000000..9657b20b --- /dev/null +++ b/tests/software/tiddit/sv/test.yml @@ -0,0 +1,27 @@ +- name: tiddit sv + command: nextflow run ./tests/software/tiddit/sv -entry test_tiddit_sv -c tests/config/nextflow.config + tags: + - tiddit + - tiddit_sv + - vcf + files: + - path: output/tiddit/test.ploidy.tab + md5sum: 207bd22e75de82160f98bedc2d3d262d + - path: output/tiddit/test.signals.tab + md5sum: 67e041b737fe0fe1a33119c3109e9eff + - path: output/tiddit/test.vcf + md5sum: 24e749d49a2e91acdfb3bc13c1c6e51d + +- name: tiddit sv no ref + command: nextflow run ./tests/software/tiddit/sv -entry test_tiddit_sv_no_ref -c tests/config/nextflow.config + tags: + - tiddit + - tiddit_sv + - vcf + files: + - path: output/tiddit/test.ploidy.tab + md5sum: 207bd22e75de82160f98bedc2d3d262d + - path: output/tiddit/test.signals.tab + md5sum: 67e041b737fe0fe1a33119c3109e9eff + - path: output/tiddit/test.vcf + md5sum: 24e749d49a2e91acdfb3bc13c1c6e51d