From f7ebc2fc48d7b0016e7dc7c9ffdf0c86d75106d1 Mon Sep 17 00:00:00 2001 From: Charles Plessy Date: Tue, 8 Jun 2021 18:13:51 +0900 Subject: [PATCH] New last/dotplot module for pairwise similarity plots (#529) * New last/dotplot module for pairwise similarity plots The `last-dotplot` tool takes a pairwise alignment in [MAF](http://genome.ucsc.edu/FAQ/FAQformat.html#format5) format, possibly compressed with gzip, or in a tabular format produced by the `maf-convert` tool, and produces a similarity dot-plot of the two sequences in one of the graphical formats supported by the Python Imaging Library. A the tool guesses the output format by the file extension of the file, which is constructed by the module at run time, I have used the `args2` option to convey this information to the module. This new module is part of the work described in Issue #464. During this development, we fix the version of LAST to 1219 to ensure consistency (hence please ignore lint's version warning). * Update the functions.nf file to the dev branch. https://raw.githubusercontent.com/nf-core/tools/dev/nf_core/module-template/software/functions.nf --- software/last/dotplot/functions.nf | 68 ++++++++++++++++++++++++++++ software/last/dotplot/main.nf | 41 +++++++++++++++++ software/last/dotplot/meta.yml | 40 ++++++++++++++++ tests/config/pytest_software.yml | 12 +++-- tests/software/last/dotplot/main.nf | 23 ++++++++++ tests/software/last/dotplot/test.yml | 17 +++++++ 6 files changed, 197 insertions(+), 4 deletions(-) create mode 100644 software/last/dotplot/functions.nf create mode 100644 software/last/dotplot/main.nf create mode 100644 software/last/dotplot/meta.yml create mode 100644 tests/software/last/dotplot/main.nf create mode 100644 tests/software/last/dotplot/test.yml diff --git a/software/last/dotplot/functions.nf b/software/last/dotplot/functions.nf new file mode 100644 index 00000000..da9da093 --- /dev/null +++ b/software/last/dotplot/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/software/last/dotplot/main.nf b/software/last/dotplot/main.nf new file mode 100644 index 00000000..ea391b7b --- /dev/null +++ b/software/last/dotplot/main.nf @@ -0,0 +1,41 @@ +// Import generic module functions +include { initOptions; saveFiles; getSoftwareName } from './functions' + +params.options = [:] +options = initOptions(params.options) + +process LAST_DOTPLOT { + 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::last=1219" : null) + if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) { + container "https://depot.galaxyproject.org/singularity/last:1219--h2e03b76_0" + } else { + container "quay.io/biocontainers/last:1219--h2e03b76_0" + } + + input: + tuple val(meta), path(maf) + + output: + tuple val(meta), path("*.{png,gif}"), emit: plot + path "*.version.txt" , emit: version + + script: + def software = getSoftwareName(task.process) + def format = options.args2 ? options.args2 : "png" + def prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}" + """ + last-dotplot \\ + $options.args \\ + $maf \\ + $prefix.$format + + # last-dotplot has no --version option so let's use lastal from the same suite + lastal --version | sed 's/lastal //' > ${software}.version.txt + """ +} diff --git a/software/last/dotplot/meta.yml b/software/last/dotplot/meta.yml new file mode 100644 index 00000000..856d7e1c --- /dev/null +++ b/software/last/dotplot/meta.yml @@ -0,0 +1,40 @@ +name: last_dotplot +description: Makes a dotplot (Oxford Grid) of pair-wise sequence alignments +keywords: + - LAST + - plot + - pair + - alignment + - MAF +tools: + - last: + description: LAST finds & aligns related regions of sequences. + homepage: https://gitlab.com/mcfrith/last + documentation: https://gitlab.com/mcfrith/last/-/blob/main/doc/last-dotplot.rst + tool_dev_url: https://gitlab.com/mcfrith/last + doi: "" + licence: ['GPL-3.0-or-later'] + +input: + - meta: + type: map + description: | + Groovy Map containing sample information + e.g. [ id:'test', single_end:false ] + - maf: + type: file + description: Multiple Aligment Format (MAF) file, compressed with gzip + pattern: "*.{maf.gz}" + +output: + - plot: + type: file + description: Pairwise alignment dot plot image, in PNG or other format. + pattern: "*.{gif,png}" + - version: + type: file + description: File containing software version + pattern: "*.{version.txt}" + +authors: + - "@charles-plessy" diff --git a/tests/config/pytest_software.yml b/tests/config/pytest_software.yml index 28bd3b0d..069b3825 100644 --- a/tests/config/pytest_software.yml +++ b/tests/config/pytest_software.yml @@ -378,6 +378,10 @@ kraken2/run: - software/untar/** - tests/software/kraken2/run/** +last/dotplot: + - software/last/dotplot/** + - tests/software/last/dotplot/** + last/lastal: - software/last/lastal/** - tests/software/last/lastal/** @@ -455,14 +459,14 @@ optitype: - software/optitype/** - tests/software/optitype/** -pairtools/flip: - - software/pairtools/flip/** - - tests/software/pairtools/flip/** - pairtools/dedup: - software/pairtools/dedup/** - tests/software/pairtools/dedup/** +pairtools/flip: + - software/pairtools/flip/** + - tests/software/pairtools/flip/** + pairtools/parse: - software/pairtools/parse/** - tests/software/pairtools/parse/** diff --git a/tests/software/last/dotplot/main.nf b/tests/software/last/dotplot/main.nf new file mode 100644 index 00000000..ae4534f1 --- /dev/null +++ b/tests/software/last/dotplot/main.nf @@ -0,0 +1,23 @@ +#!/usr/bin/env nextflow + +nextflow.enable.dsl = 2 + +include { LAST_DOTPLOT } from '../../../../software/last/dotplot/main.nf' addParams( options: [:] ) + +workflow test_last_dotplot { + + input = [ [ id:'test' ], // meta map + file(params.test_data['sarscov2']['genome']['contigs_genome_maf_gz'], checkIfExists: true) ] + + LAST_DOTPLOT ( input ) +} + +include { LAST_DOTPLOT as LAST_DOTPLOT_GIF } from '../../../../software/last/dotplot/main.nf' addParams( options: [args2:'gif'] ) + +workflow test_last_dotplot_gif { + + input = [ [ id:'test' ], // meta map + file(params.test_data['sarscov2']['genome']['contigs_genome_maf_gz'], checkIfExists: true) ] + + LAST_DOTPLOT_GIF ( input ) +} diff --git a/tests/software/last/dotplot/test.yml b/tests/software/last/dotplot/test.yml new file mode 100644 index 00000000..ffd7c32b --- /dev/null +++ b/tests/software/last/dotplot/test.yml @@ -0,0 +1,17 @@ +- name: last dotplot test_last_dotplot + command: nextflow run tests/software/last/dotplot -entry test_last_dotplot -c tests/config/nextflow.config + tags: + - last + - last/dotplot + files: + - path: output/last/test.png + md5sum: 6189aaf96f522cdb664869724997bbcd + +- name: last dotplot test_last_dotplot_gif + command: nextflow run tests/software/last/dotplot -entry test_last_dotplot_gif -c tests/config/nextflow.config + tags: + - last + - last/dotplot + files: + - path: output/last/test.gif + md5sum: 1dd2c85fb5495ca0e85c4ef1dcfce220