Skip to content

Commit 690f067

Browse files
delfiterradasatrigila
authored andcommitted
Fix dream to show more than 10 results (#9507)
* fix: dream to show more than 10 results * test: update snapshots * test: update snapshots * feat: add round digits option and update snapshots again * fix: improve code formatting and update test snapshots * Fix tests and update snapshots * Update snapshot for `abundance_differential_filter` subworkflow * Fix tests with unstable content * Fix unstable files in test for `abundance_differential_filter` subworkflow --------- Co-authored-by: Anabella Trigila <[email protected]>
1 parent 68d6485 commit 690f067

File tree

6 files changed

+137
-140
lines changed

6 files changed

+137
-140
lines changed

modules/nf-core/variancepartition/dream/templates/dream.R

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ opt <- list(
8080
winsor_tail_p = "0.05,0.1", # Winsor tail probabilities for eBayes
8181
ddf = "adaptive", # 'Satterthwaite', 'Kenward-Roger', or 'adaptive'
8282
reml = FALSE,
83+
round_digits = NULL,
8384
formula = "$formula", # User-specified formula (e.g. "~ + (1 | sample_number)")
8485
apply_voom = FALSE # Whether to apply `voomWithDreamWeights`
8586
)
@@ -107,6 +108,10 @@ opt\$p.value <- as.numeric(opt\$p.value)
107108
opt\$lfc <- as.numeric(opt\$lfc)
108109
opt\$confint <- as.logical(opt\$confint)
109110

111+
if (!is.null(opt\$round_digits)){
112+
opt\$round_digits <- as.numeric(opt\$round_digits)
113+
}
114+
110115
# Load metadata
111116
metadata <- read_delim_flexible(opt\$sample_file, header = TRUE, stringsAsFactors = TRUE)
112117
rownames(metadata) <- metadata[[opt\$sample_id_col]]
@@ -178,22 +183,28 @@ if (!is.null(opt\$contrast_string)) {
178183
stdev.coef.lim = stdev_coef_lim_vals,
179184
trend = opt\$trend, robust = opt\$robust,
180185
winsor.tail.p = winsor_tail_p_vals)
181-
results <- topTable(fit2,
186+
results <- topTable(fit2, number = Inf,
182187
adjust.method = opt\$adjust.method,
183188
p.value = opt\$p.value, lfc = opt\$lfc, confint = opt\$confint)
184189

185190
} else {
186191
coef_name <- paste0(opt\$contrast_variable, opt\$contrast_target)
187192
cat("Using default contrast matrix:", coef_name, "\n")
188193

189-
results <- topTable(fitmm, coef = coef_name,
194+
results <- topTable(fitmm, coef = coef_name, number = Inf,
190195
adjust.method = opt\$adjust.method, p.value = opt\$p.value,
191196
lfc = opt\$lfc, confint = opt\$confint)
192197
}
193198

194199
results\$gene_id <- rownames(results)
195200
results <- results[, c("gene_id", setdiff(names(results), "gene_id"))]
196201

202+
# Round results if required
203+
if (!is.null(opt\$round_digits)) {
204+
numeric_columns <- vapply(results, is.numeric, logical(1))
205+
results[numeric_columns] <- lapply(results[numeric_columns], round, digits = opt\$round_digits)
206+
}
207+
197208
# Export topTable results
198209
write.table(results, file = paste(opt\$output_prefix, 'dream.results.tsv', sep = '.'),
199210
col.names = TRUE, row.names = FALSE, sep = '\t', quote = FALSE )

modules/nf-core/variancepartition/dream/tests/main.nf.test

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ nextflow_process {
22

33
name "Test Process VARIANCEPARTITION_DREAM"
44
script "../main.nf"
5+
config "./nextflow.config"
56
process "VARIANCEPARTITION_DREAM"
67

78
tag "modules"
@@ -12,6 +13,9 @@ nextflow_process {
1213
test("RNAseq - Feature Counts - formula + comparison contrast string - interaction") {
1314

1415
when {
16+
params {
17+
module_args = "--round_digits 2"
18+
}
1519
process {
1620
"""
1721
input[0] = Channel.of([
@@ -40,8 +44,8 @@ nextflow_process {
4044
assertAll(
4145
{ assert process.success },
4246
{ assert path(process.out.results[0][1]).getText().contains("gene_id\tlogFC\tAveExpr\tt\tP.Value\tadj.P.Val\tB") },
43-
{ assert path(process.out.results[0][1]).getText().contains("0.8333") },
44-
{ assert path(process.out.results[0][1]).getText().contains("13.5\t21.125\t4.40") },
47+
{ assert path(process.out.results[0][1]).getText().contains("0.83") },
48+
{ assert path(process.out.results[0][1]).getText().contains("13.5\t21.12\t4.41") },
4549
{ assert snapshot(process.out.model, process.out.versions).match() }
4650
)
4751
}
@@ -50,6 +54,9 @@ nextflow_process {
5054
test("Mus musculus - expression table - contrasts") {
5155

5256
when {
57+
params {
58+
module_args = "--round_digits 2"
59+
}
5360
process {
5461
"""
5562
input[0] = Channel.of(['id': 'treatment_mCherry_hND6', 'variable': 'treatment', 'reference': 'mCherry', 'target': 'hND6', 'blocking_factors':null, 'formula':null])
@@ -77,6 +84,9 @@ nextflow_process {
7784
test("Mus musculus - expression table - contrasts + formula + comparison contrast string") {
7885

7986
when {
87+
params {
88+
module_args = "--round_digits 2"
89+
}
8090
process {
8191
"""
8292
input[0] = Channel.of(['id': 'treatment_mCherry_hND6', 'variable': 'treatment', 'reference': 'mCherry', 'target': 'hND6', 'blocking_factors':'sample_number', 'formula':'~ treatment', 'comparison':'treatmenthND6'])
@@ -98,16 +108,20 @@ nextflow_process {
98108
assertAll(
99109
{ assert process.success },
100110
{ assert path(process.out.results[0][1]).getText().contains("gene_id\tlogFC\tAveExpr\tt\tP.Value\tadj.P.Val\tB") },
101-
{ assert path(process.out.results[0][1]).getText().contains("849.6666") },
102-
{ assert path(process.out.results[0][1]).getText().contains("1050\t549\t3.78") }
103-
)
111+
{ assert path(process.out.results[0][1]).getText().contains("849.67") },
112+
{ assert path(process.out.results[0][1]).getText().contains("1050\t549\t3.78") },
113+
{ assert snapshot(process.out.model, process.out.versions).match() }
114+
)
104115
}
105116
}
106117

107118

108119
test("Mus musculus - expression table - contrasts + formula + weighted comparison contrast string") {
109120

110121
when {
122+
params {
123+
module_args = "--round_digits 2"
124+
}
111125
process {
112126
"""
113127
input[0] = Channel.of(['id': 'treatment_mCherry_hND6', 'variable': 'treatment', 'reference': 'mCherry', 'target': 'hND6', 'blocking_factors':'sample_number', 'formula':'~ 0 + treatment', 'comparison':'2 * treatmenthND6 - treatmentmCherry'])
@@ -128,17 +142,20 @@ nextflow_process {
128142
then {
129143
assertAll(
130144
{ assert process.success },
131-
{ assert snapshot(process.out.model, process.out.versions).match() },
132145
{ assert path(process.out.results[0][1]).getText().contains("gene_id\tlogFC\tAveExpr\tt\tP.Value\tadj.P.Val\tB") },
133-
{ assert path(process.out.results[0][1]).getText().contains("2124\t549\t4.83") },
134-
{ assert path(process.out.results[0][1]).getText().contains("1707.33") }
135-
)
146+
{ assert path(process.out.results[0][1]).getText().contains("2124\t549\t4.84") },
147+
{ assert path(process.out.results[0][1]).getText().contains("1707.33") },
148+
{ assert snapshot(process.out.model, process.out.versions).match() }
149+
)
136150
}
137151
}
138152

139153
test("Mus musculus - expression table - contrasts + formula + comparison contrast string - no intercept") {
140154

141155
when {
156+
params {
157+
module_args = "--round_digits 2"
158+
}
142159
process {
143160
"""
144161
input[0] = Channel.of(['id': 'treatment_mCherry_hND6', 'variable': 'treatment', 'reference': 'mCherry', 'target': 'hND6', 'blocking_factors':'sample_number', 'formula':'~ 0 + treatment + sample_number', 'comparison':'treatmenthND6 - treatmentmCherry'])
@@ -161,15 +178,18 @@ nextflow_process {
161178
{ assert process.success },
162179
{ assert snapshot(process.out.model, process.out.versions).match() },
163180
{ assert path(process.out.results[0][1]).getText().contains("gene_id\tlogFC\tAveExpr\tt\tP.Value\tadj.P.Val\tB") },
164-
{ assert path(process.out.results[0][1]).getText().contains("-95.6666") },
165-
{ assert path(process.out.results[0][1]).getText().contains("1050\t549\t4.15") }
166-
)
181+
{ assert path(process.out.results[0][1]).getText().contains("-95.67") },
182+
{ assert path(process.out.results[0][1]).getText().contains("1050\t549\t4.16") }
183+
)
167184
}
168185
}
169186

170187
test("Mus musculus - expression table - contrasts + blocking factors") {
171188

172189
when {
190+
params {
191+
module_args = "--round_digits 2"
192+
}
173193
process {
174194
"""
175195
input[0] = Channel.of(['id': 'treatment_mCherry_hND6', 'variable': 'treatment', 'reference': 'mCherry', 'target': 'hND6', 'blocking_factors':'sample_number', 'formula':'~ treatment + (1 | sample_number)'])
@@ -199,6 +219,9 @@ nextflow_process {
199219

200220
options '-stub'
201221
when {
222+
params {
223+
module_args = "--round_digits 2"
224+
}
202225
process {
203226
"""
204227
input[0] = Channel.of(['id': 'treatment_mCherry_hND6', 'variable': 'treatment', 'reference': 'mCherry', 'target': 'hND6', 'blocking_factors':'sample_number', 'formula':'~ treatment + (1 | sample_number)'])

modules/nf-core/variancepartition/dream/tests/main.nf.test.snap

Lines changed: 33 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
]
2121
],
2222
"meta": {
23-
"nf-test": "0.9.2",
24-
"nextflow": "25.04.6"
23+
"nf-test": "0.9.3",
24+
"nextflow": "25.10.2"
2525
},
26-
"timestamp": "2025-11-10T16:15:40.192241719"
26+
"timestamp": "2025-12-04T21:00:34.198143553"
2727
},
2828
"RNAseq - Feature Counts - formula + comparison contrast string - interaction": {
2929
"content": [
@@ -46,10 +46,10 @@
4646
]
4747
],
4848
"meta": {
49-
"nf-test": "0.9.2",
50-
"nextflow": "25.04.6"
49+
"nf-test": "0.9.3",
50+
"nextflow": "25.10.2"
5151
},
52-
"timestamp": "2025-11-10T16:14:20.039981065"
52+
"timestamp": "2025-12-04T20:59:55.416875311"
5353
},
5454
"Mus musculus - expression table - contrasts + blocking factors": {
5555
"content": [
@@ -64,7 +64,7 @@
6464
"blocking_factors": "sample_number",
6565
"formula": "~ treatment + (1 | sample_number)"
6666
},
67-
"treatment_mCherry_hND6.dream.results.tsv:md5,ad7e79a25bf407b210e3ebfbf734f68e"
67+
"treatment_mCherry_hND6.dream.results.tsv:md5,df0717ddf702543c375c1a5f4eae3fd7"
6868
]
6969
],
7070
"1": [
@@ -106,7 +106,7 @@
106106
"blocking_factors": "sample_number",
107107
"formula": "~ treatment + (1 | sample_number)"
108108
},
109-
"treatment_mCherry_hND6.dream.results.tsv:md5,ad7e79a25bf407b210e3ebfbf734f68e"
109+
"treatment_mCherry_hND6.dream.results.tsv:md5,df0717ddf702543c375c1a5f4eae3fd7"
110110
]
111111
],
112112
"versions": [
@@ -115,10 +115,10 @@
115115
}
116116
],
117117
"meta": {
118-
"nf-test": "0.9.2",
119-
"nextflow": "25.04.6"
118+
"nf-test": "0.9.3",
119+
"nextflow": "25.10.2"
120120
},
121-
"timestamp": "2025-11-10T16:18:15.340812595"
121+
"timestamp": "2025-12-04T19:20:24.632444115"
122122
},
123123
"Mus musculus - expression table - contrasts + blocking factors stub": {
124124
"content": [
@@ -210,82 +210,35 @@
210210
]
211211
],
212212
"meta": {
213-
"nf-test": "0.9.2",
214-
"nextflow": "25.04.6"
213+
"nf-test": "0.9.3",
214+
"nextflow": "25.10.2"
215215
},
216-
"timestamp": "2025-11-10T16:15:20.824781388"
216+
"timestamp": "2025-12-04T21:02:12.893838766"
217217
},
218218
"Mus musculus - expression table - contrasts + formula + comparison contrast string": {
219219
"content": [
220-
{
221-
"0": [
222-
[
223-
{
224-
"id": "treatment_mCherry_hND6",
225-
"variable": "treatment",
226-
"reference": "mCherry",
227-
"target": "hND6",
228-
"blocking_factors": "sample_number",
229-
"formula": "~ treatment",
230-
"comparison": "treatmenthND6"
231-
},
232-
"treatment_mCherry_hND6.dream.results.tsv:md5,0b9521f3aafdbc7f2df761bdc8b1a1ea"
233-
]
234-
],
235-
"1": [
236-
[
237-
{
238-
"id": "treatment_mCherry_hND6",
239-
"variable": "treatment",
240-
"reference": "mCherry",
241-
"target": "hND6",
242-
"blocking_factors": "sample_number",
243-
"formula": "~ treatment",
244-
"comparison": "treatmenthND6"
245-
},
246-
"treatment_mCherry_hND6.dream.model.txt:md5,8cb944a29e3d3d0e540048b4d8331b17"
247-
]
248-
],
249-
"2": [
250-
"versions.yml:md5,fc1f26eb2194018e99fc2916332676b7"
251-
],
252-
"model": [
253-
[
254-
{
255-
"id": "treatment_mCherry_hND6",
256-
"variable": "treatment",
257-
"reference": "mCherry",
258-
"target": "hND6",
259-
"blocking_factors": "sample_number",
260-
"formula": "~ treatment",
261-
"comparison": "treatmenthND6"
262-
},
263-
"treatment_mCherry_hND6.dream.model.txt:md5,8cb944a29e3d3d0e540048b4d8331b17"
264-
]
265-
],
266-
"results": [
267-
[
268-
{
269-
"id": "treatment_mCherry_hND6",
270-
"variable": "treatment",
271-
"reference": "mCherry",
272-
"target": "hND6",
273-
"blocking_factors": "sample_number",
274-
"formula": "~ treatment",
275-
"comparison": "treatmenthND6"
276-
},
277-
"treatment_mCherry_hND6.dream.results.tsv:md5,0b9521f3aafdbc7f2df761bdc8b1a1ea"
278-
]
279-
],
280-
"versions": [
281-
"versions.yml:md5,fc1f26eb2194018e99fc2916332676b7"
220+
[
221+
[
222+
{
223+
"id": "treatment_mCherry_hND6",
224+
"variable": "treatment",
225+
"reference": "mCherry",
226+
"target": "hND6",
227+
"blocking_factors": "sample_number",
228+
"formula": "~ treatment",
229+
"comparison": "treatmenthND6"
230+
},
231+
"treatment_mCherry_hND6.dream.model.txt:md5,8cb944a29e3d3d0e540048b4d8331b17"
282232
]
283-
}
233+
],
234+
[
235+
"versions.yml:md5,fc1f26eb2194018e99fc2916332676b7"
236+
]
284237
],
285238
"meta": {
286-
"nf-test": "0.9.2",
287-
"nextflow": "24.10.5"
239+
"nf-test": "0.9.3",
240+
"nextflow": "25.10.2"
288241
},
289-
"timestamp": "2025-04-07T17:45:38.612858235"
242+
"timestamp": "2025-12-04T21:02:02.754734146"
290243
}
291244
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
process {
2+
withName: 'VARIANCEPARTITION_DREAM' {
3+
ext.args = { [
4+
"--round_digits 2"
5+
].join(' ').trim() }
6+
ext.prefix = { "${meta.id}_${meta.differential_method}" }
7+
}
8+
}

subworkflows/nf-core/abundance_differential_filter/tests/main.nf.test

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ nextflow_workflow {
1616
tag "variancepartition/dream"
1717

1818
test("dream") {
19+
config './dream.config'
1920
tag "dream_simple"
2021

2122
when {
@@ -59,8 +60,8 @@ nextflow_workflow {
5960
then {
6061
assertAll(
6162
{ assert workflow.success },
63+
{ assert path(workflow.out.results_genewise[0][1]).getText().contains("gene_id\tlogFC\tAveExpr\tt\tP.Value\tadj.P.Val\tB") },
6264
{ assert snapshot(
63-
workflow.out.results_genewise,
6465
workflow.out.results_genewise_filtered,
6566
workflow.out.model,
6667
workflow.out.versions
@@ -70,6 +71,7 @@ nextflow_workflow {
7071
}
7172

7273
test("dream - complex contrast - literal contrast string comparison") {
74+
config './dream.config'
7375
tag "dream_complex"
7476

7577
when {
@@ -114,10 +116,8 @@ nextflow_workflow {
114116
assertAll(
115117
{ assert workflow.success },
116118
{ assert path(workflow.out.results_genewise[0][1]).getText().contains("gene_id\tlogFC\tAveExpr\tt\tP.Value\tadj.P.Val\tB") },
117-
{ assert path(workflow.out.results_genewise[0][1]).getText().contains("-95.6666") },
118-
{ assert path(workflow.out.results_genewise[0][1]).getText().contains("1050\t549\t4.15") },
119119
{ assert snapshot(
120-
file(workflow.out.results_genewise[0][1]).name,
120+
workflow.out.results_genewise_filtered,
121121
workflow.out.model,
122122
workflow.out.versions
123123
).match() }

0 commit comments

Comments
 (0)