From 3d720a24fd3c766ba56edf3d4e108a1c45d353b2 Mon Sep 17 00:00:00 2001 From: Anthony Fullam Date: Tue, 23 Mar 2021 14:37:53 +0100 Subject: [PATCH] Add alleleCounter module (#313) * Add allelecount module * Add bed file input * Added bai file * Changed conda version * Update main.nf * Update pytest_software.yml * Update pytest_software.yml * Update pytest_software.yml * Update pytest_software.yml * Update pytest_software.yml * Update pytest_software.yml * Update pytest_software.yml * Update pytest_software.yml * Update pytest_software.yml * Update pytest_software.yml * Add allelecount module * Add bed file input * Added bai file * Changed conda version * Update main.nf * Update pytest_software.yml * Update pytest_software.yml * Update pytest_software.yml * Update pytest_software.yml * Update pytest_software.yml * Update pytest_software.yml * Remove newline * Fix pytest_software.yml * Update pytest_software.yml Co-authored-by: Gregor Sturm --- software/allelecounter/functions.nf | 60 +++++++++++++++++++++++++++ software/allelecounter/main.nf | 41 ++++++++++++++++++ software/allelecounter/meta.yml | 52 +++++++++++++++++++++++ tests/config/pytest_software.yml | 4 ++ tests/software/allelecounter/main.nf | 14 +++++++ tests/software/allelecounter/test.yml | 7 ++++ 6 files changed, 178 insertions(+) create mode 100644 software/allelecounter/functions.nf create mode 100644 software/allelecounter/main.nf create mode 100644 software/allelecounter/meta.yml create mode 100644 tests/software/allelecounter/main.nf create mode 100644 tests/software/allelecounter/test.yml diff --git a/software/allelecounter/functions.nf b/software/allelecounter/functions.nf new file mode 100644 index 00000000..f177f0c8 --- /dev/null +++ b/software/allelecounter/functions.nf @@ -0,0 +1,60 @@ +/* + * ----------------------------------------------------- + * 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_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/allelecounter/main.nf b/software/allelecounter/main.nf new file mode 100644 index 00000000..cb91b5ec --- /dev/null +++ b/software/allelecounter/main.nf @@ -0,0 +1,41 @@ +// Import generic module functions +include { initOptions; saveFiles; getSoftwareName } from './functions' + +params.options = [:] +options = initOptions(params.options) + +process ALLELECOUNTER { + tag "$meta.id" + label 'process_low' + 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::cancerit-allelecount=4.2.1" : null) + if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) { + container "https://depot.galaxyproject.org/singularity/cancerit-allelecount:4.2.1--h3ecb661_0" + } else { + container "quay.io/biocontainers/cancerit-allelecount:4.2.1--h3ecb661_0" + } + + input: + tuple val(meta), path(bam), path(bai) + path loci + + output: + tuple val(meta), path("*.alleleCount"), emit: allelecount + path "*.version.txt" , emit: version + + script: + def software = getSoftwareName(task.process) + def prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}" + """ + alleleCounter \\ + $options.args \\ + -l $loci \\ + -b $bam \\ + -o ${prefix}.alleleCount + + alleleCounter --version > ${software}.version.txt + """ +} diff --git a/software/allelecounter/meta.yml b/software/allelecounter/meta.yml new file mode 100644 index 00000000..28f96836 --- /dev/null +++ b/software/allelecounter/meta.yml @@ -0,0 +1,52 @@ +name: allelecounter + +description: Generates a count of coverage of alleles +keywords: + - allele + - count +tools: + - allelecounter: + description: Takes a file of locations and a [cr|b]am file and generates a count of coverage of each allele at that location (given any filter settings) + homepage: https://github.com/cancerit/alleleCount + documentation: https://github.com/cancerit/alleleCount + tool_dev_url: https://github.com/cancerit/alleleCount + doi: "" + licence: A-GPL 3.0 + +input: + - meta: + type: map + description: | + Groovy Map containing sample information + e.g. [ id:'test', single_end:false ] + - bam: + type: file + description: BAM/CRAM/SAM file + pattern: "*.{bam,cram,sam}" + - bai: + type: file + description: BAM/CRAM/SAM index file + pattern: "*.{bai,crai,sai}" + - loci: + type: file + description: loci file + pattern: "*.{tsv}" + + +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}" + - alleleCount: + type: file + description: Allele count file + pattern: "*.{alleleCount}" + +authors: + - "@fullama" diff --git a/tests/config/pytest_software.yml b/tests/config/pytest_software.yml index 03052d0f..bd73fa13 100755 --- a/tests/config/pytest_software.yml +++ b/tests/config/pytest_software.yml @@ -2,6 +2,10 @@ adapterremoval: - software/adapterremoval/** - tests/software/adapterremoval/** +allelecounter: + - software/allelecounter/** + - tests/software/allelecounter/** + bandage_image: - software/bandage/image/** - tests/software/bandage/image/** diff --git a/tests/software/allelecounter/main.nf b/tests/software/allelecounter/main.nf new file mode 100644 index 00000000..f3d4c5e8 --- /dev/null +++ b/tests/software/allelecounter/main.nf @@ -0,0 +1,14 @@ +#!/usr/bin/env nextflow +nextflow.enable.dsl = 2 + +include { ALLELECOUNTER } from '../../../software/allelecounter/main.nf' addParams( options: [:] ) + +workflow test_allelecounter { + + def input = [] + input = [ [ id:'test', single_end:false ], // meta map + file("${launchDir}/tests/data/genomics/sarscov2/bam/test_paired_end.sorted.bam", checkIfExists: true), + file("${launchDir}/tests/data/genomics/sarscov2/bam/test_paired_end.sorted.bam.bai", checkIfExists: true)] + positions = [ file("${launchDir}/tests/data/genomics/sarscov2/bed/test.bed", checkIfExists: true) ] + ALLELECOUNTER ( input, positions ) +} diff --git a/tests/software/allelecounter/test.yml b/tests/software/allelecounter/test.yml new file mode 100644 index 00000000..aeb64e1f --- /dev/null +++ b/tests/software/allelecounter/test.yml @@ -0,0 +1,7 @@ +- name: allelecounter test_allelecounter + command: nextflow run tests/software/allelecounter -entry test_allelecounter -c tests/config/nextflow.config + tags: + - allelecounter + files: + - path: output/allelecounter/test.alleleCount + md5sum: 2bbe9d7331b78bdac30fe30dbc5fdaf3