Skip to content

Simplify dream contrast handling#11584

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

Simplify dream contrast handling#11584
grst wants to merge 4 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

}

# Use makeContrasts if contrast_string exists
if (is_valid_string(contrast_string)) {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@delfiterradas would I need this check, too? I.e. is there a valid usecase to call this module without contrast, e.g. for normalization only?

Is there any way this could have been false, als both branches of the previous if set a contrast_string?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You are right, that check was redundant!

@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>
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.

2 participants