Skip to content

Commit a19c468

Browse files
committed
fix bugs
1 parent b0e49c8 commit a19c468

File tree

5 files changed

+63
-21
lines changed

5 files changed

+63
-21
lines changed

R/SCP-analysis.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3996,6 +3996,8 @@ RunEnrichment <- function(srt = NULL, group_by = NULL, test.use = "wilcox", DE_t
39963996
results <- results[!sapply(results, is.null)]
39973997
results <- results[intersect(c(nm, paste0(nm, "_sim")), names(results))]
39983998
enrichment <- do.call(rbind, lapply(results, function(x) x@result))
3999+
enrichment[["Groups"]] <- factor(enrichment[["Groups"]], levels = levels(geneID_groups))
4000+
enrichment[["Database"]] <- factor(enrichment[["Database"]], levels = unique(db))
39994001
rownames(enrichment) <- NULL
40004002

40014003
time_end <- Sys.time()
@@ -4293,6 +4295,8 @@ RunGSEA <- function(srt = NULL, group_by = NULL, test.use = "wilcox", DE_thresho
42934295
results <- results[!sapply(results, is.null)]
42944296
results <- results[intersect(c(nm, paste0(nm, "_sim")), names(results))]
42954297
enrichment <- do.call(rbind, lapply(results, function(x) x@result))
4298+
enrichment[["Groups"]] <- factor(enrichment[["Groups"]], levels = levels(geneID_groups))
4299+
enrichment[["Database"]] <- factor(enrichment[["Database"]], levels = unique(db))
42964300
rownames(enrichment) <- NULL
42974301

42984302
time_end <- Sys.time()

R/SCP-app.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ RunSCExplorer <- function(base_dir = "SCExplorer",
595595
initial_raster = NULL,
596596
session_workers = 2,
597597
plotting_workers = 8,
598-
create_script = FALSE,
598+
create_script = TRUE,
599599
style_script = require("styler", quietly = TRUE),
600600
overwrite = FALSE) {
601601
check_R(c("rhdf5", "HDF5Array", "shiny@1.6.0", "ggplot2", "ragg", "htmlwidgets", "plotly", "bslib", "future", "promises", "BiocParallel"))

R/SCP-plot.R

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3547,8 +3547,8 @@ FeatureStatPlot <- function(srt, stat.by, group.by = NULL, split.by = NULL, bg.b
35473547
calculate_coexp = FALSE, range = c(-Inf, Inf),
35483548
same.y.lims = FALSE, y.min = NULL, y.max = NULL, y.trans = "identity", y.nbreaks = 5,
35493549
sort = FALSE, stack = FALSE, flip = FALSE,
3550-
comparisons = NULL, ref_group = NULL, pairwise_method = "wilcox.test",
3551-
multiplegroup_comparisons = FALSE, multiple_method = "kruskal.test",
3550+
comparisons = NULL, ref_group = NULL, pairwise_method = "wilcox.test", pairwise_method_args = list(),
3551+
multiplegroup_comparisons = FALSE, multiple_method = "kruskal.test", multiple_method_args = list(),
35523552
sig_label = c("p.signif", "p.format"), sig_labelsize = 3.5,
35533553
aspect.ratio = NULL, title = NULL, subtitle = NULL, xlab = NULL, ylab = "Expression",
35543554
legend.position = "right", legend.direction = "vertical",
@@ -3601,8 +3601,8 @@ FeatureStatPlot <- function(srt, stat.by, group.by = NULL, split.by = NULL, bg.b
36013601
calculate_coexp = calculate_coexp, range = range,
36023602
same.y.lims = same.y.lims, y.min = y.min, y.max = y.max, y.trans = y.trans, y.nbreaks = y.nbreaks,
36033603
sort = sort, stack = stack, flip = flip,
3604-
comparisons = comparisons, ref_group = ref_group, pairwise_method = pairwise_method,
3605-
multiplegroup_comparisons = multiplegroup_comparisons, multiple_method = multiple_method,
3604+
comparisons = comparisons, ref_group = ref_group, pairwise_method = pairwise_method, pairwise_method_args = pairwise_method_args,
3605+
multiplegroup_comparisons = multiplegroup_comparisons, multiple_method = multiple_method, multiple_method_args = multiple_method_args,
36063606
sig_label = sig_label, sig_labelsize = sig_labelsize,
36073607
aspect.ratio = aspect.ratio, title = title, subtitle = subtitle, xlab = xlab, ylab = ylab,
36083608
legend.position = legend.position, legend.direction = legend.direction,
@@ -3629,8 +3629,8 @@ FeatureStatPlot <- function(srt, stat.by, group.by = NULL, split.by = NULL, bg.b
36293629
calculate_coexp = calculate_coexp, range = range,
36303630
same.y.lims = same.y.lims, y.min = y.min, y.max = y.max, y.trans = y.trans, y.nbreaks = y.nbreaks,
36313631
sort = sort, stack = stack, flip = flip,
3632-
comparisons = comparisons, ref_group = ref_group, pairwise_method = pairwise_method,
3633-
multiplegroup_comparisons = multiplegroup_comparisons, multiple_method = multiple_method,
3632+
comparisons = comparisons, ref_group = ref_group, pairwise_method = pairwise_method, pairwise_method_args = pairwise_method_args,
3633+
multiplegroup_comparisons = multiplegroup_comparisons, multiple_method = multiple_method, multiple_method_args = multiple_method_args,
36343634
sig_label = sig_label, sig_labelsize = sig_labelsize,
36353635
aspect.ratio = aspect.ratio, title = title, subtitle = subtitle, xlab = xlab, ylab = ylab,
36363636
legend.position = legend.position, legend.direction = legend.direction,
@@ -3753,8 +3753,8 @@ ExpressionStatPlot <- function(exp.data, meta.data, stat.by, group.by = NULL, sp
37533753
calculate_coexp = FALSE, range = c(-Inf, Inf),
37543754
same.y.lims = FALSE, y.min = NULL, y.max = NULL, y.trans = "identity", y.nbreaks = 5,
37553755
sort = FALSE, stack = FALSE, flip = FALSE,
3756-
comparisons = NULL, ref_group = NULL, pairwise_method = "wilcox.test",
3757-
multiplegroup_comparisons = FALSE, multiple_method = "kruskal.test",
3756+
comparisons = NULL, ref_group = NULL, pairwise_method = "wilcox.test", pairwise_method_args = list(),
3757+
multiplegroup_comparisons = FALSE, multiple_method = "kruskal.test", multiple_method_args = list(),
37583758
sig_label = c("p.signif", "p.format"), sig_labelsize = 3.5,
37593759
aspect.ratio = NULL, title = NULL, subtitle = NULL, xlab = NULL, ylab = "Expression",
37603760
legend.position = "right", legend.direction = "vertical",
@@ -4218,6 +4218,7 @@ ExpressionStatPlot <- function(exp.data, meta.data, stat.by, group.by = NULL, sp
42184218
border_layer <- geom_vline(xintercept = border_data[["xintercept"]], linetype = 2, alpha = 0.5)
42194219
p <- p + border_layer
42204220
}
4221+
y_min_use <- layer_scales(p)$y$range$range[1]
42214222
}
42224223

42234224
if (length(comparisons) > 0) {
@@ -4226,8 +4227,10 @@ ExpressionStatPlot <- function(exp.data, meta.data, stat.by, group.by = NULL, sp
42264227
if (any(rowSums(table(dat[["group.by"]], dat[["split.by"]]) >= 2) >= 3)) {
42274228
message("Detected more than 2 groups. Use multiple_method for comparison")
42284229
method <- multiple_method
4230+
method_args <- multiple_method_args
42294231
} else {
42304232
method <- pairwise_method
4233+
method_args <- pairwise_method_args
42314234
}
42324235
p <- p + ggpubr::stat_compare_means(
42334236
data = dat[dat[["group.by"]] %in% group_use, , drop = FALSE],
@@ -4238,9 +4241,9 @@ ExpressionStatPlot <- function(exp.data, meta.data, stat.by, group.by = NULL, sp
42384241
step.increase = 0.1,
42394242
tip.length = 0.03,
42404243
vjust = 1,
4241-
method = method
4244+
method = method,
4245+
method.args = method_args,
42424246
)
4243-
42444247
y_max_use <- layer_scales(p)$y$range$range[2]
42454248
} else {
42464249
p <- p + ggpubr::stat_compare_means(
@@ -4253,20 +4256,22 @@ ExpressionStatPlot <- function(exp.data, meta.data, stat.by, group.by = NULL, sp
42534256
vjust = 0,
42544257
comparisons = comparisons,
42554258
ref.group = ref_group,
4256-
method = pairwise_method
4259+
method = pairwise_method,
4260+
method.args = pairwise_method_args,
42574261
)
42584262
y_max_use <- layer_scales(p)$y$range$range[1] + (layer_scales(p)$y$range$range[2] - layer_scales(p)$y$range$range[1]) * 1.15
42594263
}
42604264
}
42614265
if (isTRUE(multiplegroup_comparisons)) {
42624266
p <- p + ggpubr::stat_compare_means(
42634267
aes(x = .data[["group.by"]], y = .data[["value"]], group = .data[["group.unique"]]),
4264-
method = multiple_method,
42654268
label = sig_label,
42664269
label.y = y_max_use,
42674270
size = sig_labelsize,
42684271
vjust = 1.2,
4269-
hjust = 0
4272+
hjust = 0,
4273+
method = multiple_method,
4274+
method.args = multiple_method_args
42704275
)
42714276
y_max_use <- layer_scales(p)$y$range$range[1] + (layer_scales(p)$y$range$range[2] - layer_scales(p)$y$range$range[1]) * 1.15
42724277
}
@@ -4416,8 +4421,9 @@ ExpressionStatPlot <- function(exp.data, meta.data, stat.by, group.by = NULL, sp
44164421
}
44174422

44184423
if (isTRUE(stack)) {
4424+
digits <- max(gregexpr("\\.0+", as.character(y_max_use - y_min_use))[[1]][1], 1)
44194425
p <- p + scale_y_continuous(
4420-
trans = y.trans, breaks = c(y_min_use, y_max_use), labels = c(round(y_min_use, 1), round(y_max_use, 1))
4426+
trans = y.trans, breaks = c(y_min_use, y_max_use), labels = c(round(y_min_use, digits), round(y_max_use, digits))
44214427
)
44224428
} else {
44234429
p <- p + scale_y_continuous(trans = y.trans, n.breaks = y.nbreaks)
@@ -4444,6 +4450,7 @@ ExpressionStatPlot <- function(exp.data, meta.data, stat.by, group.by = NULL, sp
44444450
)
44454451
}
44464452
# plist[[paste0(f, ":", g, ":", paste0(single_group, collapse = ","), ":", paste0(sp, collapse = ","))]] <- p
4453+
return(p)
44474454
})
44484455

44494456
return(plist)
@@ -9363,9 +9370,8 @@ FeatureHeatmap <- function(srt, features = NULL, cells = NULL, group.by = NULL,
93639370
cell_groups[[cell_group]] <- unlist(lapply(levels(srt@meta.data[[cell_group]]), function(x) {
93649371
cells_sub <- colnames(srt@assays[[1]])[which(srt@meta.data[[cell_group]] == x)]
93659372
cells_sub <- intersect(cells, cells_sub)
9366-
size <- ifelse(length(cells_sub) > max_cells, max_cells, length(cells_sub))
9367-
cells_sample <- sample(cells_sub, size)
9368-
out <- setNames(rep(x, size), cells_sample)
9373+
cells_sample <- if (length(cells_sub) > max_cells) sample(cells_sub, max_cells) else cells_sub
9374+
out <- setNames(rep(x, length(cells_sample)), cells_sample)
93699375
return(out)
93709376
}), use.names = TRUE)
93719377
levels <- levels(srt@meta.data[[cell_group]])
@@ -9380,9 +9386,8 @@ FeatureHeatmap <- function(srt, features = NULL, cells = NULL, group.by = NULL,
93809386
cells_tmp <- NULL
93819387
for (sp in levels(srt@meta.data[[split.by]])) {
93829388
cells_sp <- cells_sub[srt@meta.data[cells_sub, split.by] == sp]
9383-
size <- ifelse(length(cells_sp) > max_cells, max_cells, length(cells_sp))
9384-
cells_sample <- sample(cells_sp, size)
9385-
cells_tmp <- c(cells_tmp, setNames(rep(paste0(x, " : ", sp), size), cells_sample))
9389+
cells_sample <- if (length(cells_sp) > max_cells) sample(cells_sp, max_cells) else cells_sp
9390+
cells_tmp <- c(cells_tmp, setNames(rep(paste0(x, " : ", sp), length(cells_sample)), cells_sample))
93869391
}
93879392
size <- ifelse(length(cells_tmp) > max_cells, max_cells, length(cells_tmp))
93889393
out <- sample(cells_tmp, size)

man/FeatureStatPlot.Rd

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/MergeRows.Rd

Lines changed: 31 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)