Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add custom/splitfastqbylane module #23

Merged
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions modules/msk/custom/splitfastqbylane/environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/nf-core/modules/master/modules/environment-schema.json
name: "custom_splitfastqbylane"
channels:
- conda-forge
- bioconda
- defaults
dependencies:
- "anaconda::gawk=5.1.0"
45 changes: 45 additions & 0 deletions modules/msk/custom/splitfastqbylane/main.nf
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
process CUSTOM_SPLITFASTQBYLANE {
tag "$meta.id"
label 'process_low'

conda "${moduleDir}/environment.yml"
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

script:
def args = task.ext.args ?: ''
def prefix = task.ext.prefix ?: "${meta.id}"
def read1 = [reads].flatten()[0]
def read2 = [reads].flatten().size() > 1 ? reads[1] : ''
"""
split_lanes_awk.sh ${prefix} ${read1} ${read2}

cat <<-END_VERSIONS > versions.yml
"${task.process}":
gawk: \$(awk -Wversion | sed '1!d; s/.*Awk //; s/,.*//')
END_VERSIONS
"""

stub:
def args = task.ext.args ?: ''
def prefix = task.ext.prefix ?: "${meta.id}"
"""
touch out.split.fastq
gzip out.split.fastq
cat <<-END_VERSIONS > versions.yml
"${task.process}":
gawk: \$(awk -Wversion | sed '1!d; s/.*Awk //; s/,.*//')
END_VERSIONS
"""
}
46 changes: 46 additions & 0 deletions modules/msk/custom/splitfastqbylane/meta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/nf-core/modules/master/modules/meta-schema.json
name: "custom_splitfastqbylane"
description: Split fastq into multiple fastqs by lane
keywords:
- awk
- fastq
- split
tools:
- "custom":
description: "GNU awk"
homepage: "https://www.gnu.org/software/gawk/manual/gawk.html"
licence: ["GPL v3"]

input:
- meta:
type: map
description: |
Groovy Map containing sample information
e.g. `[ id:'sample1', single_end:false ]`

- reads:
type: file
description: Paired end or single end FASTQ file(s)
pattern: "*.{fastq,fastq.gz}"

output:
- meta:
type: map
description: |
Groovy Map containing sample information
e.g. `[ id:'sample1', single_end:false ]`

- versions:
type: file
description: File containing software versions
pattern: "versions.yml"
- reads:
type: file
description: Output fastq files containing only one read lane per file.
pattern: "*.{split.fastq.gz}"

authors:
- "@anoronh4"
maintainers:
- "@anoronh4"
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash

prefix=$1
read1=$2
read2=$3


if [[ "${read1}" == *gz ]] ; then
cat_="zcat"
else
cat_="cat"
fi

function a() {
awk \
-v prefix=$3 \
-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")
}

echo "processing read1"
a 1 ${read1} ${prefix}
if [ ! -z ${read2} ] ; then
echo "processing read2"
a 2 ${read2} ${prefix}
fi
64 changes: 64 additions & 0 deletions modules/msk/custom/splitfastqbylane/tests/main.nf.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
nextflow_process {

name "Test Process CUSTOM_SPLITFASTQBYLANE"
script "../main.nf"
process "CUSTOM_SPLITFASTQBYLANE"

tag "modules"
tag "modules_nfcore"
tag "custom"
tag "custom/splitfastqbylane"

test("homo_sapiens - fastq") {

when {
process {
"""
input[0] = [
[ 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)
]
]
"""
}
}

then {
assertAll(
{ assert process.success },
{ assert snapshot(process.out).match() }
)
}

}

test("sarscov2 - fastq - stub") {

options "-stub"

when {
process {
"""
input[0] = [
[ 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)
]
]
"""
}
}

then {
assertAll(
{ assert process.success },
{ assert snapshot(process.out).match() }
)
}

}

}
82 changes: 82 additions & 0 deletions modules/msk/custom/splitfastqbylane/tests/main.nf.test.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
"sarscov2 - fastq - stub": {
"content": [
{
"0": [
[
{
"id": "test",
"single_end": false
},
"out.split.fastq.gz:md5,d41d8cd98f00b204e9800998ecf8427e"
]
],
"1": [
"versions.yml:md5,68b779fcdaf62c97ffcd67d49ab59b0e"
],
"reads": [
[
{
"id": "test",
"single_end": false
},
"out.split.fastq.gz:md5,d41d8cd98f00b204e9800998ecf8427e"
]
],
"versions": [
"versions.yml:md5,68b779fcdaf62c97ffcd67d49ab59b0e"
]
}
],
"timestamp": "2024-01-16T11:28:05.672874"
},
"homo_sapiens - fastq": {
"content": [
{
"0": [
[
{
"id": "test",
"single_end": false
},
[
"test@HK3MMAFX2_L001_R1.split.fastq.gz:md5,6fdae9563e6f3428ea953435cb71f762",
"test@HK3MMAFX2_L001_R2.split.fastq.gz:md5,a2315ba81e2993823e38af0b83b9e7bd",
"test@HK3MMAFX2_L002_R1.split.fastq.gz:md5,3c5e1d1bf430c964fa2ac1b7faf8c313",
"test@HK3MMAFX2_L002_R2.split.fastq.gz:md5,f3aee4f14f59bd2e26753ec0dda1d5dc",
"test@HK3MMAFX2_L003_R1.split.fastq.gz:md5,c98453d33b9bb4ff224ae5571489913b",
"test@HK3MMAFX2_L003_R2.split.fastq.gz:md5,898a6d549be78b5214c3d5647e7c3c49",
"test@HK3MMAFX2_L004_R1.split.fastq.gz:md5,11b776b50ea9bcc6670aaca952f6a939",
"test@HK3MMAFX2_L004_R2.split.fastq.gz:md5,a50125ecb428a7f534a944c5a22c8109"
]
]
],
"1": [
"versions.yml:md5,68b779fcdaf62c97ffcd67d49ab59b0e"
],
"reads": [
[
{
"id": "test",
"single_end": false
},
[
"test@HK3MMAFX2_L001_R1.split.fastq.gz:md5,6fdae9563e6f3428ea953435cb71f762",
"test@HK3MMAFX2_L001_R2.split.fastq.gz:md5,a2315ba81e2993823e38af0b83b9e7bd",
"test@HK3MMAFX2_L002_R1.split.fastq.gz:md5,3c5e1d1bf430c964fa2ac1b7faf8c313",
"test@HK3MMAFX2_L002_R2.split.fastq.gz:md5,f3aee4f14f59bd2e26753ec0dda1d5dc",
"test@HK3MMAFX2_L003_R1.split.fastq.gz:md5,c98453d33b9bb4ff224ae5571489913b",
"test@HK3MMAFX2_L003_R2.split.fastq.gz:md5,898a6d549be78b5214c3d5647e7c3c49",
"test@HK3MMAFX2_L004_R1.split.fastq.gz:md5,11b776b50ea9bcc6670aaca952f6a939",
"test@HK3MMAFX2_L004_R2.split.fastq.gz:md5,a50125ecb428a7f534a944c5a22c8109"
]
]
],
"versions": [
"versions.yml:md5,68b779fcdaf62c97ffcd67d49ab59b0e"
]
}
],
"timestamp": "2024-01-16T11:27:57.305806"
}
}
2 changes: 2 additions & 0 deletions modules/msk/custom/splitfastqbylane/tests/tags.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
custom/splitfastqbylane:
anoronh4 marked this conversation as resolved.
Show resolved Hide resolved
- "modules/msk/custom/splitfastqbylane/**"
3 changes: 3 additions & 0 deletions tests/config/nf-test.config
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,6 @@ includeConfig 'test_data.config'
manifest {
nextflowVersion = '!>=23.04.0'
}

nextflow.enable.moduleBinaries = true
anoronh4 marked this conversation as resolved.
Show resolved Hide resolved