@@ -3547,8 +3547,8 @@ FeatureStatPlot <- function(srt, stat.by, group.by = NULL, split.by = NULL, bg.b
3547
3547
calculate_coexp = FALSE, range = c(-Inf, Inf),
3548
3548
same.y.lims = FALSE, y.min = NULL, y.max = NULL, y.trans = "identity", y.nbreaks = 5,
3549
3549
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(),
3552
3552
sig_label = c("p.signif", "p.format"), sig_labelsize = 3.5,
3553
3553
aspect.ratio = NULL, title = NULL, subtitle = NULL, xlab = NULL, ylab = "Expression",
3554
3554
legend.position = "right", legend.direction = "vertical",
@@ -3601,8 +3601,8 @@ FeatureStatPlot <- function(srt, stat.by, group.by = NULL, split.by = NULL, bg.b
3601
3601
calculate_coexp = calculate_coexp, range = range,
3602
3602
same.y.lims = same.y.lims, y.min = y.min, y.max = y.max, y.trans = y.trans, y.nbreaks = y.nbreaks,
3603
3603
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,
3606
3606
sig_label = sig_label, sig_labelsize = sig_labelsize,
3607
3607
aspect.ratio = aspect.ratio, title = title, subtitle = subtitle, xlab = xlab, ylab = ylab,
3608
3608
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
3629
3629
calculate_coexp = calculate_coexp, range = range,
3630
3630
same.y.lims = same.y.lims, y.min = y.min, y.max = y.max, y.trans = y.trans, y.nbreaks = y.nbreaks,
3631
3631
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,
3634
3634
sig_label = sig_label, sig_labelsize = sig_labelsize,
3635
3635
aspect.ratio = aspect.ratio, title = title, subtitle = subtitle, xlab = xlab, ylab = ylab,
3636
3636
legend.position = legend.position, legend.direction = legend.direction,
@@ -3753,8 +3753,8 @@ ExpressionStatPlot <- function(exp.data, meta.data, stat.by, group.by = NULL, sp
3753
3753
calculate_coexp = FALSE, range = c(-Inf, Inf),
3754
3754
same.y.lims = FALSE, y.min = NULL, y.max = NULL, y.trans = "identity", y.nbreaks = 5,
3755
3755
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(),
3758
3758
sig_label = c("p.signif", "p.format"), sig_labelsize = 3.5,
3759
3759
aspect.ratio = NULL, title = NULL, subtitle = NULL, xlab = NULL, ylab = "Expression",
3760
3760
legend.position = "right", legend.direction = "vertical",
@@ -4218,6 +4218,7 @@ ExpressionStatPlot <- function(exp.data, meta.data, stat.by, group.by = NULL, sp
4218
4218
border_layer <- geom_vline(xintercept = border_data[["xintercept"]], linetype = 2, alpha = 0.5)
4219
4219
p <- p + border_layer
4220
4220
}
4221
+ y_min_use <- layer_scales(p)$y$range$range[1]
4221
4222
}
4222
4223
4223
4224
if (length(comparisons) > 0) {
@@ -4226,8 +4227,10 @@ ExpressionStatPlot <- function(exp.data, meta.data, stat.by, group.by = NULL, sp
4226
4227
if (any(rowSums(table(dat[["group.by"]], dat[["split.by"]]) >= 2) >= 3)) {
4227
4228
message("Detected more than 2 groups. Use multiple_method for comparison")
4228
4229
method <- multiple_method
4230
+ method_args <- multiple_method_args
4229
4231
} else {
4230
4232
method <- pairwise_method
4233
+ method_args <- pairwise_method_args
4231
4234
}
4232
4235
p <- p + ggpubr::stat_compare_means(
4233
4236
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
4238
4241
step.increase = 0.1,
4239
4242
tip.length = 0.03,
4240
4243
vjust = 1,
4241
- method = method
4244
+ method = method,
4245
+ method.args = method_args,
4242
4246
)
4243
-
4244
4247
y_max_use <- layer_scales(p)$y$range$range[2]
4245
4248
} else {
4246
4249
p <- p + ggpubr::stat_compare_means(
@@ -4253,20 +4256,22 @@ ExpressionStatPlot <- function(exp.data, meta.data, stat.by, group.by = NULL, sp
4253
4256
vjust = 0,
4254
4257
comparisons = comparisons,
4255
4258
ref.group = ref_group,
4256
- method = pairwise_method
4259
+ method = pairwise_method,
4260
+ method.args = pairwise_method_args,
4257
4261
)
4258
4262
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
4259
4263
}
4260
4264
}
4261
4265
if (isTRUE(multiplegroup_comparisons)) {
4262
4266
p <- p + ggpubr::stat_compare_means(
4263
4267
aes(x = .data[["group.by"]], y = .data[["value"]], group = .data[["group.unique"]]),
4264
- method = multiple_method,
4265
4268
label = sig_label,
4266
4269
label.y = y_max_use,
4267
4270
size = sig_labelsize,
4268
4271
vjust = 1.2,
4269
- hjust = 0
4272
+ hjust = 0,
4273
+ method = multiple_method,
4274
+ method.args = multiple_method_args
4270
4275
)
4271
4276
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
4272
4277
}
@@ -4416,8 +4421,9 @@ ExpressionStatPlot <- function(exp.data, meta.data, stat.by, group.by = NULL, sp
4416
4421
}
4417
4422
4418
4423
if (isTRUE(stack)) {
4424
+ digits <- max(gregexpr("\\.0+", as.character(y_max_use - y_min_use))[[1]][1], 1)
4419
4425
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 ))
4421
4427
)
4422
4428
} else {
4423
4429
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
4444
4450
)
4445
4451
}
4446
4452
# plist[[paste0(f, ":", g, ":", paste0(single_group, collapse = ","), ":", paste0(sp, collapse = ","))]] <- p
4453
+ return(p)
4447
4454
})
4448
4455
4449
4456
return(plist)
@@ -9363,9 +9370,8 @@ FeatureHeatmap <- function(srt, features = NULL, cells = NULL, group.by = NULL,
9363
9370
cell_groups[[cell_group]] <- unlist(lapply(levels(srt@meta.data[[cell_group]]), function(x) {
9364
9371
cells_sub <- colnames(srt@assays[[1]])[which(srt@meta.data[[cell_group]] == x)]
9365
9372
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)
9369
9375
return(out)
9370
9376
}), use.names = TRUE)
9371
9377
levels <- levels(srt@meta.data[[cell_group]])
@@ -9380,9 +9386,8 @@ FeatureHeatmap <- function(srt, features = NULL, cells = NULL, group.by = NULL,
9380
9386
cells_tmp <- NULL
9381
9387
for (sp in levels(srt@meta.data[[split.by]])) {
9382
9388
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))
9386
9391
}
9387
9392
size <- ifelse(length(cells_tmp) > max_cells, max_cells, length(cells_tmp))
9388
9393
out <- sample(cells_tmp, size)
0 commit comments