Skip to content

Commit

Permalink
Bugfix percentages in explanatory PC plot
Browse files Browse the repository at this point in the history
  • Loading branch information
alanocallaghan committed Nov 16, 2023
1 parent 92f4fe0 commit 27d0d22
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ Authors@R: c(
person("Leo", "Lahti", role=c("ctb"), email="[email protected]",
comment = c(ORCID = "0000-0001-5537-637X"))
)
Version: 1.30.0
Date: 2023-08-23
Version: 1.30.1
Date: 2023-11-16
License: GPL-3
Title: Single-Cell Analysis Toolkit for Gene Expression Data in R
Description: A collection of tools for doing various analyses of
Expand Down
3 changes: 1 addition & 2 deletions R/plotExplanatoryPCs.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@ plotExplanatoryPCs <- function(object, nvars_to_plot = 10, npcs_to_plot=50, them
df_to_plot <- data.frame(
PC=rep(seq_len(nrow(chosen_rsquared)), ncol(chosen_rsquared)),
Expl_Var=rep(ordered_vars, each=nrow(chosen_rsquared)),
Pct_Var_Explained=as.numeric(chosen_rsquared) * 100 # column major collapse.
Pct_Var_Explained=as.numeric(chosen_rsquared) # column major collapse.
)

plot_out <- ggplot(df_to_plot, aes(x = .data$PC, y = .data$"Pct_Var_Explained", colour = .data$"Expl_Var")) +
geom_point(alpha= 1, shape = 16, size = 3) +
geom_line(alpha = 0.7, linewidth = 2) +
Expand Down
22 changes: 22 additions & 0 deletions tests/testthat/test-expl-var.R
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,28 @@ test_that("getExplanatoryPCs matches with a reference function", {
}
})


test_that("getExplanatoryPCs doesn't return more than 100%", {
example_sce <- mockSCE()
example_sce <- logNormCounts(example_sce)
example_sce <- runPCA(example_sce)

r2mat <- getExplanatoryPCs(example_sce)
expect_true(all(r2mat <= 100))
})


test_that("plotExplanatoryPCs doesn't return more than 100%", {
example_sce <- mockSCE()
example_sce <- logNormCounts(example_sce)
example_sce <- runPCA(example_sce)

g <- plotExplanatoryPCs(example_sce)
expect_true(all(g$data$Pct_Var_Explained <= 100))
})



test_that("getExplanatoryPCs responds to PC-specific options", {
# Responds to differences in the reduced dimension slot.
blah <- normed
Expand Down

0 comments on commit 27d0d22

Please sign in to comment.