From 45985ff6f01c6e2e229b665ba45b159bd925513d Mon Sep 17 00:00:00 2001 From: Annick Renevey <47788523+rannick@users.noreply.github.com> Date: Sun, 21 Nov 2021 21:14:09 +0100 Subject: [PATCH] Peddy nf core2 2dev0 (#1048) * Updated module to fit nf-core2.2dev0 templates * Updated module to fit nf-core2.2dev0 templates * Linked test files to nf-core/test-dataset branch:raredisease raw files * Change order of input: vcf and tbi with meta, ped without * Change order of input: vcf and tbi with meta, ped without/adapt test * Change order of input: vcf and tbi with meta, ped without/adapt test, bugfix * Indent and rename files * Update modules/peddy/main.nf Removed newline Co-authored-by: FriederikeHanssen * Update modules/peddy/main.nf Co-authored-by: Harshil Patel * Update modules/peddy/main.nf Co-authored-by: Harshil Patel * Update modules/peddy/main.nf Co-authored-by: Harshil Patel * Update modules/peddy/meta.yml Co-authored-by: Harshil Patel * Update modules/peddy/meta.yml Co-authored-by: Harshil Patel * Update modules/peddy/main.nf Co-authored-by: Harshil Patel * Update modules/peddy/main.nf Co-authored-by: Harshil Patel * Update pytest_modules.yml * Update main.nf * Apply suggestions from code review Co-authored-by: FriederikeHanssen Co-authored-by: Harshil Patel --- modules/peddy/functions.nf | 78 +++++++++++++++++++++++++++++++++ modules/peddy/main.nf | 47 ++++++++++++++++++++ modules/peddy/meta.yml | 64 +++++++++++++++++++++++++++ tests/config/pytest_modules.yml | 4 ++ tests/config/test_data.config | 4 ++ tests/modules/peddy/main.nf | 17 +++++++ tests/modules/peddy/test.yml | 17 +++++++ 7 files changed, 231 insertions(+) create mode 100644 modules/peddy/functions.nf create mode 100644 modules/peddy/main.nf create mode 100644 modules/peddy/meta.yml create mode 100644 tests/modules/peddy/main.nf create mode 100644 tests/modules/peddy/test.yml diff --git a/modules/peddy/functions.nf b/modules/peddy/functions.nf new file mode 100644 index 00000000..85628ee0 --- /dev/null +++ b/modules/peddy/functions.nf @@ -0,0 +1,78 @@ +// +// 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() +} + +// +// Extract name of module from process name using $task.process +// +def getProcessName(task_process) { + return task_process.tokenize(':')[-1] +} + +// +// 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) { + def ioptions = initOptions(args.options) + def path_list = [ ioptions.publish_dir ?: args.publish_dir ] + + // Do not publish versions.yml unless running from pytest workflow + if (args.filename.equals('versions.yml') && !System.getenv("NF_CORE_MODULES_TEST")) { + return null + } + 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/peddy/main.nf b/modules/peddy/main.nf new file mode 100644 index 00000000..4331ed9d --- /dev/null +++ b/modules/peddy/main.nf @@ -0,0 +1,47 @@ +// Import generic module functions +include { initOptions; saveFiles; getSoftwareName; getProcessName } from './functions' + +params.options = [:] +options = initOptions(params.options) + +process PEDDY { + 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::peddy=0.4.8" : null) + if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) { + container "https://depot.galaxyproject.org/singularity/peddy:0.4.8--pyh5e36f6f_0" + } else { + container "quay.io/biocontainers/peddy:0.4.8--pyh5e36f6f_0" + } + + input: + tuple val(meta), path(vcf), path(vcf_tbi) + path ped + + output: + tuple val(meta), path("*.html") , emit: html + tuple val(meta), path("*.csv") , emit: csv + tuple val(meta), path("*.peddy.ped"), emit: ped + tuple val(meta), path("*.png") , emit: png + path "versions.yml" , emit: versions + + script: + def prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}" + """ + peddy \\ + $options.args \\ + --plot \\ + -p $task.cpus \\ + $vcf \\ + $ped + + cat <<-END_VERSIONS > versions.yml + ${getProcessName(task.process)}: + ${getSoftwareName(task.process)}: \$( peddy --version 2>&1 | sed 's/peddy, version //' ) + END_VERSIONS + """ +} diff --git a/modules/peddy/meta.yml b/modules/peddy/meta.yml new file mode 100644 index 00000000..7c3fcf45 --- /dev/null +++ b/modules/peddy/meta.yml @@ -0,0 +1,64 @@ +name: peddy +description: Manipulation, validation and exploration of pedigrees +keywords: + - pedigrees + - ped + - family + +tools: + - peddy: + description: genotype, ped correspondence check, ancestry check, sex check. directly, quickly on VCF + homepage: https://github.com/brentp/peddy + documentation: https://peddy.readthedocs.io/en/latest/ + tool_dev_url: https://github.com/brentp/peddy + doi: "https://doi.org/10.1016/j.ajhg.2017.01.017" + licence: ['MIT'] + +input: + - meta: + type: map + description: | + Groovy Map containing sample information + e.g. [ id:'test', single_end:false ] + - vcf: + type: file + description: VCF file + pattern: "*.{vcf.gz}" + - ped: + type: file + description: PED/FAM file + pattern: "*.{ped,fam}" + - vcf_tbi: + type: file + description: TBI file + pattern: "*.{vcf.gz.tbi}" + +output: + - meta: + type: map + description: | + Groovy Map containing sample information + e.g. [ id:'test', single_end:false ] + - ped: + type: file + description: PED/FAM file + pattern: "*.peddy.{ped}" + - html: + type: file + description: HTML file + pattern: "*.{html}" + - csv: + type: file + description: CSV file + pattern: "*.{csv}" + - png: + type: file + description: PNG file + pattern: "*.{png}" + - versions: + type: file + description: File containing software versions + pattern: "versions.yml" + +authors: + - "@rannick" diff --git a/tests/config/pytest_modules.yml b/tests/config/pytest_modules.yml index 7b47bfea..d68d64d0 100644 --- a/tests/config/pytest_modules.yml +++ b/tests/config/pytest_modules.yml @@ -1019,6 +1019,10 @@ picard/collecthsmetrics: - modules/picard/collecthsmetrics/** - tests/modules/picard/collecthsmetrics/** +peddy: + - modules/peddy/** + - tests/modules/peddy/** + picard/collectmultiplemetrics: - modules/picard/collectmultiplemetrics/** - tests/modules/picard/collectmultiplemetrics/** diff --git a/tests/config/test_data.config b/tests/config/test_data.config index c3bae012..0c7ce2fc 100644 --- a/tests/config/test_data.config +++ b/tests/config/test_data.config @@ -128,6 +128,10 @@ params { index_salmon = "${test_data_dir}/genomics/homo_sapiens/genome/index/salmon" repeat_expansions = "${test_data_dir}/genomics/homo_sapiens/genome/loci/repeat_expansions.json" + justhusky_ped = "${test_data_dir}/genomics/homo_sapiens/genome/vcf/ped/justhusky.ped" + justhusky_minimal_vcf_gz = "${test_data_dir}/genomics/homo_sapiens/genome/vcf/ped/justhusky_minimal.vcf.gz" + justhusky_minimal_vcf_gz_tbi = "${test_data_dir}/genomics/homo_sapiens/genome/vcf/ped/justhusky_minimal.vcf.gz.tbi" + } 'illumina' { test_paired_end_sorted_bam = "${test_data_dir}/genomics/homo_sapiens/illumina/bam/test.paired_end.sorted.bam" diff --git a/tests/modules/peddy/main.nf b/tests/modules/peddy/main.nf new file mode 100644 index 00000000..d6331752 --- /dev/null +++ b/tests/modules/peddy/main.nf @@ -0,0 +1,17 @@ +#!/usr/bin/env nextflow + +nextflow.enable.dsl = 2 + +include { PEDDY } from '../../../modules/peddy/main.nf' addParams( options: [:] ) + +workflow test_peddy { + + input = [ + [ id:'test', single_end:false ], + file(params.test_data['homo_sapiens']['genome']['justhusky_minimal_vcf_gz'], checkIfExists: true), + file(params.test_data['homo_sapiens']['genome']['justhusky_minimal_vcf_gz_tbi'], checkIfExists: true) + ] + ped = file(params.test_data['homo_sapiens']['genome']['justhusky_ped'], checkIfExists: true) + + PEDDY ( input , ped ) +} diff --git a/tests/modules/peddy/test.yml b/tests/modules/peddy/test.yml new file mode 100644 index 00000000..77bf00f6 --- /dev/null +++ b/tests/modules/peddy/test.yml @@ -0,0 +1,17 @@ +- name: peddy test_peddy + command: nextflow run tests/modules/peddy -entry test_peddy -c tests/config/nextflow.config + tags: + - peddy + files: + - path: output/peddy/justhusky_minimal.het_check.csv + md5sum: f4006d47355f2a760e40215b403926c3 + - path: output/peddy/justhusky_minimal.html + md5sum: 4f189cdbe8f03fe5c32d343c183506a5 + - path: output/peddy/justhusky_minimal.ped_check.csv + md5sum: d79a98558e280afe794d1374d2b985d4 + - path: output/peddy/justhusky_minimal.ped_check.rel-difference.csv + md5sum: 9de7e287cb30c742db2ff3622b0e63b1 + - path: output/peddy/justhusky_minimal.sex_check.csv + md5sum: 60848489bc697490da6a53b5170baf3b + - path: output/peddy/justhusky_minimal.vs.html + md5sum: 20f5f3a97fa781057c876ac79e044010