module: bwa/sampe (#625)

* Specify more guidelines on input channels

* Linting

* Updates based on code review

* Update README.md

* Fix broken sentence

* Add bwa/aln module

* Also output reads as required with SAI

* Add sampe

* Fix container paths

* Update based on code review from @grst

* Update input docs
This commit is contained in:
James A. Fellows Yates 2021-08-02 15:37:48 +02:00 committed by GitHub
parent 8a2f01c416
commit 4f1c1601cf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 204 additions and 0 deletions

View file

@ -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"
}
}
}

46
modules/bwa/sampe/main.nf Normal file
View file

@ -0,0 +1,46 @@
// Import generic module functions
include { initOptions; saveFiles; getSoftwareName } from './functions'
params.options = [:]
options = initOptions(params.options)
process BWA_SAMPE {
tag "$meta.id"
label 'process_medium'
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::bwa=0.7.17 bioconda::samtools=1.12" : null)
if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) {
container "https://depot.galaxyproject.org/singularity/mulled-v2-fe8faa35dbf6dc65a0f7f5d4ea12e31a79f73e40:66ed1b38d280722529bb8a0167b0cf02f8a0b488-0"
} else {
container "quay.io/biocontainers/mulled-v2-fe8faa35dbf6dc65a0f7f5d4ea12e31a79f73e40:66ed1b38d280722529bb8a0167b0cf02f8a0b488-0"
}
input:
tuple val(meta), path(reads), path(sai)
path index
output:
tuple val(meta), path("*.bam"), emit: bam
path "*.version.txt" , emit: version
script:
def software = getSoftwareName(task.process)
def prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}"
def read_group = meta.read_group ? "-r ${meta.read_group}" : ""
"""
INDEX=`find -L ./ -name "*.amb" | sed 's/.amb//'`
bwa sampe \\
$options.args \\
$read_group \\
\$INDEX \\
$sai \\
$reads | samtools sort -@ ${task.cpus - 1} -O bam - > ${prefix}.bam
echo \$(bwa 2>&1) | sed 's/^.*Version: //; s/Contact:.*\$//' > ${software}.version.txt
"""
}

View file

@ -0,0 +1,58 @@
name: bwa_sampe
description: Convert paired-end bwa SA coordinate files to SAM format
keywords:
- bwa
- aln
- short-read
- align
- reference
- fasta
- map
- sam
- bam
tools:
- bwa:
description: |
BWA is a software package for mapping DNA sequences against
a large reference genome, such as the human genome.
homepage: http://bio-bwa.sourceforge.net/
documentation: http://bio-bwa.sourceforge.net/
doi: "10.1093/bioinformatics/btp324"
licence: ['GPL v3']
input:
- meta:
type: map
description: |
Groovy Map containing sample information.
e.g. [ id:'test', single_end:false ]
- reads:
type: file
description: FASTQ files specified alongside meta in input channel.
pattern: "*.{fastq,fq}.gz"
- sai:
type: file
description: SAI file specified alongside meta and reads in input channel.
pattern: "*.sai"
- index:
type: directory
description: Directory containing BWA index files (amb,ann,bwt,pac,sa) from BWA_INDEX
pattern: "bwa/"
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}"
- bam:
type: file
description: BAM file
pattern: "*.bam"
authors:
- "@jfy133"

View file

@ -170,6 +170,10 @@ bwa/mem:
- modules/bwa/mem/** - modules/bwa/mem/**
- tests/modules/bwa/mem/** - tests/modules/bwa/mem/**
bwa/sampe:
- modules/bwa/sampe/**
- tests/modules/bwa/sampe/**
bwa/samse: bwa/samse:
- modules/bwa/samse/** - modules/bwa/samse/**
- tests/modules/bwa/samse/** - tests/modules/bwa/samse/**

View file

@ -0,0 +1,20 @@
#!/usr/bin/env nextflow
nextflow.enable.dsl = 2
include { BWA_INDEX } from '../../../../modules/bwa/index/main.nf' addParams( options: [:] )
include { BWA_ALN } from '../../../../modules/bwa/aln/main.nf' addParams( options: [:] )
include { BWA_SAMPE } from '../../../../modules/bwa/sampe/main.nf' addParams( options: [:] )
workflow test_bwa_sampe {
input = [ [ id:'test', single_end:false ], // meta map
[ file(params.test_data['sarscov2']['illumina']['test_1_fastq_gz'], checkIfExists: true),
file(params.test_data['sarscov2']['illumina']['test_2_fastq_gz'], checkIfExists: true) ]
]
fasta = file(params.test_data['sarscov2']['genome']['genome_fasta'], checkIfExists: true)
BWA_INDEX ( fasta )
BWA_ALN ( input, BWA_INDEX.out.index )
BWA_SAMPE ( BWA_ALN.out.sai, BWA_INDEX.out.index )
}

View file

@ -0,0 +1,8 @@
- name: bwa sampe
command: nextflow run ./tests/modules/bwa/sampe -entry test_bwa_sampe -c tests/config/nextflow.config
tags:
- bwa
- bwa/sampe
files:
- path: output/bwa/test.bam
md5sum: f6ad85d66d44c5d26e692109d2e34100