From a8720463ac0d655876bd7b8d78c6d7a00ecd9bc6 Mon Sep 17 00:00:00 2001 From: Yuk Kei Wan <41866052+yuukiiwa@users.noreply.github.com> Date: Fri, 30 Apr 2021 20:18:58 +0800 Subject: [PATCH] add graphmap index and align modules (from nanoseq modules) (#468) * add graphmap index module * add graphmap2/index * add graohmap2 align module * remove graphmap2 align md5sum --- software/graphmap2/align/functions.nf | 70 +++++++++++++++++++++++++ software/graphmap2/align/main.nf | 35 +++++++++++++ software/graphmap2/align/meta.yml | 49 +++++++++++++++++ software/graphmap2/index/functions.nf | 70 +++++++++++++++++++++++++ software/graphmap2/index/main.nf | 31 +++++++++++ software/graphmap2/index/meta.yml | 28 ++++++++++ tests/config/pytest_software.yml | 8 +++ tests/software/graphmap2/align/main.nf | 17 ++++++ tests/software/graphmap2/align/test.yml | 7 +++ tests/software/graphmap2/index/main.nf | 12 +++++ tests/software/graphmap2/index/test.yml | 8 +++ 11 files changed, 335 insertions(+) create mode 100644 software/graphmap2/align/functions.nf create mode 100644 software/graphmap2/align/main.nf create mode 100644 software/graphmap2/align/meta.yml create mode 100644 software/graphmap2/index/functions.nf create mode 100644 software/graphmap2/index/main.nf create mode 100644 software/graphmap2/index/meta.yml create mode 100644 tests/software/graphmap2/align/main.nf create mode 100644 tests/software/graphmap2/align/test.yml create mode 100644 tests/software/graphmap2/index/main.nf create mode 100644 tests/software/graphmap2/index/test.yml diff --git a/software/graphmap2/align/functions.nf b/software/graphmap2/align/functions.nf new file mode 100644 index 00000000..9d0137e3 --- /dev/null +++ b/software/graphmap2/align/functions.nf @@ -0,0 +1,70 @@ +/* + * ----------------------------------------------------- + * 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/graphmap2/align/main.nf b/software/graphmap2/align/main.nf new file mode 100644 index 00000000..4f404159 --- /dev/null +++ b/software/graphmap2/align/main.nf @@ -0,0 +1,35 @@ +// Import generic module functions +include { initOptions; saveFiles; getSoftwareName } from './functions' + +params.options = [:] +def options = initOptions(params.options) + +process GRAPHMAP2_ALIGN { + tag "$meta.id" + 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::graphmap=0.6.3" : null) + container "quay.io/biocontainers/graphmap:0.6.3--he513fc3_0" + + input: + tuple val(meta), path(fastq) + path(fasta) + path(index) + + output: + tuple val(meta), path("*.sam"), emit: align_sam + + script: + """ + graphmap2 \\ + align \\ + -t $task.cpus \\ + -r $fasta \\ + -i $index \\ + -d $fastq \\ + -o ${meta.id}.sam \\ + --extcigar + """ +} diff --git a/software/graphmap2/align/meta.yml b/software/graphmap2/align/meta.yml new file mode 100644 index 00000000..5e387d02 --- /dev/null +++ b/software/graphmap2/align/meta.yml @@ -0,0 +1,49 @@ +name: graphmap2_align +description: A versatile pairwise aligner for genomic and spliced nucleotide sequences +keywords: + - align + - fasta + - fastq + - genome + - reference +tools: + - graphmap2: + description: | + A versatile pairwise aligner for genomic and spliced nucleotide sequences. + homepage: https://github.com/lh3/minimap2 + documentation: https://github.com/lh3/minimap2#uguide +input: + - meta: + type: map + description: | + Groovy Map containing sample information + e.g. [ id:'test', single_end:false ] + - fastq: + type: file + description: | + List of input FASTQ files + and paired-end data, respectively. + - fasta: + type: file + description: | + Reference database in FASTA format. + - index: + type: file + description: | + FASTA index in gmidx. +output: + - meta: + type: map + description: | + Groovy Map containing sample information + e.g. [ id:'test', single_end:false ] + - sam: + type: file + description: Alignment in SAM format + pattern: "*.sam" + - version: + type: file + description: File containing software version + pattern: "*.{version.txt}" +authors: + - "@yuukiiwa" diff --git a/software/graphmap2/index/functions.nf b/software/graphmap2/index/functions.nf new file mode 100644 index 00000000..9d0137e3 --- /dev/null +++ b/software/graphmap2/index/functions.nf @@ -0,0 +1,70 @@ +/* + * ----------------------------------------------------- + * 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/graphmap2/index/main.nf b/software/graphmap2/index/main.nf new file mode 100644 index 00000000..1c24d8b1 --- /dev/null +++ b/software/graphmap2/index/main.nf @@ -0,0 +1,31 @@ +// Import generic module functions +include { initOptions; saveFiles; getSoftwareName } from './functions' + +params.options = [:] +def options = initOptions(params.options) + +process GRAPHMAP2_INDEX { + publishDir "${params.outdir}", + mode: params.publish_dir_mode, + saveAs: { filename -> saveFiles(filename:filename, options:params.options, publish_dir:getSoftwareName(task.process), publish_id:'') } + + conda (params.enable_conda ? "bioconda::graphmap=0.6.3" : null) + container "quay.io/biocontainers/graphmap:0.6.3--he513fc3_0" + + input: + path(fasta) + + output: + path("*.gmidx") ,emit: index + path "*.version.txt" ,emit: version + + script: + """ + graphmap2 \\ + align \\ + -t $task.cpus \\ + -I \\ + -r $fasta + echo \$(graphmap2 2>&1) > graphmap2.version.txt + """ +} diff --git a/software/graphmap2/index/meta.yml b/software/graphmap2/index/meta.yml new file mode 100644 index 00000000..07d335dc --- /dev/null +++ b/software/graphmap2/index/meta.yml @@ -0,0 +1,28 @@ +name: graphmap2_index +description: A versatile pairwise aligner for genomic and spliced nucleotide sequences +keywords: + - index + - fasta + - reference +tools: + - graphmap2: + description: | + A versatile pairwise aligner for genomic and spliced nucleotide sequences. + homepage: https://github.com/lbcb-sci/graphmap2 + documentation: https://github.com/lbcb-sci/graphmap2#graphmap2---a-highly-sensitive-and-accurate-mapper-for-long-error-prone-reads +input: + - fasta: + type: file + description: | + Reference database in FASTA format. +output: + - gmidx: + type: file + description: Graphmap2 fasta index in gmidx format + pattern: "*.gmidx" + - version: + type: file + description: File containing software version + pattern: "*.{version.txt}" +authors: + - "@yuukiiwa" diff --git a/tests/config/pytest_software.yml b/tests/config/pytest_software.yml index e75f8774..f7ec03e1 100644 --- a/tests/config/pytest_software.yml +++ b/tests/config/pytest_software.yml @@ -274,6 +274,14 @@ gffread: - software/gffread/** - tests/software/gffread/** +graphmap2/align: + - software/graphmap2/align/** + - tests/software/graphmap2/align/** + +graphmap2/index: + - software/graphmap2/index/** + - tests/software/graphmap2/index/** + gubbins: - software/gubbins/** - tests/software/gubbins/** diff --git a/tests/software/graphmap2/align/main.nf b/tests/software/graphmap2/align/main.nf new file mode 100644 index 00000000..7026c915 --- /dev/null +++ b/tests/software/graphmap2/align/main.nf @@ -0,0 +1,17 @@ +#!/usr/bin/env nextflow + +nextflow.enable.dsl = 2 + +include { GRAPHMAP2_INDEX } from '../../../../software/graphmap2/index/main.nf' addParams( options: [:] ) +include { GRAPHMAP2_ALIGN } from '../../../../software/graphmap2/align/main.nf' addParams( options: [:] ) + +workflow test_graphmap2_align { + + input = [ [ id:'test' ], // meta map + [ file(params.test_data['sarscov2']['nanopore']['test_fastq_gz'], checkIfExists: true) ] + ] + fasta = file(params.test_data['sarscov2']['genome']['genome_fasta'], checkIfExists: true) + + GRAPHMAP2_INDEX ( fasta ) + GRAPHMAP2_ALIGN ( input, fasta, GRAPHMAP2_INDEX.out.index ) +} diff --git a/tests/software/graphmap2/align/test.yml b/tests/software/graphmap2/align/test.yml new file mode 100644 index 00000000..698f6f50 --- /dev/null +++ b/tests/software/graphmap2/align/test.yml @@ -0,0 +1,7 @@ +- name: graphmap2 align + command: nextflow run ./tests/software/graphmap2/align -entry test_graphmap2_align -c tests/config/nextflow.config + tags: + - graphmap2 + - graphmap2/align + files: + - path: ./output/graphmap2/test.sam diff --git a/tests/software/graphmap2/index/main.nf b/tests/software/graphmap2/index/main.nf new file mode 100644 index 00000000..d1873678 --- /dev/null +++ b/tests/software/graphmap2/index/main.nf @@ -0,0 +1,12 @@ +#!/usr/bin/env nextflow + +nextflow.enable.dsl = 2 + +include { GRAPHMAP2_INDEX } from '../../../../software/graphmap2/index/main.nf' addParams( options: [:] ) + +workflow test_graphmap2_index { + + fasta = file(params.test_data['sarscov2']['genome']['genome_fasta'], checkIfExists: true) + + GRAPHMAP2_INDEX ( fasta ) +} diff --git a/tests/software/graphmap2/index/test.yml b/tests/software/graphmap2/index/test.yml new file mode 100644 index 00000000..d6a8d166 --- /dev/null +++ b/tests/software/graphmap2/index/test.yml @@ -0,0 +1,8 @@ +- name: graphmap2 index + command: nextflow run ./tests/software/graphmap2/index -entry test_graphmap2_index -c tests/config/nextflow.config + tags: + - graphmap2 + - graphmap2/index + files: + - path: ./output/graphmap2/genome.fasta.gmidx + md5sum: 2973f9b7fa52c78899c73908f8afc6be