From f866dae38c5c5e6e36fd29f3a506fa9a426a3af0 Mon Sep 17 00:00:00 2001 From: yuhanH Date: Fri, 1 Apr 2022 12:56:58 -0400 Subject: [PATCH 01/40] fix color --- R/visualization.R | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/R/visualization.R b/R/visualization.R index 7a717b4ba..73d7fc622 100644 --- a/R/visualization.R +++ b/R/visualization.R @@ -365,7 +365,10 @@ DoHeatmap <- function( ymax = y.max ) + coord_cartesian(ylim = c(0, y.max), clip = 'off') + - scale_color_discrete(name = "Identity", na.translate = FALSE) + scale_color_manual(values = cols[-length(cols)], + name = "Identity", + na.translate = FALSE + ) if (label) { x.max <- max(pbuild$layout$panel_params[[1]]$x.range) # Attempt to pull xdivs from x.major in ggplot2 < 3.3.0; if NULL, pull from the >= 3.3.0 slot From 7f60cbe36e690173009d5e7cf6a880a1b660e5a7 Mon Sep 17 00:00:00 2001 From: Andrew Butler Date: Fri, 13 May 2022 13:52:01 -0700 Subject: [PATCH 02/40] doc fix for RidgePlot --- R/visualization.R | 4 ++-- man/RidgePlot.Rd | 2 +- man/VlnPlot.Rd | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/R/visualization.R b/R/visualization.R index 9e65d7a92..c6bdfb61e 100644 --- a/R/visualization.R +++ b/R/visualization.R @@ -490,7 +490,7 @@ HTOHeatmap <- function( #' @param same.y.lims Set all the y-axis limits to the same values #' @param log plot the feature axis on log scale #' @param ncol Number of columns if multiple plots are displayed -#' @param slot Use non-normalized counts data for plotting +#' @param slot Slot to pull expression data from (e.g. "counts" or "data") #' @param stack Horizontally stack plots for each feature #' @param combine Combine plots into a single \code{\link[patchwork]{patchwork}ed} #' ggplot object. If \code{FALSE}, return a list of ggplot @@ -5550,7 +5550,7 @@ Col2Hex <- function(...) { # @param group.by Group (color) cells in different ways (for example, orig.ident) # @param split.by A variable to split the plot by # @param log plot Y axis on log scale -# @param slot Use non-normalized counts data for plotting +# @param slot Slot to pull expression data from (e.g. "counts" or "data") # @param stack Horizontally stack plots for multiple feature # @param combine Combine plots into a single \code{\link[patchwork]{patchwork}ed} # ggplot object. If \code{FALSE}, return a list of ggplot objects diff --git a/man/RidgePlot.Rd b/man/RidgePlot.Rd index 153d2ba25..7825a99a5 100644 --- a/man/RidgePlot.Rd +++ b/man/RidgePlot.Rd @@ -47,7 +47,7 @@ expression of the attribute being potted, can also pass 'increasing' or 'decreas \item{ncol}{Number of columns if multiple plots are displayed} -\item{slot}{Use non-normalized counts data for plotting} +\item{slot}{Slot to pull expression data from (e.g. "counts" or "data")} \item{stack}{Horizontally stack plots for each feature} diff --git a/man/VlnPlot.Rd b/man/VlnPlot.Rd index 75a30f331..ec75da8f9 100644 --- a/man/VlnPlot.Rd +++ b/man/VlnPlot.Rd @@ -59,7 +59,7 @@ expression of the attribute being potted, can also pass 'increasing' or 'decreas \item{ncol}{Number of columns if multiple plots are displayed} -\item{slot}{Use non-normalized counts data for plotting} +\item{slot}{Slot to pull expression data from (e.g. "counts" or "data")} \item{split.plot}{plot each group of the split violin plots by multiple or single violin shapes.} From 41d2426ea9f6eddcc943d20a37192834189caa34 Mon Sep 17 00:00:00 2001 From: Wang JL Date: Wed, 18 May 2022 15:26:29 +0800 Subject: [PATCH 03/40] Update preprocessing.R --- R/preprocessing.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/preprocessing.R b/R/preprocessing.R index 4f6765faa..102d50450 100644 --- a/R/preprocessing.R +++ b/R/preprocessing.R @@ -2637,7 +2637,7 @@ ScaleData.default <- function( if (any(vars.to.regress %in% rownames(x = object))) { latent.data <- cbind( latent.data, - t(x = object[vars.to.regress[vars.to.regress %in% rownames(x = object)], ]) + t(x = object[vars.to.regress[vars.to.regress %in% rownames(x = object)], , drop=F]) ) } # Currently, RegressOutMatrix will do nothing if latent.data = NULL From bbf711a5bb773228fcd31c471dcaeb86d71c4edf Mon Sep 17 00:00:00 2001 From: timoast <4591688+timoast@users.noreply.github.com> Date: Fri, 20 May 2022 15:09:41 -0400 Subject: [PATCH 04/40] Link to vignette; #5914 --- vignettes/integration_rpca.Rmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vignettes/integration_rpca.Rmd b/vignettes/integration_rpca.Rmd index e0f6c96e2..d1ae0d266 100644 --- a/vignettes/integration_rpca.Rmd +++ b/vignettes/integration_rpca.Rmd @@ -37,7 +37,7 @@ By identifying shared sources of variation between datasets, CCA is well-suited RPCA-based integration runs significantly faster, and also represents a more conservative approach where cells in different biological states are less likely to 'align' after integration. We therefore,recommend RPCA during integrative analysis where: * A substantial fraction of cells in one dataset have no matching type in the other * Datasets originate from the same platform (i.e. multiple lanes of 10x genomics) -* There are a large number of datasets or cells to integrate (see INSERT LINK for more tips on integrating large datasets) +* There are a large number of datasets or cells to integrate (see [here](integration_large_datasets.html) for more tips on integrating large datasets) Below, we demonstrate the use of reciprocal PCA to align the same stimulated and resting datasets first analyzed in our [introduction to scRNA-seq integration](integration_introduction.html) vignette. While the list of commands is nearly identical, this workflow requires users to run principal components analysis (PCA) individually on each dataset prior to integration. Users should also set the 'reduction' argument to 'rpca', when running `FindIntegrationAnchors()`. From 2be3f009cc1f3b46309074b72f5ae4cf47e036fb Mon Sep 17 00:00:00 2001 From: timoast <4591688+timoast@users.noreply.github.com> Date: Fri, 20 May 2022 15:15:13 -0400 Subject: [PATCH 05/40] Update style, imports --- R/visualization.R | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/R/visualization.R b/R/visualization.R index f6cdf6715..923f18346 100644 --- a/R/visualization.R +++ b/R/visualization.R @@ -205,7 +205,7 @@ DimHeatmap <- function( #' #' @importFrom stats median #' @importFrom scales hue_pal -#' @importFrom ggplot2 annotation_raster coord_cartesian scale_color_discrete +#' @importFrom ggplot2 annotation_raster coord_cartesian scale_color_manual #' ggplot_build aes_string geom_text #' @importFrom patchwork wrap_plots #' @export @@ -365,10 +365,11 @@ DoHeatmap <- function( ymax = y.max ) + coord_cartesian(ylim = c(0, y.max), clip = 'off') + - scale_color_manual(values = cols[-length(cols)], - name = "Identity", - na.translate = FALSE - ) + scale_color_manual( + values = cols[-length(x = cols)], + name = "Identity", + na.translate = FALSE + ) if (label) { x.max <- max(pbuild$layout$panel_params[[1]]$x.range) # Attempt to pull xdivs from x.major in ggplot2 < 3.3.0; if NULL, pull from the >= 3.3.0 slot From a04efd93966bf29523bba1cd31eb50d062b2f146 Mon Sep 17 00:00:00 2001 From: timoast <4591688+timoast@users.noreply.github.com> Date: Fri, 20 May 2022 15:25:47 -0400 Subject: [PATCH 06/40] Update docs --- NAMESPACE | 1 - 1 file changed, 1 deletion(-) diff --git a/NAMESPACE b/NAMESPACE index 20b61af05..373809068 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -521,7 +521,6 @@ importFrom(ggplot2,position_jitterdodge) importFrom(ggplot2,scale_alpha) importFrom(ggplot2,scale_alpha_ordinal) importFrom(ggplot2,scale_color_brewer) -importFrom(ggplot2,scale_color_discrete) importFrom(ggplot2,scale_color_distiller) importFrom(ggplot2,scale_color_gradient) importFrom(ggplot2,scale_color_gradientn) From 407472d17993332d0b7e3046a451e33b1ab848d5 Mon Sep 17 00:00:00 2001 From: timoast <4591688+timoast@users.noreply.github.com> Date: Fri, 20 May 2022 15:28:02 -0400 Subject: [PATCH 07/40] Update release notes --- DESCRIPTION | 4 ++-- NEWS.md | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index b23f1f21c..7862790fa 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: Seurat -Version: 4.1.1 -Date: 2022-05-01 +Version: 4.1.1.9000 +Date: 2022-05-20 Title: Tools for Single Cell Genomics Description: A toolkit for quality control, analysis, and exploration of single cell RNA sequencing data. 'Seurat' aims to enable users to identify and interpret sources of heterogeneity from single cell transcriptomic measurements, and to integrate diverse types of single cell data. See Satija R, Farrell J, Gennert D, et al (2015) , Macosko E, Basu A, Satija R, et al (2015) , Stuart T, Butler A, et al (2019) , and Hao, Hao, et al (2020) for more details. Authors@R: c( diff --git a/NEWS.md b/NEWS.md index 27201ac2e..5dd048752 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,8 @@ +# Unreleased + +## Changes +- Fix legend color in `DoHeatmap()` ([#5783](https://github.com/satijalab/seurat/issues/5783)) + # Seurat 4.1.1 (2022-05-01) ## Changes From a957e65bcdb131bd327a75ad6cfe6847ef30b92f Mon Sep 17 00:00:00 2001 From: timoast <4591688+timoast@users.noreply.github.com> Date: Fri, 20 May 2022 15:35:41 -0400 Subject: [PATCH 08/40] Update docs for VlnPlot log scale --- R/visualization.R | 2 +- man/SingleExIPlot.Rd | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/R/visualization.R b/R/visualization.R index 923f18346..9af3a6e02 100644 --- a/R/visualization.R +++ b/R/visualization.R @@ -7212,7 +7212,7 @@ SingleDimPlot <- function( #' @param pt.size Size of points for violin plots #' @param cols Colors to use for plotting #' @param seed.use Random seed to use. If NULL, don't set a seed -#' @param log plot Y axis on log scale +#' @param log plot Y axis on log10 scale #' @param raster Convert points to raster format. Requires 'ggrastr' to be installed. #' default is \code{NULL} which automatically rasterizes if ggrastr is installed and #' number of points exceed 100,000. diff --git a/man/SingleExIPlot.Rd b/man/SingleExIPlot.Rd index 9ceede508..f7b8cdb4f 100644 --- a/man/SingleExIPlot.Rd +++ b/man/SingleExIPlot.Rd @@ -41,7 +41,7 @@ expression of the attribute being potted} \item{seed.use}{Random seed to use. If NULL, don't set a seed} -\item{log}{plot Y axis on log scale} +\item{log}{plot Y axis on log10 scale} \item{raster}{Convert points to raster format. Requires 'ggrastr' to be installed. default is \code{NULL} which automatically rasterizes if ggrastr is installed and From a283a1ea03bab2e536b9ba4836d06533a0ce41c3 Mon Sep 17 00:00:00 2001 From: timoast <4591688+timoast@users.noreply.github.com> Date: Fri, 20 May 2022 17:38:03 -0400 Subject: [PATCH 09/40] Format --- R/preprocessing.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/preprocessing.R b/R/preprocessing.R index 102d50450..7ef77dcf5 100644 --- a/R/preprocessing.R +++ b/R/preprocessing.R @@ -2637,7 +2637,7 @@ ScaleData.default <- function( if (any(vars.to.regress %in% rownames(x = object))) { latent.data <- cbind( latent.data, - t(x = object[vars.to.regress[vars.to.regress %in% rownames(x = object)], , drop=F]) + t(x = object[vars.to.regress[vars.to.regress %in% rownames(x = object)], , drop=FALSE]) ) } # Currently, RegressOutMatrix will do nothing if latent.data = NULL From 522a839e6ab4b2382ad77080dee3152be11a4120 Mon Sep 17 00:00:00 2001 From: timoast <4591688+timoast@users.noreply.github.com> Date: Fri, 20 May 2022 17:38:13 -0400 Subject: [PATCH 10/40] Update release notes --- DESCRIPTION | 2 +- NEWS.md | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 7862790fa..89b447412 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: Seurat -Version: 4.1.1.9000 +Version: 4.1.1.9001 Date: 2022-05-20 Title: Tools for Single Cell Genomics Description: A toolkit for quality control, analysis, and exploration of single cell RNA sequencing data. 'Seurat' aims to enable users to identify and interpret sources of heterogeneity from single cell transcriptomic measurements, and to integrate diverse types of single cell data. See Satija R, Farrell J, Gennert D, et al (2015) , Macosko E, Basu A, Satija R, et al (2015) , Stuart T, Butler A, et al (2019) , and Hao, Hao, et al (2020) for more details. diff --git a/NEWS.md b/NEWS.md index 5dd048752..62d7ef880 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,7 @@ ## Changes - Fix legend color in `DoHeatmap()` ([#5783](https://github.com/satijalab/seurat/issues/5783)) +- Fix bug in `ScaleData()` when regressing out one gene ([#5970](https://github.com/satijalab/seurat/pull/5970)) # Seurat 4.1.1 (2022-05-01) From 9a8ec28aa1a0a7c885f56149ad2ac7f8c3e7ff96 Mon Sep 17 00:00:00 2001 From: Saket Choudhary Date: Fri, 27 May 2022 14:25:34 -0400 Subject: [PATCH 11/40] Fix PrepSCTIntegration doc --- R/integration.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/integration.R b/R/integration.R index 99a3ebe8f..2b4b6c122 100644 --- a/R/integration.R +++ b/R/integration.R @@ -2502,7 +2502,7 @@ MixingMetric <- function( #' normalization.method = "SCT", #' anchor.features = features #' ) -#' pancreas.integrated <- IntegrateData(anchors) +#' pancreas.integrated <- IntegrateData(anchors, normalization.method = "SCT") #' } #' PrepSCTIntegration <- function( From 18bc4874f5383ad44d9f492689a2c47917e53b3a Mon Sep 17 00:00:00 2001 From: Saket Choudhary Date: Fri, 27 May 2022 14:28:20 -0400 Subject: [PATCH 12/40] Update doc --- man/PrepSCTIntegration.Rd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/man/PrepSCTIntegration.Rd b/man/PrepSCTIntegration.Rd index ee1e15cac..d3fdecae4 100644 --- a/man/PrepSCTIntegration.Rd +++ b/man/PrepSCTIntegration.Rd @@ -80,7 +80,7 @@ anchors <- FindIntegrationAnchors( normalization.method = "SCT", anchor.features = features ) -pancreas.integrated <- IntegrateData(anchors) +pancreas.integrated <- IntegrateData(anchors, normalization.method = "SCT") } } From b287717f187481e63d3f5376d22314c52c1e2a07 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Wed, 15 Jun 2022 22:14:23 +0000 Subject: [PATCH 13/40] fix to account different cell ID structures. --- R/mixscape.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/mixscape.R b/R/mixscape.R index 3504563dd..9a556acfb 100644 --- a/R/mixscape.R +++ b/R/mixscape.R @@ -1027,8 +1027,8 @@ PlotPerturbScore <- function( prtb_score[, 2] <- as.factor(x = prtb_score[, 2]) gd <- setdiff(x = unique(x = prtb_score[, target.gene.class]), y = target.gene.ident) colnames(x = prtb_score)[2] <- "gene" - prtb_score$cell.bc <- sapply(rownames(prtb_score), FUN = function(x) strsplit(x, split = "[.]")[[1]][2]) - + prtb_score$cell.bc <- sapply(rownames(prtb_score), FUN = function(x) substring(x, regexpr("[.]", x) + 1)) + if (isTRUE(x = before.mixscape)) { cols <- setNames( object = c("grey49", col), From 0e938b50558ccb6f2af5ae751ebaed525ca9111e Mon Sep 17 00:00:00 2001 From: Paul Hoffman Date: Fri, 17 Jun 2022 16:29:10 -0400 Subject: [PATCH 14/40] Bump develop version --- DESCRIPTION | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 89b447412..93b768d4e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: Seurat -Version: 4.1.1.9001 -Date: 2022-05-20 +Version: 4.1.1.9002 +Date: 2022-06-17 Title: Tools for Single Cell Genomics Description: A toolkit for quality control, analysis, and exploration of single cell RNA sequencing data. 'Seurat' aims to enable users to identify and interpret sources of heterogeneity from single cell transcriptomic measurements, and to integrate diverse types of single cell data. See Satija R, Farrell J, Gennert D, et al (2015) , Macosko E, Basu A, Satija R, et al (2015) , Stuart T, Butler A, et al (2019) , and Hao, Hao, et al (2020) for more details. Authors@R: c( From b91f493deeb9aced72791dfe3dee4d81556e7093 Mon Sep 17 00:00:00 2001 From: Paul Hoffman Date: Fri, 17 Jun 2022 16:30:30 -0400 Subject: [PATCH 15/40] Update NEWS.md --- NEWS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS.md b/NEWS.md index 62d7ef880..2b799fc95 100644 --- a/NEWS.md +++ b/NEWS.md @@ -3,6 +3,7 @@ ## Changes - Fix legend color in `DoHeatmap()` ([#5783](https://github.com/satijalab/seurat/issues/5783)) - Fix bug in `ScaleData()` when regressing out one gene ([#5970](https://github.com/satijalab/seurat/pull/5970)) +- Fix name pulling in `PlotPerturbScore()` ([#6081](https://github.com/satijalab/seurat/pull/6081)) # Seurat 4.1.1 (2022-05-01) From f2bc08e9df4b45f34a12cea5f37115f0154c7d38 Mon Sep 17 00:00:00 2001 From: Stephen Williams Date: Mon, 18 Jul 2022 12:21:11 -0700 Subject: [PATCH 16/40] compatibility with spaceranger 2.0 --- R/preprocessing.R | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/R/preprocessing.R b/R/preprocessing.R index 4f6765faa..8b017dedb 100644 --- a/R/preprocessing.R +++ b/R/preprocessing.R @@ -1015,10 +1015,11 @@ Read10X_h5 <- function(filename, use.names = TRUE, unique.features = TRUE) { Read10X_Image <- function(image.dir, image.name = "tissue_lowres_image.png", filter.matrix = TRUE, ...) { image <- readPNG(source = file.path(image.dir, image.name)) scale.factors <- fromJSON(txt = file.path(image.dir, 'scalefactors_json.json')) + tissue.positions.path <- Sys.glob(file.path(image.dir, 'tissue_positions*')) tissue.positions <- read.csv( - file = file.path(image.dir, 'tissue_positions_list.csv'), + file = tissue.positions.path, col.names = c('barcodes', 'tissue', 'row', 'col', 'imagerow', 'imagecol'), - header = FALSE, + header = {ifelse(basename(tissue.positions.path) == "tissue_positions.csv", TRUE, FALSE)}, as.is = TRUE, row.names = 1 ) From 0168ea5689120032d0a9177d8043b0b6b5cb8dc2 Mon Sep 17 00:00:00 2001 From: Paul Hoffman Date: Tue, 19 Jul 2022 11:29:50 -0400 Subject: [PATCH 17/40] Style fixes --- R/preprocessing.R | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/R/preprocessing.R b/R/preprocessing.R index 8b017dedb..63229210b 100644 --- a/R/preprocessing.R +++ b/R/preprocessing.R @@ -1015,11 +1015,15 @@ Read10X_h5 <- function(filename, use.names = TRUE, unique.features = TRUE) { Read10X_Image <- function(image.dir, image.name = "tissue_lowres_image.png", filter.matrix = TRUE, ...) { image <- readPNG(source = file.path(image.dir, image.name)) scale.factors <- fromJSON(txt = file.path(image.dir, 'scalefactors_json.json')) - tissue.positions.path <- Sys.glob(file.path(image.dir, 'tissue_positions*')) + tissue.positions.path <- Sys.glob(paths = file.path(image.dir, 'tissue_positions*')) tissue.positions <- read.csv( file = tissue.positions.path, col.names = c('barcodes', 'tissue', 'row', 'col', 'imagerow', 'imagecol'), - header = {ifelse(basename(tissue.positions.path) == "tissue_positions.csv", TRUE, FALSE)}, + header = ifelse( + test = basename(tissue.positions.path) == "tissue_positions.csv", + yes = TRUE, + no = FALSE + ), as.is = TRUE, row.names = 1 ) From a01063e18cc98df2b3d41aff3fffb725626d8a4c Mon Sep 17 00:00:00 2001 From: Paul Hoffman Date: Tue, 19 Jul 2022 11:32:38 -0400 Subject: [PATCH 18/40] Update changelog Bump develop version --- DESCRIPTION | 4 ++-- NEWS.md | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index b23f1f21c..0f63bc5a9 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: Seurat -Version: 4.1.1 -Date: 2022-05-01 +Version: 4.1.1.9001 +Date: 2022-07-19 Title: Tools for Single Cell Genomics Description: A toolkit for quality control, analysis, and exploration of single cell RNA sequencing data. 'Seurat' aims to enable users to identify and interpret sources of heterogeneity from single cell transcriptomic measurements, and to integrate diverse types of single cell data. See Satija R, Farrell J, Gennert D, et al (2015) , Macosko E, Basu A, Satija R, et al (2015) , Stuart T, Butler A, et al (2019) , and Hao, Hao, et al (2020) for more details. Authors@R: c( diff --git a/NEWS.md b/NEWS.md index 27201ac2e..a8c7b5722 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,8 @@ +# Unreleased + +## Changes +- Support spaceranger 2.0 ([#6208](https://github.com/satijalab/seurat/pull/6208)) + # Seurat 4.1.1 (2022-05-01) ## Changes From 857fdf12b5ba1bceebb11c4dafa627559bb86638 Mon Sep 17 00:00:00 2001 From: Paul Hoffman Date: Tue, 19 Jul 2022 11:34:14 -0400 Subject: [PATCH 19/40] Update DESCRIPTION --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index bdfa3edeb..417b4fdc3 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: Seurat Version: 4.1.1.9003 -Date: 2022-06-17 +Date: 2022-07-19 Title: Tools for Single Cell Genomics Description: A toolkit for quality control, analysis, and exploration of single cell RNA sequencing data. 'Seurat' aims to enable users to identify and interpret sources of heterogeneity from single cell transcriptomic measurements, and to integrate diverse types of single cell data. See Satija R, Farrell J, Gennert D, et al (2015) , Macosko E, Basu A, Satija R, et al (2015) , Stuart T, Butler A, et al (2019) , and Hao, Hao, et al (2020) for more details. Authors@R: c( From eb41f83a5c6aaa77ac07baa14ae282656077c57f Mon Sep 17 00:00:00 2001 From: yuhanH Date: Fri, 22 Jul 2022 13:12:23 -0400 Subject: [PATCH 20/40] add param for add noise --- R/visualization.R | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/R/visualization.R b/R/visualization.R index 9af3a6e02..092c024b0 100644 --- a/R/visualization.R +++ b/R/visualization.R @@ -559,6 +559,7 @@ RidgePlot <- function( #' single violin shapes. #' @param adjust Adjust parameter for geom_violin #' @param flip flip plot orientation (identities on x-axis) +#' @param add.noise determine if adding a small noise for plotting #' @param raster Convert points to raster format. Requires 'ggrastr' to be installed. # default is \code{NULL} which automatically rasterizes if ggrastr is installed and # number of points exceed 100,000. @@ -597,6 +598,7 @@ VlnPlot <- function( combine = TRUE, fill.by = 'feature', flip = FALSE, + add.noise = TRUE, raster = NULL ) { if ( @@ -633,6 +635,7 @@ VlnPlot <- function( combine = combine, fill.by = fill.by, flip = flip, + add.noise = add.noise, raster = raster )) } @@ -5560,6 +5563,7 @@ Col2Hex <- function(...) { # ggplot object. If \code{FALSE}, return a list of ggplot objects # @param fill.by Color violins/ridges based on either 'feature' or 'ident' # @param flip flip plot orientation (identities on x-axis) +# @param add.noise determine if adding a small noise for plotting # @param raster Convert points to raster format, default is \code{NULL} which # automatically rasterizes if plotting more than 100,000 cells # @@ -5591,6 +5595,7 @@ ExIPlot <- function( combine = TRUE, fill.by = NULL, flip = FALSE, + add.noise = TRUE, raster = NULL ) { assay <- assay %||% DefaultAssay(object = object) @@ -5676,6 +5681,7 @@ ExIPlot <- function( pt.size = pt.size, log = log, fill.by = fill.by, + add.noise = add.noise, flip = flip )) } @@ -5693,6 +5699,7 @@ ExIPlot <- function( cols = cols, pt.size = pt.size, log = log, + add.noise = add.noise, raster = raster )) } @@ -6384,6 +6391,7 @@ MultiExIPlot <- function( seed.use = 42, log = FALSE, fill.by = NULL, + add.noise = TRUE, flip = NULL ) { if (!(fill.by %in% c("feature", "ident"))) { @@ -6451,6 +6459,9 @@ MultiExIPlot <- function( } else { noise <- rnorm(n = nrow(x = data)) / 100000 } + if (!add.noise) { + noise <- noise*0 + } for (f in unique(x = data$feature)) { if (all(data$expression[(data$feature == f)] == data$expression[(data$feature == f)][1])) { warning( @@ -7213,6 +7224,7 @@ SingleDimPlot <- function( #' @param cols Colors to use for plotting #' @param seed.use Random seed to use. If NULL, don't set a seed #' @param log plot Y axis on log10 scale +#' @param add.noise determine if adding small noise for plotting #' @param raster Convert points to raster format. Requires 'ggrastr' to be installed. #' default is \code{NULL} which automatically rasterizes if ggrastr is installed and #' number of points exceed 100,000. @@ -7242,6 +7254,7 @@ SingleExIPlot <- function( cols = NULL, seed.use = 42, log = FALSE, + add.noise = TRUE, raster = NULL ) { if (!is.null(x = raster) && isTRUE(x = raster)){ @@ -7286,6 +7299,9 @@ SingleExIPlot <- function( } else { noise <- rnorm(n = length(x = data[, feature])) / 100000 } + if (!add.noise) { + noise <- noise * 0 + } if (all(data[, feature] == data[, feature][1])) { warning(paste0("All cells have the same value of ", feature, ".")) } else{ From 876517d83de8307a3413970e69322e7c29833ee9 Mon Sep 17 00:00:00 2001 From: yuhanH Date: Fri, 22 Jul 2022 13:13:03 -0400 Subject: [PATCH 21/40] update docu --- man/SingleExIPlot.Rd | 3 +++ man/VlnPlot.Rd | 3 +++ 2 files changed, 6 insertions(+) diff --git a/man/SingleExIPlot.Rd b/man/SingleExIPlot.Rd index f7b8cdb4f..636503c5d 100644 --- a/man/SingleExIPlot.Rd +++ b/man/SingleExIPlot.Rd @@ -16,6 +16,7 @@ SingleExIPlot( cols = NULL, seed.use = 42, log = FALSE, + add.noise = TRUE, raster = NULL ) } @@ -43,6 +44,8 @@ expression of the attribute being potted} \item{log}{plot Y axis on log10 scale} +\item{add.noise}{determine if adding small noise for plotting} + \item{raster}{Convert points to raster format. Requires 'ggrastr' to be installed. default is \code{NULL} which automatically rasterizes if ggrastr is installed and number of points exceed 100,000.} diff --git a/man/VlnPlot.Rd b/man/VlnPlot.Rd index ec75da8f9..951fc2afc 100644 --- a/man/VlnPlot.Rd +++ b/man/VlnPlot.Rd @@ -25,6 +25,7 @@ VlnPlot( combine = TRUE, fill.by = "feature", flip = FALSE, + add.noise = TRUE, raster = NULL ) } @@ -73,6 +74,8 @@ ggplot object. If \code{FALSE}, return a list of ggplot} \item{flip}{flip plot orientation (identities on x-axis)} +\item{add.noise}{determine if adding a small noise for plotting} + \item{raster}{Convert points to raster format. Requires 'ggrastr' to be installed.} } \value{ From f70a71d50770697abf4709450c6d2ef1bcfc8e99 Mon Sep 17 00:00:00 2001 From: Andrew Butler Date: Fri, 22 Jul 2022 16:01:56 -0700 Subject: [PATCH 22/40] fix bug in SpatialPlot when using group.by parameter --- DESCRIPTION | 4 ++-- NEWS.md | 1 + R/visualization.R | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 89b447412..5114157c0 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: Seurat -Version: 4.1.1.9001 -Date: 2022-05-20 +Version: 4.1.1.9002 +Date: 2022-07-22 Title: Tools for Single Cell Genomics Description: A toolkit for quality control, analysis, and exploration of single cell RNA sequencing data. 'Seurat' aims to enable users to identify and interpret sources of heterogeneity from single cell transcriptomic measurements, and to integrate diverse types of single cell data. See Satija R, Farrell J, Gennert D, et al (2015) , Macosko E, Basu A, Satija R, et al (2015) , Stuart T, Butler A, et al (2019) , and Hao, Hao, et al (2020) for more details. Authors@R: c( diff --git a/NEWS.md b/NEWS.md index 62d7ef880..2064254b1 100644 --- a/NEWS.md +++ b/NEWS.md @@ -3,6 +3,7 @@ ## Changes - Fix legend color in `DoHeatmap()` ([#5783](https://github.com/satijalab/seurat/issues/5783)) - Fix bug in `ScaleData()` when regressing out one gene ([#5970](https://github.com/satijalab/seurat/pull/5970)) +- Fix bug in `SpatialDimPlot()` when using `group.by` ([#6179](https://github.com/satijalab/seurat/issues/6179)) # Seurat 4.1.1 (2022-05-01) diff --git a/R/visualization.R b/R/visualization.R index 9af3a6e02..a5101ec59 100644 --- a/R/visualization.R +++ b/R/visualization.R @@ -7682,7 +7682,7 @@ SingleSpatialPlot <- function( colors <- DiscretePalette(length(unique(data[[col.by]])), palette = cols) scale <- scale_fill_manual(values = colors, na.value = na.value) } else { - cols <- cols[names(x = cols) %in% data$ident] + cols <- cols[names(x = cols) %in% data[[gsub(pattern = '`', replacement = "", x = col.by)]]] scale <- scale_fill_manual(values = cols, na.value = na.value) } plot <- plot + scale From ca8d17057a04f7fe632a787565a88156457fe6ac Mon Sep 17 00:00:00 2001 From: yuhanH Date: Fri, 29 Jul 2022 15:29:04 -0400 Subject: [PATCH 23/40] bump version --- DESCRIPTION | 2 +- NEWS.md | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 89b447412..7c8ddf481 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: Seurat -Version: 4.1.1.9001 +Version: 4.1.1.9002 Date: 2022-05-20 Title: Tools for Single Cell Genomics Description: A toolkit for quality control, analysis, and exploration of single cell RNA sequencing data. 'Seurat' aims to enable users to identify and interpret sources of heterogeneity from single cell transcriptomic measurements, and to integrate diverse types of single cell data. See Satija R, Farrell J, Gennert D, et al (2015) , Macosko E, Basu A, Satija R, et al (2015) , Stuart T, Butler A, et al (2019) , and Hao, Hao, et al (2020) for more details. diff --git a/NEWS.md b/NEWS.md index 62d7ef880..763aa5ddd 100644 --- a/NEWS.md +++ b/NEWS.md @@ -3,6 +3,8 @@ ## Changes - Fix legend color in `DoHeatmap()` ([#5783](https://github.com/satijalab/seurat/issues/5783)) - Fix bug in `ScaleData()` when regressing out one gene ([#5970](https://github.com/satijalab/seurat/pull/5970)) +- Add `add.noise` parameter in `VlnPlot()` +([#5756](https://github.com/satijalab/seurat/issues/5756)) # Seurat 4.1.1 (2022-05-01) From 184830c3d1e9ef53b84842a9c551e2d44d11e609 Mon Sep 17 00:00:00 2001 From: AustinHartman Date: Tue, 23 Aug 2022 09:56:30 -0400 Subject: [PATCH 24/40] update coercions for Matrix deprecation --- R/clustering.R | 2 +- R/dimensional_reduction.R | 2 +- R/integration.R | 18 +++++++++--------- R/objects.R | 7 ++++--- R/preprocessing.R | 16 ++++++++-------- R/utilities.R | 2 +- tests/testthat/test_data_manipulation.R | 6 +++--- tests/testthat/test_preprocessing.R | 2 +- tests/testthat/test_utilities.R | 2 +- 9 files changed, 29 insertions(+), 28 deletions(-) diff --git a/R/clustering.R b/R/clustering.R index de0cc96c5..3e1d30bce 100644 --- a/R/clustering.R +++ b/R/clustering.R @@ -1689,7 +1689,7 @@ RunLeiden <- function( graph_from_adj_list(adjlist = object) } else if (inherits(x = object, what = c('dgCMatrix', 'matrix', 'Matrix'))) { if (inherits(x = object, what = 'Graph')) { - object <- as(object = object, Class = "dgCMatrix") + object <- as.sparse(x = object) } graph_from_adjacency_matrix(adjmatrix = object, weighted = TRUE) } else if (inherits(x = object, what = 'igraph')) { diff --git a/R/dimensional_reduction.R b/R/dimensional_reduction.R index 581f35427..0f7357057 100644 --- a/R/dimensional_reduction.R +++ b/R/dimensional_reduction.R @@ -1388,7 +1388,7 @@ RunUMAP.default <- function( if (is.list(x = object)) { if (ncol(object$idx) != model$n_neighbors) { warning("Number of neighbors between query and reference ", - "is not equal to the number of neighbros within reference") + "is not equal to the number of neighbors within reference") model$n_neighbors <- ncol(object$idx) } umap_transform( diff --git a/R/integration.R b/R/integration.R index 2b4b6c122..5da042ecf 100644 --- a/R/integration.R +++ b/R/integration.R @@ -2176,7 +2176,7 @@ MappingScore.default <- function( ref.pca <- ref.embeddings[ref.cells[anchors[, 1]], 1:ndim] rownames(x = ref.pca) <- paste0(rownames(x = ref.pca), "_reference") query.cells.projected <- Matrix::crossprod( - x = as(object = ref.pca, Class = "dgCMatrix"), + x = as.sparse(x = ref.pca), y = weights.matrix ) colnames(x = query.cells.projected) <- query.cells @@ -2215,7 +2215,7 @@ MappingScore.default <- function( orig.pca <- query.embeddings[query.cells[anchors[, 2]], ] query.cells.back.corrected <- Matrix::t( x = Matrix::crossprod( - x = as(object = orig.pca, Class = "dgCMatrix"), + x = as.sparse(x = orig.pca), y = weights.matrix)[1:ndim, ] ) query.cells.back.corrected <- as.matrix(x = query.cells.back.corrected) @@ -3037,7 +3037,7 @@ TransferData <- function( rownames(x = new.data) <- rownames(x = refdata[[rd]]) colnames(x = new.data) <- query.cells if (inherits(x = new.data, what = "Matrix")) { - new.data <- as(object = new.data, Class = "dgCMatrix") + new.data <- as.sparse(x = new.data) } if (slot == "counts") { # TODO: restore once check.matrix is in SeuratObject @@ -4031,7 +4031,7 @@ NNtoMatrix <- function(idx, distance, k) { x = as.numeric(x = nn[, 3]), Dim = as.integer(x = c(nrow(idx), nrow(x = idx))) ) - nn.matrix <- as(object = nn.matrix, Class = 'dgCMatrix') + nn.matrix <- as.sparse(x = nn.matrix) return(nn.matrix) } @@ -4353,7 +4353,7 @@ RescaleQuery <- function( if (scale) { feature.sd <- sqrt( x = SparseRowVar2( - mat = as(object = reference.data, Class = "dgCMatrix"), + mat = as.sparse(x = reference.data), mu = feature.mean, display_progress = FALSE ) @@ -4372,7 +4372,7 @@ RescaleQuery <- function( store.names <- dimnames(x = proj.data) if (is.numeric(x = feature.mean) && feature.mean[[1]] != "SCT") { proj.data <- FastSparseRowScaleWithKnownStats( - mat = as(object = proj.data, Class = "dgCMatrix"), + mat = as.sparse(x = proj.data), mu = feature.mean, sigma = feature.sd, display_progress = FALSE @@ -4840,9 +4840,9 @@ TransformDataMatrix <- function( slot = "data")[features.to.integrate, nn.cells2] ) - integrated <- IntegrateDataC(integration_matrix = as(integration.matrix, "dgCMatrix"), - weights = as(weights, "dgCMatrix"), - expression_cells2 = as(data.use2, "dgCMatrix")) + integrated <- IntegrateDataC(integration_matrix = as.sparse(x = integration.matrix), + weights = as.sparse(x = weights), + expression_cells2 = as.sparse(x = data.use2)) dimnames(integrated) <- dimnames(data.use2) new.expression <- t(rbind(data.use1, integrated)) diff --git a/R/objects.R b/R/objects.R index d84d74226..39dd56499 100644 --- a/R/objects.R +++ b/R/objects.R @@ -1905,6 +1905,7 @@ levels.SCTAssay <- function(x) { #' Merge SCTAssay objects #' #' @inheritParams SeuratObject::merge +#' @param x A \code{\link[SeuratObject]{Seurat}} object #' @param na.rm If na.rm = TRUE, this will only preserve residuals that are #' present in all SCTAssays being merged. Otherwise, missing residuals will be #' populated with NAs. @@ -2696,10 +2697,10 @@ UpdateAssay <- function(old.assay, assay){ counts <- old.assay@raw.data data <- old.assay@data if (!inherits(x = counts, what = 'dgCMatrix')) { - counts <- as(object = as.matrix(x = counts), Class = 'dgCMatrix') + counts <- as.sparse(x = as.matrix(x = counts)) } if (!inherits(x = data, what = 'dgCMatrix')) { - data <- as(object = as.matrix(x = data), Class = 'dgCMatrix') + data <- as.sparse(x = as.matrix(x = data)) } new.assay <- new( Class = 'Assay', @@ -2881,7 +2882,7 @@ ValidateDataForMerge <- function(assay, slot) { ncol = data.dims[2], dimnames = dimnames(x = GetAssayData(object = assay, slot = data.slot)) ) - mat <- as(object = mat, Class = "dgCMatrix") + mat <- as.sparse(x = mat) } return(mat) } diff --git a/R/preprocessing.R b/R/preprocessing.R index 7ef77dcf5..1f7103ec5 100644 --- a/R/preprocessing.R +++ b/R/preprocessing.R @@ -624,7 +624,7 @@ LogNormalize <- function(data, scale.factor = 1e4, verbose = TRUE) { data <- as.matrix(x = data) } if (!inherits(x = data, what = 'dgCMatrix')) { - data <- as(object = data, Class = "dgCMatrix") + data <- as.sparse(x = data) } # call Rcpp function to normalize if (verbose) { @@ -891,7 +891,7 @@ Read10X <- function( for (j in 1:length(x = full.data[[1]])) { list_of_data[[j]] <- do.call(cbind, lapply(X = full.data, FUN = `[[`, j)) # Fix for Issue #913 - list_of_data[[j]] <- as(object = list_of_data[[j]], Class = "dgCMatrix") + list_of_data[[j]] <- as.sparse(x = list_of_data[[j]]) } names(x = list_of_data) <- names(x = full.data[[1]]) # If multiple features, will return a list, otherwise @@ -961,7 +961,7 @@ Read10X_h5 <- function(filename, use.names = TRUE, unique.features = TRUE) { } rownames(x = sparse.mat) <- features colnames(x = sparse.mat) <- barcodes[] - sparse.mat <- as(object = sparse.mat, Class = 'dgCMatrix') + sparse.mat <- as.sparse(x = sparse.mat) # Split v3 multimodal if (infile$exists(name = paste0(genome, '/features'))) { types <- infile[[paste0(genome, '/features/feature_type')]][] @@ -1250,7 +1250,7 @@ ReadMtx <- function( colnames(x = data) <- cell.names rownames(x = data) <- feature.names - data <- as(data, Class = "dgCMatrix") + data <- as.sparse(x = data) return(data) } @@ -1313,7 +1313,7 @@ RelativeCounts <- function(data, scale.factor = 1, verbose = TRUE) { data <- as.matrix(x = data) } if (!inherits(x = data, what = 'dgCMatrix')) { - data <- as(object = data, Class = "dgCMatrix") + data <- as.sparse(x = data) } if (verbose) { cat("Performing relative-counts-normalization\n", file = stderr()) @@ -1463,7 +1463,7 @@ SampleUMI <- function( upsample = FALSE, verbose = FALSE ) { - data <- as(object = data, Class = "dgCMatrix") + data <- as.sparse(x = data) if (length(x = max.umi) == 1) { new_data <- RunUMISampling( data = data, @@ -1941,7 +1941,7 @@ FindVariableFeatures.default <- function( object <- as(object = as.matrix(x = object), Class = 'Matrix') } if (!inherits(x = object, what = 'dgCMatrix')) { - object <- as(object = object, Class = 'dgCMatrix') + object <- as.sparse(x = object) } if (selection.method == "vst") { if (clip.max == 'auto') { @@ -3113,7 +3113,7 @@ CustomNormalize <- function(data, custom_function, margin, verbose = TRUE) { data <- as.matrix(x = data) } if (!inherits(x = data, what = 'dgCMatrix')) { - data <- as(object = data, Class = "dgCMatrix") + data <- as.sparse(x = data) } myapply <- ifelse(test = verbose, yes = pbapply, no = apply) # margin <- switch( diff --git a/R/utilities.R b/R/utilities.R index d0d76dfba..6b93863b3 100644 --- a/R/utilities.R +++ b/R/utilities.R @@ -1894,7 +1894,7 @@ CreateDummyAssay <- function(assay) { j = {}, dims = c(nrow(x = assay), ncol(x = assay)) ) - cm <- as(object = cm, Class = "dgCMatrix") + cm <- as.sparse(x = cm) rownames(x = cm) <- rownames(x = assay) colnames(x = cm) <- colnames(x = assay) # TODO: restore once check.matrix is in SeuratObject diff --git a/tests/testthat/test_data_manipulation.R b/tests/testthat/test_data_manipulation.R index 17a715f4f..238f9a50d 100644 --- a/tests/testthat/test_data_manipulation.R +++ b/tests/testthat/test_data_manipulation.R @@ -91,7 +91,7 @@ test_that("Fast implementation of row scaling returns expected values", { expect_true(max(mat.clipped, na.rm = T) >= 0.2) }) -mat <- as(object = matrix(rnorm(100), nrow = 10, ncol = 10), Class = "dgCMatrix") +mat <- as.sparse(x = matrix(rnorm(100), nrow = 10, ncol = 10)) test_that("Row scaling with known stats works", { mat.rowmeans <- rowMeans(x = mat) @@ -147,7 +147,7 @@ test_that("Fast implementation of rbind returns expected values", { expect_equal(fcv[10,10], merged.mat[20,10]) }) -mat <- as(mat, "dgCMatrix") +mat <- as.sparse(mat) test_that("Fast implementation of ExpMean returns expected values",{ expect_equal(ExpMean(mat[1,]), FastExpMean(mat, display_progress = F)[1]) expect_equal(ExpMean(mat[5,]), FastExpMean(mat, display_progress = F)[5]) @@ -173,7 +173,7 @@ test_that("Fast implementation of LogVMR returns expected values", { test_that("Row variance calculations for sparse matrices work", { expect_equal(apply(X = mat, MARGIN = 1, FUN = var), SparseRowVar(mat = mat, display_progress = FALSE), tolerance = 1e-6) - expect_equal(apply(X = mat2, MARGIN = 1, FUN = var), SparseRowVar(mat = as(object = mat2, Class = "dgCMatrix"), display_progress = FALSE), tolerance = 1e-6) + expect_equal(apply(X = mat2, MARGIN = 1, FUN = var), SparseRowVar(mat = as.sparse(x = mat2), display_progress = FALSE), tolerance = 1e-6) }) # Tests for data structure manipulations diff --git a/tests/testthat/test_preprocessing.R b/tests/testthat/test_preprocessing.R index 89474010e..d84ef3bdd 100644 --- a/tests/testthat/test_preprocessing.R +++ b/tests/testthat/test_preprocessing.R @@ -2,7 +2,7 @@ set.seed(42) pbmc.file <- system.file('extdata', 'pbmc_raw.txt', package = 'Seurat') -pbmc.test <- as(as.matrix(read.table(pbmc.file, sep = "\t", row.names = 1)), "dgCMatrix") +pbmc.test <- as.sparse(x = as.matrix(read.table(pbmc.file, sep = "\t", row.names = 1))) # Tests for object creation (via CreateSeuratObject) # -------------------------------------------------------------------------------- diff --git a/tests/testthat/test_utilities.R b/tests/testthat/test_utilities.R index 6542d8c17..079634451 100644 --- a/tests/testthat/test_utilities.R +++ b/tests/testthat/test_utilities.R @@ -1,7 +1,7 @@ set.seed(42) pbmc.file <- system.file('extdata', 'pbmc_raw.txt', package = 'Seurat') -pbmc.test <- as(as.matrix(read.table(pbmc.file, sep = "\t", row.names = 1)), "dgCMatrix") +pbmc.test <- as.sparse(x = as.matrix(read.table(pbmc.file, sep = "\t", row.names = 1))) meta.data <- data.frame( a = rep(as.factor(c('a', 'b', 'c')), length.out = ncol(pbmc.test)), From 7a4cca797ecde884b8375de244678aedcb201f77 Mon Sep 17 00:00:00 2001 From: AustinHartman Date: Tue, 23 Aug 2022 11:33:52 -0400 Subject: [PATCH 25/40] specify min uwot version --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 7c8ddf481..58a9dc0de 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -74,7 +74,7 @@ Imports: tibble, tools, utils, - uwot (>= 0.1.9) + uwot (>= 0.1.14) LinkingTo: Rcpp (>= 0.11.0), RcppEigen, RcppProgress License: MIT + file LICENSE LazyData: true From 77fc31741f161e8a90d3557abb1727513334b3a5 Mon Sep 17 00:00:00 2001 From: AustinHartman Date: Wed, 24 Aug 2022 14:39:51 -0400 Subject: [PATCH 26/40] bump sctransform minimum version --- DESCRIPTION | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 58a9dc0de..97d9f5bb8 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: Seurat -Version: 4.1.1.9002 +Version: 4.1.1.9005 Date: 2022-05-20 Title: Tools for Single Cell Genomics Description: A toolkit for quality control, analysis, and exploration of single cell RNA sequencing data. 'Seurat' aims to enable users to identify and interpret sources of heterogeneity from single cell transcriptomic measurements, and to integrate diverse types of single cell data. See Satija R, Farrell J, Gennert D, et al (2015) , Macosko E, Basu A, Satija R, et al (2015) , Stuart T, Butler A, et al (2019) , and Hao, Hao, et al (2020) for more details. @@ -65,7 +65,7 @@ Imports: Rtsne, scales, scattermore (>= 0.7), - sctransform (>= 0.3.3), + sctransform (>= 0.3.4), SeuratObject (>= 4.1.0), shiny, spatstat.core, From bb1dce3ef7f2448208261bda3904cb17cf381a29 Mon Sep 17 00:00:00 2001 From: AustinHartman Date: Fri, 26 Aug 2022 14:03:44 -0400 Subject: [PATCH 27/40] add parameter to older uwot models --- R/dimensional_reduction.R | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/R/dimensional_reduction.R b/R/dimensional_reduction.R index 581f35427..d7cf8259b 100644 --- a/R/dimensional_reduction.R +++ b/R/dimensional_reduction.R @@ -1379,6 +1379,10 @@ RunUMAP.default <- function( object = reduction.model, slot = "model" ) + # add num_precomputed_nns to Date: Fri, 26 Aug 2022 15:37:44 -0400 Subject: [PATCH 28/40] update news and desc --- DESCRIPTION | 2 +- NEWS.md | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index d54cf74be..c0fd94752 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: Seurat -Version: 4.1.1.9003 +Version: 4.1.1.9004 Date: 2022-07-22 Title: Tools for Single Cell Genomics Description: A toolkit for quality control, analysis, and exploration of single cell RNA sequencing data. 'Seurat' aims to enable users to identify and interpret sources of heterogeneity from single cell transcriptomic measurements, and to integrate diverse types of single cell data. See Satija R, Farrell J, Gennert D, et al (2015) , Macosko E, Basu A, Satija R, et al (2015) , Stuart T, Butler A, et al (2019) , and Hao, Hao, et al (2020) for more details. diff --git a/NEWS.md b/NEWS.md index e34f2a866..99db11f4a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -6,6 +6,7 @@ - Fix bug in `SpatialDimPlot()` when using `group.by` ([#6179](https://github.com/satijalab/seurat/issues/6179)) - Add `add.noise` parameter in `VlnPlot()` ([#5756](https://github.com/satijalab/seurat/issues/5756)) +- Fix uwot model backwards compatibility ([#6345](https://github.com/satijalab/seurat/issues/6345)) # Seurat 4.1.1 (2022-05-01) From 6c759ac8bd3d0a43b038e97fe383aa960824c6d2 Mon Sep 17 00:00:00 2001 From: timoast <4591688+timoast@users.noreply.github.com> Date: Fri, 26 Aug 2022 15:38:12 -0400 Subject: [PATCH 29/40] Change default pseudocount; #6202 --- R/differential_expression.R | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/R/differential_expression.R b/R/differential_expression.R index aac07e55c..b76a6f02c 100644 --- a/R/differential_expression.R +++ b/R/differential_expression.R @@ -59,7 +59,7 @@ FindAllMarkers <- function( latent.vars = NULL, min.cells.feature = 3, min.cells.group = 3, - pseudocount.use = 1, + pseudocount.use = 1/10000, mean.fxn = NULL, fc.name = NULL, base = 2, @@ -476,7 +476,7 @@ FindConservedMarkers <- function( #' of the two groups, currently only used for poisson and negative binomial tests #' @param min.cells.group Minimum number of cells in one of the groups #' @param pseudocount.use Pseudocount to add to averaged expression values when -#' calculating logFC. 1 by default. +#' calculating logFC. 1/10000 by default. #' @param fc.results data.frame from FoldChange #' @param densify Convert the sparse matrix to a dense form before running the DE test. This can provide speedups but might require higher memory; default is FALSE #' @@ -507,7 +507,7 @@ FindMarkers.default <- function( latent.vars = NULL, min.cells.feature = 3, min.cells.group = 3, - pseudocount.use = 1, + pseudocount.use = 1/10000, fc.results = NULL, densify = FALSE, ... @@ -625,7 +625,7 @@ FindMarkers.Assay <- function( latent.vars = NULL, min.cells.feature = 3, min.cells.group = 3, - pseudocount.use = 1, + pseudocount.use = 1/10000, mean.fxn = NULL, fc.name = NULL, base = 2, @@ -704,7 +704,7 @@ FindMarkers.SCTAssay <- function( latent.vars = NULL, min.cells.feature = 3, min.cells.group = 3, - pseudocount.use = 1, + pseudocount.use = 1/10000, mean.fxn = NULL, fc.name = NULL, base = 2, @@ -806,7 +806,7 @@ FindMarkers.DimReduc <- function( latent.vars = NULL, min.cells.feature = 3, min.cells.group = 3, - pseudocount.use = 1, + pseudocount.use = 1/10000, mean.fxn = rowMeans, fc.name = NULL, densify = FALSE, @@ -927,7 +927,7 @@ FindMarkers.Seurat <- function( latent.vars = NULL, min.cells.feature = 3, min.cells.group = 3, - pseudocount.use = 1, + pseudocount.use = 1/10000, mean.fxn = NULL, fc.name = NULL, base = 2, @@ -1062,7 +1062,7 @@ FoldChange.Assay <- function( cells.2, features = NULL, slot = "data", - pseudocount.use = 1, + pseudocount.use = 1/10000, fc.name = NULL, mean.fxn = NULL, base = 2, @@ -1143,7 +1143,7 @@ FoldChange.DimReduc <- function( #' @param assay Assay to use in fold change calculation #' @param slot Slot to pull data from #' @param pseudocount.use Pseudocount to add to averaged expression values when -#' calculating logFC. 1 by default. +#' calculating logFC. 1/10000 by default. #' @param mean.fxn Function to use for fold change or average difference calculation #' @param base The base with respect to which logarithms are computed. #' @param fc.name Name of the fold change, average difference, or custom function column @@ -1163,7 +1163,7 @@ FoldChange.Seurat <- function( slot = 'data', reduction = NULL, features = NULL, - pseudocount.use = 1, + pseudocount.use = 1/10000, mean.fxn = NULL, base = 2, fc.name = NULL, From d2eaf5fffe29c65a6aa8d9b0943fd14cf1e5569e Mon Sep 17 00:00:00 2001 From: timoast <4591688+timoast@users.noreply.github.com> Date: Fri, 26 Aug 2022 15:38:22 -0400 Subject: [PATCH 30/40] Update release notes --- DESCRIPTION | 4 ++-- NEWS.md | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 417b4fdc3..a46db6a60 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: Seurat -Version: 4.1.1.9003 -Date: 2022-07-19 +Version: 4.1.1.9004 +Date: 2022-08-26 Title: Tools for Single Cell Genomics Description: A toolkit for quality control, analysis, and exploration of single cell RNA sequencing data. 'Seurat' aims to enable users to identify and interpret sources of heterogeneity from single cell transcriptomic measurements, and to integrate diverse types of single cell data. See Satija R, Farrell J, Gennert D, et al (2015) , Macosko E, Basu A, Satija R, et al (2015) , Stuart T, Butler A, et al (2019) , and Hao, Hao, et al (2020) for more details. Authors@R: c( diff --git a/NEWS.md b/NEWS.md index f2e6ddff8..c1ac6e00a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -5,6 +5,7 @@ - Fix bug in `ScaleData()` when regressing out one gene ([#5970](https://github.com/satijalab/seurat/pull/5970)) - Fix name pulling in `PlotPerturbScore()` ([#6081](https://github.com/satijalab/seurat/pull/6081)) - Support spaceranger 2.0 ([#6208](https://github.com/satijalab/seurat/pull/6208)) +- Change default pseudocount for log fold change calculation ([#6202](https://github.com/satijalab/seurat/issues/6202)) # Seurat 4.1.1 (2022-05-01) From dbe7ff3529216c2ed61db338d477ef9364ba440b Mon Sep 17 00:00:00 2001 From: AustinHartman Date: Thu, 1 Sep 2022 09:17:20 -0400 Subject: [PATCH 31/40] set pseudocount.use to null at seurat level --- NEWS.md | 2 +- R/differential_expression.R | 28 +++++++++++++++++----------- man/FindAllMarkers.Rd | 2 +- man/FindMarkers.Rd | 2 +- man/FoldChange.Rd | 6 +++--- 5 files changed, 23 insertions(+), 17 deletions(-) diff --git a/NEWS.md b/NEWS.md index 669ba3cf2..eedb432a3 100644 --- a/NEWS.md +++ b/NEWS.md @@ -5,11 +5,11 @@ - Fix bug in `ScaleData()` when regressing out one gene ([#5970](https://github.com/satijalab/seurat/pull/5970)) - Fix name pulling in `PlotPerturbScore()` ([#6081](https://github.com/satijalab/seurat/pull/6081)) - Support spaceranger 2.0 ([#6208](https://github.com/satijalab/seurat/pull/6208)) -- Change default pseudocount for log fold change calculation ([#6202](https://github.com/satijalab/seurat/issues/6202)) - Fix bug in `SpatialDimPlot()` when using `group.by` ([#6179](https://github.com/satijalab/seurat/issues/6179)) - Add `add.noise` parameter in `VlnPlot()` ([#5756](https://github.com/satijalab/seurat/issues/5756)) - Fix uwot model backwards compatibility ([#6345](https://github.com/satijalab/seurat/issues/6345)) +- Allow `pseudocount.use` in differential expression functions to be set at the `Assay` level # Seurat 4.1.1 (2022-05-01) diff --git a/R/differential_expression.R b/R/differential_expression.R index b76a6f02c..a84940545 100644 --- a/R/differential_expression.R +++ b/R/differential_expression.R @@ -59,7 +59,7 @@ FindAllMarkers <- function( latent.vars = NULL, min.cells.feature = 3, min.cells.group = 3, - pseudocount.use = 1/10000, + pseudocount.use = NULL, mean.fxn = NULL, fc.name = NULL, base = 2, @@ -476,7 +476,7 @@ FindConservedMarkers <- function( #' of the two groups, currently only used for poisson and negative binomial tests #' @param min.cells.group Minimum number of cells in one of the groups #' @param pseudocount.use Pseudocount to add to averaged expression values when -#' calculating logFC. 1/10000 by default. +#' calculating logFC. 1 by default. #' @param fc.results data.frame from FoldChange #' @param densify Convert the sparse matrix to a dense form before running the DE test. This can provide speedups but might require higher memory; default is FALSE #' @@ -507,11 +507,12 @@ FindMarkers.default <- function( latent.vars = NULL, min.cells.feature = 3, min.cells.group = 3, - pseudocount.use = 1/10000, + pseudocount.use = 1, fc.results = NULL, densify = FALSE, ... ) { + pseudocount.use <- pseudocount.use %||% 1 ValidateCellGroups( object = object, cells.1 = cells.1, @@ -625,13 +626,14 @@ FindMarkers.Assay <- function( latent.vars = NULL, min.cells.feature = 3, min.cells.group = 3, - pseudocount.use = 1/10000, + pseudocount.use = 1, mean.fxn = NULL, fc.name = NULL, base = 2, densify = FALSE, ... ) { + pseudocount.use <- pseudocount.use %||% 1 data.slot <- ifelse( test = test.use %in% DEmethods_counts(), yes = 'counts', @@ -704,7 +706,7 @@ FindMarkers.SCTAssay <- function( latent.vars = NULL, min.cells.feature = 3, min.cells.group = 3, - pseudocount.use = 1/10000, + pseudocount.use = 1, mean.fxn = NULL, fc.name = NULL, base = 2, @@ -712,6 +714,7 @@ FindMarkers.SCTAssay <- function( recorrect_umi = TRUE, ... ) { + pseudocount.use <- pseudocount.use %||% 1 data.slot <- ifelse( test = test.use %in% DEmethods_counts(), yes = 'counts', @@ -806,13 +809,14 @@ FindMarkers.DimReduc <- function( latent.vars = NULL, min.cells.feature = 3, min.cells.group = 3, - pseudocount.use = 1/10000, + pseudocount.use = 1, mean.fxn = rowMeans, fc.name = NULL, densify = FALSE, ... ) { + pseudocount.use <- pseudocount.use %||% 1 if (test.use %in% DEmethods_counts()) { stop("The following tests cannot be used for differential expression on a reduction as they assume a count model: ", paste(DEmethods_counts(), collapse=", ")) @@ -927,7 +931,7 @@ FindMarkers.Seurat <- function( latent.vars = NULL, min.cells.feature = 3, min.cells.group = 3, - pseudocount.use = 1/10000, + pseudocount.use = NULL, mean.fxn = NULL, fc.name = NULL, base = 2, @@ -1062,12 +1066,13 @@ FoldChange.Assay <- function( cells.2, features = NULL, slot = "data", - pseudocount.use = 1/10000, + pseudocount.use = 1, fc.name = NULL, mean.fxn = NULL, base = 2, ... ) { + pseudocount.use <- pseudocount.use %||% 1 data <- GetAssayData(object = object, slot = slot) mean.fxn <- mean.fxn %||% switch( EXPR = slot, @@ -1111,11 +1116,12 @@ FoldChange.DimReduc <- function( cells.2, features = NULL, slot = NULL, - pseudocount.use = NULL, + pseudocount.use = 1, fc.name = NULL, mean.fxn = NULL, ... ) { + pseudocount.use <- pseudocount.use %||% 1 mean.fxn <- mean.fxn %||% rowMeans fc.name <- fc.name %||% "avg_diff" data <- t(x = Embeddings(object = object)) @@ -1143,7 +1149,7 @@ FoldChange.DimReduc <- function( #' @param assay Assay to use in fold change calculation #' @param slot Slot to pull data from #' @param pseudocount.use Pseudocount to add to averaged expression values when -#' calculating logFC. 1/10000 by default. +#' calculating logFC. #' @param mean.fxn Function to use for fold change or average difference calculation #' @param base The base with respect to which logarithms are computed. #' @param fc.name Name of the fold change, average difference, or custom function column @@ -1163,7 +1169,7 @@ FoldChange.Seurat <- function( slot = 'data', reduction = NULL, features = NULL, - pseudocount.use = 1/10000, + pseudocount.use = NULL, mean.fxn = NULL, base = 2, fc.name = NULL, diff --git a/man/FindAllMarkers.Rd b/man/FindAllMarkers.Rd index 95da7a4be..1c8c8897d 100644 --- a/man/FindAllMarkers.Rd +++ b/man/FindAllMarkers.Rd @@ -22,7 +22,7 @@ FindAllMarkers( latent.vars = NULL, min.cells.feature = 3, min.cells.group = 3, - pseudocount.use = 1, + pseudocount.use = NULL, mean.fxn = NULL, fc.name = NULL, base = 2, diff --git a/man/FindMarkers.Rd b/man/FindMarkers.Rd index 70805a8cc..b5a864484 100644 --- a/man/FindMarkers.Rd +++ b/man/FindMarkers.Rd @@ -131,7 +131,7 @@ FindMarkers(object, ...) latent.vars = NULL, min.cells.feature = 3, min.cells.group = 3, - pseudocount.use = 1, + pseudocount.use = NULL, mean.fxn = NULL, fc.name = NULL, base = 2, diff --git a/man/FoldChange.Rd b/man/FoldChange.Rd index f4361bd26..0f2538f0f 100644 --- a/man/FoldChange.Rd +++ b/man/FoldChange.Rd @@ -31,7 +31,7 @@ FoldChange(object, ...) cells.2, features = NULL, slot = NULL, - pseudocount.use = NULL, + pseudocount.use = 1, fc.name = NULL, mean.fxn = NULL, ... @@ -47,7 +47,7 @@ FoldChange(object, ...) slot = "data", reduction = NULL, features = NULL, - pseudocount.use = 1, + pseudocount.use = NULL, mean.fxn = NULL, base = 2, fc.name = NULL, @@ -74,7 +74,7 @@ If NULL, use all features} \item{slot}{Slot to pull data from} \item{pseudocount.use}{Pseudocount to add to averaged expression values when -calculating logFC. 1 by default.} +calculating logFC.} \item{base}{The base with respect to which logarithms are computed.} From 71193c0fecab562f8495f6c0eb2873e5f75dccce Mon Sep 17 00:00:00 2001 From: Paul Hoffman Date: Fri, 2 Sep 2022 13:06:34 -0400 Subject: [PATCH 32/40] Tweaks for pseudocount.use and normalization methods for FindMarkers and FoldChange --- R/differential_expression.R | 45 +++++++++++++++++++++++-------------- man/FindMarkers.Rd | 5 ++++- man/FoldChange.Rd | 4 ++++ 3 files changed, 36 insertions(+), 18 deletions(-) diff --git a/R/differential_expression.R b/R/differential_expression.R index a84940545..67e3a9856 100644 --- a/R/differential_expression.R +++ b/R/differential_expression.R @@ -604,6 +604,9 @@ FindMarkers.default <- function( return(de.results) } +#' @param norm.method Normalization method for fold change calculation when +#' \code{slot} is \dQuote{\code{data}} +#' #' @rdname FindMarkers #' @concept differential_expression #' @export @@ -631,6 +634,7 @@ FindMarkers.Assay <- function( fc.name = NULL, base = 2, densify = FALSE, + norm.method = NULL, ... ) { pseudocount.use <- pseudocount.use %||% 1 @@ -654,7 +658,8 @@ FindMarkers.Assay <- function( pseudocount.use = pseudocount.use, mean.fxn = mean.fxn, fc.name = fc.name, - base = base + base = base, + norm.method = norm.method ) de.results <- FindMarkers( object = data.use, @@ -931,7 +936,7 @@ FindMarkers.Seurat <- function( latent.vars = NULL, min.cells.feature = 3, min.cells.group = 3, - pseudocount.use = NULL, + # pseudocount.use = NULL, mean.fxn = NULL, fc.name = NULL, base = 2, @@ -975,17 +980,14 @@ FindMarkers.Seurat <- function( } # check normalization method norm.command <- paste0("NormalizeData.", assay) - if (norm.command %in% Command(object = object) && is.null(x = reduction)) { - norm.method <- Command( + norm.method <- if (norm.command %in% Command(object = object) && is.null(x = reduction)) { + Command( object = object, command = norm.command, value = "normalization.method" ) - if (norm.method != "LogNormalize") { - mean.fxn <- function(x) { - return(log(x = rowMeans(x = x) + pseudocount.use, base = base)) - } - } + } else { + NULL } de.results <- FindMarkers( object = data.use, @@ -1004,11 +1006,12 @@ FindMarkers.Seurat <- function( latent.vars = latent.vars, min.cells.feature = min.cells.feature, min.cells.group = min.cells.group, - pseudocount.use = pseudocount.use, + # pseudocount.use = pseudocount.use, mean.fxn = mean.fxn, base = base, fc.name = fc.name, densify = densify, + norm.method = norm.method, ... ) return(de.results) @@ -1054,7 +1057,9 @@ FoldChange.default <- function( return(fc.results) } - +#' @param norm.method Normalization method for mean function selection +#' when \code{slot} is \dQuote{\code{data}} +#' #' @importFrom Matrix rowMeans #' @rdname FoldChange #' @concept differential_expression @@ -1070,19 +1075,25 @@ FoldChange.Assay <- function( fc.name = NULL, mean.fxn = NULL, base = 2, + norm.method = NULL, ... ) { pseudocount.use <- pseudocount.use %||% 1 data <- GetAssayData(object = object, slot = slot) + default.mean.fxn <- function(x) { + return(log(x = rowMeans(x = x) + pseudocount.use, base = base)) + } mean.fxn <- mean.fxn %||% switch( EXPR = slot, - 'data' = function(x) { - return(log(x = rowMeans(x = expm1(x = x)) + pseudocount.use, base = base)) - }, + 'data' = switch( + EXPR = norm.method %||% '', + 'LogNormalize' = function(x) { + return(log(x = rowMeans(x = expm1(x = x)) + pseudocount.use, base = base)) + }, + default.mean.fxn + ), 'scale.data' = rowMeans, - function(x) { - return(log(x = rowMeans(x = x) + pseudocount.use, base = base)) - } + default.mean.fxn ) # Omit the decimal value of e from the column name if base == exp(1) base.text <- ifelse( diff --git a/man/FindMarkers.Rd b/man/FindMarkers.Rd index b5a864484..160c69c0d 100644 --- a/man/FindMarkers.Rd +++ b/man/FindMarkers.Rd @@ -58,6 +58,7 @@ FindMarkers(object, ...) fc.name = NULL, base = 2, densify = FALSE, + norm.method = NULL, ... ) @@ -131,7 +132,6 @@ FindMarkers(object, ...) latent.vars = NULL, min.cells.feature = 3, min.cells.group = 3, - pseudocount.use = NULL, mean.fxn = NULL, fc.name = NULL, base = 2, @@ -243,6 +243,9 @@ slot "avg_diff".} \item{base}{The base with respect to which logarithms are computed.} +\item{norm.method}{Normalization method for fold change calculation when +\code{slot} is \dQuote{\code{data}}} + \item{recorrect_umi}{Recalculate corrected UMI counts using minimum of the median UMIs when performing DE using multiple SCT objects; default is TRUE} \item{ident.1}{Identity class to define markers for; pass an object of class diff --git a/man/FoldChange.Rd b/man/FoldChange.Rd index 0f2538f0f..edda396b5 100644 --- a/man/FoldChange.Rd +++ b/man/FoldChange.Rd @@ -22,6 +22,7 @@ FoldChange(object, ...) fc.name = NULL, mean.fxn = NULL, base = 2, + norm.method = NULL, ... ) @@ -78,6 +79,9 @@ calculating logFC.} \item{base}{The base with respect to which logarithms are computed.} +\item{norm.method}{Normalization method for mean function selection +when \code{slot} is \dQuote{\code{data}}} + \item{ident.1}{Identity class to calculate fold change for; pass an object of class \code{phylo} or 'clustertree' to calculate fold change for a node in a cluster tree; passing 'clustertree' requires \code{\link{BuildClusterTree}} to have been run} From 1bf7bba2af57c260369e28db6d3514d6b93afc16 Mon Sep 17 00:00:00 2001 From: timoast <4591688+timoast@users.noreply.github.com> Date: Fri, 2 Sep 2022 14:11:18 -0400 Subject: [PATCH 33/40] Remove pseudocount.use from Seurat method: --- R/differential_expression.R | 4 ---- 1 file changed, 4 deletions(-) diff --git a/R/differential_expression.R b/R/differential_expression.R index 67e3a9856..36aec77c6 100644 --- a/R/differential_expression.R +++ b/R/differential_expression.R @@ -59,7 +59,6 @@ FindAllMarkers <- function( latent.vars = NULL, min.cells.feature = 3, min.cells.group = 3, - pseudocount.use = NULL, mean.fxn = NULL, fc.name = NULL, base = 2, @@ -136,7 +135,6 @@ FindAllMarkers <- function( latent.vars = latent.vars, min.cells.feature = min.cells.feature, min.cells.group = min.cells.group, - pseudocount.use = pseudocount.use, mean.fxn = mean.fxn, fc.name = fc.name, base = base, @@ -936,7 +934,6 @@ FindMarkers.Seurat <- function( latent.vars = NULL, min.cells.feature = 3, min.cells.group = 3, - # pseudocount.use = NULL, mean.fxn = NULL, fc.name = NULL, base = 2, @@ -1006,7 +1003,6 @@ FindMarkers.Seurat <- function( latent.vars = latent.vars, min.cells.feature = min.cells.feature, min.cells.group = min.cells.group, - # pseudocount.use = pseudocount.use, mean.fxn = mean.fxn, base = base, fc.name = fc.name, From 015844d01d7c51bdd91d570f201ac421f384040b Mon Sep 17 00:00:00 2001 From: timoast <4591688+timoast@users.noreply.github.com> Date: Fri, 2 Sep 2022 14:11:35 -0400 Subject: [PATCH 34/40] Add more tests for FindMarkers --- tests/testthat/test_differential_expression.R | 92 ++++++++++++++++++- 1 file changed, 91 insertions(+), 1 deletion(-) diff --git a/tests/testthat/test_differential_expression.R b/tests/testthat/test_differential_expression.R index 81e231f76..bf2e92448 100644 --- a/tests/testthat/test_differential_expression.R +++ b/tests/testthat/test_differential_expression.R @@ -2,12 +2,17 @@ suppressWarnings(RNGversion(vstr = "3.5.3")) set.seed(seed = 42) -# Tests for FindMarkers default parameters +# Tests for FindMarkers # -------------------------------------------------------------------------------- context("FindMarkers") +clr.obj <- suppressWarnings(NormalizeData(pbmc_small, normalization.method = "CLR")) +sct.obj <- suppressWarnings(suppressMessages(SCTransform(pbmc_small))) + markers.0 <- suppressWarnings(FindMarkers(object = pbmc_small, ident.1 = 0, verbose = FALSE, base = exp(1))) markers.01 <- suppressWarnings(FindMarkers(object = pbmc_small, ident.1 = 0, ident.2 = 1, verbose = FALSE, base = exp(1))) +results.clr <- suppressWarnings(FindMarkers(object = clr.obj, ident.1 = 0, ident.2 = 1, verbose = FALSE, base = exp(1))) +results.sct <- suppressWarnings(FindMarkers(object = sct.obj, ident.1 = 0, ident.2 = 1, verbose = FALSE, base = exp(1))) test_that("Default settings work as expected", { expect_error(FindMarkers(object = pbmc_small)) @@ -29,6 +34,24 @@ test_that("Default settings work as expected", { expect_equal(markers.01[1, "p_val_adj"], 3.916481e-09) expect_equal(nrow(x = markers.01), 201) expect_equal(rownames(x = markers.01)[1], "TYMP") + + # CLR normalization + expect_equal(results.clr[1, "p_val"], 1.209462e-11) + expect_equal(results.clr[1, "avg_logFC"], -0.8290693, tolerance = 1e-6) + expect_equal(results.clr[1, "pct.1"], 0.111) + expect_equal(results.clr[1, "pct.2"], 0.96) + expect_equal(results.clr[1, "p_val_adj"], 2.781762e-09) + expect_equal(nrow(x = results.clr), 85) + expect_equal(rownames(x = results.clr)[1], "S100A8") + + # SCT normalization + expect_equal(results.sct[1, "p_val"], 6.225491e-11) + expect_equal(results.sct[1, "avg_logFC"], -0.6768721, tolerance = 1e-6) + expect_equal(results.sct[1, "pct.1"], 0.111) + expect_equal(results.sct[1, "pct.2"], 0.96) + expect_equal(results.sct[1, "p_val_adj"], 1.369608e-08) + expect_equal(nrow(x = results.sct), 92) + expect_equal(rownames(x = results.sct)[1], "TYMP") }) @@ -65,6 +88,28 @@ test_that("passing cell names works", { expect_equal(rownames(x = results)[1], "IFI30") }) +results <- suppressWarnings(FindMarkers(object = pbmc_small, ident.1 = 0, ident.2 = 1, verbose = FALSE, base = exp(1), pseudocount.use = 0.1)) +results.clr <- suppressWarnings(FindMarkers(object = clr.obj, ident.1 = 0, ident.2 = 1, verbose = FALSE, base = exp(1), pseudocount.use = 0.1)) +results.sct <- suppressWarnings(FindMarkers(object = sct.obj, ident.1 = 0, ident.2 = 1, verbose = FALSE, base = exp(1), pseudocount.use = 0.1)) +test_that("setting pseudocount.use works", { + expect_equal(nrow(x = results), 202) + expect_equal(results[1, "avg_logFC"], -2.630395, tolerance = 1e-6) + expect_equal(nrow(x = results.clr), 182) + expect_equal(results.clr[1, "avg_logFC"], -2.317338, tolerance = 1e-6) + expect_equal(nrow(results.sct), 185) + expect_equal(results.sct[1, "avg_logFC"], -1.845681, tolerance = 1e-6) +}) + +results <- suppressWarnings(FindMarkers(object = pbmc_small, ident.1 = 0, ident.2 = 1, verbose = FALSE, base = exp(1), mean.fxn = rowMeans)) +results.clr <- suppressWarnings(FindMarkers(object = clr.obj, ident.1 = 0, ident.2 = 1, verbose = FALSE, base = exp(1), mean.fxn = rowMeans)) +results.sct <- suppressWarnings(FindMarkers(object = sct.obj, ident.1 = 0, ident.2 = 1, verbose = FALSE, base = exp(1), mean.fxn = rowMeans)) +test_that("setting mean.fxn works", { + expect_equal(nrow(x = results), 191) + expect_equal(results[1, "avg_logFC"], -4.204346, tolerance = 1e-6) + expect_equal(results.clr[1, "avg_logFC"], -1.353025, tolerance = 1e-6) + expect_equal(results.sct[1, "avg_logFC"], -1.064042, tolerance = 1e-6) +}) + results <- suppressWarnings(FindMarkers(object = pbmc_small, ident.1 = 0, ident.2 = 1, logfc.threshold = 2, verbose = FALSE, base = exp(1))) test_that("logfc.threshold works", { expect_equal(nrow(x = results), 112) @@ -236,6 +281,51 @@ test_that("LR test works", { expect_equal(rownames(x = results)[1], "LYZ") }) +# Tests for FindAllMarkers +# ------------------------------------------------------------------------------- +results <- suppressMessages(suppressWarnings(FindAllMarkers(object = pbmc_small))) +results.clr <- suppressMessages(suppressWarnings(FindAllMarkers(object = clr.obj))) +results.sct <- suppressMessages(suppressWarnings(FindAllMarkers(object = sct.obj))) +results.pseudo <- suppressMessages(suppressWarnings(FindAllMarkers(object = pbmc_small, pseudocount.use = 0.1))) + +test_that("FindAllMarkers works as expected", { + expect_equal(colnames(x = results), c("p_val", "avg_log2FC", "pct.1", "pct.2", "p_val_adj", "cluster", "gene")) + expect_equal(results[1, "p_val"], 9.572778e-13) + expect_equal(results[1, "avg_log2FC"], -5.820829, tolerance = 1e-6) + expect_equal(results[1, "pct.1"], 0.083) + expect_equal(results[1, "pct.2"], 0.909) + expect_equal(results[1, "p_val_adj"], 2.201739e-10) + expect_equal(nrow(x = results), 222) + expect_equal(rownames(results)[1], "HLA-DPB1") + + # CLR normalization + expect_equal(results.clr[1, "p_val"], 1.209462e-11) + expect_equal(results.clr[1, "avg_log2FC"], -1.079924, tolerance = 1e-6) + expect_equal(results.clr[1, "pct.1"], 0.083) + expect_equal(results.clr[1, "pct.2"], 0.909) + expect_equal(results.clr[1, "p_val_adj"], 3.079373e-10) + expect_equal(nrow(x = results.clr), 200) + expect_equal(rownames(x = results.clr)[1], "HLA-DPB1") + + # SCT normalization + expect_equal(results.sct[1, "p_val"], 6.225491e-11) + expect_equal(results.sct[1, "avg_log2FC"], -1.265307, tolerance = 1e-6) + expect_equal(results.sct[1, "pct.1"], 0.167) + expect_equal(results.sct[1, "pct.2"], 0.909) + expect_equal(results.sct[1, "p_val_adj"], 1.369608e-08) + expect_equal(nrow(x = results.sct), 201) + expect_equal(rownames(x = results.sct)[1], "HLA-DPB1") + + # pseudocount.use = 0.1 + expect_equal(results.pseudo[1, "p_val"], 9.572778e-13) + expect_equal(results.pseudo[1, "avg_log2FC"], -6.013818, tolerance = 1e-6) + expect_equal(results.pseudo[1, "pct.1"], 0.083) + expect_equal(results.pseudo[1, "pct.2"], 0.909) + expect_equal(results.pseudo[1, "p_val_adj"], 2.201739e-10) + expect_equal(nrow(x = results.pseudo), 222) + expect_equal(rownames(results.pseudo)[1], "HLA-DPB1") +}) + # Tests for FindConservedMarkers # ------------------------------------------------------------------------------- From 731ec7c1ef010441144473e13e1729523a2e7ae2 Mon Sep 17 00:00:00 2001 From: timoast <4591688+timoast@users.noreply.github.com> Date: Fri, 2 Sep 2022 14:25:07 -0400 Subject: [PATCH 35/40] Update docs --- DESCRIPTION | 2 +- man/FeaturePlot.Rd | 8 ++++++-- man/FindAllMarkers.Rd | 4 ---- man/IntegrateData.Rd | 6 ++++-- man/IntegrateEmbeddings.Rd | 6 ++++-- man/PolyFeaturePlot.Rd | 5 +---- man/Seurat-package.Rd | 2 +- man/reexports.Rd | 2 +- 8 files changed, 18 insertions(+), 17 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 999c4610b..e85853fd4 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -95,7 +95,7 @@ Collate: 'tree.R' 'utilities.R' 'zzz.R' -RoxygenNote: 7.1.2 +RoxygenNote: 7.2.1 Encoding: UTF-8 Suggests: ape, diff --git a/man/FeaturePlot.Rd b/man/FeaturePlot.Rd index 239c0a8c2..b06367ba3 100644 --- a/man/FeaturePlot.Rd +++ b/man/FeaturePlot.Rd @@ -10,8 +10,12 @@ FeaturePlot( features, dims = c(1, 2), cells = NULL, - cols = if (blend) { c("lightgrey", "#ff0000", "#00ff00") } else { - c("lightgrey", "blue") }, + cols = if (blend) { + c("lightgrey", "#ff0000", "#00ff00") + } else { + + c("lightgrey", "blue") + }, pt.size = NULL, order = FALSE, min.cutoff = NA, diff --git a/man/FindAllMarkers.Rd b/man/FindAllMarkers.Rd index 1c8c8897d..622474624 100644 --- a/man/FindAllMarkers.Rd +++ b/man/FindAllMarkers.Rd @@ -22,7 +22,6 @@ FindAllMarkers( latent.vars = NULL, min.cells.feature = 3, min.cells.group = 3, - pseudocount.use = NULL, mean.fxn = NULL, fc.name = NULL, base = 2, @@ -113,9 +112,6 @@ of the two groups, currently only used for poisson and negative binomial tests} \item{min.cells.group}{Minimum number of cells in one of the groups} -\item{pseudocount.use}{Pseudocount to add to averaged expression values when -calculating logFC. 1 by default.} - \item{mean.fxn}{Function to use for fold change or average difference calculation. If NULL, the appropriate function will be chose according to the slot used} diff --git a/man/IntegrateData.Rd b/man/IntegrateData.Rd index c02543005..e08bd682e 100644 --- a/man/IntegrateData.Rd +++ b/man/IntegrateData.Rd @@ -64,10 +64,12 @@ should be encoded in a matrix, where each row represents one of the pairwise integration steps. Negative numbers specify a dataset, positive numbers specify the integration results from a given row (the format of the merge matrix included in the \code{\link{hclust}} function output). For example: -\code{matrix(c(-2, 1, -3, -1), ncol = 2)} gives:\preformatted{ [,1] [,2] +\code{matrix(c(-2, 1, -3, -1), ncol = 2)} gives: + +\if{html}{\out{
}}\preformatted{ [,1] [,2] [1,] -2 -3 [2,] 1 -1 -} +}\if{html}{\out{
}} Which would cause dataset 2 and 3 to be integrated first, then the resulting object integrated with dataset 1. diff --git a/man/IntegrateEmbeddings.Rd b/man/IntegrateEmbeddings.Rd index c3f96ffa5..dc0469132 100644 --- a/man/IntegrateEmbeddings.Rd +++ b/man/IntegrateEmbeddings.Rd @@ -75,10 +75,12 @@ should be encoded in a matrix, where each row represents one of the pairwise integration steps. Negative numbers specify a dataset, positive numbers specify the integration results from a given row (the format of the merge matrix included in the \code{\link{hclust}} function output). For example: -\code{matrix(c(-2, 1, -3, -1), ncol = 2)} gives:\preformatted{ [,1] [,2] +\code{matrix(c(-2, 1, -3, -1), ncol = 2)} gives: + +\if{html}{\out{
}}\preformatted{ [,1] [,2] [1,] -2 -3 [2,] 1 -1 -} +}\if{html}{\out{
}} Which would cause dataset 2 and 3 to be integrated first, then the resulting object integrated with dataset 1. diff --git a/man/PolyFeaturePlot.Rd b/man/PolyFeaturePlot.Rd index 1eacd0ecd..a2b2fc588 100644 --- a/man/PolyFeaturePlot.Rd +++ b/man/PolyFeaturePlot.Rd @@ -33,10 +33,7 @@ PolyFeaturePlot( \item{ncol}{Number of columns to split the plot into} -\item{min.cutoff}{Vector of minimum and maximum cutoff values for each feature, -may specify quantile in the form of 'q##' where '##' is the quantile (eg, 'q1', 'q10')} - -\item{max.cutoff}{Vector of minimum and maximum cutoff values for each feature, +\item{min.cutoff, max.cutoff}{Vector of minimum and maximum cutoff values for each feature, may specify quantile in the form of 'q##' where '##' is the quantile (eg, 'q1', 'q10')} \item{common.scale}{...} diff --git a/man/Seurat-package.Rd b/man/Seurat-package.Rd index 9b3fc3749..351af75c9 100644 --- a/man/Seurat-package.Rd +++ b/man/Seurat-package.Rd @@ -6,7 +6,7 @@ \alias{Seurat-package} \title{Seurat: Tools for Single Cell Genomics} \description{ -A toolkit for quality control, analysis, and exploration of single cell RNA sequencing data. 'Seurat' aims to enable users to identify and interpret sources of heterogeneity from single cell transcriptomic measurements, and to integrate diverse types of single cell data. See Satija R, Farrell J, Gennert D, et al (2015) , Macosko E, Basu A, Satija R, et al (2015) , Stuart T, Butler A, et al (2019) , and Hao, Hao, et al (2020) for more details. +A toolkit for quality control, analysis, and exploration of single cell RNA sequencing data. 'Seurat' aims to enable users to identify and interpret sources of heterogeneity from single cell transcriptomic measurements, and to integrate diverse types of single cell data. See Satija R, Farrell J, Gennert D, et al (2015) \doi{10.1038/nbt.3192}, Macosko E, Basu A, Satija R, et al (2015) \doi{10.1016/j.cell.2015.05.002}, Stuart T, Butler A, et al (2019) \doi{10.1016/j.cell.2019.05.031}, and Hao, Hao, et al (2020) \doi{10.1101/2020.10.12.335331} for more details. } \section{Package options}{ diff --git a/man/reexports.Rd b/man/reexports.Rd index 2c9dbf1e5..4e5b1716e 100644 --- a/man/reexports.Rd +++ b/man/reexports.Rd @@ -68,6 +68,6 @@ These objects are imported from other packages. Follow the links below to see their documentation. \describe{ - \item{SeuratObject}{\code{\link[SeuratObject]{AddMetaData}}, \code{\link[SeuratObject:ObjectAccess]{Assays}}, \code{\link[SeuratObject]{Cells}}, \code{\link[SeuratObject]{CellsByIdentities}}, \code{\link[SeuratObject]{Command}}, \code{\link[SeuratObject]{CreateAssayObject}}, \code{\link[SeuratObject]{CreateDimReducObject}}, \code{\link[SeuratObject]{CreateSeuratObject}}, \code{\link[SeuratObject]{DefaultAssay}}, \code{\link[SeuratObject:DefaultAssay]{DefaultAssay<-}}, \code{\link[SeuratObject]{Distances}}, \code{\link[SeuratObject]{Embeddings}}, \code{\link[SeuratObject]{FetchData}}, \code{\link[SeuratObject:AssayData]{GetAssayData}}, \code{\link[SeuratObject]{GetImage}}, \code{\link[SeuratObject]{GetTissueCoordinates}}, \code{\link[SeuratObject:VariableFeatures]{HVFInfo}}, \code{\link[SeuratObject]{Idents}}, \code{\link[SeuratObject:Idents]{Idents<-}}, \code{\link[SeuratObject]{Images}}, \code{\link[SeuratObject]{Index}}, \code{\link[SeuratObject:Index]{Index<-}}, \code{\link[SeuratObject]{Indices}}, \code{\link[SeuratObject]{IsGlobal}}, \code{\link[SeuratObject]{JS}}, \code{\link[SeuratObject:JS]{JS<-}}, \code{\link[SeuratObject]{Key}}, \code{\link[SeuratObject:Key]{Key<-}}, \code{\link[SeuratObject]{Loadings}}, \code{\link[SeuratObject:Loadings]{Loadings<-}}, \code{\link[SeuratObject]{LogSeuratCommand}}, \code{\link[SeuratObject]{Misc}}, \code{\link[SeuratObject:Misc]{Misc<-}}, \code{\link[SeuratObject:ObjectAccess]{Neighbors}}, \code{\link[SeuratObject]{Project}}, \code{\link[SeuratObject:Project]{Project<-}}, \code{\link[SeuratObject]{Radius}}, \code{\link[SeuratObject:ObjectAccess]{Reductions}}, \code{\link[SeuratObject]{RenameCells}}, \code{\link[SeuratObject:Idents]{RenameIdents}}, \code{\link[SeuratObject:Idents]{ReorderIdent}}, \code{\link[SeuratObject]{RowMergeSparseMatrices}}, \code{\link[SeuratObject:VariableFeatures]{SVFInfo}}, \code{\link[SeuratObject:AssayData]{SetAssayData}}, \code{\link[SeuratObject:Idents]{SetIdent}}, \code{\link[SeuratObject:VariableFeatures]{SpatiallyVariableFeatures}}, \code{\link[SeuratObject:Idents]{StashIdent}}, \code{\link[SeuratObject]{Stdev}}, \code{\link[SeuratObject]{Tool}}, \code{\link[SeuratObject:Tool]{Tool<-}}, \code{\link[SeuratObject]{UpdateSeuratObject}}, \code{\link[SeuratObject]{VariableFeatures}}, \code{\link[SeuratObject:VariableFeatures]{VariableFeatures<-}}, \code{\link[SeuratObject]{WhichCells}}, \code{\link[SeuratObject]{as.Graph}}, \code{\link[SeuratObject]{as.Neighbor}}, \code{\link[SeuratObject]{as.Seurat}}, \code{\link[SeuratObject]{as.sparse}}} + \item{SeuratObject}{\code{\link[SeuratObject]{AddMetaData}}, \code{\link[SeuratObject]{as.Graph}}, \code{\link[SeuratObject]{as.Neighbor}}, \code{\link[SeuratObject]{as.Seurat}}, \code{\link[SeuratObject]{as.sparse}}, \code{\link[SeuratObject:ObjectAccess]{Assays}}, \code{\link[SeuratObject]{Cells}}, \code{\link[SeuratObject]{CellsByIdentities}}, \code{\link[SeuratObject]{Command}}, \code{\link[SeuratObject]{CreateAssayObject}}, \code{\link[SeuratObject]{CreateDimReducObject}}, \code{\link[SeuratObject]{CreateSeuratObject}}, \code{\link[SeuratObject]{DefaultAssay}}, \code{\link[SeuratObject:DefaultAssay]{DefaultAssay<-}}, \code{\link[SeuratObject]{Distances}}, \code{\link[SeuratObject]{Embeddings}}, \code{\link[SeuratObject]{FetchData}}, \code{\link[SeuratObject:AssayData]{GetAssayData}}, \code{\link[SeuratObject]{GetImage}}, \code{\link[SeuratObject]{GetTissueCoordinates}}, \code{\link[SeuratObject:VariableFeatures]{HVFInfo}}, \code{\link[SeuratObject]{Idents}}, \code{\link[SeuratObject:Idents]{Idents<-}}, \code{\link[SeuratObject]{Images}}, \code{\link[SeuratObject]{Index}}, \code{\link[SeuratObject:Index]{Index<-}}, \code{\link[SeuratObject]{Indices}}, \code{\link[SeuratObject]{IsGlobal}}, \code{\link[SeuratObject]{JS}}, \code{\link[SeuratObject:JS]{JS<-}}, \code{\link[SeuratObject]{Key}}, \code{\link[SeuratObject:Key]{Key<-}}, \code{\link[SeuratObject]{Loadings}}, \code{\link[SeuratObject:Loadings]{Loadings<-}}, \code{\link[SeuratObject]{LogSeuratCommand}}, \code{\link[SeuratObject]{Misc}}, \code{\link[SeuratObject:Misc]{Misc<-}}, \code{\link[SeuratObject:ObjectAccess]{Neighbors}}, \code{\link[SeuratObject]{Project}}, \code{\link[SeuratObject:Project]{Project<-}}, \code{\link[SeuratObject]{Radius}}, \code{\link[SeuratObject:ObjectAccess]{Reductions}}, \code{\link[SeuratObject]{RenameCells}}, \code{\link[SeuratObject:Idents]{RenameIdents}}, \code{\link[SeuratObject:Idents]{ReorderIdent}}, \code{\link[SeuratObject]{RowMergeSparseMatrices}}, \code{\link[SeuratObject:AssayData]{SetAssayData}}, \code{\link[SeuratObject:Idents]{SetIdent}}, \code{\link[SeuratObject:VariableFeatures]{SpatiallyVariableFeatures}}, \code{\link[SeuratObject:Idents]{StashIdent}}, \code{\link[SeuratObject]{Stdev}}, \code{\link[SeuratObject:VariableFeatures]{SVFInfo}}, \code{\link[SeuratObject]{Tool}}, \code{\link[SeuratObject:Tool]{Tool<-}}, \code{\link[SeuratObject]{UpdateSeuratObject}}, \code{\link[SeuratObject]{VariableFeatures}}, \code{\link[SeuratObject:VariableFeatures]{VariableFeatures<-}}, \code{\link[SeuratObject]{WhichCells}}} }} From c4a5fd3bd3a7afaab8e603a116fe31c0c015cda2 Mon Sep 17 00:00:00 2001 From: timoast <4591688+timoast@users.noreply.github.com> Date: Tue, 20 Sep 2022 15:46:18 -0400 Subject: [PATCH 36/40] Ensure cells are character vector --- R/integration.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/integration.R b/R/integration.R index 5da042ecf..8cc53cc27 100644 --- a/R/integration.R +++ b/R/integration.R @@ -5384,7 +5384,7 @@ ValidateParams_IntegrateEmbeddings_TransferAnchors <- function( } reference.cells <- slot(object = anchorset, name = "reference.cells") reference.cells <- gsub(pattern = "_reference", replacement = "", x = reference.cells) - if (!isTRUE(x = all.equal(target = reference.cells, current = Cells(x = reference)))) { + if (!isTRUE(x = all.equal(target = reference.cells, current = as.character(x = Cells(x = reference))))) { stop("The set of cells used as a reference in the AnchorSet does not match ", "the set of cells provided in the reference object.") } From 144421c6efed083d551d0f704757d391f7354a4d Mon Sep 17 00:00:00 2001 From: timoast <4591688+timoast@users.noreply.github.com> Date: Tue, 20 Sep 2022 15:48:30 -0400 Subject: [PATCH 37/40] Increase dev version; --- DESCRIPTION | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 999c4610b..492ef4073 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: Seurat -Version: 4.1.1.9005 -Date: 2022-08-29 +Version: 4.1.1.9006 +Date: 2022-09-20 Title: Tools for Single Cell Genomics Description: A toolkit for quality control, analysis, and exploration of single cell RNA sequencing data. 'Seurat' aims to enable users to identify and interpret sources of heterogeneity from single cell transcriptomic measurements, and to integrate diverse types of single cell data. See Satija R, Farrell J, Gennert D, et al (2015) , Macosko E, Basu A, Satija R, et al (2015) , Stuart T, Butler A, et al (2019) , and Hao, Hao, et al (2020) for more details. Authors@R: c( From ef07a34b6e4e682a0526560b51bf60004cba8cc7 Mon Sep 17 00:00:00 2001 From: timoast <4591688+timoast@users.noreply.github.com> Date: Tue, 20 Sep 2022 16:00:19 -0400 Subject: [PATCH 38/40] Add back check.matrix --- R/clustering.R | 4 +-- R/integration.R | 72 ++++++++++++----------------------------------- R/mixscape.R | 25 ++++------------ R/preprocessing.R | 8 ++---- R/utilities.R | 36 +++++------------------- 5 files changed, 33 insertions(+), 112 deletions(-) diff --git a/R/clustering.R b/R/clustering.R index 3e1d30bce..786a18fef 100644 --- a/R/clustering.R +++ b/R/clustering.R @@ -259,9 +259,7 @@ PredictAssay <- function( ) colnames(x = predicted) <- Cells(x = object) if (return.assay) { - # TODO: restore once check.matrix is implemented in SeuratObject - # predicted.assay <- CreateAssayObject(data = predicted, check.matrix = FALSE) - predicted.assay <- CreateAssayObject(data = predicted) + predicted.assay <- CreateAssayObject(data = predicted, check.matrix = FALSE) return (predicted.assay) } else { return (predicted) diff --git a/R/integration.R b/R/integration.R index 8cc53cc27..6fceae087 100644 --- a/R/integration.R +++ b/R/integration.R @@ -1461,19 +1461,12 @@ IntegrateData <- function( } else { active.assay <- DefaultAssay(object = ref[[1]]) reference.integrated[[active.assay]] <- NULL - # TODO: restore once check.matrix is in SeuratObject - # reference.integrated[[active.assay]] <- CreateAssayObject( - # data = GetAssayData( - # object = reference.integrated[[new.assay.name]], - # slot = 'data' - # ), - # check.matrix = FALSE - # ) reference.integrated[[active.assay]] <- CreateAssayObject( data = GetAssayData( object = reference.integrated[[new.assay.name]], slot = 'data' - ) + ), + check.matrix = FALSE ) DefaultAssay(object = reference.integrated) <- active.assay reference.integrated[[new.assay.name]] <- NULL @@ -1496,13 +1489,9 @@ IntegrateData <- function( ) # Construct final assay object - # TODO: restore once check.matrix is in SeuratObject - # integrated.assay <- CreateAssayObject( - # data = integrated.data, - # check.matrix = FALSE - # ) integrated.assay <- CreateAssayObject( - data = integrated.data + data = integrated.data, + check.matrix = FALSE ) if (normalization.method == "SCT") { integrated.assay <- CreateSCTAssayObject( @@ -1594,13 +1583,9 @@ IntegrateEmbeddings.IntegrationAnchorSet <- function( embeddings <- t(x = Embeddings(object = reductions)[cell.names.map[Cells(x = object.list[[i]])], dims.to.integrate]) rownames(x = embeddings) <- dims.names fake.assay <- suppressWarnings( - # TODO: restore once check.matrix is in SeuratObject - # expr = CreateAssayObject( - # data = embeddings, - # check.matrix = FALSE - # ) expr = CreateAssayObject( - data = embeddings + data = embeddings, + check.matrix = FALSE ) ) object.list[[i]][['drtointegrate']] <- fake.assay @@ -1636,18 +1621,11 @@ IntegrateEmbeddings.IntegrationAnchorSet <- function( } active.assay <- DefaultAssay(object = object.list[reference.datasets][[1]]) reference.integrated[[active.assay]] <- NULL - # TODO: restore once check.matrix is in SeuratObject - # reference.integrated[[active.assay]] <- CreateAssayObject( - # data = GetAssayData( - # object = reference.integrated[[new.reduction.name.safe]], - # slot = 'data', - # check.matrix = FALSE - # ) - # ) reference.integrated[[active.assay]] <- CreateAssayObject( data = GetAssayData( object = reference.integrated[[new.reduction.name.safe]], - slot = 'data' + slot = 'data', + check.matrix = FALSE ) ) DefaultAssay(object = reference.integrated) <- active.assay @@ -1734,13 +1712,9 @@ IntegrateEmbeddings.TransferAnchorSet <- function( )[ , dims.to.integrate]) rownames(x = embeddings) <- dims.names fake.assay <- suppressWarnings( - # TODO restore once check.matrix is in SeuratObject - # expr = CreateAssayObject( - # data = embeddings, - # check.matrix = FALSE - # ) expr = CreateAssayObject( - data = embeddings + data = embeddings, + check.matrix = FALSE ) ) object.list[[i]][['drtointegrate']] <- fake.assay @@ -3014,9 +2988,9 @@ TransferData <- function( stringsAsFactors = FALSE ) if (prediction.assay || !is.null(x = query)) { - # TODO: restore once check.matrix is in SeuratObject - # predictions <- CreateAssayObject(data = t(x = as.matrix(x = prediction.scores)), check.matrix = FALSE) - predictions <- CreateAssayObject(data = t(x = as.matrix(x = prediction.scores))) + predictions <- CreateAssayObject( + data = t(x = as.matrix(x = prediction.scores)), check.matrix = FALSE + ) Key(object = predictions) <- paste0("predictionscore", rd.name, "_") } if (is.null(x = query)) { @@ -3040,13 +3014,9 @@ TransferData <- function( new.data <- as.sparse(x = new.data) } if (slot == "counts") { - # TODO: restore once check.matrix is in SeuratObject - # new.assay <- CreateAssayObject(counts = new.data, check.matrix = FALSE) - new.assay <- CreateAssayObject(counts = new.data) + new.assay <- CreateAssayObject(counts = new.data, check.matrix = FALSE) } else if (slot == "data") { - # TODO: restore once check.matrix is in SeuratObject - # new.assay <- CreateAssayObject(data = new.data, check.matrix = FALSE) - new.assay <- CreateAssayObject(data = new.data) + new.assay <- CreateAssayObject(data = new.data, check.matrix = FALSE) } Key(object = new.assay) <- paste0(rd.name, "_") if (is.null(x = query)) { @@ -4096,13 +4066,9 @@ PairwiseIntegrateReference <- function( features.to.integrate <- features.to.integrate %||% features if (length(x = reference.objects) == 1) { ref.obj <- object.list[[reference.objects]] - # TODO: restore once check.matrix is in SeuratObject - # ref.obj[[new.assay.name]] <- CreateAssayObject( - # data = GetAssayData(ref.obj, slot = 'data')[features.to.integrate, ], - # check.matrix = FALSE - # ) ref.obj[[new.assay.name]] <- CreateAssayObject( - data = GetAssayData(ref.obj, slot = 'data')[features.to.integrate, ] + data = GetAssayData(ref.obj, slot = 'data')[features.to.integrate, ], + check.matrix = FALSE ) DefaultAssay(object = ref.obj) <- new.assay.name return(ref.obj) @@ -4225,9 +4191,7 @@ PairwiseIntegrateReference <- function( verbose = verbose ) integrated.matrix <- cbind(integrated.matrix, GetAssayData(object = object.1, slot = 'data')[features.to.integrate, ]) - # TODO: restore once check.matrix is in SeuratObject - # merged.obj[[new.assay.name]] <- CreateAssayObject(data = integrated.matrix, check.matrix = FALSE) - merged.obj[[new.assay.name]] <- CreateAssayObject(data = integrated.matrix) + merged.obj[[new.assay.name]] <- CreateAssayObject(data = integrated.matrix, check.matrix = FALSE) DefaultAssay(object = merged.obj) <- new.assay.name object.list[[as.character(x = ii)]] <- merged.obj object.list[[merge.pair[[1]]]] <- NULL diff --git a/R/mixscape.R b/R/mixscape.R index 9a556acfb..a003ab7ba 100644 --- a/R/mixscape.R +++ b/R/mixscape.R @@ -106,17 +106,11 @@ CalcPerturbSig <- function( slot(object = object, name = "tools")[[paste("CalcPerturbSig", assay, reduction, sep = ".")]] <- all_neighbors all_diff <- do.call(what = cbind, args = all_diff) prtb.assay <- suppressWarnings( - # TODO: restore once check.matrix is in SeuratObject - # expr = CreateAssayObject( - # data = all_diff[, colnames(x = object)], - # min.cells = -Inf, - # min.features = -Inf, - # check.matrix = FALSE - # ) expr = CreateAssayObject( data = all_diff[, colnames(x = object)], min.cells = -Inf, - min.features = -Inf + min.features = -Inf, + check.matrix = FALSE ) ) object[[new.assay.name]] <- prtb.assay @@ -1028,7 +1022,7 @@ PlotPerturbScore <- function( gd <- setdiff(x = unique(x = prtb_score[, target.gene.class]), y = target.gene.ident) colnames(x = prtb_score)[2] <- "gene" prtb_score$cell.bc <- sapply(rownames(prtb_score), FUN = function(x) substring(x, regexpr("[.]", x) + 1)) - + if (isTRUE(x = before.mixscape)) { cols <- setNames( object = c("grey49", col), @@ -1217,23 +1211,14 @@ GetMissingPerturb <- function(object, assay, features, verbose = TRUE) { } all_diff <- do.call(what = cbind, args = all_diff) all_diff <- all_diff[, colnames(x = object[[assay]]), drop = FALSE] - # TODO: restore once check.matrix is in SeuratObject - # new.assay <- CreateAssayObject( - # data = rbind( - # GetAssayData(object = object[[assay]], slot = "data"), - # all_diff - # ), - # min.cells = 0, - # min.features = 0, - # check.matrix = FALSE - # ) new.assay <- CreateAssayObject( data = rbind( GetAssayData(object = object[[assay]], slot = "data"), all_diff ), min.cells = 0, - min.features = 0 + min.features = 0, + check.matrix = FALSE ) new.assay <- SetAssayData( object = new.assay, diff --git a/R/preprocessing.R b/R/preprocessing.R index 59f1fd0bc..f04423829 100644 --- a/R/preprocessing.R +++ b/R/preprocessing.R @@ -1790,14 +1790,10 @@ SCTransform <- function( if (verbose) { message('Place corrected count matrix in counts slot') } - # TODO: restore once check.matrix is in SeuratObject - # assay.out <- CreateAssayObject(counts = vst.out$umi_corrected, check.matrix = FALSE) - assay.out <- CreateAssayObject(counts = vst.out$umi_corrected,) + assay.out <- CreateAssayObject(counts = vst.out$umi_corrected, check.matrix = FALSE) vst.out$umi_corrected <- NULL } else { - # TODO: restore once check.matrix is in SeuratObject - # assay.out <- CreateAssayObject(counts = umi, check.matrix = FALSE) - assay.out <- CreateAssayObject(counts = umi) + assay.out <- CreateAssayObject(counts = umi, check.matrix = FALSE) } # set the variable genes VariableFeatures(object = assay.out) <- residual.features %||% top.features diff --git a/R/utilities.R b/R/utilities.R index 6b93863b3..0b7560fb2 100644 --- a/R/utilities.R +++ b/R/utilities.R @@ -1339,18 +1339,11 @@ PseudobulkExpression <- function( if (slot[1] == 'scale.data') { na.matrix <- data.return[[1]] na.matrix[1:length(x = na.matrix)] <- NA - # TODO: restore once check.matrix is in SeuratObject - # toRet <- CreateSeuratObject( - # counts = na.matrix, - # project = if (pb.method == "average") "Average" else "Aggregate", - # assay = names(x = data.return)[1], - # check.matrix = FALSE, - # ... - # ) toRet <- CreateSeuratObject( counts = na.matrix, project = if (pb.method == "average") "Average" else "Aggregate", assay = names(x = data.return)[1], + check.matrix = FALSE, ... ) toRet <- SetAssayData( @@ -1372,18 +1365,11 @@ PseudobulkExpression <- function( new.data = data.return[[1]] ) } else { - # TODO: restore once check.matrix is in SeuratObject - # toRet <- CreateSeuratObject( - # counts = data.return[[1]], - # project = if (pb.method == "average") "Average" else "Aggregate", - # assay = names(x = data.return)[1], - # check.matrix = FALSE, - # ... - # ) toRet <- CreateSeuratObject( counts = data.return[[1]], project = if (pb.method == "average") "Average" else "Aggregate", assay = names(x = data.return)[1], + check.matrix = FALSE, ... ) toRet <- SetAssayData( @@ -1399,9 +1385,7 @@ PseudobulkExpression <- function( if (slot[i] == 'scale.data') { na.matrix <- data.return[[i]] na.matrix[1:length(x = na.matrix)] <- NA - # TODO: restore once check.matrix is in SeuratObject - # toRet[[names(x = data.return)[i]]] <- CreateAssayObject(counts = na.matrix, check.matrix = FALSE) - toRet[[names(x = data.return)[i]]] <- CreateAssayObject(counts = na.matrix) + toRet[[names(x = data.return)[i]]] <- CreateAssayObject(counts = na.matrix, check.matrix = FALSE) toRet <- SetAssayData( object = toRet, assay = names(x = data.return)[i], @@ -1421,9 +1405,7 @@ PseudobulkExpression <- function( new.data = as.matrix(x = data.return[[i]]) ) } else { - # TODO: restore once check.matrix is in SeuratObject - # toRet[[names(x = data.return)[i]]] <- CreateAssayObject(counts = data.return[[i]], check.matrix = FALSE) - toRet[[names(x = data.return)[i]]] <- CreateAssayObject(counts = data.return[[i]]) + toRet[[names(x = data.return)[i]]] <- CreateAssayObject(counts = data.return[[i]], check.matrix = FALSE) toRet <- SetAssayData( object = toRet, assay = names(x = data.return)[i], @@ -1897,13 +1879,9 @@ CreateDummyAssay <- function(assay) { cm <- as.sparse(x = cm) rownames(x = cm) <- rownames(x = assay) colnames(x = cm) <- colnames(x = assay) - # TODO: restore once check.matrix is in SeuratObject - # return(CreateAssayObject( - # counts = cm, - # check.matrix = FALSE - # )) return(CreateAssayObject( - counts = cm + counts = cm, + check.matrix = FALSE )) } @@ -2336,7 +2314,7 @@ RowSumSparse <- function(mat) { names(x = output) <- rownames(x = mat) return(output) } - + # Calculate row variance of a sparse matrix # # @param mat sparse matrix From fc285f5dde70a3711356800a0e80fddc5b362fb7 Mon Sep 17 00:00:00 2001 From: AustinHartman Date: Wed, 21 Sep 2022 16:28:24 -0400 Subject: [PATCH 39/40] 4.2.0 --- DESCRIPTION | 8 ++++---- R/utilities.R | 2 +- cran-comments.md | 5 +---- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 78b74e676..56107bfc3 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: Seurat -Version: 4.1.1.9006 -Date: 2022-09-20 +Version: 4.2.0 +Date: 2022-09-21 Title: Tools for Single Cell Genomics Description: A toolkit for quality control, analysis, and exploration of single cell RNA sequencing data. 'Seurat' aims to enable users to identify and interpret sources of heterogeneity from single cell transcriptomic measurements, and to integrate diverse types of single cell data. See Satija R, Farrell J, Gennert D, et al (2015) , Macosko E, Basu A, Satija R, et al (2015) , Stuart T, Butler A, et al (2019) , and Hao, Hao, et al (2020) for more details. Authors@R: c( @@ -48,7 +48,7 @@ Imports: leiden (>= 0.3.1), lmtest, MASS, - Matrix (>= 1.2-14), + Matrix (>= 1.5.0), matrixStats, miniUI, patchwork, @@ -66,7 +66,7 @@ Imports: scales, scattermore (>= 0.7), sctransform (>= 0.3.4), - SeuratObject (>= 4.1.0), + SeuratObject (>= 4.1.2), shiny, spatstat.core, spatstat.geom, diff --git a/R/utilities.R b/R/utilities.R index 0b7560fb2..faac63d5a 100644 --- a/R/utilities.R +++ b/R/utilities.R @@ -2340,7 +2340,7 @@ RowVarSparse <- function(mat) { RowSparseCheck <- function(mat) { if (!inherits(x = mat, what = "sparseMatrix")) { stop("Input should be sparse matrix") - } else if (class(x = mat) != "dgCMatrix") { + } else if (!is(object = mat, class2 = "dgCMatrix")) { warning("Input matrix is converted to dgCMatrix.") mat <- as.sparse(x = mat) } diff --git a/cran-comments.md b/cran-comments.md index 2e206a8e3..82439ff3d 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,10 +1,7 @@ -# Seurat v4.1.1 +# Seurat v4.2.0 ## Test environments * local Ubuntu 20.04 install, R 4.1.3 -* Ubuntu 16.04.6 (on travis-ci), R 4.0.0, R devel -* macOS 10.13.6 (on travis-ci), R 4.0.2 -* Windows Server 2012 R2 (on AppVeyor), R 4.1.0 Patched * win-builder (release, devel) ## R CMD check results From 3d26669c90795106cb2d6e96cf02fd0d48426174 Mon Sep 17 00:00:00 2001 From: AustinHartman Date: Wed, 21 Sep 2022 16:34:13 -0400 Subject: [PATCH 40/40] update changelog --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index eedb432a3..27eb81bf8 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# Unreleased +# Seurat 4.2.0 (2022-09-21) ## Changes - Fix legend color in `DoHeatmap()` ([#5783](https://github.com/satijalab/seurat/issues/5783))