Skip to content

feat(plots): standardize output figures across MOSuite function calls#223

Open
phoman14 wants to merge 28 commits into
mainfrom
FigOutSync
Open

feat(plots): standardize output figures across MOSuite function calls#223
phoman14 wants to merge 28 commits into
mainfrom
FigOutSync

Conversation

@phoman14

@phoman14 phoman14 commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR standardizes the appearance of MOSuite output figures across direct plotting calls, workflow calls, and the matching Code Ocean capsules. The intent is that the same data and grouping metadata produce consistent colors, category order, point sizing, and readable legends whether a figure is created by plot_pca_2d(), plot_pca_3d(), plot_histogram(), plot_read_depth(), filter_counts(), normalize_counts(), batch_correct_counts(), or an affected capsule.

Changes

  • Align MOSuite plot color defaults with Code Ocean capsule defaults while keeping get_mosuite_colors() available for later use.
  • Preserve random color generation as a fallback only when a selected or provided palette has too few colors.
  • Respect factor level order for factor grouping columns and metadata first appearance for non-factor grouping columns.
  • Improve top and bottom legend wrapping and automatic legend text sizing for PCA and histogram plots with many or long labels.
  • Align filter_counts(), normalize_counts(), and batch_correct_counts() PCA/histogram defaults and forwarded settings.
  • Add optional group coloring to plot_read_depth() and the clean_raw_counts() read-depth output while preserving the single-color default when no group is selected.
  • Add package tests for color resolution, PCA legends, histogram legends, filter defaults, normalize defaults, batch correction defaults, and read-depth group coloring/fallback behavior.
  • Update NEWS.md for the user-facing plotting changes.

Affected capsule repos from these package changes:

Validation:

  • test-plot_pca.R: PASS 21
  • test-plot_histogram.R: PASS 14
  • test-filter.R: PASS 27
  • test-normalize.R: PASS 22
  • test-batch-correction.R: PASS 22
  • Focused package validation on FigOutSync@6631ece: devtools::test(filter = plots|plot_read_depth|clean): PASS 25
  • Clean capsule validation: Rscript tests/testthat.R: PASS 13
  • Workspace Rmd render succeeded and generated no-group, grouped-color, and one-color fallback read-depth examples in tests/plotting-parameters-test-output/figures/read_depth/.
  • Rd syntax validations passed for updated PCA/histogram, batch correction, clean, and read-depth docs.
  • devtools::check(error_on = never) was run locally earlier on FigOutSync@dbf0405: DESeq2 integration and graphics-device-sensitive plot snapshots are skipped during R CMD check; result was 1 error, 0 warnings, 0 notes because two untouched macOS differential-analysis tests still fail. Full check was not rerun after the read-depth follow-up.

Issues

No linked issue.

PR Checklist

(Strikethrough any points that are not applicable.)

  • This comment contains a description of changes with justifications, with any relevant issues linked.
  • Write unit tests for any new features, bug fixes, or other code changes.
  • Update the docs if there are any API changes (roxygen2 comments, vignettes, readme, etc.).
  • Update NEWS.md with a short description of any user-facing changes and reference the PR number. Follow the style described in https://style.tidyverse.org/news.html
  • Run devtools::check() locally and fix all notes, warnings, and errors. Local devtools::check(error_on = never) was run on macOS earlier; DESeq2 integration and plot snapshot checks are skipped during R CMD check, leaving 0 warnings and 0 notes, but the check still has 1 test error from untouched differential-analysis expectations in test-differential.R.

phoman14 added 10 commits June 29, 2026 19:58
Use the MOSuite palette as the hardcoded filter and normalize plot color default, extend short explicit palettes through the selected palette path, and keep random colors as the get_colors_vctr fallback. Update docs, JSON defaults, and focused color/filter/normalize tests.
@github-actions github-actions Bot added the MOSuite RepoName label Jul 2, 2026
@phoman14
phoman14 requested a review from kelly-sovacool July 2, 2026 19:52
@phoman14 phoman14 changed the title Align plot defaults with capsule behavior Standardize output figures across MOSuite function calls Jul 2, 2026
@codecov

codecov Bot commented Jul 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.41722% with 38 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.81%. Comparing base (ce1865a) to head (ee8f925).
⚠️ Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
R/batch-correction.R 83.87% 10 Missing ⚠️
R/plot_heatmap.R 57.14% 9 Missing ⚠️
R/filter.R 62.50% 6 Missing ⚠️
R/plot_pca.R 80.64% 6 Missing ⚠️
R/plots.R 90.90% 4 Missing ⚠️
R/plot_read_depth.R 95.12% 2 Missing ⚠️
R/colors.R 97.77% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #223      +/-   ##
==========================================
+ Coverage   79.66%   79.81%   +0.15%     
==========================================
  Files          22       22              
  Lines        3398     3612     +214     
==========================================
+ Hits         2707     2883     +176     
- Misses        691      729      +38     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

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.

Pull request overview

This PR standardizes MOSuite figure defaults (colors, legend layout, and sizing) so that plots created directly via plotting functions and those produced indirectly by filter_counts(), normalize_counts(), and batch_correct_counts() render consistently (including in downstream capsule workflows).

Changes:

  • Introduces deterministic color-resolution helpers (including factor-level / first-observed ordering) and applies them across PCA, histogram, and heatmap plots.
  • Adds automatic legend text sizing and top/bottom legend wrapping for dense legends.
  • Aligns workflow functions’ plotting defaults/forwarding and expands test coverage + updates docs/JSON defaults.

Reviewed changes

Copilot reviewed 45 out of 47 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
tests/testthat/test-plot_pca.R Adds PCA tests for color resolution and wrapped legends.
tests/testthat/test-plot_histogram.R Adds histogram tests for legend wrapping and deterministic color mapping.
tests/testthat/test-plot_heatmap.R Adds heatmap tests for annotation color resolution order.
tests/testthat/test-normalize.R Adds tests ensuring normalize forwards plotting args/default colors.
tests/testthat/test-filter.R Adds tests ensuring filter forwards plotting args/default colors.
tests/testthat/test-colors.R Updates palette expectations; adds tests for resolve_plot_colors().
tests/testthat/test-batch-correction.R Adds tests ensuring batch correction forwards plotting args/default colors.
tests/testthat/_snaps/E2E.md Updates snapshot output reflecting new default colors_for_plots type.
R/plots.R Adds internal legend sizing/wrapping helpers for ggplot color legends.
R/plot_pca.R Updates PCA defaults; applies deterministic colors + legend layout logic.
R/plot_histogram.R Applies deterministic colors + legend sizing/wrapping to histograms.
R/plot_heatmap.R Uses shared color resolver for heatmap annotations; adjusts palette expansion.
R/normalize.R Aligns normalize defaults and forwards histogram axis/legend settings.
R/filter.R Aligns filter defaults; improves plot saving sizing and forwards plotting args.
R/colors.R Adds MOSuite palette + observed-order helper + resolve_plot_colors().
R/batch-correction.R Aligns batch-correct plotting defaults/forwarding; adds interactive option.
PCA_COLOR_MATCH_NOTES.md Adds internal design notes for the color-matching changes.
NEWS.md Documents user-facing plotting default changes.
man/set_color_pal.Rd Updates default palette function documentation.
man/plot_pca_3d.Rd Updates color mapping documentation for PCA 3D.
man/plot_pca_2d.Rd Updates defaults + documents legend font sizing and color mapping rules.
man/plot_histogram.data.frame.Rd Documents color mapping rules + auto legend font sizing.
man/plot_expr_heatmap.Rd Documents color mapping rules for heatmap group colors.
man/plot_corr_heatmap-data.frame.Rd Documents color mapping rules for correlation heatmap annotations.
man/normalize_counts.Rd Updates defaults and clarifies color/legend behavior.
man/get_colors_vctr.Rd Updates default palette + ordering behavior documentation.
man/get_colors_lst.Rd Updates default palette documentation.
man/filter_counts.Rd Updates defaults and clarifies color/legend behavior.
man/batch_correct_counts.Rd Updates defaults + documents new forwarded plotting parameters.
inst/extdata/json_args/defaults/plot_pca_2d.json Updates JSON defaults to match new PCA defaults.
inst/extdata/json_args/defaults/normalize_counts.json Updates JSON defaults to match new normalize defaults.
inst/extdata/json_args/defaults/filter_counts.json Updates JSON defaults to match new filter defaults.
inst/extdata/json_args/defaults/batch_correct_counts.json Updates JSON defaults to match new batch-correct defaults.
inst/extdata/json_args/common/plot_pca_2d.json Updates shared JSON defaults for PCA point size.
inst/extdata/json_args/common/normalize_counts.json Updates shared JSON defaults for normalize colors/legend size.
inst/extdata/json_args/common/filter_counts.json Updates shared JSON defaults for filter colors/legend size.
inst/extdata/galaxy/2_blueprints/plot_pca_3d.json Updates blueprint descriptions re: deterministic color assignment.
inst/extdata/galaxy/2_blueprints/plot_pca_2d.json Updates blueprint defaults + descriptions for PCA 2D.
inst/extdata/galaxy/2_blueprints/normalize_counts.json Updates blueprint defaults + descriptions for normalize.
inst/extdata/galaxy/2_blueprints/filter_counts.json Updates blueprint defaults + descriptions for filter.
inst/extdata/galaxy/2_blueprints/batch_correct_counts.json Updates blueprint defaults + descriptions for batch correction.
inst/extdata/galaxy/1_mosuite-templates/normalize_counts.json Updates template default for histogram grouping.
inst/extdata/galaxy/1_mosuite-templates/filter_counts.json Updates template default for histogram grouping.
inst/extdata/galaxy/0_nidap-1.0/Normalization_CCBR_.code-template.json Updates legacy template default for histogram grouping.
inst/extdata/galaxy/0_nidap-1.0/Filter_Low_Counts_CCBR_.code-template.json Updates legacy template default for histogram grouping.
inst/extdata/galaxy/0_nidap-1.0/Batch_Correction_CCBR_.code-template.json Updates legacy template default for histogram grouping.
CITATION.cff Updates a referenced author email.
Files not reviewed (2)
  • man/batch_correct_counts.Rd: Generated file
  • man/filter_counts.Rd: Generated file

Comment thread R/colors.R
return(unname(colorspace::hex(colorspace::LAB(km$centers))))
}

get_mosuite_colors <- function(n, ...) {
Comment thread R/colors.R
Comment on lines +167 to +171
if (!is.null(names(color_values))) {
if (all(obs %in% names(color_values))) {
return(color_values)
}
}
Comment thread R/plot_pca.R
Comment on lines 395 to 402
fill = NA,
linewidth = 1
),
axis.ticks = ggplot2::element_line(linewidth = 1),
legend.text = ggplot2::element_text(size = 18)
legend.text = ggplot2::element_text(size = legend_font_size),
aspect.ratio = 1
) +
ggplot2::coord_fixed(ratio = 1.5) +
ggplot2::scale_colour_manual(values = color_values) +
Comment thread PCA_COLOR_MATCH_NOTES.md Outdated
Comment on lines +34 to +38
1. Accept `color_values` and the observed group labels.
2. Preserve existing names when `color_values` is already a named vector for those labels.
3. Treat named vectors whose names do not cover the observed groups as palette-label names for compatibility.
4. When `color_values` is unnamed, assign names deterministically using first-observed group labels, matching `get_colors_vctr()`.
5. Error when there are more observed groups than colors.
Comment thread PCA_COLOR_MATCH_NOTES.md Outdated
Implemented helper shape:

```r
resolve_plot_colors(dat, colname, color_values = NULL, palette_fun = grDevices::palette.colors, ...)

@kelly-sovacool kelly-sovacool left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Here's an initial review for changes that definitely need to be made. I'm taking a closer look at the color-picking code locally and will have more suggestions for that soon.

Comment thread PCA_COLOR_MATCH_NOTES.md Outdated
Comment thread .Rbuildignore Outdated
Comment thread tests/testthat/test-plots.R Outdated
Comment thread tests/testthat/test-plots.R Outdated
Comment thread PCA_COLOR_MATCH_NOTES.md Outdated
@kelly-sovacool kelly-sovacool changed the title Standardize output figures across MOSuite function calls feat(plots): standardize output figures across MOSuite function calls Jul 7, 2026
phoman14 and others added 6 commits July 7, 2026 11:53
AI notes are removed from file and so not included in .Rbuildignore

Co-authored-by: Kelly Sovacool, PhD <kelly-sovacool@users.noreply.github.com>
already skipped on ci (gh actions). this line is redundant.

Co-authored-by: Kelly Sovacool, PhD <kelly-sovacool@users.noreply.github.com>
Issue should not be skipped locally. If error the issue should be addressed

Co-authored-by: Kelly Sovacool, PhD <kelly-sovacool@users.noreply.github.com>
@phoman14
phoman14 requested a review from kelly-sovacool July 7, 2026 17:47
Comment thread tests/testthat/test-deseq2.R Outdated
phoman14 and others added 2 commits July 9, 2026 12:35
Co-authored-by: Kelly Sovacool, PhD <kelly-sovacool@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

MOSuite RepoName

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants