Skip to content

Commit

Permalink
Merge pull request #6467 from satijalab/release/4.2.0
Browse files Browse the repository at this point in the history
Seurat v4.2.0
  • Loading branch information
mojaveazure authored Sep 26, 2022
2 parents 3bee84a + 3d26669 commit c463873
Show file tree
Hide file tree
Showing 31 changed files with 289 additions and 212 deletions.
14 changes: 7 additions & 7 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: Seurat
Version: 4.1.1
Date: 2022-05-01
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) <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.
Authors@R: c(
Expand Down Expand Up @@ -48,7 +48,7 @@ Imports:
leiden (>= 0.3.1),
lmtest,
MASS,
Matrix (>= 1.2-14),
Matrix (>= 1.5.0),
matrixStats,
miniUI,
patchwork,
Expand All @@ -65,16 +65,16 @@ Imports:
Rtsne,
scales,
scattermore (>= 0.7),
sctransform (>= 0.3.3),
SeuratObject (>= 4.1.0),
sctransform (>= 0.3.4),
SeuratObject (>= 4.1.2),
shiny,
spatstat.core,
spatstat.geom,
stats,
tibble,
tools,
utils,
uwot (>= 0.1.9)
uwot (>= 0.1.14)
LinkingTo: Rcpp (>= 0.11.0), RcppEigen, RcppProgress
License: MIT + file LICENSE
LazyData: true
Expand All @@ -95,7 +95,7 @@ Collate:
'tree.R'
'utilities.R'
'zzz.R'
RoxygenNote: 7.1.2
RoxygenNote: 7.2.1
Encoding: UTF-8
Suggests:
ape,
Expand Down
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# Seurat 4.2.0 (2022-09-21)

## 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))
- Support spaceranger 2.0 ([#6208](https://github.com/satijalab/seurat/pull/6208))
- 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)

## Changes
Expand Down
6 changes: 2 additions & 4 deletions R/clustering.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -1689,7 +1687,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')) {
Expand Down
57 changes: 35 additions & 22 deletions R/differential_expression.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ FindAllMarkers <- function(
latent.vars = NULL,
min.cells.feature = 3,
min.cells.group = 3,
pseudocount.use = 1,
mean.fxn = NULL,
fc.name = NULL,
base = 2,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -512,6 +510,7 @@ FindMarkers.default <- function(
densify = FALSE,
...
) {
pseudocount.use <- pseudocount.use %||% 1
ValidateCellGroups(
object = object,
cells.1 = cells.1,
Expand Down Expand Up @@ -603,6 +602,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
Expand Down Expand Up @@ -630,8 +632,10 @@ FindMarkers.Assay <- function(
fc.name = NULL,
base = 2,
densify = FALSE,
norm.method = NULL,
...
) {
pseudocount.use <- pseudocount.use %||% 1
data.slot <- ifelse(
test = test.use %in% DEmethods_counts(),
yes = 'counts',
Expand All @@ -652,7 +656,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,
Expand Down Expand Up @@ -712,6 +717,7 @@ FindMarkers.SCTAssay <- function(
recorrect_umi = TRUE,
...
) {
pseudocount.use <- pseudocount.use %||% 1
data.slot <- ifelse(
test = test.use %in% DEmethods_counts(),
yes = 'counts',
Expand Down Expand Up @@ -813,6 +819,7 @@ FindMarkers.DimReduc <- function(
...

) {
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=", "))
Expand Down Expand Up @@ -927,7 +934,6 @@ FindMarkers.Seurat <- function(
latent.vars = NULL,
min.cells.feature = 3,
min.cells.group = 3,
pseudocount.use = 1,
mean.fxn = NULL,
fc.name = NULL,
base = 2,
Expand Down Expand Up @@ -971,17 +977,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,
Expand All @@ -1000,11 +1003,11 @@ 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,
densify = densify,
norm.method = norm.method,
...
)
return(de.results)
Expand Down Expand Up @@ -1050,7 +1053,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
Expand All @@ -1066,18 +1071,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(
Expand Down Expand Up @@ -1111,11 +1123,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))
Expand Down Expand Up @@ -1143,7 +1156,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.
#' @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
Expand All @@ -1163,7 +1176,7 @@ FoldChange.Seurat <- function(
slot = 'data',
reduction = NULL,
features = NULL,
pseudocount.use = 1,
pseudocount.use = NULL,
mean.fxn = NULL,
base = 2,
fc.name = NULL,
Expand Down
6 changes: 5 additions & 1 deletion R/dimensional_reduction.R
Original file line number Diff line number Diff line change
Expand Up @@ -1379,6 +1379,10 @@ RunUMAP.default <- function(
object = reduction.model,
slot = "model"
)
# add num_precomputed_nns to <v0.1.13 uwot models to prevent errors with newer versions of uwot
if (!"num_precomputed_nns" %in% names(model)) {
model$num_precomputed_nns <- 1
}
if (length(x = model) == 0) {
stop(
"The provided reduction.model does not have a model stored. Please try running umot-learn on the object first",
Expand All @@ -1388,7 +1392,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(
Expand Down
Loading

0 comments on commit c463873

Please sign in to comment.