Skip to content

Simplify dream contrast handling#11584

Open
grst wants to merge 8 commits into
nf-core:masterfrom
grst:fix-dream
Open

Simplify dream contrast handling#11584
grst wants to merge 8 commits into
nf-core:masterfrom
grst:fix-dream

Conversation

@grst
Copy link
Copy Markdown
Member

@grst grst commented May 11, 2026

I was running into an error in the repeated call of eBayes after fit.contrasts.

r$> fit2 <- eBayes(fit2, proportion = opt$proportion,
stdev.coef.lim = stdev_coef_lim_vals,
trend = opt$trend, robust = opt$robust,
winsor.tail.p = winsor_tail_p_vals)
Error in tmp[, j, drop = FALSE] : subscript out of bounds

r$> traceback()
7: [.MArrayLM2(out, , realcoef)
6: out[, realcoef]
5: is.data.frame(x)
4: rowMeans(out[, realcoef]$df.total)
3: .standard_transform(fit_eb, sigma = sqrt(fit_eb$s2.post))
2: eBayes(fit2, proportion = opt$proportion, stdev.coef.lim = stdev_coef_lim_vals,
trend = opt$trend, robust = opt$robust, winsor.tail.p = winsor_tail_p_vals)
1: eBayes(fit2, proportion = opt$proportion, stdev.coef.lim = stdev_coef_lim_vals,
trend = opt$trend, robust = opt$robust, winsor.tail.p = winsor_tail_p_vals)

It turns out that according to the dream vignette the recommended way of setting contrasts it to directly pass it to the dream() call via L=.

Using nobars() + design() before calling dream, we can construct the contrast vector beforehand also avoiding the manipulation of matrix dimnames after the dream call.

In summary, I think this version is cleaner, more computationally efficient, and solves the specific error I had.

PR checklist

Closes #XXX

  • This comment contains a description of changes (with reason).
  • If you've fixed a bug or added code that should be tested, add tests!
  • If you've added a new tool - have you followed the module conventions in the contribution docs
  • If necessary, include test data in your PR.
  • Remove all TODO statements.
  • Broadcast software version numbers to topic: versions - See version_topics
  • Follow the naming conventions.
  • Follow the parameters requirements.
  • Follow the input/output options guidelines.
  • Add a resource label
  • Use BioConda and BioContainers if possible to fulfil software requirements.
  • Ensure that the test works with either Docker / Singularity. Conda CI tests can be quite flaky:
    • For modules:
      • nf-core modules test <MODULE> --profile docker
      • nf-core modules test <MODULE> --profile singularity
      • nf-core modules test <MODULE> --profile conda
    • For subworkflows:
      • nf-core subworkflows test <SUBWORKFLOW> --profile docker
      • nf-core subworkflows test <SUBWORKFLOW> --profile singularity
      • nf-core subworkflows test <SUBWORKFLOW> --profile conda

Comment thread modules/nf-core/variancepartition/dream/templates/dream.R
@grst grst requested a review from delfiterradas May 11, 2026 14:38
@grst
Copy link
Copy Markdown
Member Author

grst commented May 11, 2026

@delfiterradas et al. could you please take that over and make sure the change trickles down into differentialabundance?

@grst
Copy link
Copy Markdown
Member Author

grst commented May 11, 2026

pre-commit failure is unrelated (API rate limit)

Comment thread modules/nf-core/variancepartition/dream/templates/dream.R Outdated
Co-authored-by: Delfina Terradas <155591053+delfiterradas@users.noreply.github.com>
Comment thread modules/nf-core/variancepartition/dream/templates/dream.R Outdated
Comment thread modules/nf-core/variancepartition/dream/templates/dream.R Outdated
Copy link
Copy Markdown
Member

@pinin4fjords pinin4fjords left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Backing the direction here from the differentialabundance side: it matches the upstream dream-method.Rd example and removes the double-eBayes flaw. I pulled the branch, applied a tightened version of @delfiterradas's single-coef branch suggestion, and ran the full module nf-test suite under docker against the latest variancePartition container - all 9 tests pass. Inline suggestion below rewrites the contrast block.

The seeded test's dream.results.tsv md5 in tests/main.nf.test.snap shifts under the new single-eBayes flow (numerics still match the existing value assertions in the no-seed tests, so the change is just precision-level reordering). Two occurrences to bump (snapshot file isn't in this PR's diff so I can't suggest it inline):

  • 90a06e6b4945c706025582a4c9fddf2c865d9c5da7d3749e371231bd2e3727b3

Non-blocking: makeContrastsDream() would be the strictest-correct path but would reject the existing 2 * treatmenthND6 - treatmentmCherry test (weights don't sum to ±1) - worth its own discussion separate from this PR.

Comment thread modules/nf-core/variancepartition/dream/templates/dream.R Outdated
Comment thread modules/nf-core/variancepartition/dream/templates/dream.R
Comment thread modules/nf-core/variancepartition/dream/templates/dream.R Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants