module: bwa/aln (#624)

* 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

* fix container paths

* Sync bwa version samese/sampe

* Apply suggestions from code review

Co-authored-by: Harshil Patel <drpatelh@users.noreply.github.com>
This commit is contained in:
James A. Fellows Yates 2021-07-27 09:13:48 +02:00 committed by GitHub
parent a21cc95c69
commit 45dee96bdf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 275 additions and 6 deletions

View file

@ -429,6 +429,16 @@ using a combination of `bwa` and `samtools` to output a BAM file instead of a SA
- All function names MUST follow the `camelCase` convention. - All function names MUST follow the `camelCase` convention.
#### Input/output options
- Input channel declarations MUST be defined for all _possible_ input files (i.e. both required and optional files).
- Directly associated auxiliary files to an input file MAY be defined within the same input channel alongside the main input channel (e.g. [BAM and BAI](https://github.com/nf-core/modules/blob/e937c7950af70930d1f34bb961403d9d2aa81c7d/modules/samtools/flagstat/main.nf#L22)).
- Other generic auxiliary files used across different input files (e.g. common reference sequences) MAY be defined using a dedicated input channel (e.g. [reference files](https://github.com/nf-core/modules/blob/3cabc95d0ed8a5a4e07b8f9b1d1f7ff9a70f61e1/modules/bwa/mem/main.nf#L21-L23)).
- Named file extensions MUST be emitted for ALL output channels e.g. `path "*.txt", emit: txt`.
- Optional inputs are not currently supported by Nextflow. However, passing an empty list (`[]`) instead of a file as a module parameter can be used to work around this issue.
#### Module parameters #### Module parameters
- A module file SHOULD only define input and output files as command-line parameters to be executed within the process. - A module file SHOULD only define input and output files as command-line parameters to be executed within the process.
@ -439,12 +449,6 @@ using a combination of `bwa` and `samtools` to output a BAM file instead of a SA
- Any parameters that need to be evaluated in the context of a particular sample e.g. single-end/paired-end data MUST also be defined within the process. - Any parameters that need to be evaluated in the context of a particular sample e.g. single-end/paired-end data MUST also be defined within the process.
#### Input/output options
- Named file extensions MUST be emitted for ALL output channels e.g. `path "*.txt", emit: txt`.
- Optional inputs are not currently supported by Nextflow. However, passing an empty list (`[]`) instead of a file as a module parameter can be used to work around this issue.
#### Resource requirements #### Resource requirements
- An appropriate resource `label` MUST be provided for the module as listed in the [nf-core pipeline template](https://github.com/nf-core/tools/blob/master/nf_core/pipeline-template/conf/base.config#L29-L46) e.g. `process_low`, `process_medium` or `process_high`. - An appropriate resource `label` MUST be provided for the module as listed in the [nf-core pipeline template](https://github.com/nf-core/tools/blob/master/nf_core/pipeline-template/conf/base.config#L29-L46) e.g. `process_low`, `process_medium` or `process_high`.

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

67
modules/bwa/aln/main.nf Normal file
View file

@ -0,0 +1,67 @@
// Import generic module functions
include { initOptions; saveFiles; getSoftwareName } from './functions'
params.options = [:]
options = initOptions(params.options)
process BWA_ALN {
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" : null)
if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) {
container "https://depot.galaxyproject.org/singularity/bwa:0.7.17--h5bf99c6_8"
} else {
container "quay.io/biocontainers/bwa:0.7.17--h5bf99c6_8"
}
input:
tuple val(meta), path(reads)
path index
output:
tuple val(meta), path(reads), path("*.sai"), emit: sai
path "*.version.txt" , emit: version
script:
def software = getSoftwareName(task.process)
def prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}"
if (meta.single_end) {
"""
INDEX=`find -L ./ -name "*.amb" | sed 's/.amb//'`
bwa aln \\
$options.args \\
-t $task.cpus \\
-f ${prefix}.sai \\
\$INDEX \\
${reads}
echo \$(bwa 2>&1) | sed 's/^.*Version: //; s/Contact:.*\$//' > ${software}.version.txt
"""
} else {
"""
INDEX=`find -L ./ -name "*.amb" | sed 's/.amb//'`
bwa aln \\
$options.args \\
-t $task.cpus \\
-f ${prefix}.1.sai \\
\$INDEX \\
${reads[0]}
bwa aln \\
$options.args \\
-t $task.cpus \\
-f ${prefix}.2.sai \\
\$INDEX \\
${reads[1]}
echo \$(bwa 2>&1) | sed 's/^.*Version: //; s/Contact:.*\$//' > ${software}.version.txt
"""
}
}

54
modules/bwa/aln/meta.yml Normal file
View file

@ -0,0 +1,54 @@
name: bwa_aln
description: Find SA coordinates of the input reads for bwa short-read mapping
keywords:
- bwa
- aln
- short-read
- align
- reference
- fasta
- map
- fastq
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: |
List of input FastQ files of size 1 and 2 for single-end and paired-end data,
respectively.
- index:
type: file
description: BWA genome index files
pattern: "Directory containing BWA index *.{amb,ann,bwt,pac,sa}"
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}"
- sai:
type: file
description: SA coordinate file
pattern: "*.sai"
authors:
- "@jfy133"

View file

@ -158,6 +158,10 @@ bowtie2/build:
- modules/bowtie2/build/** - modules/bowtie2/build/**
- tests/modules/bowtie2/build_test/** - tests/modules/bowtie2/build_test/**
bwa/aln:
- modules/bwa/aln/**
- tests/modules/bwa/aln/**
bwa/index: bwa/index:
- modules/bwa/index/** - modules/bwa/index/**
- tests/modules/bwa/index/** - tests/modules/bwa/index/**

View file

@ -0,0 +1,33 @@
#!/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: [:] )
//
// Test with single-end data
//
workflow test_bwa_aln_single_end {
input = [ [ id:'test', single_end:true ], // meta map
[ file(params.test_data['sarscov2']['illumina']['test_1_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 )
}
//
// Test with paired-end data
//
workflow test_bwa_aln_paired_end {
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 )
}

View file

@ -0,0 +1,39 @@
- name: bwa aln single-end
command: nextflow run ./tests/modules/bwa/aln -entry test_bwa_aln_single_end -c tests/config/nextflow.config
tags:
- bwa
- bwa/aln
files:
- path: ./output/bwa/test.sai
md5sum: aaaf39b6814c96ca1a5eacc662adf926
- path: ./output/index/bwa/genome.bwt
md5sum: 0469c30a1e239dd08f68afe66fde99da
- path: ./output/index/bwa/genome.amb
md5sum: 3a68b8b2287e07dd3f5f95f4344ba76e
- path: ./output/index/bwa/genome.ann
md5sum: c32e11f6c859f166c7525a9c1d583567
- path: ./output/index/bwa/genome.pac
md5sum: 983e3d2cd6f36e2546e6d25a0da78d66
- path: ./output/index/bwa/genome.sa
md5sum: ab3952cabf026b48cd3eb5bccbb636d1
- name: bwa aln paired-end
command: nextflow run ./tests/modules/bwa/aln -entry test_bwa_aln_paired_end -c tests/config/nextflow.config
tags:
- bwa
- bwa/aln
files:
- path: ./output/bwa/test.1.sai
md5sum: aaaf39b6814c96ca1a5eacc662adf926
- path: ./output/bwa/test.2.sai
md5sum: b4f185d9b4cb256dd5c377070a536124
- path: ./output/index/bwa/genome.bwt
md5sum: 0469c30a1e239dd08f68afe66fde99da
- path: ./output/index/bwa/genome.amb
md5sum: 3a68b8b2287e07dd3f5f95f4344ba76e
- path: ./output/index/bwa/genome.ann
md5sum: c32e11f6c859f166c7525a9c1d583567
- path: ./output/index/bwa/genome.pac
md5sum: 983e3d2cd6f36e2546e6d25a0da78d66
- path: ./output/index/bwa/genome.sa
md5sum: ab3952cabf026b48cd3eb5bccbb636d1