Skip to content

plotClusterTree(gobject, tree): defaults from a giottoTree - #153

Merged
jiajic merged 1 commit into
refactor/retire-cluster-dendrogramfrom
feat/plot-cluster-tree-defaults
Oct 1, 2026
Merged

jiajic merged 1 commit into
refactor/retire-cluster-dendrogramfrom
feat/plot-cluster-tree-defaults

Conversation

@jiajic

@jiajic jiajic commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator

Stacked on #152 (the showClusterDendrogram() deprecation). The base is that PR's branch. Merge #152 into gsource first and delete its branch, so GitHub retargets this PR to gsource. Otherwise, retarget this PR to gsource by hand before merging it.

Brings plotClusterTree() in line with Giotto's tree consumers after Giotto#1321, where calculateClusterTree() started returning a giottoTree that records what it was built from.

Changes

  • Signature: plotClusterTree(gobject, tree, labels = NULL, spat_unit, feat_type, cluster_column = NULL, view = NULL, k, ...).
    • tree is now the second argument.
    • labels is optional. plotClusterTree(g, tree) draws the tree on its own, labelled with the cluster IDs, which makes it the in-suite ggplot replacement for the deprecated showClusterDendrogram().
  • Defaults from the tree: cluster_column, spat_unit, feat_type and view default to those recorded on a giottoTree, following the same rule as Giotto:
    • inheriting a view prints a short message
    • an explicit value wins, with a warning when it differs from the tree's
    • a plain hclust needs cluster_column passed explicitly
  • view: narrows the cells the size track counts, so counts and tree describe the same cells. Only cell metadata is narrowed, since that's all the plot reads from the object.
  • Leaf check: a tree whose leaves don't match the clusters in the data is an error naming "clusters with no leaf" and "leaves with no cells". Before, a leaf with no cells drew as an empty cluster, and a cluster with no leaf was dropped from the counts.
  • File rename: R/plot_dendrogram.R → R/plot_cluster_tree.R, with Collate updated. It follows the naming rule: "tree" for the object, "dendrogram" only for the drawing or R's dendrogram class.

The context and leaf-check logic is a short copy of Giotto's (.pct_tree_context(), .pct_check_leaves()). GiottoVisuals can't call Giotto, because Giotto imports GiottoVisuals, so it's duplicated rather than exported from either package.

The unreleased 0.2.16 NEWS bullet for plotClusterTree() is amended in place.

Verification

Four new tests in test-plot-cluster-tree.R:

  • a giottoTree renders with neither labels nor cluster_column
  • a plain hclust needs cluster_column
  • a tree from another clustering is refused at the leaf check
  • the view is inherited with a message, and an overriding view warns, then errors at the leaf check because it brings back clusters the tree has no leaf for

All 42 tests pass (91 expectations). The tests call Giotto::calculateClusterTree(view =), which is on Giotto gsource as of #1320.

🤖 Generated with Claude Code

labels is optional, tree is second, and cluster_column / units / view for the
size track default to the tree's. Leaves are checked against the data.
Renames plot_dendrogram.R to plot_cluster_tree.R.
@jiajic
jiajic merged commit 32bd7f7 into refactor/retire-cluster-dendrogram Oct 1, 2026
0 of 6 checks passed
@jiajic
jiajic deleted the feat/plot-cluster-tree-defaults branch October 1, 2026 14:42
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.

1 participant