Skip to content

Commit b54e482

Browse files
committed
Add index and threads to trgt/merge
1 parent 22bb4dc commit b54e482

File tree

4 files changed

+260
-25
lines changed

4 files changed

+260
-25
lines changed

modules/nf-core/trgt/merge/main.nf

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ process TRGT_MERGE {
1414

1515
output:
1616
tuple val(meta), path("*.{vcf,vcf.gz,bcf,bcf.gz}"), emit: vcf
17+
tuple val(meta), path("*.{tbi,csi}") , emit: index, optional: true
1718
tuple val("${task.process}"), val('trgt'), eval("trgt --version | sed 's/.* //g'"), emit: versions_trgt, topic: versions
1819

1920
when:
@@ -32,15 +33,11 @@ process TRGT_MERGE {
3233

3334
"""
3435
trgt merge \\
36+
--threads ${task.cpus} \\
3537
$args \\
3638
$reference \\
3739
$output \\
3840
--vcf ${vcfs}
39-
40-
cat <<-END_VERSIONS > versions.yml
41-
"${task.process}":
42-
trgt: \$(trgt --version |& sed '1!d ; s/trgt //')
43-
END_VERSIONS
4441
"""
4542

4643
stub:
@@ -52,12 +49,10 @@ process TRGT_MERGE {
5249
args.contains("--output-type v") || args.contains("-Ov") ? "vcf" :
5350
"vcf"
5451
def create_cmd = extension.endsWith(".gz") ? "echo '' | gzip >" : "touch"
52+
def index_type = extension == "vcf.gz" ? "tbi" : extension == "bcf.gz" ? "csi" : ''
53+
def create_index = args.contains("--write-index") && extension.endsWith(".gz") ? "touch ${prefix}.${extension}.${index_type}" : ''
5554
"""
5655
$create_cmd ${prefix}.${extension}
57-
58-
cat <<-END_VERSIONS > versions.yml
59-
"${task.process}":
60-
trgt: \$(trgt --version |& sed '1!d ; s/trgt //')
61-
END_VERSIONS
56+
$create_index
6257
"""
6358
}

modules/nf-core/trgt/merge/meta.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,17 @@ output:
7272
description: "Merged output file"
7373
pattern: "*.{vcf,vcf.gz,bcf,bcf.gz}"
7474
ontologies: []
75+
index:
76+
- - meta:
77+
type: map
78+
description: |
79+
Groovy Map containing sample information
80+
e.g. `[ id:'sample1', single_end:false ]`
81+
- "*.{tbi,csi}":
82+
type: file
83+
description: "Index of merged output file"
84+
pattern: "*.{tbi,csi}"
85+
ontologies: []
7586
versions_trgt:
7687
- - ${task.process}:
7788
type: string

modules/nf-core/trgt/merge/tests/main.nf.test

Lines changed: 83 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ nextflow_process {
9595
path(process.out.vcf.get(0).get(1)).vcf.variantsMD5,
9696
path(process.out.vcf.get(0).get(1)).vcf.summary,
9797
path(process.out.vcf.get(0).get(1)).vcf.sampleCount,
98+
process.out.index,
9899
process.out.findAll { key, val -> key.startsWith("versions")}
99100
).match() }
100101
)
@@ -120,6 +121,7 @@ nextflow_process {
120121
path(process.out.vcf.get(0).get(1)).vcf.variantsMD5,
121122
path(process.out.vcf.get(0).get(1)).vcf.summary,
122123
path(process.out.vcf.get(0).get(1)).vcf.sampleCount,
124+
process.out.index,
123125
process.out.findAll { key, val -> key.startsWith("versions")}
124126
).match() }
125127
)
@@ -132,6 +134,7 @@ nextflow_process {
132134
input[0] = BCFTOOLS_SORT.out.vcf
133135
.join(BCFTOOLS_SORT.out.tbi)
134136
.first()
137+
.map { meta, vcf, tbi -> [ [ id : 'test' ], vcf, tbi ] }
135138
input[1] = GUNZIP.out.gunzip
136139
input[2] = SAMTOOLS_FAIDX.out.fai
137140
"""
@@ -143,16 +146,17 @@ nextflow_process {
143146
)
144147
}
145148
}
146-
test("homo sapiens - 1 VCF - --force-single") {
149+
test("homo sapiens - 1 VCF - --force-single --output-type z --write-index") {
147150
when {
148151
params {
149-
trgt_merge_args = "--force-single"
152+
trgt_merge_args = "--force-single --output-type z --write-index"
150153
}
151154
process {
152155
"""
153156
input[0] = BCFTOOLS_SORT.out.vcf
154157
.join(BCFTOOLS_SORT.out.tbi)
155158
.first()
159+
.map { meta, vcf, tbi -> [ [ id : 'test' ], vcf, tbi ] }
156160
input[1] = GUNZIP.out.gunzip
157161
input[2] = SAMTOOLS_FAIDX.out.fai
158162
"""
@@ -165,11 +169,87 @@ nextflow_process {
165169
path(process.out.vcf.get(0).get(1)).vcf.variantsMD5,
166170
path(process.out.vcf.get(0).get(1)).vcf.summary,
167171
path(process.out.vcf.get(0).get(1)).vcf.sampleCount,
172+
process.out.index,
168173
process.out.findAll { key, val -> key.startsWith("versions")}
169174
).match() }
170175
)
171176
}
172177
}
178+
test("homo sapiens - 1 VCF - --force-single --output-type b --write-index") {
179+
when {
180+
params {
181+
trgt_merge_args = "--force-single --output-type b --write-index"
182+
}
183+
process {
184+
"""
185+
input[0] = BCFTOOLS_SORT.out.vcf
186+
.join(BCFTOOLS_SORT.out.tbi)
187+
.first()
188+
.map { meta, vcf, tbi -> [ [ id : 'test' ], vcf, tbi ] }
189+
input[1] = GUNZIP.out.gunzip
190+
input[2] = SAMTOOLS_FAIDX.out.fai
191+
"""
192+
}
193+
}
194+
then {
195+
assertAll(
196+
{ assert process.success },
197+
{ assert snapshot(
198+
file(process.out.vcf.get(0).get(1)).name,
199+
process.out.index,
200+
process.out.findAll { key, val -> key.startsWith("versions")}
201+
).match() }
202+
)
203+
}
204+
}
205+
test("homo sapiens - 2 VCFs - tbi index - stub") {
206+
options "-stub"
207+
when {
208+
params {
209+
trgt_merge_args = "--output-type z --write-index"
210+
}
211+
process {
212+
"""
213+
input[0] = BCFTOOLS_SORT.out.vcf
214+
.join(BCFTOOLS_SORT.out.tbi)
215+
.map { meta, vcf, tbi -> [ [ id : 'test' ], vcf, tbi ] }
216+
.groupTuple()
217+
input[1] = [[],[]]
218+
input[2] = [[],[]]
219+
"""
220+
}
221+
}
222+
then {
223+
assertAll(
224+
{ assert process.success },
225+
{ assert snapshot(process.out).match() }
226+
)
227+
}
228+
}
229+
test("homo sapiens - 2 VCFs - csi index - stub") {
230+
options "-stub"
231+
when {
232+
params {
233+
trgt_merge_args = "--output-type b --write-index"
234+
}
235+
process {
236+
"""
237+
input[0] = BCFTOOLS_SORT.out.vcf
238+
.join(BCFTOOLS_SORT.out.tbi)
239+
.map { meta, vcf, tbi -> [ [ id : 'test' ], vcf, tbi ] }
240+
.groupTuple()
241+
input[1] = [[],[]]
242+
input[2] = [[],[]]
243+
"""
244+
}
245+
}
246+
then {
247+
assertAll(
248+
{ assert process.success },
249+
{ assert snapshot(process.out).match() }
250+
)
251+
}
252+
}
173253
test("homo sapiens - 2 VCFs - stub") {
174254
options "-stub"
175255
when {
@@ -187,10 +267,7 @@ nextflow_process {
187267
then {
188268
assertAll(
189269
{ assert process.success },
190-
{ assert snapshot(
191-
process.out,
192-
process.out.findAll { key, val -> key.startsWith("versions")}
193-
).match() }
270+
{ assert snapshot(process.out).match() }
194271
)
195272
}
196273
}

0 commit comments

Comments
 (0)