Skip to content

Fix single-sample crash in plotSubclonePie (Columns 2 and 3 must be named) (#53)#55

Merged
jiaying2508 merged 1 commit into
KarchinLab:mainfrom
alexanderchang1:fix/issue-53-single-sample-plotsubclonepie
Jul 8, 2026
Merged

Fix single-sample crash in plotSubclonePie (Columns 2 and 3 must be named) (#53)#55
jiaying2508 merged 1 commit into
KarchinLab:mainfrom
alexanderchang1:fix/issue-53-single-sample-plotsubclonepie

Conversation

@alexanderchang1

Copy link
Copy Markdown
Contributor

Closes #53.

Problem

A single-sample (S=1) runPictograph() completes JAGS sampling and writes all core outputs (tree.csv, mcf.csv, mutationClusterAssign.csv, subclone_proportion.csv), then aborts drawing the pie chart:

Error in `as_tibble()`: ! Columns 2 and 3 must be named.
Calls: runPictograph -> print -> plotSubclonePie -> ... -> as_tibble

Because the error propagates out of runPictograph(), inference has already succeeded but downstream steps (e.g. runDeconvolution) are skipped. Multi-sample runs are unaffected.

Root cause

In runPictograph, subclone_props is reordered with matrix subsetting:

subclone_props <- subclone_props[order(as.numeric(rownames(subclone_props))), ]

For a K×1 matrix this drops the dimension (default drop=TRUE) and collapses it to a length-K vector. plotSubclonePie() then takes the is.null(dim(...)) branch and as_tibble_row() produces a 1-row K-column tibble, but sample_names has length 1, so the columns come out unnamed and as_tibble() errors.

Fix

  • Preserve the matrix dimension at the source with drop = FALSE at both reorder sites in runPictograph (the single-tree and per-tree paths).
  • Add a defensive guard at the top of plotSubclonePie() that restores a dropped dimension, so the function is robust to a vector argument from any caller.

Validated on single-sample PDO runs that previously aborted at the pie chart.

…named")

In a single-sample (S=1) run, runPictograph reorders subclone_props with
matrix subsetting:

  subclone_props <- subclone_props[order(as.numeric(rownames(subclone_props))), ]

For a K x 1 matrix this drops the dimension (default drop=TRUE) and collapses
it to a length-K vector. plotSubclonePie() then takes the is.null(dim(...))
branch and as_tibble_row() yields a 1-row K-column tibble, but sample_names
has length 1, so the columns come out unnamed and as_tibble() aborts with
"Columns 2 and 3 must be named". Because the error propagates out of
runPictograph(), inference has already succeeded and the core CSVs are written,
but downstream steps (e.g. runDeconvolution) are skipped. Multi-sample runs are
unaffected.

Two-part fix:
- Preserve the matrix dimension at the source with drop = FALSE at both
  reorder sites in runPictograph (single-tree and per-tree paths).
- Add a defensive guard at the top of plotSubclonePie that restores a dropped
  dimension, so the function is robust to a vector argument from any caller.

Validated on single-sample PDO runs that previously aborted at the pie chart.

Fixes KarchinLab#53
@jiaying2508 jiaying2508 merged commit 02a4fa9 into KarchinLab:main Jul 8, 2026
1 check passed
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.

Single-sample runPictograph crashes in plotSubclonePie() ("Columns 2 and 3 must be named")

2 participants