Skip to content

Commit 9c94e66

Browse files
Bugfix percentages in explanatory PC plot
1 parent 61e60d5 commit 9c94e66

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

DESCRIPTION

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ Authors@R: c(
1212
person("Leo", "Lahti", role=c("ctb"), email="leo.lahti@utu.fi",
1313
comment = c(ORCID = "0000-0001-5537-637X"))
1414
)
15-
Version: 1.31.0
16-
Date: 2023-08-23
15+
Version: 1.31.1
16+
Date: 2023-11-16
1717
License: GPL-3
1818
Title: Single-Cell Analysis Toolkit for Gene Expression Data in R
1919
Description: A collection of tools for doing various analyses of

R/plotExplanatoryPCs.R

+1-2
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,8 @@ plotExplanatoryPCs <- function(object, nvars_to_plot = 10, npcs_to_plot=50, them
4747
df_to_plot <- data.frame(
4848
PC=rep(seq_len(nrow(chosen_rsquared)), ncol(chosen_rsquared)),
4949
Expl_Var=rep(ordered_vars, each=nrow(chosen_rsquared)),
50-
Pct_Var_Explained=as.numeric(chosen_rsquared) * 100 # column major collapse.
50+
Pct_Var_Explained=as.numeric(chosen_rsquared) # column major collapse.
5151
)
52-
5352
plot_out <- ggplot(df_to_plot, aes(x = .data$PC, y = .data$"Pct_Var_Explained", colour = .data$"Expl_Var")) +
5453
geom_point(alpha= 1, shape = 16, size = 3) +
5554
geom_line(alpha = 0.7, linewidth = 2) +

tests/testthat/test-expl-var.R

+22
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,28 @@ test_that("getExplanatoryPCs matches with a reference function", {
151151
}
152152
})
153153

154+
155+
test_that("getExplanatoryPCs doesn't return more than 100%", {
156+
example_sce <- mockSCE()
157+
example_sce <- logNormCounts(example_sce)
158+
example_sce <- runPCA(example_sce)
159+
160+
r2mat <- getExplanatoryPCs(example_sce)
161+
expect_true(all(r2mat <= 100))
162+
})
163+
164+
165+
test_that("plotExplanatoryPCs doesn't return more than 100%", {
166+
example_sce <- mockSCE()
167+
example_sce <- logNormCounts(example_sce)
168+
example_sce <- runPCA(example_sce)
169+
170+
g <- plotExplanatoryPCs(example_sce)
171+
expect_true(all(g$data$Pct_Var_Explained <= 100))
172+
})
173+
174+
175+
154176
test_that("getExplanatoryPCs responds to PC-specific options", {
155177
# Responds to differences in the reduced dimension slot.
156178
blah <- normed

0 commit comments

Comments
 (0)