Skip to content

Commit ba2031a

Browse files
GallVpSPPearce
authored andcommitted
Added cram output to samtools/fixmate (nf-core#7820)
* Added cram output to samtools/fixmate * Fixed tag * Fixed tag * Fixed linting * Updated onts * Use nft-bam, update output glob * Fixed meta.yml --------- Co-authored-by: Simon Pearce <24893913+SPPearce@users.noreply.github.com>
1 parent fca1b35 commit ba2031a

8 files changed

Lines changed: 237 additions & 30 deletions

File tree

modules/nf-core/samtools/fixmate/main.nf

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,49 @@ process SAMTOOLS_FIXMATE {
88
'biocontainers/samtools:1.21--h50ea8bc_0' }"
99

1010
input:
11-
tuple val(meta), path(bam)
11+
tuple val(meta), path(input)
1212

1313
output:
14-
tuple val(meta), path("*.bam"), emit: bam
15-
path "versions.yml" , emit: versions
14+
tuple val(meta), path("${prefix}.bam") , emit: bam , optional: true
15+
tuple val(meta), path("${prefix}.cram"), emit: cram, optional: true
16+
tuple val(meta), path("${prefix}.sam") , emit: sam , optional: true
17+
path "versions.yml" , emit: versions
1618

1719
when:
1820
task.ext.when == null || task.ext.when
1921

2022
script:
2123
def args = task.ext.args ?: ''
22-
def prefix = task.ext.prefix ?: "${meta.id}"
23-
if ("$bam" == "${prefix}.bam") error "Input and output names are the same, use \"task.ext.prefix\" to disambiguate!"
24+
prefix = task.ext.prefix ?: "${meta.id}_fixmate"
25+
def extension = args.contains("--output-fmt sam") ? "sam" :
26+
args.contains("--output-fmt bam") ? "bam" :
27+
args.contains("--output-fmt cram") ? "cram" :
28+
"bam"
29+
if ("$input" == "${prefix}.${extension}") error "Input and output names are the same, use \"task.ext.prefix\" to disambiguate!"
2430
"""
2531
samtools \\
2632
fixmate \\
2733
$args \\
2834
--threads ${task.cpus-1} \\
29-
$bam \\
30-
${prefix}.bam \\
35+
$input \\
36+
${prefix}.${extension} \\
37+
38+
cat <<-END_VERSIONS > versions.yml
39+
"${task.process}":
40+
samtools: \$(echo \$(samtools --version 2>&1) | sed 's/^.*samtools //; s/Using.*\$//')
41+
END_VERSIONS
42+
"""
43+
44+
stub:
45+
def args = task.ext.args ?: ''
46+
prefix = task.ext.prefix ?: "${meta.id}_fixmate"
47+
def extension = args.contains("--output-fmt sam") ? "sam" :
48+
args.contains("--output-fmt bam") ? "bam" :
49+
args.contains("--output-fmt cram") ? "cram" :
50+
"bam"
51+
if ("$input" == "${prefix}.${extension}") error "Input and output names are the same, use \"task.ext.prefix\" to disambiguate!"
52+
"""
53+
touch ${prefix}.${extension}
3154
3255
cat <<-END_VERSIONS > versions.yml
3356
"${task.process}":

modules/nf-core/samtools/fixmate/meta.yml

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,28 +29,74 @@ input:
2929
description: |
3030
Groovy Map containing sample information
3131
e.g. [ id:'test', single_end:false ]
32-
- bam:
32+
- input:
3333
type: file
3434
description: BAM/CRAM/SAM file, must be sorted by name, not coordinate
3535
pattern: "*.{bam,cram,sam}"
36+
ontologies:
37+
- edam: http://edamontology.org/format_2572 # BAM
38+
- edam: http://edamontology.org/format_3462 # CRAM
39+
- edam: http://edamontology.org/format_2573 # SAM
3640
output:
3741
- bam:
3842
- meta:
3943
type: map
4044
description: |
4145
Groovy Map containing sample information
4246
e.g. [ id:'test', single_end:false ]
43-
- "*.bam":
44-
type: file
45-
description: A BAM/CRAM/SAM file with mate information added and/or proper pairs
46-
recalled
47-
pattern: "*.{bam,cram,sam}"
47+
pattern: "*.{bam}"
48+
ontologies:
49+
- edam: http://edamontology.org/format_2572
50+
- ${prefix}.bam:
51+
type: map
52+
description: |
53+
Groovy Map containing sample information
54+
e.g. [ id:'test', single_end:false ]
55+
pattern: "*.{bam}"
56+
ontologies:
57+
- edam: http://edamontology.org/format_2572
58+
- cram:
59+
- meta:
60+
type: map
61+
description: |
62+
Groovy Map containing sample information
63+
e.g. [ id:'test', single_end:false ]
64+
pattern: "*.{cram}"
65+
ontologies:
66+
- edam: http://edamontology.org/format_3462
67+
- ${prefix}.cram:
68+
type: map
69+
description: |
70+
Groovy Map containing sample information
71+
e.g. [ id:'test', single_end:false ]
72+
pattern: "*.{cram}"
73+
ontologies:
74+
- edam: http://edamontology.org/format_3462
75+
- sam:
76+
- meta:
77+
type: map
78+
description: |
79+
Groovy Map containing sample information
80+
e.g. [ id:'test', single_end:false ]
81+
pattern: "*.{sam}"
82+
ontologies:
83+
- edam: http://edamontology.org/format_2573
84+
- ${prefix}.sam:
85+
type: map
86+
description: |
87+
Groovy Map containing sample information
88+
e.g. [ id:'test', single_end:false ]
89+
pattern: "*.{sam}"
90+
ontologies:
91+
- edam: http://edamontology.org/format_2573
4892
- versions:
4993
- versions.yml:
5094
type: file
5195
description: File containing software versions
5296
pattern: "versions.yml"
97+
ontologies: []
5398
authors:
5499
- "@sppearce"
55100
maintainers:
56101
- "@sppearce"
102+
- "@GallVp"

modules/nf-core/samtools/fixmate/tests/main.nf.test

Lines changed: 85 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
1-
// TODO nf-core: Once you have added the required tests, please run the following command to build this file:
2-
// nf-core modules test samtools/fixmate
31
nextflow_process {
42

53
name "Test Process SAMTOOLS_FIXMATE"
64
script "../main.nf"
75
process "SAMTOOLS_FIXMATE"
6+
config "./nextflow.config"
87

98
tag "modules"
109
tag "modules_nfcore"
1110
tag "samtools"
1211
tag "samtools/fixmate"
12+
tag "samtools/sort"
1313

1414
test("sarscov2 - bam") {
1515

1616
when {
17+
params {
18+
module_args = ''
19+
samtools_sort_args = ''
20+
}
1721
process {
1822
"""
1923
input[0] = Channel.of([
@@ -27,9 +31,85 @@ nextflow_process {
2731
then {
2832
assertAll(
2933
{ assert process.success },
30-
{ assert snapshot(file(process.out.bam[0][1]).name).match("bam") },
31-
{ assert snapshot(process.out.versions).match("versions") }
34+
{ assert snapshot(
35+
bam(process.out.bam[0][1]).getReadsMD5(),
36+
process.out.versions)
37+
.match()
38+
}
39+
)
40+
}
41+
}
42+
43+
test("human - cram") {
44+
45+
setup {
46+
run("SAMTOOLS_SORT") {
47+
script "../../../samtools/sort/main.nf"
48+
process {
49+
"""
50+
input[0] = [
51+
[ id:'test', single_end:false ], // meta map
52+
file(params.modules_testdata_base_path + 'genomics/homo_sapiens/illumina/cram/test.paired_end.sorted.cram', checkIfExists: true)
53+
]
54+
input[1] = [
55+
[ id:'test' ], // meta map
56+
file(params.modules_testdata_base_path + 'genomics/homo_sapiens/genome/genome.fasta', checkIfExists: true)
57+
]
58+
"""
59+
}
60+
}
61+
}
62+
63+
when {
64+
params {
65+
module_args = '--output-fmt cram'
66+
samtools_sort_args = '--template-coordinate --output-fmt cram'
67+
}
68+
process {
69+
"""
70+
input[0] = SAMTOOLS_SORT.out.cram
71+
"""
72+
}
73+
}
74+
75+
then {
76+
assertAll(
77+
{ assert process.success },
78+
{ assert snapshot(
79+
file(process.out.cram[0][1]).name,
80+
process.out.versions
81+
).match()
82+
}
3283
)
3384
}
85+
86+
}
87+
88+
test("human - cram - stub") {
89+
90+
options "-stub"
91+
92+
when {
93+
params {
94+
module_args = '--output-fmt cram'
95+
samtools_sort_args = ''
96+
}
97+
process {
98+
"""
99+
input[0] = [
100+
[ id:'test', single_end:false ], // meta map
101+
file(params.modules_testdata_base_path + 'genomics/homo_sapiens/illumina/cram/test.paired_end.sorted.cram', checkIfExists: true)
102+
]
103+
"""
104+
}
105+
}
106+
107+
then {
108+
assertAll(
109+
{ assert process.success },
110+
{ assert snapshot(process.out).match() }
111+
)
112+
}
113+
34114
}
35-
}
115+
}
Lines changed: 60 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,75 @@
11
{
2-
"versions": {
2+
"human - cram - stub": {
33
"content": [
4+
{
5+
"0": [
6+
7+
],
8+
"1": [
9+
[
10+
{
11+
"id": "test",
12+
"single_end": false
13+
},
14+
"test_fixmate.cram:md5,d41d8cd98f00b204e9800998ecf8427e"
15+
]
16+
],
17+
"2": [
18+
19+
],
20+
"3": [
21+
"versions.yml:md5,d1afb9aa7c14a683e2a0b8a43daa5d31"
22+
],
23+
"bam": [
24+
25+
],
26+
"cram": [
27+
[
28+
{
29+
"id": "test",
30+
"single_end": false
31+
},
32+
"test_fixmate.cram:md5,d41d8cd98f00b204e9800998ecf8427e"
33+
]
34+
],
35+
"sam": [
36+
37+
],
38+
"versions": [
39+
"versions.yml:md5,d1afb9aa7c14a683e2a0b8a43daa5d31"
40+
]
41+
}
42+
],
43+
"meta": {
44+
"nf-test": "0.9.2",
45+
"nextflow": "24.10.5"
46+
},
47+
"timestamp": "2025-03-21T06:53:59.470746689"
48+
},
49+
"human - cram": {
50+
"content": [
51+
"test_fixmate.cram",
452
[
553
"versions.yml:md5,d1afb9aa7c14a683e2a0b8a43daa5d31"
654
]
755
],
856
"meta": {
9-
"nf-test": "0.9.0",
10-
"nextflow": "24.04.4"
57+
"nf-test": "0.9.2",
58+
"nextflow": "24.10.5"
1159
},
12-
"timestamp": "2024-09-16T08:01:53.33860034"
60+
"timestamp": "2025-03-21T06:53:49.930885979"
1361
},
14-
"bam": {
62+
"sarscov2 - bam": {
1563
"content": [
16-
"test.bam"
64+
"762e859a3d0ed1553655cde77665c940",
65+
[
66+
"versions.yml:md5,d1afb9aa7c14a683e2a0b8a43daa5d31"
67+
]
1768
],
1869
"meta": {
19-
"nf-test": "0.8.4",
20-
"nextflow": "23.04.3"
70+
"nf-test": "0.9.2",
71+
"nextflow": "24.10.5"
2172
},
22-
"timestamp": "2024-02-12T18:24:59.755324"
73+
"timestamp": "2025-03-21T06:47:32.759541463"
2374
}
2475
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
process {
2+
withName: 'SAMTOOLS_FIXMATE' {
3+
ext.args = params.module_args
4+
}
5+
withName: 'SAMTOOLS_SORT' {
6+
ext.args = params.samtools_sort_args
7+
ext.prefix = { "${meta.id}.sorted" }
8+
}
9+
}

modules/nf-core/samtools/fixmate/tests/tags.yml

Lines changed: 0 additions & 2 deletions
This file was deleted.

modules/nf-core/samtools/markdup/tests/main.nf.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,4 @@ nextflow_process {
8787

8888
}
8989

90-
}
90+
}

modules/yaml-schema.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

modules/yaml-schema.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
meta-schema.json

0 commit comments

Comments
 (0)