Skip to content

Extract heatmap core logic into testable R package functions#375

Closed
Copilot wants to merge 14 commits intomasterfrom
copilot/fix-218
Closed

Extract heatmap core logic into testable R package functions#375
Copilot wants to merge 14 commits intomasterfrom
copilot/fix-218

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Aug 26, 2025

Heatmap visualization logic was embedded in Shiny module, making it untestable and unreusable. Extracted into proper package functions with comprehensive test coverage.

Changes

New package functions (R/vis_custom_heatmap.R):

  • parse_custom_groups() - Parse group definition strings
  • prepare_heatmap_data() - Transform data to long format with grouping
  • generate_custom_heatmap() - Core visualization with tidyHeatmap
  • vis_custom_heatmap() - High-level wrapper

Test coverage (tests/testthat/test-vis_custom_heatmap.R):

  • 21 test cases covering all functions, edge cases, and error handling

Shiny module refactoring:

  • Replaced 100 lines of embedded logic with package function calls
  • Module now handles only UI reactivity and display

Usage

Functions are now independently usable:

library(UCSCXenaShiny)

data <- data.frame(
  sample = rep(paste0("S", 1:20), each = 10),
  gene = rep(paste0("Gene", 1:10), 20),
  value = rnorm(200)
)

groups <- "Responders: S1,S2,S3,S4,S5\nNon-responders: S6,S7,S8,S9,S10"

hm <- vis_custom_heatmap(
  data = data,
  groups = groups,
  color_palette = "viridis",
  cluster_rows = TRUE
)

Architecture

Before: Monolithic Shiny module (500 lines, untestable)
After: Package functions (356 lines) + thin Shiny wrapper (450 lines)

All core logic is now testable without Shiny, reusable in scripts/pipelines, and properly documented with roxygen2.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits August 26, 2025 03:28
Co-authored-by: ShixiangWang <25057508+ShixiangWang@users.noreply.github.com>
Co-authored-by: ShixiangWang <25057508+ShixiangWang@users.noreply.github.com>
Co-authored-by: ShixiangWang <25057508+ShixiangWang@users.noreply.github.com>
Copilot AI changed the title [WIP] 自定义分组热图 Implement custom grouped heatmap feature for expression data visualization Aug 26, 2025
Copilot AI requested a review from ShixiangWang August 26, 2025 03:37
@ShixiangWang ShixiangWang requested a review from lishensuo August 26, 2025 04:52
@ShixiangWang
Copy link
Copy Markdown
Member

@lishensuo 有空看看ai的代码写的怎么样哈?是不是改改就能合并

@lishensuo
Copy link
Copy Markdown
Collaborator

@lishensuo 有空看看ai的代码写的怎么样哈?是不是改改就能合并

收到老师。等周末左右的时候,会一起处理下~

@ShixiangWang
Copy link
Copy Markdown
Member

ShixiangWang commented Aug 26, 2025 via email

@ShixiangWang
Copy link
Copy Markdown
Member

@copilot 只引入 tidyHeatmap 作为 suggests 依赖实现目标功能,请重新实现和测试。

Copilot AI and others added 4 commits February 8, 2026 15:14
Co-authored-by: ShixiangWang <25057508+ShixiangWang@users.noreply.github.com>
Co-authored-by: ShixiangWang <25057508+ShixiangWang@users.noreply.github.com>
Co-authored-by: ShixiangWang <25057508+ShixiangWang@users.noreply.github.com>
Co-authored-by: ShixiangWang <25057508+ShixiangWang@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Feb 8, 2026

@copilot 只引入 tidyHeatmap 作为 suggests 依赖实现目标功能,请重新实现和测试。

Refactoring complete! The custom heatmap module now uses only tidyHeatmap as a Suggests dependency.

Key changes:

  • Removed 5 packages (ComplexHeatmap, pheatmap, viridis, circlize, grid)
  • Kept only tidyHeatmap
  • Reduced code by 196 lines (~28%)
  • All features preserved
  • Added comprehensive documentation

Commits:

Ready for testing. All functionality including custom grouping, multiple color palettes, and export features have been preserved.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • cran.r-project.org
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node /home/REDACTED/work/_temp/ghcca-node/node/bin/node --enable-source-maps /home/REDACTED/work/_temp/copilot-developer-action-main/dist/index.js (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI and others added 2 commits February 8, 2026 16:00
- Simplify dataset selection to match other GA modules pattern
- Add "NONE" option as default to ensure dropdown renders
- Add validation to warn if no dataset selected
- Update UI text from "expression data" to "molecular data"
- Change "genes" terminology to generic "features" throughout
- Improve error messages to be dataset-type agnostic

Co-authored-by: ShixiangWang <25057508+ShixiangWang@users.noreply.github.com>
Co-authored-by: ShixiangWang <25057508+ShixiangWang@users.noreply.github.com>
Copilot AI changed the title Implement custom grouped heatmap feature for expression data visualization Fix custom heatmap dataset selection and remove expression data limitation Feb 8, 2026
- Add get_dataset_features() function to fetch available features from Xena datasets
- Update custom heatmap module to automatically load features when dataset is selected
- Default select first 10-20 features for better UX
- Add helpful UI text explaining automatic feature loading
- Add jsonlite dependency for JSON parsing
- Improve error handling and user notifications

Co-authored-by: ShixiangWang <25057508+ShixiangWang@users.noreply.github.com>
Copilot AI changed the title Fix custom heatmap dataset selection and remove expression data limitation Add dynamic feature loading to custom heatmap with auto-selection Feb 8, 2026
Remove get_dataset_features() function and API calls. Instead, use
all_preload_identifiers which already contains all molecular IDs
(Gene, Protein, miRNA). Simply select first 15 items as defaults.

This is much simpler, more reliable, and doesn't require API calls
that may fail. The preloaded identifiers list is comprehensive and
sufficient for most use cases.

Changes:
- Remove get_dataset_features() from R/query_value.R
- Simplify observe() block in custom heatmap module
- Use all_preload_identifiers directly
- Pre-select first 15 features by default
- Remove complex error handling and API call logic
- Remove unnecessary help text about feature loading

Co-authored-by: ShixiangWang <25057508+ShixiangWang@users.noreply.github.com>
Copilot AI changed the title Add dynamic feature loading to custom heatmap with auto-selection Remove unreliable API-based feature loading, use preloaded identifiers Feb 8, 2026
Copilot AI and others added 2 commits February 8, 2026 16:36
Create R/vis_custom_heatmap.R with testable functions:
- parse_custom_groups(): Parse group definition strings
- prepare_heatmap_data(): Prepare data for visualization
- generate_custom_heatmap(): Core heatmap generation
- vis_custom_heatmap(): High-level wrapper function

Add comprehensive tests in tests/testthat/test-vis_custom_heatmap.R

These functions can now be tested independently of Shiny,
used programmatically, and are properly documented with roxygen2.

Next step: Refactor Shiny module to use these package functions.

Co-authored-by: ShixiangWang <25057508+ShixiangWang@users.noreply.github.com>
Update modules-ga-custom-heatmap.R to use the new package functions:
- Replace custom group parsing logic with parse_custom_groups()
- Replace heatmap generation logic with generate_custom_heatmap()
- Shiny module now acts as thin UI wrapper
- Reduced code complexity: 67 lines removed, 35 lines added
- All core logic now testable independently

The Shiny module now focuses on:
- UI reactivity and user input handling
- Calling package functions with appropriate parameters
- Displaying results and notifications

Benefits:
- Cleaner separation of concerns
- Core logic can be tested without Shiny
- Easier to maintain and debug
- Can reuse functions in other contexts

Co-authored-by: ShixiangWang <25057508+ShixiangWang@users.noreply.github.com>
Copilot AI changed the title Remove unreliable API-based feature loading, use preloaded identifiers Extract heatmap core logic into testable R package functions Feb 8, 2026
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.

3 participants