From 893331a5751097dc6fdcef360c8f3367d8187467 Mon Sep 17 00:00:00 2001 From: Manuel Garber Date: Tue, 3 Dec 2024 10:23:45 -0500 Subject: [PATCH 1/3] Include R/ToMeta.R in the commit --- .DS_Store | Bin 6148 -> 6148 bytes .gitignore | 2 ++ R/.DS_Store | Bin 6148 -> 0 bytes R/ToMeta.R | 6 +++--- 4 files changed, 5 insertions(+), 3 deletions(-) delete mode 100644 R/.DS_Store diff --git a/.DS_Store b/.DS_Store index 59a5ce16dcdb67a0bb1cbef079cd8cf8a8bbb432..97bf6332f9d14cb57bdb0bf3c028b8fefba1bfb4 100644 GIT binary patch literal 6148 zcmeHKJxc>Y5S@*OL@i7sh}9K>U?KPqPKjWwf~o8@iJ#=WXiO{jPb{qL1TDlLU}K>O z7M7O&2Mgcq4!X-3?Nnq2cHiF2&c3-9ZZ}IrX0hL%C#n!p8I3U-MfZtuoLj+4;+X&% zUZb-;-)LoNw=h#3s(>o+7Zu=dH=;S(rd>J;zTeWxtRG9WYPH$Pn(&pM4j$KPt(%1~ z-u^P)-SPH@@;Opz47{tJe_U93%%S$GfGVI0yeq)_LyX3l2<8s$)`8Am0e}(Q)-bkb7BFT9FcHih z!UHod73flpTrrGGhd-8iiD2%~rIWGDSVx$R+)&(!34d&-lSv$EuL`IFp#nqhvBKy7 z(%}1ln50jtfGY5>6fjY>QC-9<$=Og~M2EhfP?*IS* delta 343 zcmZoMXfc=|#>B)qF;Q%yo+2aL#(>?7vTO_t3@i*O42cXS42e1EhQZ1CxdlKmFqj;` zD#6~n=+VJtF-Ionvr59*{j5^;5G9NZK}qGs1xY#iNkD-eNd-BX#U%y?*BF_YSyuu5=%;pof3$r&#oQC)3hVWFd7P^+U*ZD?$1q@!SHU}{iX z%gG_CtZy9@pPiGNm)`|-EhB_x;DypKsvF1vdZjG5C@&{JFCE0&EXX0oGO=LdW_AvK b4q&hW`QMo*^NTogfHVOOV%Z!avW6J|JwI77 diff --git a/.gitignore b/.gitignore index 5b6a065..7dbcaca 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ .Rhistory .RData .Ruserdata +.DS_Store +R/.DS_Store diff --git a/R/.DS_Store b/R/.DS_Store deleted file mode 100644 index 5008ddfcf53c02e82d7eee2e57c38e5672ef89f6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 Date: Sat, 3 Jan 2026 21:23:02 -0500 Subject: [PATCH 2/3] Updated the function to be Seurat 5 compatible where slot is not supported and replaced by layer. --- R/VlnPlot.xlabel.R | 94 +++++++++++++++++++++++++++++++++------------- 1 file changed, 68 insertions(+), 26 deletions(-) diff --git a/R/VlnPlot.xlabel.R b/R/VlnPlot.xlabel.R index 6494713..bfa3c0d 100644 --- a/R/VlnPlot.xlabel.R +++ b/R/VlnPlot.xlabel.R @@ -12,15 +12,43 @@ -VlnPlot.xlabel <- function (object, gene, group.by, group.order = NULL, split.order = NULL, title = "", assay = "RNA", slot = "data", log_scale = F, - colors = NULL, split.by = NULL, spread = NULL, jitter_pts = T, - plot_mean = T, size = 1, sig = 3, number_labels = T, text_sizes = c(15, 10, 7, 10, 7, 7, 2.5), alpha = 0.5, theme = "classic") +VlnPlot.xlabel <- function (object, + gene, + group.by, + group.order = NULL, + split.order = NULL, + title = "", + assay = "RNA", + layer = "data", + slot = NULL, ## Deprecated only here to support old versions of Seurat, use layer instead + log_scale = F, + colors = NULL, + split.by = NULL, + spread = NULL, + jitter_pts = T, + plot_mean = T, + size = 1, + sig = 3, + number_labels = T, + text_sizes = c(15, 10, 7, 10, 7, 7, 2.5), + alpha = 0.5, + theme = "classic") { + # --- Backwards compatibility: if someone passes slot=, map it to layer --- + if (!is.null(slot)) { + layer <- slot + } + + x_var <- rlang::sym(group.by) + y_var <- rlang::sym("plot") + fill_var <- rlang::sym(group.by) + col_var <- rlang::sym(group.by) df <- object@meta.data[, colnames(object@meta.data) %in% c(gene, group.by, split.by), drop = F] assay <- assay %||% DefaultAssay(object = object) DefaultAssay(object = object) <- assay - geneExp <- FetchData(object = object, vars = gene, slot = slot) + # Seurat v5: use layer= instead of slot= + geneExp <- SeuratObject::FetchData(object = object, vars = gene, layer = layer) if (sum(geneExp) == 0){ warning("No expression in data") return() @@ -78,20 +106,29 @@ VlnPlot.xlabel <- function (object, gene, group.by, group.order = NULL, split.or g <- g + theme(legend.position = "none", plot.title = element_text(hjust = 0.5), axis.title.x = element_blank(), axis.ticks.x = element_blank(), axis.text.x = element_text(hjust = 1, vjust = 1, angle = 90)) - if (jitter_pts == T) - g <- g + geom_jitter(aes_string(x = group.by, y = "plot", - col = group.by), width = 0.2, size = size) - g <- g + geom_violin(aes_string(x = group.by, y = "plot", - fill = group.by), col = "black", trim = T, scale = "width", alpha = alpha) - if (number_labels == T) { - g <- g + stat_summary(aes_string(x = group.by, y = "value"), - fun.data = function(x) { - return(c(y = -max(df$plot)/25, label = length(x))) - }, colour = "black", geom = "text", size = text_sizes[7]) - g <- g + stat_summary(aes_string(x = group.by, y = "value"), - fun.data = function(x) { - return(c(y = -max(df$plot)/10, label = round(mean(as.numeric(x > 0)), sig))) - }, colour = "black", geom = "text", size = text_sizes[7]) + if (isTRUE(jitter_pts)) { + g <- g + geom_jitter( + aes(x = !!x_var, y = !!y_var, col = !!col_var), + width = 0.2, size = size + ) + } + + g <- g + geom_violin( + aes(x = !!x_var, y = !!y_var, fill = !!fill_var), + col = "black", trim = TRUE, scale = "width", alpha = alpha + ) + + if (isTRUE(number_labels)) { + g <- g + stat_summary( + aes(x = !!x_var, y = value), + fun.data = function(x) c(y = -max(df$plot)/25, label = length(x)), + colour = "black", geom = "text", size = text_sizes[7] + ) + g <- g + stat_summary( + aes(x = !!x_var, y = value), + fun.data = function(x) c(y = -max(df$plot)/10, label = round(mean(as.numeric(x > 0)), sig)), + colour = "black", geom = "text", size = text_sizes[7] + ) } if (plot_mean == TRUE) { scale <- max(df$plot)/max(tapply(df$value, INDEX = as.list(df[, colnames(df) %in% c(group.by, split.by), drop = F]), @@ -99,14 +136,19 @@ VlnPlot.xlabel <- function (object, gene, group.by, group.order = NULL, split.or g <- g + suppressWarnings(stat_summary(aes_string(x = group.by, y = "value"), fun.y = function(x) mean(x) * (scale * 0.5), colour = "black", geom = "point", size = 2)) g <- g + scale_y_continuous(sec.axis = sec_axis(~./(scale * 0.5), name = "Mean Expression")) } - if (length(split.by) == 1) { - g <- g + facet_grid(facets = reformulate(split.by), scales = "free_x", space = "free_x") - } - else if (length(split.by) == 2) { - g <- g + facet_grid(facets = reformulate(split.by[1], split.by[2]), scales = "free_x", space = "free_x") - } - else if (length(split.by) > 2) { - stop("Parameter split.by needs to be a string with equal or less than two variables.") + if (!is.null(split.by)) { + if (length(split.by) == 1) { + g <- g + facet_grid(rows = vars(.data[[split.by]]), scales = "free_x", space = "free_x") + } else if (length(split.by) == 2) { + g <- g + facet_grid( + rows = vars(.data[[split.by[1]]]), + cols = vars(.data[[split.by[2]]]), + scales = "free_x", + space = "free_x" + ) + } else if (length(split.by) > 2) { + stop("Parameter split.by needs to be a string with equal or less than two variables.") + } } if (!is.null(split.by)) g <- g + theme(strip.text.x = element_text(size = text_sizes[6])) From a6d4cc7cc94a29aad460a5534a36d6c5371789d8 Mon Sep 17 00:00:00 2001 From: Manuel Garber Date: Sat, 3 Jan 2026 21:29:36 -0500 Subject: [PATCH 3/3] Ignore macOS .DS_Store and local excel artifact --- .DS_Store | Bin 6148 -> 0 bytes .gitignore | 1 + 2 files changed, 1 insertion(+) delete mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 97bf6332f9d14cb57bdb0bf3c028b8fefba1bfb4..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHKJxc>Y5S@*OL@i7sh}9K>U?KPqPKjWwf~o8@iJ#=WXiO{jPb{qL1TDlLU}K>O z7M7O&2Mgcq4!X-3?Nnq2cHiF2&c3-9ZZ}IrX0hL%C#n!p8I3U-MfZtuoLj+4;+X&% zUZb-;-)LoNw=h#3s(>o+7Zu=dH=;S(rd>J;zTeWxtRG9WYPH$Pn(&pM4j$KPt(%1~ z-u^P)-SPH@@;Opz47{tJe_U93%%S$GfGVI0yeq)_LyX3l2<8s$)`8Am0e}(Q)-bkb7BFT9FcHih z!UHod73flpTrrGGhd-8iiD2%~rIWGDSVx$R+)&(!34d&-lSv$EuL`IFp#nqhvBKy7 z(%}1ln50jtfGY5>6fjY>QC-9<$=Og~M2EhfP?*IS* diff --git a/.gitignore b/.gitignore index 7dbcaca..449ddab 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ .Ruserdata .DS_Store R/.DS_Store +.DS_Store