Skip to content

test: add unit tests for seurat_clustering and cluster_metrics#52

Open
bianjh-cloud wants to merge 41 commits into
mainfrom
51-seurat-clustering-unit-tests
Open

test: add unit tests for seurat_clustering and cluster_metrics#52
bianjh-cloud wants to merge 41 commits into
mainfrom
51-seurat-clustering-unit-tests

Conversation

@bianjh-cloud

@bianjh-cloud bianjh-cloud commented Apr 21, 2026

Copy link
Copy Markdown
Collaborator

Changes

test-cluster_metrics.R

  • imports BRCA fixture data, clustered by seurat_clustering
  • verifies output shape for silhouette parameter
  • checks numeric results, consistency across metadata variables
  • expect errors for missing cluster columns, invalid reduction

test-seurat_clustering.R

  • verifies default parameters
  • run function on BRCA fixture
  • checks that low / high resolution cluster(s) numbers are plotted correctly
  • checks errors for invalid npcs_in, resolution, and algorithm inputs

Issues

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.
  • R-CMD-check succeeds on the most recent user commit.

bianjh-cloud and others added 7 commits March 23, 2026 10:05
- Add test-make_bubble_plot.R and test-make_volcano_plot.R
- Update test-split_featurePlot.R
- Remove source() calls from test-make_volcano_plot.R
- Rename avg_log2FC to avg_log_2_fc in make_volcano_plot.R and tests
- Hardcode fixed math expectations (log10 transforms)
- Regenerate man/make_volcano_plot.Rd

Generated using AI
Add missing test helper that defines selectData(), needed by
test-make_bubble_plot.R and test-split_featurePlot.R at load time.
@bianjh-cloud bianjh-cloud linked an issue Apr 21, 2026 that may be closed by this pull request
@github-actions github-actions Bot added the SCOT RepoName label Apr 21, 2026

@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.

Take a look at my review of #49 and apply those concepts here as well

@kelly-sovacool

Copy link
Copy Markdown
Member

@wong-nw do you have suggestions for new names to seurat_clustering and cluster_metrics so they are verbs per the style guide? https://style.tidyverse.org/functions.html

@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.

Looks like you accidentally made a commit on this branch with changes that were supposed to be on the other branch: b6254bd
This PR should only contain changes related to seurat_clustering, cluster_metrics, and the BRCA dataset. Make sure you're aware of which branch you're on when you're making changes so you only work on what is relevant to that particular pull request.

Please revert that commit on this branch and push again:

git revert b6254bd
git push

This reverts commit b6254bd, reversing
changes made to 84015e8.

revert branch; remove changes that were supposed to be in other feature branches
@bianjh-cloud

Copy link
Copy Markdown
Collaborator Author

Looks like you accidentally made a commit on this branch with changes that were supposed to be on the other branch: b6254bd This PR should only contain changes related to seurat_clustering, cluster_metrics, and the BRCA dataset. Make sure you're aware of which branch you're on when you're making changes so you only work on what is relevant to that particular pull request.

Please revert that commit on this branch and push again:

git revert b6254bd
git push

Reverted, added changes made specifically to clustering functions, along with relevant fixtures and helper scripts.

@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.

this is an improvement! see my comments for more details on how to improve this

Comment thread R/seurat_clustering.R Outdated
Comment on lines +10 to +13
# Load the current fixture
brca <- readRDS(
"tests/testthat/fixtures/BRCA_Combine_and_Renormalize_SO_downsample.rds"
)

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.

how did you generate the rds file in the first place? it needs to be documented from the very beginning, including where you downloaded it from.

also, use testthat::test_path() to build the path, i.e.

Suggested change
# Load the current fixture
brca <- readRDS(
"tests/testthat/fixtures/BRCA_Combine_and_Renormalize_SO_downsample.rds"
)
# Load the current fixture
brca <- readRDS(
test_path(
"fixtures", "BRCA_Combine_and_Renormalize_SO_downsample.rds"
)
)

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.

still not seeing any documentation or code explaining where the dataset originated from

Comment thread tests/testthat/fixtures/downsample_BRCA.R Outdated
Comment thread tests/testthat/fixtures/downsample_BRCA.R Outdated
Comment thread tests/testthat/fixtures/generate_mtx_fixtures.R Outdated
Comment thread tests/testthat/test-cluster_metrics.R
Comment thread tests/testthat/test-seurat_clustering.R Outdated
Comment thread tests/testthat/test-seurat_clustering.R Outdated
ccbr-bot Bot and others added 17 commits May 19, 2026 22:25
Co-authored-by: Kelly Sovacool, PhD <kelly-sovacool@users.noreply.github.com>
Co-authored-by: Kelly Sovacool, PhD <kelly-sovacool@users.noreply.github.com>
Co-authored-by: Kelly Sovacool, PhD <kelly-sovacool@users.noreply.github.com>
Co-authored-by: Kelly Sovacool, PhD <kelly-sovacool@users.noreply.github.com>
Co-authored-by: Kelly Sovacool, PhD <kelly-sovacool@users.noreply.github.com>
Co-authored-by: Kelly Sovacool, PhD <kelly-sovacool@users.noreply.github.com>
features = Seurat::VariableFeatures(ifnb)[1:500]
)

saveRDS(ifnb_sub, file = "tests/testthat/fixtures/ifnb_sub.rds")

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.

use test_path here

Comment on lines +10 to +13
# Load the current fixture
brca <- readRDS(
"tests/testthat/fixtures/BRCA_Combine_and_Renormalize_SO_downsample.rds"
)

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.

still not seeing any documentation or code explaining where the dataset originated from

@wong-nw

wong-nw commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

@wong-nw do you have suggestions for new names to seurat_clustering and cluster_metrics so they are verbs per the style guide? https://style.tidyverse.org/functions.html

seurat_clustering -> cluster_object
cluster_metrics -> calc_cluster_scores

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

SCOT RepoName

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Seurat Clustering Unit Tests

3 participants