module: bwa/samse (#626)

* 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 bwa samse

* Fix container paths

* remove TODO comment

* Updated based on code from from @grst on bwa/sampe

* Clarify output docs
This commit is contained in:
James A. Fellows Yates 2021-08-02 15:21:23 +02:00 committed by GitHub
parent e01a98a704
commit 8a2f01c416
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/samse/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_SAMSE {
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 samse \\
$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,59 @@
name: bwa_samse
description: Convert bwa SA coordinate file 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/samse:
- modules/bwa/samse/**
- tests/modules/bwa/samse/**
bwamem2/index: bwamem2/index:
- modules/bwamem2/index/** - modules/bwamem2/index/**
- tests/modules/bwamem2/index/** - tests/modules/bwamem2/index/**

View file

@ -0,0 +1,19 @@
#!/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_SAMSE } from '../../../../modules/bwa/samse/main.nf' addParams( options: [:] )
workflow test_bwa_samse {
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 )
BWA_SAMSE ( BWA_ALN.out.sai, BWA_INDEX.out.index )
}

View file

@ -0,0 +1,8 @@
- name: bwa samse
command: nextflow run ./tests/modules/bwa/samse -entry test_bwa_samse -c tests/config/nextflow.config
tags:
- bwa
- bwa/samse
files:
- path: output/bwa/test.bam
md5sum: 27eb91146e45dee65664c18596be4262