Skip to content

Commit 429d56a

Browse files
Modify shasum to accept multiple input files (#12113)
* Accept multiple number of files * Change file input to files and update description * Add as_separate_files option in meta.yml Add 'as_separate_files' boolean option to metadata * Refactor checksum generation for separate files option * Fix meta.yml * Update tests * Fix description in meta.yml Updated description for 'as_separate_files' to reflect shasum usage.
1 parent 9f913ac commit 429d56a

4 files changed

Lines changed: 106 additions & 20 deletions

File tree

modules/nf-core/shasum/main.nf

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ process SHASUM {
88
: 'community.wave.seqera.io/library/coreutils_grep_gzip_lbzip2_pruned:838ba80435a629f8'}"
99

1010
input:
11-
tuple val(meta), path(file)
11+
tuple val(meta), path(files)
12+
val as_separate_files
1213

1314
output:
1415
tuple val(meta), path("*.sha256"), emit: checksum
@@ -19,15 +20,36 @@ process SHASUM {
1920

2021
script:
2122
def args = task.ext.args ?: ''
22-
"""
23-
sha256sum \\
24-
${args} \\
25-
${file} \\
26-
> ${file}.sha256
27-
"""
23+
def prefix = task.ext.prefix ?: "${meta.id}"
24+
// will only use when as_separate_files = false
25+
if (as_separate_files) {
26+
"""
27+
find -L * -maxdepth 0 -type f \\
28+
! -name '*.sha256' \\
29+
-exec sh -c 'sha256sum ${args} "\$1" > "\$1.sha256"' _ "{}" \\;
30+
"""
31+
}
32+
else {
33+
"""
34+
find -L * -type f \\
35+
! -name '*.sha256' \\
36+
-exec sha256sum ${args} "{}" + \\
37+
> ${prefix}.sha256
38+
"""
39+
}
2840

2941
stub:
30-
"""
31-
touch ${file}.sha256
32-
"""
42+
def prefix = task.ext.prefix ?: "${meta.id}"
43+
if (as_separate_files) {
44+
"""
45+
find -L * -type f \\
46+
! -name '*.sha256' \\
47+
-exec sh -c 'touch "\$1.sha256"' _ "{}" \\;
48+
"""
49+
}
50+
else {
51+
"""
52+
touch ${prefix}.sha256
53+
"""
54+
}
3355
}

modules/nf-core/shasum/meta.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,16 @@ input:
1818
description: |
1919
Groovy Map containing sample information
2020
e.g. [ id:'test', single_end:false ]
21-
- file:
21+
- files:
2222
type: file
23-
description: Any file
23+
description: Any number of files
2424
pattern: "*.*"
2525
ontologies: []
26+
- as_separate_files:
27+
type: boolean
28+
description: |
29+
If true, each file will have its own shasum file. If false, all files will be
30+
checksummed into a single shasum file.
2631
output:
2732
checksum:
2833
- - meta:

modules/nf-core/shasum/tests/main.nf.test

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,44 @@ nextflow_process {
99
tag "modules_nfcore"
1010
tag "shasum"
1111

12-
test("test-shasum") {
12+
test("test-shasum, separate") {
1313

1414
when {
1515
process {
1616
"""
1717
input[0] = [
1818
[ id:'test', single_end:false ], // meta map
19-
file(params.modules_testdata_base_path + 'genomics/sarscov2/illumina/bam/test.paired_end.bam', checkIfExists: true)
19+
[
20+
file(params.modules_testdata_base_path + 'genomics/sarscov2/illumina/fastq/test_1.fastq.gz', checkIfExists: true),
21+
file(params.modules_testdata_base_path + 'genomics/sarscov2/illumina/fastq/test_2.fastq.gz', checkIfExists: true)
22+
]
2023
]
24+
input[1] = true
25+
"""
26+
}
27+
}
2128

29+
then {
30+
assertAll(
31+
{ assert process.success },
32+
{ assert snapshot(sanitizeOutput(process.out)).match() }
33+
)
34+
}
35+
}
36+
37+
test("test-shasum, combined") {
38+
39+
when {
40+
process {
41+
"""
42+
input[0] = [
43+
[ id:'test', single_end:false ], // meta map
44+
[
45+
file(params.modules_testdata_base_path + 'genomics/sarscov2/illumina/fastq/test_1.fastq.gz', checkIfExists: true),
46+
file(params.modules_testdata_base_path + 'genomics/sarscov2/illumina/fastq/test_2.fastq.gz', checkIfExists: true)
47+
]
48+
]
49+
input[1] = false
2250
"""
2351
}
2452
}
@@ -42,6 +70,7 @@ nextflow_process {
4270
[ id:'test', single_end:false ], // meta map
4371
file(params.modules_testdata_base_path + 'genomics/sarscov2/illumina/bam/test.paired_end.bam', checkIfExists: true)
4472
]
73+
input[1] = true
4574

4675
"""
4776
}

modules/nf-core/shasum/tests/main.nf.test.snap

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"test-shasum": {
2+
"test-shasum, combined": {
33
"content": [
44
{
55
"checksum": [
@@ -8,7 +8,7 @@
88
"id": "test",
99
"single_end": false
1010
},
11-
"test.paired_end.bam.sha256:md5,138a19e100f09fc975ea1b717da9b6dd"
11+
"test.sha256:md5,cbe368d92c146935e6d72a00c2c2c804"
1212
]
1313
],
1414
"versions_sha256sum": [
@@ -20,10 +20,10 @@
2020
]
2121
}
2222
],
23-
"timestamp": "2026-05-03T20:43:40.688253838",
23+
"timestamp": "2026-06-19T13:40:52.588704139",
2424
"meta": {
2525
"nf-test": "0.9.5",
26-
"nextflow": "24.10.4"
26+
"nextflow": "26.04.4"
2727
}
2828
},
2929
"test-shasum - stub": {
@@ -47,10 +47,40 @@
4747
]
4848
}
4949
],
50-
"timestamp": "2026-05-03T20:43:46.125782074",
50+
"timestamp": "2026-06-19T13:40:59.232985121",
5151
"meta": {
5252
"nf-test": "0.9.5",
53-
"nextflow": "24.10.4"
53+
"nextflow": "26.04.4"
54+
}
55+
},
56+
"test-shasum, separate": {
57+
"content": [
58+
{
59+
"checksum": [
60+
[
61+
{
62+
"id": "test",
63+
"single_end": false
64+
},
65+
[
66+
"test_1.fastq.gz.sha256:md5,d200e9d01dfc874b9c5efe894181b430",
67+
"test_2.fastq.gz.sha256:md5,0035d52e9b642206858b826f2b49d7a3"
68+
]
69+
]
70+
],
71+
"versions_sha256sum": [
72+
[
73+
"SHASUM",
74+
"sha256sum",
75+
"9.5"
76+
]
77+
]
78+
}
79+
],
80+
"timestamp": "2026-06-19T13:40:45.551657784",
81+
"meta": {
82+
"nf-test": "0.9.5",
83+
"nextflow": "26.04.4"
5484
}
5585
}
5686
}

0 commit comments

Comments
 (0)