diff --git a/modules/nf-core/custom/splitfastqbylane/main.nf b/modules/nf-core/custom/splitfastqbylane/main.nf new file mode 100644 index 000000000000..5844fd8dd3bb --- /dev/null +++ b/modules/nf-core/custom/splitfastqbylane/main.nf @@ -0,0 +1,35 @@ +process CUSTOM_SPLITFASTQBYLANE { + tag "$meta.id" + label 'process_single' + + conda "anaconda::gawk=5.1.0" + container "${ workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container ? + 'https://depot.galaxyproject.org/singularity/gawk:5.1.0' : + 'biocontainers/gawk:5.1.0' }" + + input: + tuple val(meta), path(reads) + + output: + tuple val(meta), path("*.split.fastq.gz"), emit: reads + path "versions.yml" , emit: versions + + when: + task.ext.when == null || task.ext.when + + shell: + args = task.ext.args ?: '' + prefix = task.ext.prefix ?: "${meta.id}" + read1 = [reads].flatten()[0] + read2 = [reads].flatten().size() > 1 ? reads[1] : null + template 'split_lanes_awk.sh' + + stub: + """ + touch out.split.fastq.gz + cat <<-END_VERSIONS > versions.yml + "${task.process}": + gawk: \$(awk -Wversion | sed '1!d; s/.*Awk //; s/,.*//') + END_VERSIONS + """ +} diff --git a/modules/nf-core/custom/splitfastqbylane/meta.yml b/modules/nf-core/custom/splitfastqbylane/meta.yml new file mode 100644 index 000000000000..307b1c29cfcd --- /dev/null +++ b/modules/nf-core/custom/splitfastqbylane/meta.yml @@ -0,0 +1,46 @@ +name: "custom_splitfastqbylane" +description: | + Splits fastq files with multiple or unknown number of merged flowcell+lane sources into separate fastq files, each with single flowcell+line sources. +keywords: + - splitlanesbyfastq + - awk + - custom + - fastq + - split + - lanes +tools: + - "gawk": + description: "The awk utility interprets a special-purpose programming language that makes it easy to handle simple data-reformatting jobs." + homepage: "https://www.gnu.org/software/gawk/manual/gawk.html" + documentation: "https://www.gnu.org/software/gawk/manual/gawk.html" + tool_dev_url: "http://savannah.gnu.org/projects/gawk/" + 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. + pattern: "*.{fastq,fastq.gz}" + +output: + - meta: + type: map + description: | + Groovy Map containing sample information + e.g. [ id:'test', single_end:false ] + - versions: + type: file + description: File containing software versions + pattern: "versions.yml" + - reads: + type: file + description: List of output FastQ files of size of multiples of 1 and 2, for single-end and paired-end data, respectively. + pattern: "*.split.fastq.gz" + +authors: + - "@anoronh4" diff --git a/modules/nf-core/custom/splitfastqbylane/templates/split_lanes_awk.sh b/modules/nf-core/custom/splitfastqbylane/templates/split_lanes_awk.sh new file mode 100644 index 000000000000..6ca616154b53 --- /dev/null +++ b/modules/nf-core/custom/splitfastqbylane/templates/split_lanes_awk.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +if [[ "!{read1}" == *gz ]] ; then + cat_="zcat" +else + cat_="cat" +fi + +function a() { + awk \ + -v prefix=!{prefix} \ + -v readnumber=$1 \ + ' + BEGIN {FS = ":"} + { + lane=$(NF-3) + flowcell=$(NF-4) + outfastq=prefix"@"flowcell"_L00"lane"_R"readnumber".split.fastq.gz" + print | "gzip > "outfastq + for (i = 1; i <= 3; i++) { + getline + print | "gzip > "outfastq + } + } + ' <( eval "$cat_ $2") +} + +a 1 !{read1} +if [ ! -z !{read2} ] ; then + a 2 !{read2} +fi + +cat <<-END_VERSIONS > versions.yml +"!{task.process}": + gawk: $(awk -Wversion | sed '1!d; s/.*Awk //; s/,.*//') +END_VERSIONS diff --git a/tests/config/pytest_modules.yml b/tests/config/pytest_modules.yml index 6631fdb97a9e..24546d13f39e 100644 --- a/tests/config/pytest_modules.yml +++ b/tests/config/pytest_modules.yml @@ -866,6 +866,10 @@ custom/matrixfilter: - modules/nf-core/custom/matrixfilter/** - tests/modules/nf-core/custom/matrixfilter/** +custom/splitfastqbylane: + - modules/nf-core/custom/splitfastqbylane/** + - tests/modules/nf-core/custom/splitfastqbylane/** + custom/sratoolsncbisettings: - modules/nf-core/custom/sratoolsncbisettings/** - tests/modules/nf-core/custom/sratoolsncbisettings/** diff --git a/tests/modules/nf-core/custom/splitfastqbylane/main.nf b/tests/modules/nf-core/custom/splitfastqbylane/main.nf new file mode 100644 index 000000000000..6cc2165e3293 --- /dev/null +++ b/tests/modules/nf-core/custom/splitfastqbylane/main.nf @@ -0,0 +1,27 @@ +#!/usr/bin/env nextflow + +nextflow.enable.dsl = 2 + +include { CUSTOM_SPLITFASTQBYLANE } from '../../../../../modules/nf-core/custom/splitfastqbylane/main.nf' + +workflow test_custom_splitfastqbylane { + + 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) + ] + ] + + CUSTOM_SPLITFASTQBYLANE ( input ) +} + +workflow test_custom_splitfastqbylane_single_end { + + input = [ + [ id:'test', single_end:true ], + file(params.test_data['sarscov2']['illumina']['test_1_fastq_gz'], checkIfExists: true) + ] + CUSTOM_SPLITFASTQBYLANE ( input ) +} diff --git a/tests/modules/nf-core/custom/splitfastqbylane/nextflow.config b/tests/modules/nf-core/custom/splitfastqbylane/nextflow.config new file mode 100644 index 000000000000..50f50a7a3579 --- /dev/null +++ b/tests/modules/nf-core/custom/splitfastqbylane/nextflow.config @@ -0,0 +1,5 @@ +process { + + publishDir = { "${params.outdir}/${task.process.tokenize(':')[-1].tokenize('_')[0].toLowerCase()}" } + +} \ No newline at end of file diff --git a/tests/modules/nf-core/custom/splitfastqbylane/test.yml b/tests/modules/nf-core/custom/splitfastqbylane/test.yml new file mode 100644 index 000000000000..9798fc496a39 --- /dev/null +++ b/tests/modules/nf-core/custom/splitfastqbylane/test.yml @@ -0,0 +1,31 @@ +- name: custom splitfastqbylane test_custom_splitfastqbylane + command: nextflow run ./tests/modules/nf-core/custom/splitfastqbylane -entry test_custom_splitfastqbylane -c ./tests/config/nextflow.config -c ./tests/modules/nf-core/custom/splitfastqbylane/nextflow.config + tags: + - custom + - custom/splitfastqbylane + files: + - path: output/custom/test@HK3MMAFX2_L001_R1.split.fastq.gz + - path: output/custom/test@HK3MMAFX2_L001_R2.split.fastq.gz + - path: output/custom/test@HK3MMAFX2_L002_R1.split.fastq.gz + - path: output/custom/test@HK3MMAFX2_L002_R2.split.fastq.gz + - path: output/custom/test@HK3MMAFX2_L003_R1.split.fastq.gz + - path: output/custom/test@HK3MMAFX2_L003_R2.split.fastq.gz + - path: output/custom/test@HK3MMAFX2_L004_R1.split.fastq.gz + - path: output/custom/test@HK3MMAFX2_L004_R2.split.fastq.gz + - path: output/custom/versions.yml + contains: + - "gawk" + +- name: custom splitfastqbylane test_custom_splitfastqbylane_single_end + command: nextflow run ./tests/modules/nf-core/custom/splitfastqbylane -entry test_custom_splitfastqbylane_single_end -c ./tests/config/nextflow.config -c ./tests/modules/nf-core/custom/splitfastqbylane/nextflow.config + tags: + - custom + - custom/splitfastqbylane + files: + - path: output/custom/test@HK3MMAFX2_L001_R1.split.fastq.gz + - path: output/custom/test@HK3MMAFX2_L002_R1.split.fastq.gz + - path: output/custom/test@HK3MMAFX2_L003_R1.split.fastq.gz + - path: output/custom/test@HK3MMAFX2_L004_R1.split.fastq.gz + - path: output/custom/versions.yml + contains: + - "gawk"