Skip to content

Commit

Permalink
Added stub for sratools (#5625)
Browse files Browse the repository at this point in the history
* Added stub for sratools

* Added command echo for fasterqdump
  • Loading branch information
GallVp authored May 18, 2024
1 parent 839651c commit dd93531
Show file tree
Hide file tree
Showing 9 changed files with 255 additions and 12 deletions.
50 changes: 49 additions & 1 deletion modules/nf-core/sratools/fasterqdump/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ process SRATOOLS_FASTERQDUMP {
def args = task.ext.args ?: ''
def args2 = task.ext.args2 ?: ''
def prefix = task.ext.prefix ?: "${meta.id}"
def outfile = meta.single_end ? "${prefix}.fastq" : prefix
def outfile = "${prefix}.fastq"
def exclude_third = meta.single_end ? '' : "mv $outfile $prefix || echo 'No third file'"
// Excludes the "${prefix}.fastq" file from output `reads` channel for paired end cases and
// avoids the '.' in the path bug: https://github.com/ncbi/sra-tools/issues/865
def key_file = ''
if (certificate.toString().endsWith('.jwt')) {
key_file += " --perm ${certificate}"
Expand All @@ -40,6 +43,51 @@ process SRATOOLS_FASTERQDUMP {
${key_file} \\
${sra}
$exclude_third
pigz \\
$args2 \\
--no-name \\
--processes $task.cpus \\
*.fastq
cat <<-END_VERSIONS > versions.yml
"${task.process}":
sratools: \$(fasterq-dump --version 2>&1 | grep -Eo '[0-9.]+')
pigz: \$( pigz --version 2>&1 | sed 's/pigz //g' )
END_VERSIONS
"""

stub:
def args = task.ext.args ?: ''
def args2 = task.ext.args2 ?: ''
def prefix = task.ext.prefix ?: "${meta.id}"
def outfile = "${prefix}.fastq"
def exclude_third = meta.single_end ? '' : "mv $outfile $prefix || echo 'No third file'"
// Excludes the "${prefix}.fastq" file from output `reads` channel for paired end cases and
// avoids the '.' in the path bug: https://github.com/ncbi/sra-tools/issues/865
def key_file = ''
if (certificate.toString().endsWith('.jwt')) {
key_file += " --perm ${certificate}"
} else if (certificate.toString().endsWith('.ngc')) {
key_file += " --ngc ${certificate}"
}
def touch_outfiles = meta.single_end ? "${prefix}.fastq" : "${prefix}_1.fastq ${prefix}_2.fastq"
"""
touch $touch_outfiles
export NCBI_SETTINGS="\$PWD/${ncbi_settings}"
echo \\
"fasterq-dump \\
$args \\
--threads $task.cpus \\
--outfile $outfile \\
${key_file} \\
${sra}"
$exclude_third
pigz \\
$args2 \\
--no-name \\
Expand Down
1 change: 1 addition & 0 deletions modules/nf-core/sratools/fasterqdump/meta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,4 @@ authors:
- "@Midnighter"
maintainers:
- "@Midnighter"
- "@gallvp"
51 changes: 50 additions & 1 deletion modules/nf-core/sratools/fasterqdump/tests/main.nf.test
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
nextflow_process {
name "Test Process SRATOOLS_FASTERQDUMP"
script "../main.nf"
config "./nextflow.config"
process "SRATOOLS_FASTERQDUMP"
tag "modules"
tag "modules_nfcore"
Expand Down Expand Up @@ -70,4 +69,54 @@ nextflow_process {
)
}
}

test("Single-end-stub") {

options '-stub'

when {
process {
"""
input[0] = [
[ id:'test_single_end', single_end:true ],
file(params.modules_testdata_base_path + 'genomics/sarscov2/illumina/sra/SRR13255544.tar.gz', checkIfExists: true)
]
input[1] = file(params.modules_testdata_base_path + 'generic/config/ncbi_user_settings.mkfg', checkIfExists: true)
input[2] = []
"""
}
}

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

test("Paired-end-stub") {

options '-stub'

when {
process {
"""
input[0] = [
[ id:'test_paired_end', single_end:false ],
file(params.modules_testdata_base_path + 'genomics/sarscov2/illumina/sra/SRR11140744.tar.gz', checkIfExists: true)
]
input[1] = file(params.modules_testdata_base_path + 'generic/config/ncbi_user_settings.mkfg', checkIfExists: true)
input[2] = []
"""
}
}

then {
assertAll(
{ assert process.success },
{ assert snapshot(process.out).match() }
)
}
}
}
84 changes: 80 additions & 4 deletions modules/nf-core/sratools/fasterqdump/tests/main.nf.test.snap
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,44 @@
],
"meta": {
"nf-test": "0.8.4",
"nextflow": "24.01.0"
"nextflow": "23.10.1"
},
"timestamp": "2024-02-28T15:25:52.837288"
"timestamp": "2024-05-17T22:01:43.486256"
},
"Single-end-stub": {
"content": [
{
"0": [
[
{
"id": "test_single_end",
"single_end": true
},
"test_single_end.fastq.gz:md5,d41d8cd98f00b204e9800998ecf8427e"
]
],
"1": [
"versions.yml:md5,a3d61a9761e1606ef8459f0b68821d7a"
],
"reads": [
[
{
"id": "test_single_end",
"single_end": true
},
"test_single_end.fastq.gz:md5,d41d8cd98f00b204e9800998ecf8427e"
]
],
"versions": [
"versions.yml:md5,a3d61a9761e1606ef8459f0b68821d7a"
]
}
],
"meta": {
"nf-test": "0.8.4",
"nextflow": "23.10.1"
},
"timestamp": "2024-05-17T21:40:42.335786"
},
"Paired-end": {
"content": [
Expand Down Expand Up @@ -71,8 +106,49 @@
],
"meta": {
"nf-test": "0.8.4",
"nextflow": "24.01.0"
"nextflow": "23.10.1"
},
"timestamp": "2024-05-17T22:09:55.6396"
},
"Paired-end-stub": {
"content": [
{
"0": [
[
{
"id": "test_paired_end",
"single_end": false
},
[
"test_paired_end_1.fastq.gz:md5,d41d8cd98f00b204e9800998ecf8427e",
"test_paired_end_2.fastq.gz:md5,d41d8cd98f00b204e9800998ecf8427e"
]
]
],
"1": [
"versions.yml:md5,a3d61a9761e1606ef8459f0b68821d7a"
],
"reads": [
[
{
"id": "test_paired_end",
"single_end": false
},
[
"test_paired_end_1.fastq.gz:md5,d41d8cd98f00b204e9800998ecf8427e",
"test_paired_end_2.fastq.gz:md5,d41d8cd98f00b204e9800998ecf8427e"
]
]
],
"versions": [
"versions.yml:md5,a3d61a9761e1606ef8459f0b68821d7a"
]
}
],
"meta": {
"nf-test": "0.8.4",
"nextflow": "23.10.1"
},
"timestamp": "2024-02-28T15:26:42.466223"
"timestamp": "2024-05-17T20:35:44.782058"
}
}
5 changes: 0 additions & 5 deletions modules/nf-core/sratools/fasterqdump/tests/nextflow.config

This file was deleted.

12 changes: 12 additions & 0 deletions modules/nf-core/sratools/prefetch/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,16 @@ process SRATOOLS_PREFETCH {
}

template 'retry_with_backoff.sh'

stub:
"""
mkdir $id
touch $id/${id}.sra
cat <<-END_VERSIONS > versions.yml
"${task.process}":
sratools: \$(prefetch --version 2>&1 | grep -Eo '[0-9.]+')
curl: \$(curl --version | head -n 1 | sed 's/^curl //; s/ .*\$//')
END_VERSIONS
"""
}
1 change: 1 addition & 0 deletions modules/nf-core/sratools/prefetch/meta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,4 @@ authors:
- "@Midnighter"
maintainers:
- "@Midnighter"
- "@gallvp"
22 changes: 22 additions & 0 deletions modules/nf-core/sratools/prefetch/tests/main.nf.test
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,26 @@ nextflow_process {
)
}
}

test("sratools/prefetch/stub") {

options '-stub'

when {
process {
"""
input[0] = Channel.of([ [ id:'test', single_end:false ], 'DRR000774' ])
input[1] = file(params.modules_testdata_base_path + 'generic/config/ncbi_user_settings.mkfg', checkIfExists: true)
input[2] = []
"""
}
}

then {
assertAll (
{ assert process.success },
{ assert snapshot(process.out).match() }
)
}
}
}
41 changes: 40 additions & 1 deletion modules/nf-core/sratools/prefetch/tests/main.nf.test.snap
Original file line number Diff line number Diff line change
@@ -1,4 +1,43 @@
{
"sratools/prefetch/stub": {
"content": [
{
"0": [
[
{
"id": "test",
"single_end": false
},
[
"DRR000774.sra:md5,d41d8cd98f00b204e9800998ecf8427e"
]
]
],
"1": [
"versions.yml:md5,83d1b23f5ff5b2ad1b96d17d7d7594ee"
],
"sra": [
[
{
"id": "test",
"single_end": false
},
[
"DRR000774.sra:md5,d41d8cd98f00b204e9800998ecf8427e"
]
]
],
"versions": [
"versions.yml:md5,83d1b23f5ff5b2ad1b96d17d7d7594ee"
]
}
],
"meta": {
"nf-test": "0.8.4",
"nextflow": "23.10.1"
},
"timestamp": "2024-05-17T20:07:31.627115"
},
"sratools/prefetch with sralite": {
"content": [
{
Expand Down Expand Up @@ -77,4 +116,4 @@
},
"timestamp": "2024-02-28T11:48:37.428307"
}
}
}

0 comments on commit dd93531

Please sign in to comment.