diff --git a/.github/workflows/bowtie_align.yml b/.github/workflows/bowtie_align.yml new file mode 100644 index 00000000..8b9a19fe --- /dev/null +++ b/.github/workflows/bowtie_align.yml @@ -0,0 +1,42 @@ +name: bowtie_align +on: + push: + paths: + - software/bowtie/align/** + - software/bowtie/index/** + - .github/workflows/bowtie_align.yml + - tests/software/bowtie/** + pull_request: + paths: + - software/bowtie/align/** + - software/bowtie/index/** + - .github/workflows/bowtie_align.yml + - tests/software/bowtie/** + +jobs: + ci_test: + runs-on: ubuntu-latest + strategy: + matrix: + nxf_version: [20.11.0-edge] + env: + NXF_ANSI_LOG: false + steps: + - uses: actions/checkout@v2 + + - name: Install Nextflow + env: + NXF_VER: ${{ matrix.nxf_version }} + run: | + wget -qO- get.nextflow.io | bash + sudo mv nextflow /usr/local/bin/ + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: "3.x" + - name: Install dependencies + run: python -m pip install --upgrade pip pytest-workflow + + # Test the module + - run: pytest --tag bowtie_align --symlink --wt 2 diff --git a/.github/workflows/bowtie_index.yml b/.github/workflows/bowtie_index.yml new file mode 100644 index 00000000..291d04f5 --- /dev/null +++ b/.github/workflows/bowtie_index.yml @@ -0,0 +1,40 @@ +name: bowtie_index +on: + push: + paths: + - software/bowtie/index/** + - .github/workflows/bowtie_index.yml + - tests/software/bowtie/** + pull_request: + paths: + - software/bowtie/index/** + - .github/workflows/bowtie_index.yml + - tests/software/bowtie/** + +jobs: + ci_test: + runs-on: ubuntu-latest + strategy: + matrix: + nxf_version: [20.11.0-edge] + env: + NXF_ANSI_LOG: false + steps: + - uses: actions/checkout@v2 + + - name: Install Nextflow + env: + NXF_VER: ${{ matrix.nxf_version }} + run: | + wget -qO- get.nextflow.io | bash + sudo mv nextflow /usr/local/bin/ + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: "3.x" + - name: Install dependencies + run: python -m pip install --upgrade pip pytest-workflow + + # Test the module + - run: pytest --tag bowtie_index --symlink --wt 2 diff --git a/software/bowtie/align/functions.nf b/software/bowtie/align/functions.nf new file mode 100644 index 00000000..6f3b4b29 --- /dev/null +++ b/software/bowtie/align/functions.nf @@ -0,0 +1,60 @@ + +/* + * ----------------------------------------------------- + * 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.publish_by_id = args.publish_by_id ?: false + 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_id) { + path_list.add(args.publish_id) + } + 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/bowtie/align/main.nf b/software/bowtie/align/main.nf new file mode 100644 index 00000000..de9e8b3d --- /dev/null +++ b/software/bowtie/align/main.nf @@ -0,0 +1,59 @@ +// Import generic module functions +include { initOptions; saveFiles; getSoftwareName } from './functions' + +params.options = [:] +def options = initOptions(params.options) + +process BOWTIE_ALIGN { + tag "$meta.id" + label 'process_high' + publishDir "${params.outdir}", + mode: params.publish_dir_mode, + saveAs: { filename -> saveFiles(filename:filename, options:params.options, publish_dir:getSoftwareName(task.process), publish_id:meta.id) } + + conda (params.enable_conda ? 'bioconda::bowtie=1.3.0 bioconda::samtools=1.10' : null) + if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) { + container 'https://depot.galaxyproject.org/singularity/mulled-v2-ffbf83a6b0ab6ec567a336cf349b80637135bca3:9e14e16c284d6860574cf5b624bbc44c793cb024-0' + } else { + container 'quay.io/biocontainers/mulled-v2-ffbf83a6b0ab6ec567a336cf349b80637135bca3:9e14e16c284d6860574cf5b624bbc44c793cb024-0' + } + + input: + tuple val(meta), path(reads) + path index + + output: + tuple val(meta), path('*.bam'), emit: bam + tuple val(meta), path('*.out'), emit: log + path '*.version.txt' , emit: version + tuple val(meta), path('*fastq.gz'), optional:true, emit: fastq + + script: + def software = getSoftwareName(task.process) + def prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}" + def unaligned = params.save_unaligned ? "--un ${prefix}.unmapped.fastq" : '' + def endedness = meta.single_end ? "$reads" : "-1 ${reads[0]} -2 ${reads[1]}" + """ + INDEX=`find -L ./ -name "*.3.ebwt" | sed 's/.3.ebwt//'` + bowtie \\ + --threads $task.cpus \\ + --sam \\ + -x \$INDEX \\ + -q \\ + $unaligned \\ + $options.args \\ + $endedness \\ + 2> ${prefix}.out \\ + | samtools view $options.args2 -@ $task.cpus -bS -o ${prefix}.bam - + + if [ -f ${prefix}.unmapped.fastq ]; then + gzip ${prefix}.unmapped.fastq + fi + if [ -f ${prefix}.unmapped_1.fastq ]; then + gzip ${prefix}.unmapped_1.fastq + gzip ${prefix}.unmapped_2.fastq + fi + + echo \$(bowtie --version 2>&1) | sed 's/^.*bowtie-align-s version //; s/ .*\$//' > ${software}.version.txt + """ +} diff --git a/software/bowtie/align/meta.yml b/software/bowtie/align/meta.yml new file mode 100644 index 00000000..ebadcdca --- /dev/null +++ b/software/bowtie/align/meta.yml @@ -0,0 +1,69 @@ +name: bowtie_align +description: Align reads to a reference genome using bowtie +keywords: + - align + - fasta + - genome + - reference +tools: + - bowtie: + description: | + bowtie is a software package for mapping DNA sequences against + a large reference genome, such as the human genome. + homepage: http://bowtie-bio.sourceforge.net/index.shtml + documentation: http://bowtie-bio.sourceforge.net/manual.shtml + arxiv: arXiv:1303.3997 +params: + - outdir: + type: string + description: | + The pipeline's output directory. By default, the module will + output files into `$params.outdir/` + - publish_dir_mode: + type: string + description: | + Value for the Nextflow `publishDir` mode parameter. + Available: symlink, rellink, link, copy, copyNoFollow, move. + - enable_conda: + type: boolean + description: | + Run the module with Conda using the software specified + via the `conda` directive + - singularity_pull_docker_container: + type: boolean + description: | + Instead of directly downloading Singularity images for use with Singularity, + force the workflow to pull and convert Docker containers instead. + - save_unaligned: + type: boolean + description: Save unaligned reads +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: Bowtie genome index files + pattern: "*.ebwt" +output: + - bam: + type: file + description: Output BAM file containing read alignments + pattern: "*.{bam}" + - version: + type: file + description: File containing software version + pattern: "*.{version.txt}" + - fastq: + type: file + description: Unaligned FastQ files + pattern: "*.fastq.gz" +authors: + - "@kevinmenden" diff --git a/software/bowtie/index/functions.nf b/software/bowtie/index/functions.nf new file mode 100644 index 00000000..6f3b4b29 --- /dev/null +++ b/software/bowtie/index/functions.nf @@ -0,0 +1,60 @@ + +/* + * ----------------------------------------------------- + * 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.publish_by_id = args.publish_by_id ?: false + 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_id) { + path_list.add(args.publish_id) + } + 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/bowtie/index/main.nf b/software/bowtie/index/main.nf new file mode 100644 index 00000000..8b982bcf --- /dev/null +++ b/software/bowtie/index/main.nf @@ -0,0 +1,35 @@ +// Import generic module functions +include { initOptions; saveFiles; getSoftwareName } from './functions' + +params.options = [:] +def options = initOptions(params.options) + +process BOWTIE_INDEX { + tag "$fasta" + label 'process_high' + 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::bowtie=1.3.0' : null) + if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) { + container 'https://depot.galaxyproject.org/singularity/bowtie:1.3.0--py38hed8969a_1' + } else { + container 'quay.io/biocontainers/bowtie:1.3.0--py38hed8969a_1' + } + + input: + path fasta + + output: + path 'bowtie', emit: index + path '*.version.txt', emit: version + + script: + def software = getSoftwareName(task.process) + """ + mkdir bowtie + bowtie-build --threads $task.cpus $fasta bowtie/${fasta.baseName} + echo \$(bowtie --version 2>&1) | sed 's/^.*bowtie-align-s version //; s/ .*\$//' > ${software}.version.txt + """ +} diff --git a/software/bowtie/index/meta.yml b/software/bowtie/index/meta.yml new file mode 100644 index 00000000..e5296b05 --- /dev/null +++ b/software/bowtie/index/meta.yml @@ -0,0 +1,51 @@ +name: bowtie_index +description: Create bowtie index for reference genome +keywords: + - index + - fasta + - genome + - reference +tools: + - bowtie: + description: | + bowtie is a software package for mapping DNA sequences against + a large reference genome, such as the human genome. + homepage: http://bowtie-bio.sourceforge.net/index.shtml + documentation: http://bowtie-bio.sourceforge.net/manual.shtml + arxiv: arXiv:1303.3997 +params: + - outdir: + type: string + description: | + The pipeline's output directory. By default, the module will + output files into `$params.outdir/` + - publish_dir_mode: + type: string + description: | + Value for the Nextflow `publishDir` mode parameter. + Available: symlink, rellink, link, copy, copyNoFollow, move. + - enable_conda: + type: boolean + description: | + Run the module with Conda using the software specified + via the `conda` directive + - singularity_pull_docker_container: + type: boolean + description: | + Instead of directly downloading Singularity images for use with Singularity, + force the workflow to pull and convert Docker containers instead. +input: + - fasta: + type: file + description: Input genome fasta file +output: + - index: + type: file + description: Bowtie genome index files + pattern: "*.ebwt" + - version: + type: file + description: File containing software version + pattern: "*.{version.txt}" +authors: + - "@kevinmenden" diff --git a/tests/software/bowtie/main.nf b/tests/software/bowtie/main.nf new file mode 100644 index 00000000..c496a619 --- /dev/null +++ b/tests/software/bowtie/main.nf @@ -0,0 +1,33 @@ +#!/usr/bin/env nextflow + +nextflow.enable.dsl = 2 + +include { BOWTIE_INDEX } from '../../../software/bowtie/index/main.nf' addParams( options: [:] ) +include { BOWTIE_ALIGN } from '../../../software/bowtie/align/main.nf' addParams( options: [:] ) + +workflow test_bowtie_index { + fasta = file("${launchDir}/tests/data/fasta/E_coli/NC_010473.fa", checkIfExists: true) + BOWTIE_INDEX ( fasta ) +} + +workflow test_bowtie_alignment_single_end { + + fasta = file("${launchDir}/tests/data/fasta/E_coli/NC_010473.fa", checkIfExists: true) + BOWTIE_INDEX ( fasta ) + + def input = [] + input = [ [ id:'test', single_end:true ], // meta map + [ file("${launchDir}/tests/data/fastq/rna/test_R1.fastq.gz", checkIfExists: true) ] ] + BOWTIE_ALIGN ( input, BOWTIE_INDEX.out.index ) +} + +workflow test_bowtie_alignment_paired_end { + fasta = file("${launchDir}/tests/data/fasta/E_coli/NC_010473.fa", checkIfExists: true) + BOWTIE_INDEX ( fasta ) + + def input = [] + input = [ [ id:'test', single_end:false ], // meta map + [ file("${launchDir}/tests/data/fastq/rna/test_R1.fastq.gz", checkIfExists: true), + file("${launchDir}/tests/data/fastq/rna/test_R2.fastq.gz", checkIfExists: true) ] ] + BOWTIE_ALIGN ( input, BOWTIE_INDEX.out.index ) +} diff --git a/tests/software/bowtie/test.yml b/tests/software/bowtie/test.yml new file mode 100644 index 00000000..229165ac --- /dev/null +++ b/tests/software/bowtie/test.yml @@ -0,0 +1,64 @@ +- name: Run bowtie index + command: nextflow run ./tests/software/bowtie -profile docker -entry test_bowtie_index -c tests/config/nextflow.config + tags: + - bowtie + - bowtie_index + files: + - path: output/bowtie/bowtie/NC_010473.1.ebwt + md5sum: 90f0b7aa5bbaeaaa999839ac13ad203c + - path: output/bowtie/bowtie/NC_010473.2.ebwt + md5sum: bfd10c5319c6a0dbc540fd789254a5dd + - path: output/bowtie/bowtie/NC_010473.3.ebwt + md5sum: cd201e81724f3099131aec16ef2cc53b + - path: output/bowtie/bowtie/NC_010473.4.ebwt + md5sum: bbb9d6d21ad765d135f95290204e8433 + - path: output/bowtie/bowtie/NC_010473.rev.1.ebwt + md5sum: 44f719c2fe42e1f35d54e798775846d1 + - path: output/bowtie/bowtie/NC_010473.rev.2.ebwt + md5sum: f3c398bba5158f4039334a932d79c051 + +- name: Run bowtie index and align single-end + command: nextflow run ./tests/software/bowtie -profile docker -entry test_bowtie_alignment_single_end -c tests/config/nextflow.config + tags: + - bowtie + - bowtie_align + files: + - path: output/bowtie/bowtie/NC_010473.1.ebwt + md5sum: 90f0b7aa5bbaeaaa999839ac13ad203c + - path: output/bowtie/bowtie/NC_010473.2.ebwt + md5sum: bfd10c5319c6a0dbc540fd789254a5dd + - path: output/bowtie/bowtie/NC_010473.3.ebwt + md5sum: cd201e81724f3099131aec16ef2cc53b + - path: output/bowtie/bowtie/NC_010473.4.ebwt + md5sum: bbb9d6d21ad765d135f95290204e8433 + - path: output/bowtie/bowtie/NC_010473.rev.1.ebwt + md5sum: 44f719c2fe42e1f35d54e798775846d1 + - path: output/bowtie/bowtie/NC_010473.rev.2.ebwt + md5sum: f3c398bba5158f4039334a932d79c051 + - path: output/bowtie/test.out + md5sum: a81cb18024616415a6cec3108a36fccd + - path: output/bowtie/test.bam + md5sum: 9feed8a55d4b5e600dcc577768ef07fc + +- name: Run bowtie index and align paired-end + command: nextflow run ./tests/software/bowtie -profile docker -entry test_bowtie_alignment_paired_end -c tests/config/nextflow.config + tags: + - bowtie + - bowtie_align + files: + - path: output/bowtie/bowtie/NC_010473.1.ebwt + md5sum: 90f0b7aa5bbaeaaa999839ac13ad203c + - path: output/bowtie/bowtie/NC_010473.2.ebwt + md5sum: bfd10c5319c6a0dbc540fd789254a5dd + - path: output/bowtie/bowtie/NC_010473.3.ebwt + md5sum: cd201e81724f3099131aec16ef2cc53b + - path: output/bowtie/bowtie/NC_010473.4.ebwt + md5sum: bbb9d6d21ad765d135f95290204e8433 + - path: output/bowtie/bowtie/NC_010473.rev.1.ebwt + md5sum: 44f719c2fe42e1f35d54e798775846d1 + - path: output/bowtie/bowtie/NC_010473.rev.2.ebwt + md5sum: f3c398bba5158f4039334a932d79c051 + - path: output/bowtie/test.out + md5sum: a23e9a2a76e949aeb3693bcfae41a615 + - path: output/bowtie/test.bam + md5sum: cf6a6381aa504e8342638ff3b509721e