Skip to content

fix: skip gene-set testing when no methods are given - #564

Merged
ivokwee merged 1 commit into
develfrom
agent/fix-empty-methods-098f13e8d84f
Dec 1, 2026
Merged

ivokwee merged 1 commit into
develfrom
agent/fix-empty-methods-098f13e8d84f

Conversation

@BigomicsYoda

@BigomicsYoda BigomicsYoda commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

This is by an automated agent, not a human.

Reported in #563: computePGX crashes with subscript out of bounds when a dataset is computed with include_default_gmt: false and gset.methods: [].

Cause

Species GO sets are still added, so the gene-set matrix is not empty and compute_testGenesets() calls gset.fitContrastsWithAllMethods(methods = character(0)). No method runs, Q stays empty, and methods <- colnames(Q[[1]]) in R/gset-meta.r raises subscript out of bounds. With a pristine checkout the same input fails even earlier: if (is.null(methods) || methods[1] == "*") evaluates NA for an empty vector, so the condition errors with missing value where TRUE/FALSE needed.

Fix

  • gset.fitContrastsWithAllMethods(): only expand "*" when methods is non-empty, and return empty gene-set results (meta, sig.counts, outputs, matrices as empty lists, timings as a 0 x 5 matrix) as soon as the intersected method vector is empty. This also protects direct API/SDK callers; NULL and "*" still mean all supported methods.
  • compute_testGenesets(): skip the gene-set step when test.methods is an empty vector (returns pgx unchanged, so gene-set results stay empty), and keep results empty if none of the requested methods is supported instead of failing on the empty timings matrix. This matches the expected behaviour in the issue: skip testing, leave gene-set results empty, return without an error.
  • Docstring/.Rd wording for both test.methods and methods updated to state the empty-vector behaviour.

Downstream already tolerates missing gene-set results (compute_prepare4display() guards with if (!is.null(geneSets))), so no caller changes were needed. The sibling ngs.fitContrastsWithAllMethods() is not on this path and was left untouched.

Tests

New tests/testthat/test-gset-meta.R on a small deterministic fixture (200 genes, 6 samples, 4 gene sets):

  • methods = character(0) -> no error, empty result structure, no gene-set statistics.
  • unsupported method names -> handled like no methods.
  • compute_testGenesets(pgx, test.methods = character(0)) -> no error, gset.meta/gsetX stay NULL, expression matrix and gene sets untouched.
  • regression guard: gene-set statistics (p/q sums, significant-set counts, matrix shapes) pinned for camera+fry and spearman, so the early return cannot silently change results when methods are given.

Verification

  • Reproduced both failure modes locally on pristine HEAD, then confirmed the patched code returns empty results with no error for methods = character(0) and for test.methods = character(0).
  • Confirmed the gene-set statistics are identical before/after the change for camera+fry, spearman, and camera+fry+spearman on the fixture.
  • tests/testthat/test-gset-meta.R (4 tests, 32 assertions) and tests/testthat/test-gset-rankcor.R pass locally; test-pgx-compute.R is skipped by its own high-memory guard in this environment.

Limitation: the full local suite could not be run here (devtools::load_all() stops because the Boruta dependency listed in DESCRIPTION is not installed in this environment), so verification ran against the installed playbase 4.1.3 namespace with the two patched functions injected. The CI unittest build runs the full devtools::test().

CI status

The unittest check is red, but not because of this change. In the run for this head (46012964512) the gene-set contexts pass (gset-meta: 32 assertions in 12.4 s, gset-rankcor: 4), and the only failures are [ FAIL 2 | WARN 3 | SKIP 8 | PASS 356 ], both inside tests/testthat/test-wgcna-improvements.R, which arrived on devel with PR #556:

  • test-wgcna-improvements.R:138 — local_mocked_bindings(ai.ask = ...) fails with Can't find binding for ai.ask. ai.ask was removed from playbase in cdc23cb10 ("superseded by omicsai"), yet wgcna.create_module_titles() still calls it bare, so the mock has no binding to replace.
  • test-wgcna-improvements.R:116 — the mocked graphics::plot.default never runs, so captured is NULL instead of the expected layout positions.

The same two failures appear unchanged in the unittest run of the WGCNA branch itself (run 43435521605, feat-clust-wgcna @ dbdfcdc8b, [ FAIL 2 | WARN 3 | SKIP 8 | PASS 315 ]), so the devel test suite is already red before this PR. Repairing it means changing the WGCNA/AI module, which is outside this ticket's scope.

@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 17dce54f-8cb4-482a-bc7f-c1d07941123b

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@BigomicsYoda

Copy link
Copy Markdown
Collaborator Author

@BigomicsYoda please review with pr-agent

computePGX died with 'subscript out of bounds' when a dataset was computed
with include_default_gmt: false and gset.methods: []. Species GO sets are
still added, so compute_testGenesets() reached gset.fitContrastsWithAllMethods()
with an empty method vector: no method ran, Q stayed empty, and indexing the
first result list failed. An empty methods vector also broke the "*" check
(methods[1] is NA there).

Guard both layers: return early in gset.fitContrastsWithAllMethods() so direct
API and SDK callers get empty gene-set results, and skip the genesets step in
compute_testGenesets() so the pgx object keeps empty gene-set results. NULL and
"*" still mean all supported methods.

Adds tests/testthat/test-gset-meta.R covering the empty-methods path (no error,
no gene-set statistics) plus the unsupported-method-names path, and pins the
gene-set statistics for a small fixture so the guard cannot silently change
results when methods are given.
@BigomicsYoda
BigomicsYoda force-pushed the agent/fix-empty-methods-098f13e8d84f branch from 1540211 to 936d1ba Compare November 27, 2026 14:06
@BigomicsYoda

Copy link
Copy Markdown
Collaborator Author

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

563 - Partially compliant

Compliant requirements:

  • gset.fitContrastsWithAllMethods() returns empty gene-set results when the method vector is empty or unsupported.
  • compute_testGenesets() skips gene-set testing when test.methods is an empty vector.
  • compute_testGenesets() keeps gene-set results empty when no supported methods produce results.
  • Tests were added for the empty-methods path and assert no error and no gene-set statistics.

Non-compliant requirements:

  • None

Requires further human verification:

  • End-to-end computePGX behavior with include_default_gmt: false and gset.methods: [].
  • Downstream display/export behavior when gene-set results are absent.
  • Monorepo pin bump after merge.
⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ No major issues detected

@ivokwee
ivokwee merged commit dc5f6c7 into devel Dec 1, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants