From b261c1f549db29574c880f65a15e70ada4864eb2 Mon Sep 17 00:00:00 2001 From: Anders Jemt Date: Mon, 16 Aug 2021 17:47:42 +0200 Subject: [PATCH] Expansionhunter (#666) Please enter the commit message for your changes. Lines starting * adds expansionhunter module Co-authored-by: Maxime U. Garcia --- modules/expansionhunter/functions.nf | 68 ++++++++++++++++++++++++++ modules/expansionhunter/main.nf | 45 +++++++++++++++++ modules/expansionhunter/meta.yml | 50 +++++++++++++++++++ tests/config/pytest_modules.yml | 4 ++ tests/config/test_data.config | 1 + tests/modules/expansionhunter/main.nf | 17 +++++++ tests/modules/expansionhunter/test.yml | 7 +++ 7 files changed, 192 insertions(+) create mode 100644 modules/expansionhunter/functions.nf create mode 100644 modules/expansionhunter/main.nf create mode 100644 modules/expansionhunter/meta.yml create mode 100644 tests/modules/expansionhunter/main.nf create mode 100644 tests/modules/expansionhunter/test.yml diff --git a/modules/expansionhunter/functions.nf b/modules/expansionhunter/functions.nf new file mode 100644 index 00000000..da9da093 --- /dev/null +++ b/modules/expansionhunter/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/expansionhunter/main.nf b/modules/expansionhunter/main.nf new file mode 100644 index 00000000..41c6ed6c --- /dev/null +++ b/modules/expansionhunter/main.nf @@ -0,0 +1,45 @@ +// Import generic module functions +include { initOptions; saveFiles; getSoftwareName } from './functions' + +params.options = [:] +options = initOptions(params.options) + +process EXPANSIONHUNTER { + 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), meta:meta, publish_by_meta:['id']) } + + conda (params.enable_conda ? "bioconda::expansionhunter=4.0.2" : null) + if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) { + container "https://depot.galaxyproject.org/singularity/expansionhunter:4.0.2--he785bd8_0" + } else { + container "quay.io/biocontainers/expansionhunter:4.0.2--he785bd8_0" + } + + input: + tuple val(meta), path(bam), path(bai) + path fasta + path variant_catalog + + output: + 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}" + def gender = (meta.gender == 'male' || meta.gender == 1 || meta.gender == 'XY') ? "male" : "female" + """ + ExpansionHunter \\ + $options.args \\ + --reads $bam \\ + --output-prefix $prefix \\ + --reference $fasta \\ + --variant-catalog $variant_catalog \\ + --sex $gender + + echo \$(ExpansionHunter --version 2>&1) | sed 's/^.*ExpansionHunter //' > ${software}.version.txt + """ +} diff --git a/modules/expansionhunter/meta.yml b/modules/expansionhunter/meta.yml new file mode 100644 index 00000000..cac3ed2b --- /dev/null +++ b/modules/expansionhunter/meta.yml @@ -0,0 +1,50 @@ +name: expansionhunter +description: write your description here +keywords: + - STR + - repeat_expansions +tools: + - expansionhunter: + description: A tool for estimating repeat sizes + homepage: https://github.com/Illumina/ExpansionHunter + documentation: https://github.com/Illumina/ExpansionHunter/blob/master/docs/01_Introduction.md + tool_dev_url: None + doi: "10.1093/bioinformatics/btz431" + licence: ['Apache v2.0'] + +input: + - meta: + type: map + description: | + Groovy Map containing sample information + e.g. [ id:'test', single_end:false ] + - bam: + type: file + description: BAM/CRAM file + pattern: "*.{bam,cram}" + - fasta: + type: file + description: Reference genome + pattern: "*.{fa,fasta}" + - variant_catalog: + type: file + description: json file with repeat expansion sites to genotype + pattern: "*.{json}" + +output: + - meta: + type: map + description: | + Groovy Map containing sample information + e.g. [ id:'test', gender:'female' ] + - version: + type: file + description: File containing software version + pattern: "*.{version.txt}" + - vcf: + type: file + description: VCF with repeat expansions + pattern: "*.{vcf}" + +authors: + - "@jemten" diff --git a/tests/config/pytest_modules.yml b/tests/config/pytest_modules.yml index 0482c672..a65879cb 100644 --- a/tests/config/pytest_modules.yml +++ b/tests/config/pytest_modules.yml @@ -270,6 +270,10 @@ ensemblvep: - modules/ensemblvep/** - tests/modules/ensemblvep/** +expansionhunter: + - modules/expansionhunter/** + - tests/modules/expansionhunter/** + fastp: - modules/fastp/** - tests/modules/fastp/** diff --git a/tests/config/test_data.config b/tests/config/test_data.config index 5643c364..73232088 100644 --- a/tests/config/test_data.config +++ b/tests/config/test_data.config @@ -107,6 +107,7 @@ params { mills_and_1000g_indels_vcf_gz = "${test_data_dir}/genomics/homo_sapiens/genome/vcf/mills_and_1000G.indels.vcf.gz" mills_and_1000g_indels_vcf_gz_tbi = "${test_data_dir}/genomics/homo_sapiens/genome/vcf/mills_and_1000G.indels.vcf.gz.tbi" index_salmon = "${test_data_dir}/genomics/homo_sapiens/genome/index/salmon" + repeat_expansions = "${test_data_dir}/genomics/homo_sapiens/genome/loci/repeat_expansions.json" } 'illumina' { test_paired_end_sorted_bam = "${test_data_dir}/genomics/homo_sapiens/illumina/bam/test.paired_end.sorted.bam" diff --git a/tests/modules/expansionhunter/main.nf b/tests/modules/expansionhunter/main.nf new file mode 100644 index 00000000..a7acbff4 --- /dev/null +++ b/tests/modules/expansionhunter/main.nf @@ -0,0 +1,17 @@ +#!/usr/bin/env nextflow + +nextflow.enable.dsl = 2 + +include { EXPANSIONHUNTER } from '../../../modules/expansionhunter/main.nf' addParams( options: [:] ) + +workflow test_expansionhunter { + + input = [ [ id:'test', gender:'male' ], // meta map + file(params.test_data['homo_sapiens']['illumina']['test_paired_end_recalibrated_sorted_bam'], checkIfExists: true), + file(params.test_data['homo_sapiens']['illumina']['test_paired_end_recalibrated_sorted_bam_bai'], checkIfExists: true), + ] + fasta = file(params.test_data['homo_sapiens']['genome']['genome_fasta'], checkIfExists: true) + variant_catalog = file(params.test_data['homo_sapiens']['genome']['repeat_expansions'], checkIfExists: true) + + EXPANSIONHUNTER ( input, fasta, variant_catalog ) +} diff --git a/tests/modules/expansionhunter/test.yml b/tests/modules/expansionhunter/test.yml new file mode 100644 index 00000000..78d5c002 --- /dev/null +++ b/tests/modules/expansionhunter/test.yml @@ -0,0 +1,7 @@ +- name: expansionhunter test_expansionhunter + command: nextflow run tests/modules/expansionhunter -entry test_expansionhunter -c tests/config/nextflow.config + tags: + - expansionhunter + files: + - path: output/expansionhunter/test.vcf + md5sum: ef6c2101d7bd67211bb5a5a132690e02